Package org.jdbi.v3.core
Class Jdbi
java.lang.Object
org.jdbi.v3.core.Jdbi
- All Implemented Interfaces:
- Configurable<Jdbi>
Main entry point; configurable wrapper around a JDBC 
DataSource.
 Use it to obtain Handle instances and provide configuration
 for all handles obtained from it.- 
Method SummaryModifier and TypeMethodDescriptionstatic JdbiCreates a newJdbiinstance from a database URL.static JdbiCreates a newJdbiinstance from a database URL.static Jdbicreate(String url, Properties properties) Creates a newJdbiinstance from a database URL.static Jdbicreate(Connection connection) Creates a newJdbiobject from aConnection.static Jdbicreate(DataSource dataSource) Creates a newJdbiobject from aDataSource.static Jdbicreate(ConnectionFactory connectionFactory) Factory used to allow for obtaining a Connection in a customized manner.Returns the configuration registry associated with this object.Returns the currentStatementBuilderFactory.Returns theTransactionHandler.installPlugin(JdbiPlugin plugin) Install a givenJdbiPlugininstance that will configure any providedHandleinstances.Use theServiceLoaderAPI to detect and install plugins automagically.<R,X extends Exception> 
 RinTransaction(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> 
 RinTransaction(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> ECreates an extension instance that uses the currentJdbiinstance for database operations.open()Obtain a Handle to the data source wrapped by this Jdbi instance.static HandleObtain a handle with just a JDBC URLstatic HandleObtain a handle with just a JDBC URLstatic Handleopen(String url, Properties props) Obtain a handle with just a JDBC URLstatic Handleopen(Connection connection) Create a Handle wrapping a particular JDBC Connectionstatic Handleopen(DataSource dataSource) Convenience method used to obtain a handle from a specific data sourcestatic Handleopen(ConnectionFactory connectionFactory) Convenience method used to obtain a handle from aConnectionFactory.Allows customization of how prepared statements are created.setTransactionHandler(TransactionHandler handler) Specify the TransactionHandler instance to use.<E,X extends Exception> 
 voiduseExtension(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>
 voiduseHandle(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>
 voiduseTransaction(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>
 voiduseTransaction(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> 
 RwithExtension(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> 
 RwithHandle(HandleCallback<R, X> callback) A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jdbi.v3.core.config.ConfigurableaddCustomizer, configure, define, getConfig, registerArgument, registerArgument, registerArrayType, registerArrayType, registerArrayType, registerArrayType, registerCodecFactory, registerCollector, registerCollector, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerExtension, registerRowMapper, registerRowMapper, registerRowMapper, registerRowMapper, setMapKeyColumn, setMapValueColumn, setSqlArrayArgumentStrategy, setSqlLogger, setSqlParser, setTemplateEngine, setTimingCollector
- 
Method Details- 
createCreates a newJdbiobject from aConnection.- Parameters:
- connection- A- Connectionobject.
- Returns:
- A Jdbiinstance that uses a single database connection.
 
- 
createCreates a newJdbiobject from aDataSource.- Parameters:
- dataSource- the data source.
- Returns:
- a Jdbi which uses the given data source as a connection factory.
 
- 
createFactory used to allow for obtaining a Connection in a customized manner.The ConnectionFactory.openConnection()method will be invoked to obtain a connection instance whenever a Handle is opened.- Parameters:
- connectionFactory- Provides JDBC connections to Handle instances
- Returns:
- a Jdbi which uses the given connection factory.
 
- 
createCreates a newJdbiinstance from a database URL.- Parameters:
- url- A JDBC URL for connections.
- Returns:
- a Jdbi which usesDriverManageras a connection factory.
 
- 
createCreates a newJdbiinstance from a database URL.- Parameters:
- url- JDBC URL for connections
- properties- Properties to pass to DriverManager.getConnection(url, props) for each new handle
- Returns:
- a Jdbi which uses DriverManageras a connection factory.
 
- 
createCreates a newJdbiinstance from a database URL.- Parameters:
- url- JDBC URL for connections
- username- User name for connection authentication
- password- Password for connection authentication
- Returns:
- a Jdbi which uses DriverManageras a connection factory.
 
- 
openConvenience method used to obtain a handle from a specific data source- Parameters:
- dataSource- the JDBC data source.
- Returns:
- Handle using a Connection obtained from the provided DataSource
 
- 
openConvenience method used to obtain a handle from aConnectionFactory.- Parameters:
- connectionFactory- the connection factory
- Returns:
- Handle using a Connection obtained from the provided connection factory
 
- 
openCreate a Handle wrapping a particular JDBC Connection- Parameters:
- connection- the JDBC connection
- Returns:
- Handle bound to connection
 
- 
openObtain a handle with just a JDBC URL- Parameters:
- url- JDBC Url
- Returns:
- newly opened Handle
 
- 
openObtain a handle with just a JDBC URL- Parameters:
- url- JDBC Url
- username- JDBC username for authentication
- password- JDBC password for authentication
- Returns:
- newly opened Handle
 
- 
openObtain a handle with just a JDBC URL- Parameters:
- url- JDBC Url
- props- JDBC properties
- Returns:
- newly opened Handle
 
- 
installPluginsUse theServiceLoaderAPI to detect and install plugins automagically. Some people consider this feature dangerous; some consider it essential -- use at your own risk.- Returns:
- this
 
- 
installPluginInstall a givenJdbiPlugininstance that will configure any providedHandleinstances.- Parameters:
- plugin- the plugin to install
- Returns:
- this
 
- 
setStatementBuilderFactoryAllows customization of how prepared statements are created. When a Handle is created against this Jdbi instance the factory will be used to create a StatementBuilder for that specific handle. When the handle is closed, the StatementBuilder's close method will be invoked.- Parameters:
- factory- the new statement builder factory.
- Returns:
- this
 
- 
getStatementBuilderFactoryReturns the currentStatementBuilderFactory.- Returns:
- the current StatementBuilderFactory
 
- 
getConfigDescription copied from interface:ConfigurableReturns the configuration registry associated with this object.- Specified by:
- getConfigin interface- Configurable<Jdbi>
- Returns:
- the configuration registry associated with this object.
 
- 
setTransactionHandlerSpecify the TransactionHandler instance to use. This allows overriding transaction semantics, or mapping into different transaction management systems.The default version uses local transactions on the database Connection instances obtained. - Parameters:
- handler- The TransactionHandler to use for all Handle instances obtained from this Jdbi
- Returns:
- this
 
- 
getTransactionHandlerReturns theTransactionHandler.- Returns:
- the TransactionHandler
 
- 
openObtain a Handle to the data source wrapped by this Jdbi instance. You own this expensive resource and are required to close it or risk leaks. Using atry-with-resourcesblock is recommended.- Returns:
- an open Handle instance
- See Also:
 
- 
withHandleA convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.- Type Parameters:
- R- type returned by the callback
- X- exception type thrown by the callback, if any.
- Parameters:
- callback- A callback which will receive an open Handle
- Returns:
- the value returned by callback
- Throws:
- X- any exception thrown by the callback
 
- 
useHandleA convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.- Type Parameters:
- X- exception type thrown by the callback, if any.
- Parameters:
- consumer- A callback which will receive an open Handle
- Throws:
- X- any exception thrown by the callback
 
- 
inTransactionA 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.- Type Parameters:
- R- type returned by the callback
- X- exception type thrown by the callback, if any.
- Parameters:
- callback- A callback which will receive an open Handle, in a transaction
- Returns:
- the value returned by callback
- Throws:
- X- any exception thrown by the callback
 
- 
useTransactionA 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.- Type Parameters:
- X- exception type thrown by the callback, if any.
- Parameters:
- callback- A callback which will receive an open Handle, in a transaction
- Throws:
- X- any exception thrown by the callback
 
- 
inTransactionpublic <R,X extends Exception> R inTransaction(TransactionIsolationLevel level, HandleCallback<R, X> callback) throws XA 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. - Type Parameters:
- R- type returned by the callback
- 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:
- the value returned by callback
- Throws:
- X- any exception thrown by the callback
 
- 
useTransactionpublic <X extends Exception> void useTransaction(TransactionIsolationLevel level, HandleConsumer<X> callback) throws X 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. - 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
- Throws:
- X- any exception thrown by the callback
 
- 
withExtensionpublic <R,E, R withExtensionX extends Exception> (Class<E> extensionType, ExtensionCallback<R, E, throws XX> 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.- Type Parameters:
- R- the return type
- E- the extension type
- X- the exception type optionally thrown by the callback
- Parameters:
- extensionType- the type of extension.
- callback- a callback which will receive the extension.
- Returns:
- the value returned by the callback.
- Throws:
- NoSuchExtensionException- if no- ExtensionFactoryis registered which supports the given extension type.
- X- if thrown by the callback.
 
- 
useExtensionpublic <E,X extends Exception> void useExtension(Class<E> extensionType, ExtensionConsumer<E, X> callback) throws XA 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.- Type Parameters:
- E- the extension type
- X- the exception type optionally thrown by the callback
- Parameters:
- extensionType- the type of extension
- callback- a callback which will receive the extension
- Throws:
- NoSuchExtensionException- if no- ExtensionFactoryis registered which supports the given extension type.
- X- if thrown by the callback.
 
- 
onDemandCreates an extension instance that uses the currentJdbiinstance for database operations.- Type Parameters:
- E- the extension type
- Parameters:
- extensionType- the type of extension. Must be a public interface type.
- Returns:
- an extension which opens and closes handles (as needed) for individual method calls. Only public interface types may be used as on-demand extensions.
 
 
-