Package org.apache.geronimo.transaction.context

Examples of org.apache.geronimo.transaction.context.TransactionContext


        if (connectionReturnAction == ConnectionReturnAction.DESTROY) {
            next.returnConnection(connectionInfo, connectionReturnAction);
            return;
        }

        TransactionContext transactionContext = TransactionContext.getContext();
        if (transactionContext.isActive()) {
            return;
        }
        if (connectionInfo.getManagedConnectionInfo().hasConnectionHandles()) {
            return;
        }
View Full Code Here


        workInfo.initialize(worker, executorTask);
        return workInfo;
    }

    void registerSynchronization(Synchronization sync) throws RollbackException, SystemException {
        TransactionContext transactionContext = TransactionContext.getContext();
        Transaction transaction = transactionContext == null ? null : transactionContext.getTransaction();
        if (transaction == null) {
            sync.beforeCompletion();
            sync.afterCompletion(Status.STATUS_COMMITTED);
        } else {
            assert transactionContext.isActive(): "Trying to register a sync on an inactive transaction context";
            transaction.registerSynchronization(sync);
        }
    }
View Full Code Here

            transactionContextManager.setContext(null);
        }
    }

    public void testTasksInTransaction() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (long i = 0; i < COUNT; i++) {
            timer.schedule(userTaskFactory, key, userId, userKey, i);
        }
        Thread.currentThread().sleep(COUNT + SLOP);
        assertEquals(0, counter.get());
        transactionContext.commit();
        Thread.currentThread().sleep(COUNT + SLOP);
        assertEquals(COUNT, counter.get());
    }
View Full Code Here

        for (long i = 0; i < COUNT; i++) {
            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, DELAY, DELAY);
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (int i = 0; i < workInfos.length; i++) {
            workInfos[i].getExecutorFeedingTimerTask().cancel();
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        transactionContext.commit();
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
    }
View Full Code Here

        for (long i = 0; i < COUNT; i++) {
            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, DELAY, DELAY);
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (int i = 0; i < workInfos.length; i++) {
            workInfos[i].getExecutorFeedingTimerTask().cancel();
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        transactionContext.rollback();
        Thread.currentThread().sleep(SLOP + DELAY);
        // Catches up with two periods.
        assertEquals(3 * COUNT, counter.get());
    }
View Full Code Here

    public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
        next.getConnection(connectionInfo);
        try {
            ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
            TransactionContext transactionContext = TransactionContext.getContext();
            if (transactionContext.isActive()) {
                XAResource xares = mci.getXAResource();
                transactionContext.getTransaction().enlistResource(xares);
            }

        } catch (SystemException e) {
            throw new ResourceException("Could not get transaction", e);
        } catch (RollbackException e) {
View Full Code Here

    public void returnConnection(
            ConnectionInfo connectionInfo,
            ConnectionReturnAction connectionReturnAction) {
        try {
            ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
            TransactionContext transactionContext = TransactionContext.getContext();
            if (transactionContext.isActive()) {
                XAResource xares = mci.getXAResource();
                transactionContext.getTransaction().delistResource(xares, XAResource.TMSUSPEND);
            }

        } catch (SystemException e) {
            //maybe we should warn???
            connectionReturnAction = ConnectionReturnAction.DESTROY;
View Full Code Here

* */
public class ConnectionManagerTest extends ConnectionManagerTestUtils {


    public void testSingleTransactionCall() throws Throwable {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        defaultComponentInterceptor.invoke(defaultComponentContext);
        MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
        transactionContext.commit();
        assertNotNull("Should be committed", mockXAResource.getCommitted());
    }
View Full Code Here

        assertEquals("XAResource should know 0 xid", 0, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
    }

    public void testOneTransactionTwoCalls() throws Throwable {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        defaultComponentInterceptor.invoke(defaultComponentContext);
        MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
        defaultComponentInterceptor.invoke(defaultComponentContext);
        assertEquals("Expected same XAResource", mockXAResource, mockManagedConnection.getXAResource());
        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
        transactionContext.commit();
        assertNotNull("Should be committed", mockXAResource.getCommitted());
    }
View Full Code Here

                mockConnection2.close();
                return null;
            }

        };
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        defaultComponentInterceptor.invoke(defaultComponentContext);
        MockXAResource mockXAResource = (MockXAResource) mockManagedConnection.getXAResource();
        assertEquals("XAResource should know one xid", 1, mockXAResource.getKnownXids().size());
        assertNull("Should not be committed", mockXAResource.getCommitted());
        transactionContext.commit();
        assertNotNull("Should be committed", mockXAResource.getCommitted());
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.transaction.context.TransactionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.