public class Jdbi extends Object implements Configurable<Jdbi>
DataSource.
Use it to obtain Handle instances and provide configuration
for all handles obtained from it.| Modifier and Type | Method and Description |
|---|---|
static Jdbi |
create(Connection connection) |
static Jdbi |
create(ConnectionFactory connectionFactory)
Factory used to allow for obtaining a Connection in a customized manner.
|
static Jdbi |
create(DataSource dataSource) |
static Jdbi |
create(String url) |
static Jdbi |
create(String url,
Properties properties) |
static Jdbi |
create(String url,
String username,
String password) |
ConfigRegistry |
getConfig()
Returns the configuration registry associated with this object.
|
StatementBuilderFactory |
getStatementBuilderFactory() |
TransactionHandler |
getTransactionHandler() |
Jdbi |
installPlugin(JdbiPlugin plugin)
Install a given
JdbiPlugin instance that will configure any
provided Handle instances. |
Jdbi |
installPlugins()
Use the
ServiceLoader API to detect and install plugins automagically. |
<R,X extends Exception> |
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> |
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> E |
onDemand(Class<E> extensionType) |
Handle |
open()
Obtain a Handle to the data source wrapped by this Jdbi instance.
|
static Handle |
open(Connection connection)
Create a Handle wrapping a particular JDBC Connection
|
static Handle |
open(ConnectionFactory connectionFactory)
Convenience method used to obtain a handle from a
ConnectionFactory. |
static Handle |
open(DataSource dataSource)
Convenience method used to obtain a handle from a specific data source
|
static Handle |
open(String url)
Obtain a handle with just a JDBC URL
|
static Handle |
open(String url,
Properties props)
Obtain a handle with just a JDBC URL
|
static Handle |
open(String url,
String username,
String password)
Obtain a handle with just a JDBC URL
|
Jdbi |
setStatementBuilderFactory(StatementBuilderFactory factory)
Allows customization of how prepared statements are created.
|
Jdbi |
setTransactionHandler(TransactionHandler handler)
Specify the TransactionHandler instance to use.
|
<E,X extends Exception> |
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> |
useHandle(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> |
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> |
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> |
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> |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddCustomizer, configure, define, getConfig, registerArgument, registerArrayType, registerArrayType, registerArrayType, registerArrayType, registerCollector, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerExtension, registerRowMapper, registerRowMapper, registerRowMapper, registerRowMapper, setMapKeyColumn, setMapValueColumn, setSqlArrayArgumentStrategy, setSqlLogger, setSqlParser, setTemplateEnginepublic static Jdbi create(Connection connection)
connection - db connectionpublic static Jdbi create(ConnectionFactory connectionFactory)
The ConnectionFactory.openConnection() method will be invoked to obtain a connection instance
whenever a Handle is opened.
connectionFactory - Provides JDBC connections to Handle instancespublic static Jdbi create(DataSource dataSource)
dataSource - the data source.public static Jdbi create(String url)
url - JDBC URL for connectionsDriverManager as a connection factory.public static Jdbi create(String url, Properties properties)
url - JDBC URL for connectionsproperties - Properties to pass to DriverManager.getConnection(url, props) for each new handleDriverManager as a connection factory.public static Jdbi create(String url, String username, String password)
url - JDBC URL for connectionsusername - User name for connection authenticationpassword - Password for connection authenticationDriverManager as a connection factory.public ConfigRegistry getConfig()
ConfigurablegetConfig in interface Configurable<Jdbi>public StatementBuilderFactory getStatementBuilderFactory()
StatementBuilderFactorypublic TransactionHandler getTransactionHandler()
TransactionHandlerpublic Jdbi installPlugin(JdbiPlugin plugin)
JdbiPlugin instance that will configure any
provided Handle instances.plugin - the plugin to installpublic Jdbi installPlugins()
ServiceLoader API to detect and install plugins automagically.
Some people consider this feature dangerous; some consider it essential --
use at your own risk.public <R,X extends Exception> R inTransaction(HandleCallback<R,X> callback) throws X extends Exception
R - type returned by the callbackX - exception type thrown by the callback, if any.callback - A callback which will receive an open Handle, in a transactionX - any exception thrown by the callbackX extends Exceptionpublic <R,X extends Exception> R inTransaction(TransactionIsolationLevel level, HandleCallback<R,X> callback) throws X extends 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.
R - type returned by the callbackX - exception type thrown by the callback, if any.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 transactionX - any exception thrown by the callbackX extends Exceptionpublic <E> E onDemand(Class<E> extensionType)
E - the extension typeextensionType - the type of extension. Must be a public interface type.public Handle open()
try-with-resources block is recommended.useHandle(HandleConsumer),
withHandle(HandleCallback)public static Handle open(Connection connection)
connection - the JDBC connectionpublic static Handle open(ConnectionFactory connectionFactory)
ConnectionFactory.connectionFactory - the connection factorypublic static Handle open(DataSource dataSource)
dataSource - the JDBC data source.public static Handle open(String url)
url - JDBC Urlpublic static Handle open(String url, Properties props)
url - JDBC Urlprops - JDBC propertiespublic static Handle open(String url, String username, String password)
url - JDBC Urlusername - JDBC username for authenticationpassword - JDBC password for authenticationpublic Jdbi setStatementBuilderFactory(StatementBuilderFactory factory)
factory - the new statement builder factory.public Jdbi setTransactionHandler(TransactionHandler handler)
The default version uses local transactions on the database Connection instances obtained.
handler - The TransactionHandler to use for all Handle instances obtained
from this Jdbipublic <E,X extends Exception> void useExtension(Class<E> extensionType, ExtensionConsumer<E,X> callback) throws X extends Exception
E - the extension typeX - the exception type optionally thrown by the callbackextensionType - the type of extensioncallback - a callback which will receive the extensionNoSuchExtensionException - if no ExtensionFactory is registered which supports the given extension type.X - if thrown by the callback.X extends Exceptionpublic <X extends Exception> void useHandle(HandleConsumer<X> callback) throws X extends Exception
X - exception type thrown by the callback, if any.callback - A callback which will receive an open HandleX - any exception thrown by the callbackX extends Exceptionpublic <X extends Exception> void useTransaction(HandleConsumer<X> callback) throws X extends Exception
X - exception type thrown by the callback, if any.callback - A callback which will receive an open Handle, in a transactionX - any exception thrown by the callbackX extends Exceptionpublic <X extends Exception> void useTransaction(TransactionIsolationLevel level, HandleConsumer<X> callback) throws X extends 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.
X - exception type thrown by the callback, if any.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 transactionX - any exception thrown by the callbackX extends Exceptionpublic <R,E,X extends Exception> R withExtension(Class<E> extensionType, ExtensionCallback<R,E,X> callback) throws X extends Exception
R - the return typeE - the extension typeX - the exception type optionally thrown by the callbackextensionType - the type of extension.callback - a callback which will receive the extension.NoSuchExtensionException - if no ExtensionFactory is registered which supports the given extension
type.X - if thrown by the callback.X extends Exceptionpublic <R,X extends Exception> R withHandle(HandleCallback<R,X> callback) throws X extends Exception
R - type returned by the callbackX - exception type thrown by the callback, if any.callback - A callback which will receive an open HandleX - any exception thrown by the callbackX extends ExceptionCopyright © 2019. All rights reserved.