Search in sources :

Example 46 with RollbackException

use of javax.transaction.RollbackException in project geode by apache.

the class ClientServerTransactionDUnitTest method doJTATx1.

private void doJTATx1(String regionName, CountDownLatch latch1, CountDownLatch latch2) {
    TransactionManagerImpl tm = TransactionManagerImpl.getTransactionManager();
    Region r = getClientRegion(regionName);
    try {
        UserTransaction utx = new UserTransactionImpl();
        utx.begin();
        latch1.await();
        r.put(key1, "value2");
        utx.commit();
        fail("Do not get expected RollbackException");
    } catch (Exception e) {
        if (e instanceof RollbackException) {
        // expected exception.
        } else {
            Assert.fail("Unexpected exception while doing JTA Transaction1 ", e);
        }
    } finally {
        latch2.countDown();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) RollbackException(javax.transaction.RollbackException) RollbackException(javax.transaction.RollbackException)

Example 47 with RollbackException

use of javax.transaction.RollbackException in project ignite by apache.

the class CacheJtaManager method checkJta.

/** {@inheritDoc} */
@Override
public void checkJta() throws IgniteCheckedException {
    if (jtaTm == null) {
        try {
            CacheTmLookup tmLookup = tmLookupRef.get();
            if (tmLookup == null)
                return;
            jtaTm = tmLookup.getTm();
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to get transaction manager: " + e, e);
        }
    }
    if (jtaTm != null) {
        CacheJtaResource rsrc = this.rsrc.get();
        if (rsrc == null || rsrc.isFinished()) {
            try {
                Transaction jtaTx = jtaTm.getTransaction();
                if (jtaTx != null) {
                    GridNearTxLocal tx = cctx.tm().userTx();
                    if (tx == null) {
                        TransactionConfiguration tCfg = cctx.kernalContext().config().getTransactionConfiguration();
                        tx = cctx.tm().newTx(/*implicit*/
                        false, /*implicit single*/
                        false, null, tCfg.getDefaultTxConcurrency(), tCfg.getDefaultTxIsolation(), tCfg.getDefaultTxTimeout(), /*store enabled*/
                        true, /*tx size*/
                        0);
                    }
                    rsrc = new CacheJtaResource(tx, cctx.kernalContext());
                    if (useJtaSync)
                        jtaTx.registerSynchronization(rsrc);
                    else if (!jtaTx.enlistResource(rsrc))
                        throw new IgniteCheckedException("Failed to enlist XA resource to JTA user transaction.");
                    this.rsrc.set(rsrc);
                }
            } catch (SystemException e) {
                throw new IgniteCheckedException("Failed to obtain JTA transaction.", e);
            } catch (RollbackException e) {
                throw new IgniteCheckedException("Failed to enlist XAResource to JTA transaction.", e);
            }
        }
    }
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) RollbackException(javax.transaction.RollbackException) CacheTmLookup(org.apache.ignite.cache.jta.CacheTmLookup) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 48 with RollbackException

use of javax.transaction.RollbackException in project jackrabbit by apache.

the class XATest method testLockTwice.

/**
     * Test locking a node inside a transaction that has been locked in another
     * session, which leads to a failure when committing.
     * @throws Exception
     */
public void testLockTwice() throws Exception {
    Session other = getHelper().getSuperuserSession();
    try {
        // add node that is both lockable and referenceable, save
        Node n = testRootNode.addNode(nodeName1);
        n.addMixin(mixLockable);
        n.addMixin(mixReferenceable);
        testRootNode.save();
        // reference node in second session
        Node nOther = other.getNodeByUUID(n.getUUID());
        // verify node is not locked in either session
        assertFalse("Node not locked in session 1", n.isLocked());
        assertFalse("Node not locked in session 2", nOther.isLocked());
        // get user transaction object, start and lock node
        UserTransaction utx = new UserTransactionImpl(superuser);
        utx.begin();
        n.lock(false, true);
        // lock node in non-transactional session, too
        nOther.lock(false, true);
        // verify node is locked in both sessions
        assertTrue("Node locked in session 1", n.isLocked());
        assertTrue("Node locked in session 2", nOther.isLocked());
        assertTrue("Node locked in session 2", nOther.hasProperty(jcrLockOwner));
        // assertion: commit must fail since node has already been locked
        try {
            utx.commit();
            fail("Commit succeeds with double locking");
        } catch (RollbackException e) {
        /* expected */
        }
        // verify node is locked in both sessions
        assertTrue("Node locked in session 1", n.isLocked());
        assertTrue("Node locked in session 2", nOther.isLocked());
        assertTrue("Node locked in session 2", nOther.hasProperty(jcrlockIsDeep));
    } finally {
        // logout
        other.logout();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) RollbackException(javax.transaction.RollbackException) Session(javax.jcr.Session)

Example 49 with RollbackException

use of javax.transaction.RollbackException in project jackrabbit by apache.

the class XATest method testAddReference.

/**
     * Add reference to some node in one session while removing
     * the node in another.
     * @throws Exception
     */
public void testAddReference() throws Exception {
    // add two nodes, second one referenceable
    Node n1 = testRootNode.addNode(nodeName1);
    Node n2 = testRootNode.addNode(nodeName2);
    n2.addMixin(mixReferenceable);
    testRootNode.save();
    // get user transaction object
    UserTransaction utx = new UserTransactionImpl(superuser);
    // start transaction
    utx.begin();
    // add reference and save
    n1.setProperty(propertyName1, n2);
    testRootNode.save();
    // remove referenced node in other session
    Session otherSuperuser = getHelper().getSuperuserSession();
    Node otherRootNode = otherSuperuser.getRootNode().getNode(testPath);
    otherSuperuser.getNodeByUUID(n2.getUUID()).remove();
    otherRootNode.save();
    // assertion: commit must fail since integrity violated
    try {
        utx.commit();
        fail("Commit succeeds with violated integrity");
    } catch (RollbackException e) {
    /* expected */
    }
    // logout
    otherSuperuser.logout();
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) RollbackException(javax.transaction.RollbackException) Session(javax.jcr.Session)

Example 50 with RollbackException

use of javax.transaction.RollbackException in project tomee by apache.

the class BaseEjbProxyHandler method getLiveHandleRegistry.

public ConcurrentMap getLiveHandleRegistry() {
    final BeanContext beanContext = getBeanContext();
    final ThreadContext tc = ThreadContext.getThreadContext();
    if (tc != null && tc.getBeanContext() != beanContext && /* parent bean */
    tc.getCurrentOperation() == Operation.BUSINESS) {
        ProxyRegistry registry = tc.get(ProxyRegistry.class);
        if (registry == null) {
            registry = new ProxyRegistry();
            tc.set(ProxyRegistry.class, registry);
        }
        return registry.liveHandleRegistry;
    } else {
        // use the tx if there
        final SystemInstance systemInstance = SystemInstance.get();
        final TransactionManager txMgr = systemInstance.getComponent(TransactionManager.class);
        try {
            final Transaction tx = txMgr.getTransaction();
            if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
                final TransactionSynchronizationRegistry registry = systemInstance.getComponent(TransactionSynchronizationRegistry.class);
                final String resourceKey = ProxyRegistry.class.getName();
                ConcurrentMap map = ConcurrentMap.class.cast(registry.getResource(resourceKey));
                if (map == null) {
                    map = new ConcurrentHashMap();
                    registry.putResource(resourceKey, map);
                    try {
                        final ConcurrentMap tmp = map;
                        tx.registerSynchronization(new Synchronization() {

                            @Override
                            public void beforeCompletion() {
                            // no-op
                            }

                            @Override
                            public void afterCompletion(final int status) {
                                tmp.clear();
                            }
                        });
                    } catch (final RollbackException e) {
                    // not really possible since we check the status
                    // let it go to default
                    }
                }
                return map;
            }
        } catch (final SystemException e) {
        // let it go to default
        }
        // back to default but it doesnt release the memory
        ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
        if (proxyRegistry == null) {
            proxyRegistry = new ProxyRegistry();
            beanContext.set(ProxyRegistry.class, proxyRegistry);
        }
        return proxyRegistry.liveHandleRegistry;
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) ConcurrentMap(java.util.concurrent.ConcurrentMap) Synchronization(javax.transaction.Synchronization) RollbackException(javax.transaction.RollbackException) BeanContext(org.apache.openejb.BeanContext) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) SystemInstance(org.apache.openejb.loader.SystemInstance) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

RollbackException (javax.transaction.RollbackException)57 SystemException (javax.transaction.SystemException)25 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)15 Transaction (javax.transaction.Transaction)14 UserTransaction (javax.transaction.UserTransaction)14 HeuristicMixedException (javax.transaction.HeuristicMixedException)12 Test (org.junit.Test)11 Connection (java.sql.Connection)8 XAException (javax.transaction.xa.XAException)8 PreparedStatement (java.sql.PreparedStatement)7 NotSupportedException (javax.transaction.NotSupportedException)7 IOException (java.io.IOException)6 EJBException (javax.ejb.EJBException)6 Account (org.apache.openejb.test.object.Account)6 RemoteException (java.rmi.RemoteException)5 CreateException (javax.ejb.CreateException)5 DataSource (javax.sql.DataSource)5 SQLException (java.sql.SQLException)4 Synchronization (javax.transaction.Synchronization)4 XAResource (javax.transaction.xa.XAResource)4