public interface Handle extends Closeable
Modifier and Type | Method and Description |
---|---|
<SqlObjectType> |
attach(Class<SqlObjectType> sqlObjectType)
Create a a sql object of the specified type bound to this handle.
|
Handle |
begin()
Start a transaction
|
Handle |
checkpoint(String name)
Create a transaction checkpoint (savepoint in JDBC terminology) with the name provided.
|
void |
close() |
Handle |
commit()
Commit a transaction
|
Batch |
createBatch()
Create a non-prepared (no bound parameters, but different SQL, batch statement
|
Call |
createCall(String callableSql)
Create a call to a stored procedure
|
Query<Map<String,Object>> |
createQuery(String sql)
Return a default Query instance which can be executed later, as long as this handle remains open.
|
Script |
createScript(String name)
Creates an SQL script, looking for the source of the script using the
current statement locator (which defaults to searching the classpath)
|
Update |
createStatement(String sql)
Create an Insert or Update statement which returns the number of rows modified.
|
void |
define(String key,
Object value)
Define a statement attribute which will be applied to all
StatementContext
instances for statements created from this handle |
void |
execute(String sql,
Object... args)
Execute some SQL with no return value
|
Connection |
getConnection()
Get the JDBC Connection this Handle uses
|
SqlObjectContext |
getSqlObjectContext() |
TransactionIsolationLevel |
getTransactionIsolationLevel()
Obtain the current transaction isolation level
|
int |
insert(String sql,
Object... args)
Execute a simple insert statement
|
<ReturnType> |
inTransaction(TransactionCallback<ReturnType> callback)
Executes
callback in a transaction. |
<ReturnType> |
inTransaction(TransactionIsolationLevel level,
TransactionCallback<ReturnType> callback)
Executes
callback in a transaction. |
boolean |
isClosed() |
boolean |
isInTransaction()
Is the handle in a transaction? It defers to the underlying
TransactionHandler |
PreparedBatch |
prepareBatch(String sql)
Prepare a batch to execute.
|
void |
registerArgumentFactory(ArgumentFactory argumentFactory) |
void |
registerColumnMapper(ResultColumnMapper mapper)
Register a result column mapper which will have its parameterized type inspected to determine what it maps to
Column mappers may be reused by
ResultSetMapper to map individual columns. |
void |
registerColumnMapper(ResultColumnMapperFactory factory)
Register a result column mapper factory.
|
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.
|
Handle |
release(String checkpointName)
Release a previously created checkpoint
|
Handle |
rollback()
Rollback a transaction
|
Handle |
rollback(String checkpointName)
Rollback a transaction to a named checkpoint
|
List<Map<String,Object>> |
select(String sql,
Object... args)
Convenience method which executes a select with purely positional arguments
|
void |
setSQLLog(SQLLog log)
Specify the class used to log sql statements.
|
void |
setSqlObjectContext(SqlObjectContext context) |
void |
setStatementBuilder(StatementBuilder builder)
Specify the statement builder to use for this handle
|
void |
setStatementLocator(StatementLocator locator)
Allows for overiding the default statement locator.
|
void |
setStatementRewriter(StatementRewriter rewriter)
Allows for overiding the default statement rewriter.
|
void |
setTimingCollector(TimingCollector timingCollector)
Specify the class used to collect timing information.
|
void |
setTransactionIsolation(int level)
Set the transaction isolation level on the underlying connection
|
void |
setTransactionIsolation(TransactionIsolationLevel level)
Set the transaction isolation level on the underlying connection
|
int |
update(String sql,
Object... args)
Execute a simple update statement
|
void |
useTransaction(TransactionConsumer callback)
Executes
callback in a transaction. |
void |
useTransaction(TransactionIsolationLevel level,
TransactionConsumer callback)
Executes
callback in a transaction. |
<SqlObjectType> SqlObjectType attach(Class<SqlObjectType> sqlObjectType)
SqlObjectType
- sqlObjectType
- Handle begin()
Handle checkpoint(String name)
name
- The name of the checkpointvoid close()
close
in interface AutoCloseable
close
in interface Closeable
Handle commit()
Batch createBatch()
prepareBatch(String)
Call createCall(String callableSql)
callableSql
- Query<Map<String,Object>> createQuery(String sql)
sql
- the select sqlScript createScript(String name)
Update createStatement(String sql)
sql
- The statement sqlvoid define(String key, Object value)
StatementContext
instances for statements created from this handlekey
- Attribute namevalue
- Attribute valuevoid execute(String sql, Object... args)
sql
- the sql to executeargs
- arguments to bind to the sqlConnection getConnection()
SqlObjectContext getSqlObjectContext()
TransactionIsolationLevel getTransactionIsolationLevel()
int insert(String sql, Object... args)
sql
- the insert SQL<ReturnType> ReturnType inTransaction(TransactionCallback<ReturnType> callback) throws TransactionFailedException
callback
in a transaction. If the transaction succeeds, the
result of the callback will be returned. If it fails a TransactionFailedException
will be thrown.TransactionFailedException
- if the transaction failed in the callback<ReturnType> ReturnType inTransaction(TransactionIsolationLevel level, TransactionCallback<ReturnType> callback) throws TransactionFailedException
callback
in a transaction. If the transaction succeeds, the
result of the callback will be returned. If it fails a TransactionFailedException
will be thrown.
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.
TransactionFailedException
- if the transaction failed in the callbackboolean isClosed()
boolean isInTransaction()
TransactionHandler
PreparedBatch prepareBatch(String sql)
sql
- the batch SQLvoid registerArgumentFactory(ArgumentFactory argumentFactory)
void registerColumnMapper(ResultColumnMapper mapper)
ResultSetMapper
to map individual columns.void registerColumnMapper(ResultColumnMapperFactory factory)
ResultSetMapper
to map individual columns.void registerContainerFactory(ContainerFactory<?> factory)
void registerMapper(ResultSetMapper mapper)
Query.mapTo(Class)
for registered mappings.void registerMapper(ResultSetMapperFactory factory)
Query.mapTo(Class)
for registerd mappings.Handle release(String checkpointName)
checkpointName
- the name of the checkpoint to releaseHandle rollback()
Handle rollback(String checkpointName)
checkpointName
- the name of the checkpoint, previously declared with checkpoint(java.lang.String)
List<Map<String,Object>> select(String sql, Object... args)
sql
- SQL or named statementargs
- arguments to bind positionallyvoid setSQLLog(SQLLog log)
void setSqlObjectContext(SqlObjectContext context)
void setStatementBuilder(StatementBuilder builder)
builder
- StatementBuilder to be usedvoid setStatementLocator(StatementLocator locator)
void setStatementRewriter(StatementRewriter rewriter)
void setTimingCollector(TimingCollector timingCollector)
void setTransactionIsolation(int level)
level
- the isolation level to usevoid setTransactionIsolation(TransactionIsolationLevel level)
level
- the isolation level to useint update(String sql, Object... args)
sql
- the update SQLargs
- positional argumentsvoid useTransaction(TransactionConsumer callback) throws TransactionFailedException
callback
in a transaction. If the transaction succeeds, the
result of the callback will be returned. If it fails a TransactionFailedException
will be thrown.TransactionFailedException
- if the transaction failed in the callbackvoid useTransaction(TransactionIsolationLevel level, TransactionConsumer callback) throws TransactionFailedException
callback
in a transaction. If the transaction succeeds, the
result of the callback will be returned. If it fails a TransactionFailedException
will be thrown.
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.
TransactionFailedException
- if the transaction failed in the callbackCopyright © 2018. All rights reserved.