public class Handle extends Object implements Closeable, Configurable<Handle>
| Modifier and Type | Method and Description |
|---|---|
<T> T |
attach(Class<T> extensionType)
Create a Jdbi extension object of the specified type bound to this handle.
|
Handle |
begin()
Start a transaction.
|
void |
close()
Closes the handle, its connection, and any other database resources it is holding.
|
Handle |
commit()
Commit a transaction.
|
Batch |
createBatch()
Create a non-prepared (no bound parameters, but different SQL) batch statement.
|
Call |
createCall(String sql)
Create a call to a stored procedure.
|
Query |
createQuery(String sql)
Return a Query instance that executes a statement
with bound parameters and maps the result set into Java types.
|
Script |
createScript(String sql)
Creates a Script from the given SQL script.
|
Update |
createUpdate(String sql)
Create an Insert or Update statement which returns the number of rows modified.
|
int |
execute(String sql,
Object... args)
Execute a SQL statement, and return the number of rows affected by the statement.
|
ConfigRegistry |
getConfig()
Returns the configuration registry associated with this object.
|
Connection |
getConnection()
Get the JDBC Connection this Handle uses.
|
ExtensionMethod |
getExtensionMethod() |
StatementBuilder |
getStatementBuilder() |
TransactionIsolationLevel |
getTransactionIsolationLevel()
Obtain the current transaction isolation level.
|
<R,X extends Exception> |
inTransaction(HandleCallback<R,X> callback)
Executes
callback in a transaction, and returns the result of the callback. |
<R,X extends Exception> |
inTransaction(TransactionIsolationLevel level,
HandleCallback<R,X> callback)
Executes
callback in a transaction, and returns the result of the callback. |
boolean |
isClosed() |
boolean |
isInTransaction() |
boolean |
isReadOnly() |
PreparedBatch |
prepareBatch(String sql)
Prepare a batch to execute.
|
Handle |
release(String savepointName)
Release a previously created savepoint.
|
Handle |
rollback()
Rollback a transaction.
|
Handle |
rollbackToSavepoint(String savepointName)
Rollback a transaction to a named savepoint.
|
Handle |
savepoint(String name)
Create a transaction savepoint with the name provided.
|
Query |
select(String sql,
Object... args)
Convenience method which creates a query with the given positional arguments
|
Handle |
setReadOnly(boolean readOnly)
Set the Handle readOnly.
|
Handle |
setStatementBuilder(StatementBuilder builder)
Specify the statement builder to use for this handle.
|
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.
|
<X extends Exception> |
useTransaction(HandleConsumer<X> callback)
Executes
callback in a transaction. |
<X extends Exception> |
useTransaction(TransactionIsolationLevel level,
HandleConsumer<X> callback)
Executes
callback in a transaction. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigure, define, getConfig, registerArgument, registerArrayType, registerArrayType, registerArrayType, registerCollector, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerExtension, registerRowMapper, registerRowMapper, registerRowMapper, setMapKeyColumn, setMapValueColumn, setSqlArrayArgumentStrategy, setSqlParser, setTemplateEngine, setTimingCollectorpublic <T> T attach(Class<T> extensionType)
T - the extension typeextensionType - the extension classpublic Handle begin()
public void close()
close in interface Closeableclose in interface AutoCloseableCloseException - if any resources throw exception while closingTransactionException - if called while the handle has a transaction open. The open transaction will be
rolled back.public Handle commit()
public Batch createBatch()
prepareBatch(String)public Call createCall(String sql)
sql - the stored procedure sqlpublic Query createQuery(String sql)
sql - SQL that may return resultspublic Script createScript(String sql)
sql - the SQL scriptpublic Update createUpdate(String sql)
sql - the statement sqlpublic int execute(String sql, Object... args)
sql - the SQL statement to execute, using positional parameters (if any)args - positional argumentspublic ConfigRegistry getConfig()
ConfigurablegetConfig in interface Configurable<Handle>public Connection getConnection()
public ExtensionMethod getExtensionMethod()
public StatementBuilder getStatementBuilder()
StatementBuilderpublic TransactionIsolationLevel getTransactionIsolationLevel()
public <R,X extends Exception> R inTransaction(HandleCallback<R,X> callback) throws X extends Exception
callback in a transaction, and returns the result of the callback.R - type returned by callbackX - exception type thrown by the callback, if anycallback - a callback which will receive an open handle, in a transaction.X - any exception thrown by the callbackX extends Exceptionpublic <R,X extends Exception> R inTransaction(TransactionIsolationLevel level, HandleCallback<R,X> callback) throws X extends Exception
callback in a transaction, and returns the result of the callback.
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 callbackX - exception type thrown by the callback, if anylevel - 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.X - any exception thrown by the callbackX extends Exceptionpublic boolean isClosed()
public boolean isInTransaction()
TransactionHandler.public boolean isReadOnly()
Connection.isReadOnly()public PreparedBatch prepareBatch(String sql)
sql - the batch SQLpublic Handle release(String savepointName)
savepointName - the name of the savepoint to releasepublic Handle rollback()
public Handle rollbackToSavepoint(String savepointName)
savepointName - the name of the savepoint, previously declared with savepoint(java.lang.String)public Handle savepoint(String name)
name - The name of the savepointpublic Query select(String sql, Object... args)
sql - SQL or named statementargs - arguments to bind positionallypublic Handle setReadOnly(boolean readOnly)
readOnly - whether the Handle is readOnlyConnection.setReadOnly(boolean)public Handle setStatementBuilder(StatementBuilder builder)
builder - StatementBuilder to be usedpublic void setTransactionIsolation(int level)
level - the isolation level to usepublic void setTransactionIsolation(TransactionIsolationLevel level)
level - the isolation level to usepublic <X extends Exception> void useTransaction(HandleConsumer<X> callback) throws X extends Exception
callback in a transaction.X - exception type thrown by the callback, if anycallback - a callback which will receive an open handle, in a transaction.X - any exception thrown by the callbackX extends Exceptionpublic <X extends Exception> void useTransaction(TransactionIsolationLevel level, HandleConsumer<X> callback) throws X extends Exception
callback in a transaction.
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 anylevel - 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.X - any exception thrown by the callbackX extends ExceptionCopyright © 2017. All rights reserved.