Class JdbcTransaction
- java.lang.Object
-
- org.apache.ibatis.transaction.jdbc.JdbcTransaction
-
- All Implemented Interfaces:
Transaction
public class JdbcTransaction extends java.lang.Object implements Transaction
Transaction
that makes use of the JDBC commit and rollback facilities directly. It relies on the connection retrieved from the dataSource to manage the scope of the transaction. Delays connection retrieval until getConnection() is called. Ignores commit or rollback requests when autocommit is on.- Author:
- Clinton Begin
- See Also:
JdbcTransactionFactory
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
autoCommit
protected java.sql.Connection
connection
protected javax.sql.DataSource
dataSource
protected TransactionIsolationLevel
level
-
Constructor Summary
Constructors Constructor Description JdbcTransaction(java.sql.Connection connection)
JdbcTransaction(javax.sql.DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit)
-
Method Summary
Modifier and Type Method Description void
close()
Close inner database connection.void
commit()
Commit inner database connection.java.sql.Connection
getConnection()
Retrieve inner database connection.java.lang.Integer
getTimeout()
Get transaction timeout if set.protected void
openConnection()
protected void
resetAutoCommit()
void
rollback()
Rollback inner database connection.protected void
setDesiredAutoCommit(boolean desiredAutoCommit)
-
-
-
Field Detail
-
connection
protected java.sql.Connection connection
-
dataSource
protected javax.sql.DataSource dataSource
-
level
protected TransactionIsolationLevel level
-
autoCommit
protected boolean autoCommit
-
-
Constructor Detail
-
JdbcTransaction
public JdbcTransaction(javax.sql.DataSource ds, TransactionIsolationLevel desiredLevel, boolean desiredAutoCommit)
-
JdbcTransaction
public JdbcTransaction(java.sql.Connection connection)
-
-
Method Detail
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Description copied from interface:Transaction
Retrieve inner database connection.- Specified by:
getConnection
in interfaceTransaction
- Returns:
- DataBase connection
- Throws:
java.sql.SQLException
-
commit
public void commit() throws java.sql.SQLException
Description copied from interface:Transaction
Commit inner database connection.- Specified by:
commit
in interfaceTransaction
- Throws:
java.sql.SQLException
-
rollback
public void rollback() throws java.sql.SQLException
Description copied from interface:Transaction
Rollback inner database connection.- Specified by:
rollback
in interfaceTransaction
- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.SQLException
Description copied from interface:Transaction
Close inner database connection.- Specified by:
close
in interfaceTransaction
- Throws:
java.sql.SQLException
-
setDesiredAutoCommit
protected void setDesiredAutoCommit(boolean desiredAutoCommit)
-
resetAutoCommit
protected void resetAutoCommit()
-
openConnection
protected void openConnection() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getTimeout
public java.lang.Integer getTimeout() throws java.sql.SQLException
Description copied from interface:Transaction
Get transaction timeout if set.- Specified by:
getTimeout
in interfaceTransaction
- Throws:
java.sql.SQLException
-
-