public class KeepAliveLocalTransaction extends LocalTransaction
But the connection is closed, if any exceptions are thrown.
This instance is thread safe.
KeepAliveLocalTransaction tx = DbConfig.singleton().getKeepAliveLocalTransaction();
tx.init();
try {
try {
tx.begin();
Employee employee = dao.selectById(1);
employee.setName("SMITH");
employee.setJobType(JobType.PRESIDENT);
dao.update(employee);
tx.commit();
} finally {
tx.rollback();
}
try {
tx.begin();
Employee employee = dao.selectById(2);
employee.setName("foo");
employee.setJobType(JobType.SALESMAN);
dao.update(employee);
tx.commit();
} finally {
tx.rollback();
}
} finally {
tx.destroy();
}
className, dataSource, defaultTransactionIsolationLevel, jdbcLogger, localTxContextHolder| Modifier | Constructor and Description |
|---|---|
protected |
KeepAliveLocalTransaction(javax.sql.DataSource dataSource,
java.lang.ThreadLocal<LocalTransactionContext> localTxContextHolder,
JdbcLogger jdbcLogger)
Creates an instance.
|
protected |
KeepAliveLocalTransaction(javax.sql.DataSource dataSource,
java.lang.ThreadLocal<LocalTransactionContext> localTxContextHolder,
JdbcLogger jdbcLogger,
TransactionIsolationLevel defaultTransactionIsolationLevel)
Creates an instance with the specified transaction isolation level.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Destroy the transaction context.
|
protected void |
endInternal(LocalTransactionContext context,
java.lang.String callerMethodName)
Ends the transaction, but does not close the JDBC connection.
|
protected LocalTransactionContext |
getLocalTransactionContext() |
void |
init()
Initializes a transaction context.
|
protected boolean |
isActiveInternal(LocalTransactionContext context) |
begin, begin, beginInternal, closeConnection, commit, end, hasSavepoint, isActive, isRollbackOnly, release, releaseSavepoint, resume, rollback, rollback, rollbackInternal, setRollbackOnly, setSavepoint, suspend, toStringprotected KeepAliveLocalTransaction(javax.sql.DataSource dataSource,
java.lang.ThreadLocal<LocalTransactionContext> localTxContextHolder,
JdbcLogger jdbcLogger)
dataSource - the data sourcelocalTxContextHolder - the holder of the transaction contextjdbcLogger - the loggerprotected KeepAliveLocalTransaction(javax.sql.DataSource dataSource,
java.lang.ThreadLocal<LocalTransactionContext> localTxContextHolder,
JdbcLogger jdbcLogger,
TransactionIsolationLevel defaultTransactionIsolationLevel)
dataSource - the data sourcelocalTxContextHolder - the holder of the transaction contextjdbcLogger - the loggerdefaultTransactionIsolationLevel - the default transaction isolation levelpublic void init()
This method establishes a JDBC connection.
If you invoke LocalTransaction.begin() before invoking this method, the LocalTransaction.begin() method
establishes a JDBC connection.
JdbcException - if a JDBC related error occursprotected LocalTransactionContext getLocalTransactionContext()
getLocalTransactionContext in class LocalTransactionpublic void destroy()
This method closes the JDBC connection.
This method does not throw any exceptions.
protected void endInternal(LocalTransactionContext context, java.lang.String callerMethodName)
endInternal in class LocalTransactionprotected boolean isActiveInternal(LocalTransactionContext context)
isActiveInternal in class LocalTransaction