/** * Builds a transaction object around a user provided connection. The returned transaction * allows the store to work against an externally managed transaction, such as in J2EE * enviroments. It is the duty of the caller to ensure the connection is to the same database * managed by this {@link JDBCDataStore}. * * <p>Calls to {@link Transaction#commit()}, {@link Transaction#rollback()} and {@link * Transaction#close()} will not result in corresponding calls to the provided {@link * Connection} object. * * @param conn The externally managed connection */ public Transaction buildTransaction(Connection cx) { DefaultTransaction tx = new DefaultTransaction(); State state = new JDBCTransactionState(cx, this, true); tx.putState(this, state); return tx; }
@Test public void testSetTransactionNullWithExternalConnection() throws Exception { JDBCTransactionState state = new JDBCTransactionState(mockConnection, dataStore, true); // init state state.setTransaction(mockTransaction); // clear state state.setTransaction(null); // make sure connection is closed verify(mockConnection, times(0)).close(); testLogWarnings(state); }
void testLogWarnings(JDBCTransactionState state) { Assert.assertEquals("Regular close, no warnings expected.", 0, warningsCount); state.setTransaction(null); Assert.assertEquals("Duplicate close, warning expected.", 1, warningsCount); } }
tstate = new JDBCTransactionState(cx, this); t.putState(this, tstate); return cx;
/** * Tests if connection gets closed on internally managed connections and creation of log * statements. * * @throws IOException * @throws SQLException */ @Test public void testSetTransactionNullWithInternalConnection() throws IOException, SQLException { JDBCTransactionState state = new JDBCTransactionState(mockConnection, dataStore); // init state state.setTransaction(mockTransaction); // clear state state.setTransaction(null); // make sure connection is closed verify(mockConnection, times(1)).close(); testLogWarnings(state); }
/** * Builds a transaction object around a user provided connection. The returned transaction * allows the store to work against an externally managed transaction, such as in J2EE * enviroments. It is the duty of the caller to ensure the connection is to the same database * managed by this {@link JDBCDataStore}. * * Calls to {@link Transaction#commit()}, {@link Transaction#rollback()} and * {@link Transaction#close()} will not result in corresponding calls to the provided * {@link Connection} object. * * @param conn * The externally managed connection */ public Transaction buildTransaction(Connection cx) { DefaultTransaction tx = new DefaultTransaction(); State state = new JDBCTransactionState(cx, this, true); tx.putState(this, state); return tx; }
tstate = new JDBCTransactionState(cx, this); t.putState(this, tstate); return cx;
state.getTransaction().putState(state, new JDBCTransactionState( cx, this ) );