Interface JdbiExecutor
- All Known Implementing Classes:
AbstractJdbiExecutor
-
Method Summary
Modifier and TypeMethodDescriptionstatic JdbiExecutor
Create aJdbiExecutor
.<R,
X extends Exception>
CompletionStage<R>inTransaction
(HandleCallback<R, X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.<R,
X extends Exception>
CompletionStage<R>inTransaction
(TransactionIsolationLevel level, HandleCallback<R, X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.<E,
X extends Exception>
CompletionStage<Void>useExtension
(Class<E> extensionType, ExtensionConsumer<E, X> callback) A convenience method which opens an extension of the given type, and yields it to a callback.<X extends Exception>
CompletionStage<Void>useHandle
(HandleConsumer<X> consumer) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.<X extends Exception>
CompletionStage<Void>useTransaction
(HandleConsumer<X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.<X extends Exception>
CompletionStage<Void>useTransaction
(TransactionIsolationLevel level, HandleConsumer<X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.<R,
E, X extends Exception>
CompletionStage<R>withExtension
(Class<E> extensionType, ExtensionCallback<R, E, X> callback) A convenience method which opens an extension of the given type, yields it to a callback, and returns the result of the callback.<R,
X extends Exception>
CompletionStage<R>withHandle
(HandleCallback<R, X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.
-
Method Details
-
create
Create aJdbiExecutor
.The executor to pass in needs to be sized to the use case. A rule of thumb is to have the max number of workers be equal to the max number of connections in the connection pool. The worker queue in the executor should probably be bounded, unless the caller(s) already has a bound for the number of outstanding requests. Making the queue bounded will mean you are blocking the calling thread when the queue fills up. Whether or not that is acceptable depends on if and how your service limits incoming requests
- Parameters:
jdbi
- the initialized Jdbi classexecutor
- an executor to use for all database calls
-
withHandle
A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.The callback will be executed in a thread supplied by the executor
- Type Parameters:
R
- type returned by the callbackX
- exception type thrown by the callback, if any.- Parameters:
callback
- A callback which will receive an open Handle- Returns:
- a completion stage which completes when the callback returns a value or throws an exception
-
inTransaction
A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients. The handle will be in a transaction when the callback is invoked, and that transaction will be committed if the callback finishes normally, or rolled back if the callback raises an exception.The callback will be executed in a thread supplied by the executor
- Type Parameters:
R
- type returned by the callbackX
- exception type thrown by the callback, if any.- Parameters:
callback
- A callback which will receive an open Handle, in a transaction- Returns:
- a completion stage which completes when the callback returns a value or throws an exception
-
inTransaction
<R,X extends Exception> CompletionStage<R> inTransaction(TransactionIsolationLevel level, HandleCallback<R, X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients. The handle will be in a transaction when the callback is invoked, and that transaction will be committed if the callback finishes normally, or rolled back if the callback raises an exception.This form accepts a transaction isolation level which will be applied to the connection for the scope of this transaction, after which the original isolation level will be restored.
The callback will be executed in a thread supplied by the executor
- Type Parameters:
R
- type returned by the callbackX
- exception type thrown by the callback, if any.- Parameters:
level
- the transaction isolation level which will be applied to the connection for the scope of this transaction, after which the original isolation level will be restored.callback
- A callback which will receive an open Handle, in a transaction- Returns:
- a completion stage which completes when the callback returns a value or throws an exception
-
useHandle
A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.The callback will be executed in a thread supplied by the executor
- Type Parameters:
X
- exception type thrown by the callback, if any.- Parameters:
consumer
- A callback which will receive an open Handle- Returns:
- a completion stage which completes when the callback returns or throws an exception
-
useTransaction
A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients. The handle will be in a transaction when the callback is invoked, and that transaction will be committed if the callback finishes normally, or rolled back if the callback raises an exception.The callback will be executed in a thread supplied by the executor
- Type Parameters:
X
- exception type thrown by the callback, if any.- Parameters:
callback
- A callback which will receive an open Handle, in a transaction- Returns:
- a completion stage which completes when the callback returns or throws an exception
-
useTransaction
<X extends Exception> CompletionStage<Void> useTransaction(TransactionIsolationLevel level, HandleConsumer<X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients. The handle will be in a transaction when the callback is invoked, and that transaction will be committed if the callback finishes normally, or rolled back if the callback raises an exception.This form accepts a transaction isolation level which will be applied to the connection for the scope of this transaction, after which the original isolation level will be restored.
The callback will be executed in a thread supplied by the executor
- Type Parameters:
X
- exception type thrown by the callback, if any.- Parameters:
level
- the transaction isolation level which will be applied to the connection for the scope of this transaction, after which the original isolation level will be restored.callback
- A callback which will receive an open Handle, in a transaction- Returns:
- a completion stage which completes when the callback returns or throws an exception
-
withExtension
<R,E, CompletionStage<R> withExtensionX extends Exception> (Class<E> extensionType, ExtensionCallback<R, E, X> callback) A convenience method which opens an extension of the given type, yields it to a callback, and returns the result of the callback. A handle is opened if needed by the extension, and closed before returning to the caller.The callback will be executed in a thread supplied by the executor
- Type Parameters:
R
- the return typeE
- the extension typeX
- the exception type optionally thrown by the callback- Parameters:
extensionType
- the type of extension.callback
- a callback which will receive the extension.- Returns:
- a completion stage which completes when the callback returns a value or throws an exception, or will complete with NoSuchExtensionException if no
ExtensionFactory
is registered which supports the given extension type.
-
useExtension
<E,X extends Exception> CompletionStage<Void> useExtension(Class<E> extensionType, ExtensionConsumer<E, X> callback) A convenience method which opens an extension of the given type, and yields it to a callback. A handle is opened if needed by the extention, and closed before returning to the caller.The callback will be executed in a thread supplied by the executor
- Type Parameters:
E
- the extension typeX
- the exception type optionally thrown by the callback- Parameters:
extensionType
- the type of extensioncallback
- a callback which will receive the extension- Returns:
- a completion stage which completes when the callback returns or throws an exception, or will complete with NoSuchExtensionException if no
ExtensionFactory
is registered which supports the given extension type.
-