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
    Release the resources associated with the query result.
    Gets the row metadata.
    default boolean
    Return whether this result has rows to iterate using the iterator() method.
    Returns the iterator over the result rows.
    default Stream<SqlRow>
    Returns a stream of result rows.
    long
    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
    • stream

      @Nonnull default Stream<SqlRow> stream()
      Returns a stream of result rows.

      It uses internally iterator() method, so it cannot be called twice.

      You should still call close() method after the stream is used (or use this method inside try-with-resources block. You should not pass the Stream from this method outside try-with-resources block, if it's used.

      Returns:
      Stream of result rows
      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
      Since:
      5.4
    • 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