Constructor and Description |
---|
DBI(ConnectionFactory connectionFactory)
Constructor used to allow for obtaining a Connection in a customized manner.
|
DBI(DataSource dataSource)
Constructor for use with a DataSource which will provide
|
DBI(String url)
Create a DBI which directly uses the DriverManager
|
DBI(String url,
Properties props)
Create a DBI which directly uses the DriverManager
|
DBI(String url,
String username,
String password)
Create a DBI which directly uses the DriverManager
|
Modifier and Type | Method and Description |
---|---|
void |
close(Object sqlObject)
Used to close a sql object which lacks a close() method.
|
void |
define(String key,
Object value)
Define an attribute on every
StatementContext for every statement created
from a handle obtained from this DBI instance. |
SQLLog |
getSQLLog() |
StatementBuilderFactory |
getStatementBuilderFactory() |
StatementLocator |
getStatementLocator() |
StatementRewriter |
getStatementRewriter() |
TimingCollector |
getTimingCollector() |
TransactionHandler |
getTransactionHandler() |
<ReturnType> |
inTransaction(TransactionCallback<ReturnType> callback)
A convenience function which manages the lifecycle of a handle and yields it to a callback
for use by clients.
|
<ReturnType> |
inTransaction(TransactionIsolationLevel isolation,
TransactionCallback<ReturnType> callback)
A convenience function which manages the lifecycle of a handle and yields it to a callback
for use by clients.
|
<SqlObjectType> |
onDemand(Class<SqlObjectType> sqlObjectType)
Create a new sql object which will obtain and release connections from this dbi instance, as it needs to,
and can, respectively.
|
Handle |
open()
Obtain a Handle to the data source wrapped by this DBI instance
|
<SqlObjectType> |
open(Class<SqlObjectType> sqlObjectType)
Open a handle and attach a new sql object of the specified type to that handle.
|
static Handle |
open(Connection connection)
Create a Handle wrapping a particular JDBC Connection
|
static Handle |
open(DataSource dataSource)
Convenience methd 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
|
void |
registerArgumentFactory(ArgumentFactory<?> argumentFactory) |
void |
registerContainerFactory(ContainerFactory<?> factory) |
void |
registerMapper(ResultSetMapper mapper)
Register a result set mapper which will have its parameterized type inspected to determine what it maps to
Will be used with
Query.mapTo(Class) for registered mappings. |
void |
registerMapper(ResultSetMapperFactory factory)
Register a result set mapper factory.
|
void |
setSQLLog(SQLLog log)
Specify the class used to log sql statements.
|
void |
setStatementBuilderFactory(StatementBuilderFactory factory)
Allows customization of how prepared statements are created.
|
void |
setStatementLocator(StatementLocator locator)
Use a non-standard StatementLocator to look up named statements for all
handles created from this DBi instance.
|
void |
setStatementRewriter(StatementRewriter rewriter)
Use a non-standard StatementRewriter to transform SQL for all Handle instances
created by this DBI.
|
void |
setTimingCollector(TimingCollector timingCollector)
Add a callback to accumulate timing information about the queries running from this
data source.
|
void |
setTransactionHandler(TransactionHandler handler)
Specify the TransactionHandler instance to use.
|
<ReturnType> |
withHandle(HandleCallback<ReturnType> callback)
A convenience function which manages the lifecycle of a handle and yields it to a callback
for use by clients.
|
public DBI(ConnectionFactory connectionFactory)
ConnectionFactory.openConnection()
method will
be invoked to obtain a connection instance whenever a Handle is opened.connectionFactory
- PrvidesJDBC connections to Handle instancespublic DBI(DataSource dataSource)
dataSource
- public DBI(String url)
url
- JDBC URL for connectionspublic DBI(String url, Properties props)
url
- JDBC URL for connectionsprops
- Properties to pass to DriverManager.getConnection(url, props) for each new handlepublic void close(Object sqlObject)
public void define(String key, Object value)
StatementContext
for every statement created
from a handle obtained from this DBI instance.public SQLLog getSQLLog()
public StatementBuilderFactory getStatementBuilderFactory()
public StatementLocator getStatementLocator()
public StatementRewriter getStatementRewriter()
public TimingCollector getTimingCollector()
public TransactionHandler getTransactionHandler()
public <ReturnType> ReturnType inTransaction(TransactionCallback<ReturnType> callback) throws CallbackFailedException
inTransaction
in interface IDBI
callback
- A callback which will receive an open Handle, in a transactionCallbackFailedException
- Will be thrown if callback raises an exception. This exception will
wrap the exception thrown by the callback.public <ReturnType> ReturnType inTransaction(TransactionIsolationLevel isolation, TransactionCallback<ReturnType> callback) throws CallbackFailedException
IDBI
inTransaction
in interface IDBI
isolation
- The transaction isolation level to setcallback
- A callback which will receive an open Handle, in a transactionCallbackFailedException
- Will be thrown if callback raises an exception. This exception will
wrap the exception thrown by the callback.public <SqlObjectType> SqlObjectType onDemand(Class<SqlObjectType> sqlObjectType)
public Handle open()
public <SqlObjectType> SqlObjectType open(Class<SqlObjectType> sqlObjectType)
IDBI.close(Object)
public static Handle open(Connection connection)
connection
- public static Handle open(DataSource dataSource)
dataSource
- 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 void registerArgumentFactory(ArgumentFactory<?> argumentFactory)
public void registerContainerFactory(ContainerFactory<?> factory)
public void registerMapper(ResultSetMapper mapper)
Query.mapTo(Class)
for registered mappings.public void registerMapper(ResultSetMapperFactory factory)
Query.mapTo(Class)
for registerd mappings.public void setSQLLog(SQLLog log)
public void setStatementBuilderFactory(StatementBuilderFactory factory)
public void setStatementLocator(StatementLocator locator)
locator
- StatementLocator which will be used by all Handle instances
created from this DBIpublic void setStatementRewriter(StatementRewriter rewriter)
rewriter
- StatementRewriter to use on all Handle instancespublic void setTimingCollector(TimingCollector timingCollector)
public void setTransactionHandler(TransactionHandler handler)
handler
- The TransactionHandler to use for all Handle instances obtained
from this DBIpublic <ReturnType> ReturnType withHandle(HandleCallback<ReturnType> callback) throws CallbackFailedException
withHandle
in interface IDBI
callback
- A callback which will receive an open HandleCallbackFailedException
- Will be thrown if callback raises an exception. This exception will
wrap the exception thrown by the callback.Copyright © 2015. All rights reserved.