@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);
 }
Example #3
0
 protected Connection getConnection(Log statementLog) throws SQLException {
   Connection connection = transaction.getConnection();
   if (statementLog.isDebugEnabled() || connectionLog.isDebugEnabled()) {
     return ConnectionLogger.newInstance(connection, statementLog);
   } else {
     return connection;
   }
 }
Example #4
0
 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.
     }
   }
 }
Example #6
0
 public void rollback(boolean required) throws SQLException {
   if (!closed) {
     try {
       clearLocalCache();
       flushStatements(true);
     } finally {
       if (required) {
         transaction.rollback();
       }
     }
   }
 }
Example #7
0
 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;
   }
 }