Package com.hazelcast.sql
Interface SqlResult
- All Superinterfaces:
AutoCloseable
,Iterable<SqlRow>
SQL query result. Depending on the statement type it represents a stream of
rows or an update count.
Usage for a stream of rows
- Use
iterator()
to iterate over the rows. - 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 TypeMethodDescriptionvoid
close()
Release the resources associated with the query result.Gets the row metadata.default boolean
isRowSet()
Return whether this result has rows to iterate using theiterator()
method.iterator()
Returns the iterator over the result rows.stream()
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 theiterator()
method. -
getRowMetadata
Gets the row metadata.- Throws:
IllegalStateException
- if the result doesn't have rows, but only an update count
-
iterator
Returns the iterator over the result rows.The iterator may be requested only once.
- Specified by:
iterator
in interfaceIterable<SqlRow>
- Returns:
- iterator
- Throws:
IllegalStateException
- if the method is invoked more than once or if this result doesn't have rowsHazelcastSqlException
- in case of an SQL-related error condition
-
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 insidetry-with-resources
block. You should not pass theStream
from this method outsidetry-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 rowsHazelcastSqlException
- 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 interfaceAutoCloseable
-