@Test public void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnections() throws Exception { TransactionFactory tf = new ManagedTransactionFactory(); tf.setProperties(new Properties()); Transaction tx = tf.newTransaction(conn); assertEquals(conn, tx.getConnection()); tx.commit(); tx.rollback(); tx.close(); verify(conn).close(); }
@Test public void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnectionsAndDoesNotCloseConnection() throws Exception { TransactionFactory tf = new ManagedTransactionFactory(); Properties props = new Properties(); props.setProperty("closeConnection", "false"); tf.setProperties(props); Transaction tx = tf.newTransaction(conn); assertEquals(conn, tx.getConnection()); tx.commit(); tx.rollback(); tx.close(); verifyNoMoreInteractions(conn); }
protected Connection getConnection(Log statementLog) throws SQLException { Connection connection = transaction.getConnection(); if (statementLog.isDebugEnabled() || connectionLog.isDebugEnabled()) { return ConnectionLogger.newInstance(connection, statementLog); } else { return connection; } }
public void commit(boolean required) throws SQLException { if (closed) throw new ExecutorException("Cannot commit, transaction is already closed"); clearLocalCache(); flushStatements(); if (required) { transaction.commit(); } }
private void closeTransaction(Transaction tx) { if (tx != null) { try { tx.close(); } catch (SQLException ignore) { // Intentionally ignore. Prefer previous error. } } }
public void rollback(boolean required) throws SQLException { if (!closed) { try { clearLocalCache(); flushStatements(true); } finally { if (required) { transaction.rollback(); } } } }
public void close(boolean forceRollback) { try { try { rollback(forceRollback); } finally { if (transaction != null) transaction.close(); } } catch (SQLException e) { // Ignore. There's nothing that can be done at this point. log.debug("Unexpected exception on closing transaction. Cause: " + e); } finally { transaction = null; deferredLoads = null; localCache = null; localOutputParameterCache = null; batchResults = null; closed = true; } }