com.ibatis.sqlmap.client
public interface SqlMapTransactionManager
See Also: SqlMapSession SqlMapClient
| Method Summary | |
|---|---|
| void | commitTransaction()
Commits the currently started transaction.
|
| void | endTransaction()
Ends a transaction and rolls back if necessary. |
| Connection | getCurrentConnection()
Returns the current connection in use. |
| DataSource | getDataSource()
Returns the DataSource instance currently being used by the SqlMapSession.
|
| Connection | getUserConnection()
Returns the current user supplied connection as set by setUserConnection().
|
| void | setUserConnection(Connection connnection)
Allows the developer to easily use an externally supplied connection
when executing statements.
|
| void | startTransaction()
Demarcates the beginning of a transaction scope. |
| void | startTransaction(int transactionIsolation)
Demarcates the beginning of a transaction scope using the specified transaction
isolation. |
Throws: SQLException If an error occurs while committing the transaction, or the transaction could not be committed.
Throws: SQLException If an error occurs during rollback or the transaction could not be ended.
Returns: The current connection or null.
Throws: SQLException
Returns: The DataSource instance currently being used by the SqlMapSession.
Deprecated: Use getCurrentConnection() instead.
Returns the current user supplied connection as set by setUserConnection(). TODO : DEPRECATEDReturns: The current user supplied connection.
Throws: SQLException
try {
Connection connection = dataSource.getConnection();
sqlMap.setUserConnection(connection);
// do work
connection.commit();
} catch (SQLException e) {
try {
if (connection != null) commit.rollback();
} catch (SQLException ignored) {
// generally ignored
}
throw e; // rethrow the exception
} finally {
try {
if (connection != null) connection.close();
} catch (SQLException ignored) {
// generally ignored
}
}
Parameters: connnection
Throws: SQLException
try {
sqlMap.startTransaction();
// do work
sqlMap.commitTransaction();
} finally {
sqlMap.endTransaction();
}
Always call endTransaction() once startTransaction() has been called.
Throws: java.sql.SQLException If an error occurs while starting the transaction, or the transaction could not be started.
try {
sqlMap.startTransaction(Connection.TRANSACTION_REPEATABLE_READ);
// do work
sqlMap.commitTransaction();
} finally {
sqlMap.endTransaction();
}
Always call endTransaction() once startTransaction() has been called.
Throws: java.sql.SQLException If an error occurs while starting the transaction, or the transaction could not be started.