// this should work since the DS is managed MyBatis
@Test
public void testNonSpringTxFactoryNonSpringDSWithTx() throws java.sql.SQLException {
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
MockDataSource mockDataSource = new MockDataSource();
mockDataSource.setupConnection(createMockConnection());
Environment nonSpring = new Environment("non-spring", new JdbcTransactionFactory(), mockDataSource);
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
TransactionStatus status = null;
try {
status = txManager.getTransaction(new DefaultTransactionDefinition());
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.commit();
session.close();
txManager.commit(status);
// txManager still uses original connection
assertCommit();
assertSingleConnection();
// SqlSession uses its own connection
// that connection will not have commited since no SQL was executed by the session
MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
assertEquals("should call commit on Connection", 0, mockConnection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());
assertCommitSession();
} finally {
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);