-
public interface DbResultDbExecute.createNamedStatement(String)(and other generic statements) execution result. This is used when we do not know in advance whether we execute a query or a DML statement (such as insert, update, delete).This class represents a future of two possible types - either a DML result returning the number of changed rows (objects - depending on database type), or a query result returning the
DbRows.One of the consumers on this interface is called as soon as it is known what type of statement was executed - for SQL this would be when we finish execution of the prepared statement.
Alternative (or in combination) is to use the methods that return
CompletionStageto process the results when (and if) they are done.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CompletionStage<Long>dmlFuture()This future completes if (and only if) the statement was a DML statement.DbResultexceptionally(Consumer<Throwable> exceptionHandler)In case any exception occurs during processing, the handler is invoked.CompletionStage<Throwable>exceptionFuture()This future completes if (and only if) the statement finished with an exception, either when executing the statement, or when processing the result set.CompletionStage<DbRows<DbRow>>rsFuture()This future completes if (and only if) the statement was a query statement.DbResultwhenDml(Consumer<Long> consumer)For DML statements, number of changed rows/objects is provided as soon as the statement completes.DbResultwhenRs(Consumer<DbRows<DbRow>> consumer)For query statements,DbRowsis provided as soon as the statement completes.
-
-
-
Method Detail
-
whenDml
DbResult whenDml(Consumer<Long> consumer)
For DML statements, number of changed rows/objects is provided as soon as the statement completes.- Parameters:
consumer- consumer that eventually receives the count- Returns:
- DbResult to continue with processing a possible query result
-
whenRs
DbResult whenRs(Consumer<DbRows<DbRow>> consumer)
For query statements,DbRowsis provided as soon as the statement completes. For example in SQL, this would be the time we get the ResultSet from the database. Nevertheless the rows may not be read (DbRowsitself represents a future of rows)- Parameters:
consumer- consumer that eventually processes the query result- Returns:
- DbResult to continue with processing a possible dml result
-
exceptionally
DbResult exceptionally(Consumer<Throwable> exceptionHandler)
In case any exception occurs during processing, the handler is invoked.- Parameters:
exceptionHandler- handler to handle exceptional cases when processing the asynchronous request- Returns:
- DbResult ot continue with other methods
-
dmlFuture
CompletionStage<Long> dmlFuture()
This future completes if (and only if) the statement was a DML statement. In case of any exception before the identification of statement type, all ofdmlFuture(),rsFuture()finish exceptionally, andexceptionFuture()completes with the exception. In case the exception occurs after the identification of statement type, such as when processing a result set of a query, only theexceptionFuture()completes. Exceptions that occur during processing of result set are handled by methods in theDbRows.- Returns:
- future for the DML result
-
rsFuture
CompletionStage<DbRows<DbRow>> rsFuture()
This future completes if (and only if) the statement was a query statement. In case of any exception before the identification of statement type, all ofdmlFuture(),rsFuture()finish exceptionally, andexceptionFuture()completes with the exception. In case the exception occurs after the identification of statement type, such as when processing a result set of a query, only theexceptionFuture()completes. Exceptions that occur during processing of result set are handled by methods in theDbRows.- Returns:
- future for the query result
-
exceptionFuture
CompletionStage<Throwable> exceptionFuture()
This future completes if (and only if) the statement finished with an exception, either when executing the statement, or when processing the result set.- Returns:
- future for an exceptional result
-
-