Search in sources :

Example 76 with Transaction

use of javax.transaction.Transaction in project hibernate-orm by hibernate.

the class QueryResultsRegionImpl method evictAll.

@Override
public void evictAll() throws CacheException {
    transactionContext.clear();
    final Transaction tx = suspend();
    try {
        // Invalidate the local region and then go remote
        invalidateRegion();
        Caches.broadcastEvictAll(cache);
    } finally {
        resume(tx);
    }
}
Also used : Transaction(javax.transaction.Transaction)

Example 77 with Transaction

use of javax.transaction.Transaction in project hibernate-orm by hibernate.

the class JtaAwareConnectionProviderImpl method getConnection.

@Override
public Connection getConnection() throws SQLException {
    Transaction currentTransaction = findCurrentTransaction();
    try {
        if (currentTransaction == null) {
            // this block handles non enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Connection connection = delegate.getConnection();
            nonEnlistedConnections.add(connection);
            return connection;
        }
        // this portion handles enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Connection connection = (Connection) TestingJtaPlatformImpl.synchronizationRegistry().getResource(CONNECTION_KEY);
        if (connection == null) {
            connection = delegate.getConnection();
            TestingJtaPlatformImpl.synchronizationRegistry().putResource(CONNECTION_KEY, connection);
            XAResourceWrapper xaResourceWrapper = new XAResourceWrapper(this, connection);
            currentTransaction.enlistResource(xaResourceWrapper);
        }
        return connection;
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SQLException(java.sql.SQLException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException)

Example 78 with Transaction

use of javax.transaction.Transaction in project hazelcast by hazelcast.

the class HazelcastXATest method testRollback.

@Test
public void testRollback() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    HazelcastXAResource xaResource = instance.getXAResource();
    tm.begin();
    Transaction transaction = tm.getTransaction();
    transaction.enlistResource(xaResource);
    TransactionContext context = xaResource.getTransactionContext();
    boolean error = false;
    try {
        final TransactionalMap m = context.getMap("m");
        m.put("key", "value");
        throw new RuntimeException("Exception for rolling back");
    } catch (Exception e) {
        error = true;
    } finally {
        close(error, xaResource);
    }
    assertNull(instance.getMap("m").get("key"));
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Transaction(javax.transaction.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 79 with Transaction

use of javax.transaction.Transaction in project hazelcast by hazelcast.

the class HazelcastXATest method txn.

private void txn(HazelcastInstance instance) throws Exception {
    HazelcastXAResource xaResource = instance.getXAResource();
    tm.begin();
    Transaction transaction = tm.getTransaction();
    transaction.enlistResource(xaResource);
    boolean error = false;
    try {
        TransactionContext context = xaResource.getTransactionContext();
        TransactionalMap m = context.getMap("m");
        m.put(random.nextInt(10), "value");
    } catch (Exception e) {
        logger.severe("Exception during transaction", e);
        error = true;
    } finally {
        close(error, xaResource);
    }
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) Transaction(javax.transaction.Transaction) TransactionContext(com.hazelcast.transaction.TransactionContext) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource)

Example 80 with Transaction

use of javax.transaction.Transaction in project hazelcast by hazelcast.

the class ClientXATest method close.

private void close(boolean error, XAResource... xaResource) throws Exception {
    int flag = XAResource.TMSUCCESS;
    // get the current tx
    Transaction tx = tm.getTransaction();
    // closeConnection
    if (error)
        flag = XAResource.TMFAIL;
    for (XAResource resource : xaResource) {
        tx.delistResource(resource, flag);
    }
    if (error)
        tm.rollback();
    else
        tm.commit();
}
Also used : XAResource(javax.transaction.xa.XAResource) HazelcastXAResource(com.hazelcast.transaction.HazelcastXAResource) Transaction(javax.transaction.Transaction)

Aggregations

Transaction (javax.transaction.Transaction)160 SystemException (javax.transaction.SystemException)55 Test (org.junit.Test)42 RollbackException (javax.transaction.RollbackException)26 TransactionManager (javax.transaction.TransactionManager)24 UserTransaction (javax.transaction.UserTransaction)19 NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)14 NotSupportedException (javax.transaction.NotSupportedException)13 Synchronization (javax.transaction.Synchronization)10 XAResource (javax.transaction.xa.XAResource)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)10 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)8 InvalidTransactionException (javax.transaction.InvalidTransactionException)7 TransactionContext (com.hazelcast.transaction.TransactionContext)6 RemoteException (java.rmi.RemoteException)6 ResourceException (javax.resource.ResourceException)6 ManagedConnection (javax.resource.spi.ManagedConnection)6 SQLException (java.sql.SQLException)5 HeuristicMixedException (javax.transaction.HeuristicMixedException)5 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)5