use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.
the class TxContextBindingConnection method getDelegate.
@Override
protected final Connection getDelegate() {
TransactionContext txContext = txControl.getCurrentContext();
if (txContext == null) {
throw new TransactionException("The resource " + provider + " cannot be accessed outside of an active Transaction Context");
}
Connection existing = (Connection) txContext.getScopedValue(resourceId);
if (existing != null) {
return existing;
}
Connection toReturn;
Connection toClose;
try {
if (txContext.getTransactionStatus() == NO_TRANSACTION) {
toClose = provider.getConnection();
toReturn = new ScopedConnectionWrapper(toClose);
} else if (txContext.supportsLocal()) {
toClose = provider.getConnection();
toReturn = new TxConnectionWrapper(toClose);
txContext.registerLocalResource(getLocalResource(toClose));
} else {
throw new TransactionException("There is a transaction active, but it does not support local participants");
}
} catch (Exception sqle) {
throw new TransactionException("There was a problem getting hold of a database connection", sqle);
}
txContext.postCompletion(x -> {
try {
toClose.close();
} catch (SQLException sqle) {
}
});
txContext.putScopedValue(resourceId, toReturn);
return toReturn;
}
use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.
the class TxConnectionWrapperTest method testIsClosed.
@Test
public void testIsClosed() throws SQLException {
Connection wrapped = new TxConnectionWrapper(conn);
wrapped.isClosed();
Mockito.verify(conn).isClosed();
}
use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.
the class TxConnectionWrapperTest method testIsWrapperFor.
@Test
public void testIsWrapperFor() throws SQLException {
Connection wrapped = new TxConnectionWrapper(conn);
wrapped.isWrapperFor(List.class);
Mockito.verify(conn).isWrapperFor(List.class);
}
use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.
the class TxConnectionWrapperTest method testGetAutoCommit.
@Test
public void testGetAutoCommit() throws SQLException {
Connection wrapped = new TxConnectionWrapper(conn);
wrapped.getAutoCommit();
Mockito.verify(conn).getAutoCommit();
}
use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.
the class TxConnectionWrapperTest method testCreateStatement.
@Test
public void testCreateStatement() throws SQLException {
Connection wrapped = new TxConnectionWrapper(conn);
wrapped.createStatement();
Mockito.verify(conn).createStatement();
}
Aggregations