Package com.hazelcast.sql
Interface SqlResult
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.lang.Iterable<SqlRow>
public interface SqlResult extends java.lang.Iterable<SqlRow>, java.lang.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
- 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 callclose()
in this case.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods 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 theiterator()
method.java.util.Iterator<SqlRow>
iterator()
Returns the iterator over the result rows.default java.util.stream.Stream<SqlRow>
stream()
Returns a stream of result rows.long
updateCount()
Returns the number of rows updated by the statement or -1 if this result is a row set.
-
-
-
Method Detail
-
isRowSet
default boolean isRowSet()
Return whether this result has rows to iterate using theiterator()
method.
-
getRowMetadata
@Nonnull SqlRowMetadata getRowMetadata()
Gets the row metadata.- Throws:
java.lang.IllegalStateException
- if the result doesn't have rows, but only an update count
-
iterator
@Nonnull java.util.Iterator<SqlRow> iterator()
Returns the iterator over the result rows.The iterator may be requested only once.
- Specified by:
iterator
in interfacejava.lang.Iterable<SqlRow>
- Returns:
- iterator
- Throws:
java.lang.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
@Nonnull default java.util.stream.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 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:
java.lang.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 interfacejava.lang.AutoCloseable
-
-