Interface SqlResult

All Superinterfaces:
AutoCloseable, Iterable<SqlRow>

public interface SqlResult
extends Iterable<SqlRow>, AutoCloseable
SQL query result. Depending on the statement type it represents a stream of rows or an update count.

Usage for a stream of rows

  1. Use iterator() to iterate over the rows.
  2. Use close() to release the resources associated with the result.

Code example:

 try (SqlResult result = hazelcastInstance.getSql().execute("SELECT ...")) {
     for (SqlRow row : result) {
         // Process the row.
     }
 }
 

Usage for update count

     long updated = hazelcastInstance.getSql().execute("UPDATE ...").updateCount();
 
You don't need to call close() in this case.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Release the resources associated with the query result.
    SqlRowMetadata getRowMetadata()
    Gets the row metadata.
    default boolean isRowSet()
    Return whether this result has rows to iterate using the iterator() method.
    Iterator<SqlRow> iterator()
    Returns the iterator over the result rows.
    long updateCount()
    Returns the number of rows updated by the statement or -1 if this result is a row set.

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • isRowSet

      default boolean isRowSet()
      Return whether this result has rows to iterate using the iterator() method.
    • getRowMetadata

      @Nonnull SqlRowMetadata getRowMetadata()
      Gets the row metadata.
      Throws:
      IllegalStateException - if the result doesn't have rows, but only an update count
    • iterator

      @Nonnull Iterator<SqlRow> iterator()
      Returns the iterator over the result rows.

      The iterator may be requested only once.

      Specified by:
      iterator in interface Iterable<SqlRow>
      Returns:
      iterator
      Throws:
      IllegalStateException - if the method is invoked more than once or if this result doesn't have rows
      HazelcastSqlException - in case of an SQL-related error condition
    • updateCount

      long updateCount()
      Returns the number of rows updated by the statement or -1 if this result is a row set. In case the result doesn't contain rows but the update count isn't applicable or known, 0 is returned.
    • close

      void close()
      Release the resources associated with the query result.

      The query engine delivers the rows asynchronously. The query may become inactive even before all rows are consumed. The invocation of this command will cancel the execution of the query on all members if the query is still active. Otherwise it is no-op. For a result with an update count it is always no-op.

      Specified by:
      close in interface AutoCloseable