Search in sources :

Example 11 with TxConnectionWrapper

use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.

the class TxConnectionWrapperTest method testRollback.

@Test(expected = TransactionException.class)
public void testRollback() throws SQLException {
    Connection wrapped = new TxConnectionWrapper(conn);
    wrapped.rollback();
}
Also used : TxConnectionWrapper(org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper) Connection(java.sql.Connection) Test(org.junit.Test)

Example 12 with TxConnectionWrapper

use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.

the class TxConnectionWrapperTest method testIsReadOnly.

@Test
public void testIsReadOnly() throws SQLException {
    Connection wrapped = new TxConnectionWrapper(conn);
    wrapped.isReadOnly();
    Mockito.verify(conn).isReadOnly();
}
Also used : TxConnectionWrapper(org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper) Connection(java.sql.Connection) Test(org.junit.Test)

Example 13 with TxConnectionWrapper

use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.

the class TxConnectionWrapperTest method testUnwrap.

@Test
public void testUnwrap() throws SQLException {
    Connection wrapped = new TxConnectionWrapper(conn);
    wrapped.unwrap(List.class);
    Mockito.verify(conn).unwrap(List.class);
}
Also used : TxConnectionWrapper(org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper) Connection(java.sql.Connection) Test(org.junit.Test)

Example 14 with TxConnectionWrapper

use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.

the class XAEnabledTxContextBindingConnection 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.supportsXA() && xaEnabled) {
            toClose = provider.getConnection();
            toReturn = new TxConnectionWrapper(toClose);
            txContext.registerXAResource(getXAResource(toClose), recoveryIdentifier);
        } else if (txContext.supportsLocal() && localEnabled) {
            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;
}
Also used : TransactionException(org.osgi.service.transaction.control.TransactionException) SQLException(java.sql.SQLException) TransactionContext(org.osgi.service.transaction.control.TransactionContext) TxConnectionWrapper(org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper) Connection(java.sql.Connection) ScopedConnectionWrapper(org.apache.aries.tx.control.jdbc.common.impl.ScopedConnectionWrapper) TransactionException(org.osgi.service.transaction.control.TransactionException) SQLException(java.sql.SQLException)

Example 15 with TxConnectionWrapper

use of org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper in project aries by apache.

the class TxConnectionWrapperTest method testSetSavepoint.

@Test(expected = TransactionException.class)
public void testSetSavepoint() throws SQLException {
    Connection wrapped = new TxConnectionWrapper(conn);
    wrapped.setSavepoint();
}
Also used : TxConnectionWrapper(org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper) Connection(java.sql.Connection) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)23 TxConnectionWrapper (org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper)23 Test (org.junit.Test)21 SQLException (java.sql.SQLException)2 ScopedConnectionWrapper (org.apache.aries.tx.control.jdbc.common.impl.ScopedConnectionWrapper)2 TransactionContext (org.osgi.service.transaction.control.TransactionContext)2 TransactionException (org.osgi.service.transaction.control.TransactionException)2 Executor (java.util.concurrent.Executor)1