org.mybatis.spring.transaction
Class SpringManagedTransaction

java.lang.Object
  extended by org.mybatis.spring.transaction.SpringManagedTransaction
All Implemented Interfaces:
org.apache.ibatis.transaction.Transaction

public class SpringManagedTransaction
extends Object
implements org.apache.ibatis.transaction.Transaction

MyBatis has two TransactionManagers out of the box: The JdbcTransaction and the ManagedTransaction. When MyBatis runs under a Spring transaction none of them will work fine because JdbcTransaction will commit/rollback/close and it should not and ManagedTransaction will close the connection and it should not. SpringManagedTransaction looks if the current connection is being managed by Spring. In that case it will no-op all commit/rollback/close calls assuming that the Spring transaction manager will do the job. Otherwise it will behave almost like JdbcTransaction.

Version:
$Id: SpringManagedTransaction.java 3406 2010-12-20 17:58:31Z eduardo.macarron $

Constructor Summary
SpringManagedTransaction(Connection connection, DataSource dataSource)
          Constructor that discovers if this Transaction should manage connection or let it to Spring.
 
Method Summary
 void close()
          
 void commit()
          
 Connection getConnection()
          
 void rollback()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringManagedTransaction

public SpringManagedTransaction(Connection connection,
                                DataSource dataSource)
Constructor that discovers if this Transaction should manage connection or let it to Spring. It gets both the Connection and the DataSource it was built from and asks Spring if they are bundled to the current transaction.

Parameters:
connection - JDBC connection to manage
dataSource - The DataSource that was configured in current SqlSessionFactory
Method Detail

getConnection

public Connection getConnection()

Specified by:
getConnection in interface org.apache.ibatis.transaction.Transaction

commit

public void commit()
            throws SQLException

Specified by:
commit in interface org.apache.ibatis.transaction.Transaction
Throws:
SQLException

rollback

public void rollback()
              throws SQLException

Specified by:
rollback in interface org.apache.ibatis.transaction.Transaction
Throws:
SQLException

close

public void close()
           throws SQLException

Specified by:
close in interface org.apache.ibatis.transaction.Transaction
Throws:
SQLException


Copyright © 2010-2011 MyBatis.org. All Rights Reserved.