Interface ResultSet

All Superinterfaces:
AutoCloseable, Iterable<ResultRow>
All Known Implementing Classes:
AbstractResultSet, AbstractResultSet, AskResultSet, AskResultSet, SelectResultSet, SelectResultSet

public interface ResultSet extends AutoCloseable, Iterable<ResultRow>
Represents a set of results of a SPARQL query.

This interface declares methods for getting values from a set of results of a SPARQL query issued to an ontology.

While this class is iterable, it is still necessary to close it either explicitly, or by declaring it within a try-with-resource block.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this result set releasing any sub-resources it holds.
    int
    findColumn(String columnLabel)
    Retrieves index of a column with the specified label.
    void
    Move the cursor to the first row.
    boolean
    getBoolean(int columnIndex)
    Retrieves value from column at the specified index and returns it as a boolean.
    boolean
    getBoolean(String columnLabel)
    Retrieves value from column with the specified label and returns it as a boolean.
    byte
    getByte(int columnIndex)
    Retrieves value from column at the specified index and returns it as byte.
    byte
    getByte(String columnLabel)
    Retrieves value from column with the specified label and returns it as byte.
    int
    Gets the count of available columns.
    double
    getDouble(int columnIndex)
    Retrieves value from column at the specified index and returns it as double.
    double
    getDouble(String columnLabel)
    Retrieves value from column with the specified label and returns it as double.
    float
    getFloat(int columnIndex)
    Retrieves value from column at the specified index and returns it as float.
    float
    getFloat(String columnLabel)
    Retrieves value from column with the specified label and returns it as float.
    int
    getInt(int columnIndex)
    Retrieves value from column at the specified index and returns it as int.
    int
    getInt(String columnLabel)
    Retrieves value from column with the specified label and returns it as int.
    long
    getLong(int columnIndex)
    Retrieves value from column at the specified index and returns it as long.
    long
    getLong(String columnLabel)
    Retrieves value from column with the specified label and returns it as long.
    getObject(int columnIndex)
    Retrieves value from column at the specified index and returns it as Object.
    <T> T
    getObject(int columnIndex, Class<T> cls)
    Retrieves value from column at the specified index and returns it as an instance of the specified class.
    getObject(String columnLabel)
    Retrieves value from column with the specified label and returns it as Object.
    <T> T
    getObject(String columnLabel, Class<T> cls)
    Retrieves value from column with the specified label and returns it as an instance of the specified class.
    int
    Retrieves index of the current row.
    short
    getShort(int columnIndex)
    Retrieves value of column at the specified index and returns it as short.
    short
    getShort(String columnLabel)
    Retrieves value of column with the specified label and returns it as short.
    Retrieves the Statement that produced this ResultSet object.
    getString(int columnIndex)
    Retrieves value of column at the specified index and returns it as String.
    getString(String columnLabel)
    Retrieves value of column with the specified label and returns it as String.
    boolean
    Returns true if the cursor does not point at the last row in this result set.
    boolean
    isBound(int variableIndex)
    Checks whether a value at the specified index is bound in the current result row.
    boolean
    isBound(String variableName)
    Checks whether a value of the specified variable is bound in the current result row.
    boolean
    Returns true if the cursor is at the first row of this result set.
    boolean
    Retrieves status of this result set.
    Creates a Iterator over this result set.
    void
    Move the cursor to the last row in this results set.
    void
    Move the cursor one row forward.
    void
    Move the cursor one row backwards.
    void
    relative(int rows)
    Move the cursor a relative number of rows, either positive or negative.
    void
    setRowIndex(int rowIndex)
    Move the cursor to the specified row index.
    Creates a Spliterator over this result set.
    default Stream<ResultRow>
    Creates a sequential Stream over this result set.

    Methods inherited from interface java.lang.Iterable

    forEach
  • Method Details

    • findColumn

      int findColumn(String columnLabel)
      Retrieves index of a column with the specified label.
      Parameters:
      columnLabel - Label of the column
      Returns:
      index of the column or -1 if there is no such column
      Throws:
      IllegalStateException - If called on a closed result set
    • getColumnCount

      int getColumnCount()
      Gets the count of available columns.

      This number corresponds to the number of result variables bound in the query.

      Returns:
      Number of columns in the result set
      Throws:
      IllegalStateException - If called on a closed result set
    • isBound

      boolean isBound(int variableIndex) throws OntoDriverException
      Checks whether a value at the specified index is bound in the current result row.

      Note that this method will return false also in case the index is out of range of the variables known to the result set as a whole.

      Parameters:
      variableIndex - Index of the variable
      Returns:
      true when value is bound in the current row, false otherwise
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - When unable to resolve binding status
    • isBound

      boolean isBound(String variableName) throws OntoDriverException
      Checks whether a value of the specified variable is bound in the current result row.

      Note that this method will return false also in case the variable is not known to the result set at all.

      Parameters:
      variableName - Variable name
      Returns:
      true when value is bound in the current row, false otherwise
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - When unable to resolve binding status
    • first

      void first() throws OntoDriverException
      Move the cursor to the first row.
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • getBoolean

      boolean getBoolean(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as a boolean.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      boolean value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to boolean or there occurs some other error
    • getBoolean

      boolean getBoolean(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as a boolean.
      Parameters:
      columnLabel - Label of the column
      Returns:
      boolean value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to boolean or there occurs some other error
    • getByte

      byte getByte(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as byte.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      byte value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to byte or there occurs some other error
    • getByte

      byte getByte(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as byte.
      Parameters:
      columnLabel - Label of the column
      Returns:
      byte value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to byte or there occurs some other error
    • getDouble

      double getDouble(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as double.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      double value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to double or there occurs some other error
    • getDouble

      double getDouble(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as double.
      Parameters:
      columnLabel - Label of the column
      Returns:
      double value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to double or there occurs some other error
    • getFloat

      float getFloat(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as float.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      float value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to float or there occurs some other error
    • getFloat

      float getFloat(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as float.
      Parameters:
      columnLabel - Label of the column
      Returns:
      float value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to float or there occurs some other error
    • getInt

      int getInt(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as int.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      int value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to int or there occurs some other error
    • getInt

      int getInt(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as int.
      Parameters:
      columnLabel - Label of the column
      Returns:
      int value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to int or there occurs some other error
    • getLong

      long getLong(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as long.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      long value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to long or there occurs some other error
    • getLong

      long getLong(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as long.
      Parameters:
      columnLabel - Label of the column
      Returns:
      long value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to long or there occurs some other error
    • getObject

      Object getObject(int columnIndex) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as Object.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      column value cast to Object
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index or there occurs some other error
    • getObject

      Object getObject(String columnLabel) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as Object.
      Parameters:
      columnLabel - Label of the column
      Returns:
      column value cast to Object
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label or there occurs some other error
    • getObject

      <T> T getObject(int columnIndex, Class<T> cls) throws OntoDriverException
      Retrieves value from column at the specified index and returns it as an instance of the specified class.

      The mechanism of transforming the value to the specified class is not specified, it can be merely type casting or calling a constructor of the specified type.

      Type Parameters:
      T - Return type
      Parameters:
      columnIndex - Column index, the first column has index 0
      cls - Requested class type
      Returns:
      Value of the column
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to the specified type or there occurs some other error
    • getObject

      <T> T getObject(String columnLabel, Class<T> cls) throws OntoDriverException
      Retrieves value from column with the specified label and returns it as an instance of the specified class.

      The mechanism of transforming the value to the specified class is not specified, it can be merely type casting or calling a constructor of the specified type.

      Type Parameters:
      T - Return type
      Parameters:
      columnLabel - Label of the column
      cls - Requested class type
      Returns:
      Value of the column.
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to the specified type or there occurs some other error
    • getRowIndex

      int getRowIndex() throws OntoDriverException
      Retrieves index of the current row.

      The first row has index 0.

      Returns:
      the current row index, -1 if there is no current row
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • getShort

      short getShort(int columnIndex) throws OntoDriverException
      Retrieves value of column at the specified index and returns it as short.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      short value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to short or there occurs some other error
    • getShort

      short getShort(String columnLabel) throws OntoDriverException
      Retrieves value of column with the specified label and returns it as short.
      Parameters:
      columnLabel - Label of the column
      Returns:
      short value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to short or there occurs some other error
    • getStatement

      Statement getStatement() throws OntoDriverException
      Retrieves the Statement that produced this ResultSet object. If this result set was generated some other way, this method will return null.
      Returns:
      The Statement that produced this ResultSet or null
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • getString

      String getString(int columnIndex) throws OntoDriverException
      Retrieves value of column at the specified index and returns it as String.
      Parameters:
      columnIndex - Column index, the first column has index 0
      Returns:
      String value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the columnIndex is not a valid column index, the value cannot be cast to String or there occurs some other error
    • getString

      String getString(String columnLabel) throws OntoDriverException
      Retrieves value of column with the specified label and returns it as String.
      Parameters:
      columnLabel - Label of the column
      Returns:
      String value
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If there is no column with the specified label, the value cannot be cast to String or there occurs some other error
    • isFirst

      boolean isFirst() throws OntoDriverException
      Returns true if the cursor is at the first row of this result set.
      Returns:
      True if the cursor is at the first row, false otherwise
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • hasNext

      boolean hasNext() throws OntoDriverException
      Returns true if the cursor does not point at the last row in this result set.
      Returns:
      True if there is at least one next row
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • last

      void last() throws OntoDriverException
      Move the cursor to the last row in this results set.

      Note that since the result set may be asynchronously updated, the last row does not have to always be the same.

      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • next

      void next() throws OntoDriverException
      Move the cursor one row forward.
      Throws:
      NoSuchElementException - If there are no more elements
      IllegalStateException - If called on a closed result set
      OntoDriverException - If some other error occurs
    • previous

      void previous() throws OntoDriverException
      Move the cursor one row backwards.
      Throws:
      IllegalStateException - If called on a closed result set or the cursor is at the first row
      OntoDriverException - If some other error occurs
    • relative

      void relative(int rows) throws OntoDriverException
      Move the cursor a relative number of rows, either positive or negative.
      Parameters:
      rows - The number of rows to move the cursor of
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the rows number is not valid or some other error occurs
    • setRowIndex

      void setRowIndex(int rowIndex) throws OntoDriverException
      Move the cursor to the specified row index.

      The first row has index 0.

      Parameters:
      rowIndex - Index to move the cursor to
      Throws:
      IllegalStateException - If called on a closed result set
      OntoDriverException - If the index is not valid row index or some other error occurs
    • close

      void close() throws OntoDriverException
      Closes this result set releasing any sub-resources it holds.

      After closing the result set is not usable any more and calling methods on it (except close and isOpen) will result in OntoDriverException.

      Calling close on already closed resource does nothing.

      Calling this method also results in immediate disconnection of all registered observers and cancellation of any running reasoning associated with this result set.

      Specified by:
      close in interface AutoCloseable
      Throws:
      OntoDriverException - If an ontology access error occurs.
    • isOpen

      boolean isOpen()
      Retrieves status of this result set.
      Returns:
      true if the resource is open, false otherwise
    • iterator

      default Iterator<ResultRow> iterator()
      Creates a Iterator over this result set.

      Note that the iterator does not close this result set after finishing its iteration. The result has to be closed by the caller.

      Specified by:
      iterator in interface Iterable<ResultRow>
      Returns:
      Iterator over this result set
    • spliterator

      default Spliterator<ResultRow> spliterator()
      Creates a Spliterator over this result set.

      Note that the spliterator does not close this result set after finishing its iteration. The result has to be closed by the caller.

      Specified by:
      spliterator in interface Iterable<ResultRow>
      Returns:
      Spliterator over this result set
    • stream

      default Stream<ResultRow> stream()
      Creates a sequential Stream over this result set.

      The default implementation creates a stream using the default spliterator().

      Note that the stream does not close this result set after finishing its iteration. The result set has to be closed by the caller.

      Returns:
      A Stream over this result set.