private TransactionFactory transactionManagerElement(XNode context) throws Exception { if (context != null) { String type = context.getStringAttribute("type"); Properties props = context.getChildrenAsProperties(); TransactionFactory factory = (TransactionFactory) resolveClass(type).newInstance(); factory.setProperties(props); return factory; } throw new BuilderException("Environment declaration requires a TransactionFactory."); }
@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); }