Examples of TransactionContext


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

        assertTrue("Expected returned", returned);
        assertTrue("Expected not committed", !committed);
    }

    public void testTransactionShareableConnection() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo = makeConnectionInfo();
        transactionEnlistingInterceptor.getConnection(connectionInfo);
        assertTrue("Expected started", started);
        assertTrue("Expected not ended", !ended);
        started = false;
        transactionEnlistingInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
        assertTrue("Expected not started", !started);
        assertTrue("Expected ended", ended);
        assertTrue("Expected returned", returned);
        transactionContext.commit();
        assertTrue("Expected committed", committed);
    }
View Full Code Here

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

        transactionContext.commit();
        assertTrue("Expected committed", committed);
    }

    public void testTransactionUnshareableConnection() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo = makeConnectionInfo();
        connectionInfo.setUnshareable(true);
        transactionEnlistingInterceptor.getConnection(connectionInfo);
        assertTrue("Expected started", started);
        assertTrue("Expected not ended", !ended);
        started = false;
        transactionEnlistingInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
        assertTrue("Expected not started", !started);
        assertTrue("Expected ended", ended);
        assertTrue("Expected returned", returned);
        transactionContext.commit();
        assertTrue("Expected committed", committed);
    }
View Full Code Here

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

        this.threadPooledTimer = threadPooledTimer;
        this.transactionContextManager = transactionContextManager;
    }

    public void run() {
        TransactionContext oldTransactionContext = transactionContextManager.getContext();
        TransactionContext transactionContext = transactionContextManager.newUnspecifiedTransactionContext();
        try {
            try {
                userTask.run();
            } catch (Exception e) {
                log.warn("Exception running task", e);
            }
            try {
                threadPooledTimer.workPerformed(workInfo);
            } catch (PersistenceException e) {
                log.warn("Exception completing task", e);
            }
            if (workInfo.isOneTime()) {
                threadPooledTimer.removeWorkInfo(workInfo);
            }
        } finally {
            try {
                transactionContext.commit();
            } catch (Exception e) {
                log.error("Unable to commit transaction context", e);
            }
            transactionContextManager.setContext(oldTransactionContext);
        }
View Full Code Here

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

        this.transactionContextManager = transactionContextManager;
        this.repeatCount = repeatCount;
    }
   
    public void run() {
        TransactionContext transactionContext = null;
        for (int tries = 0; tries < repeatCount; tries++) {
            try {
                transactionContext = transactionContextManager.newContainerTransactionContext();
            } catch (Exception e) {
                log.warn("Exception occured while starting container transaction", e);
                break;
            }
            try {
                try {
                    userTask.run();
                } catch (Exception e) {
                    log.warn("Exception occured while running user task", e);
                }
                try {
                    threadPooledTimer.workPerformed(workInfo);
                } catch (PersistenceException e) {
                    log.warn("Exception occured while updating timer persistent state", e);
                }
            } finally {
                try {
                    transactionContextManager.setContext(null);
                    if (transactionContext.commit()) {
                        if (workInfo.isOneTime()) {
                            threadPooledTimer.removeWorkInfo(workInfo);
                        }
                        // todo this is a very weird code structure.... returning from a finally is very confusing
                        return;
View Full Code Here

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

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

    void registerSynchronization(Synchronization sync) throws RollbackException, SystemException {
        TransactionContext transactionContext = transactionContextManager.getContext();
        if (transactionContext != null && transactionContext.isInheritable() && transactionContext.isActive()) {
            transactionContext.registerSynchronization(sync);
        } else {
            sync.beforeCompletion();
            sync.afterCompletion(Status.STATUS_COMMITTED);
        }
    }
View Full Code Here

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

* */
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

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

        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

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

                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

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

        this.trackedConnectionAssociator = trackedConnectionAssociator;
        this.transactionContextManager = transactionContextManager;
    }

    public Object invoke(InstanceContext newInstanceContext) throws Throwable {
        TransactionContext transactionContext = transactionContextManager.getContext();
        if (transactionContext == null) {
            transactionContextManager.newUnspecifiedTransactionContext();
        }
        try {
            InstanceContext oldInstanceContext = trackedConnectionAssociator.enter(newInstanceContext);
            try {
                return next.invoke(newInstanceContext);
            } finally {
                trackedConnectionAssociator.exit(oldInstanceContext);
            }
        } finally {
            if (transactionContext == null) {
                transactionContext = transactionContextManager.getContext();
                transactionContext.commit();
                transactionContextManager.setContext(null);
            }
        }
    }
View Full Code Here

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

        transactionContextManager = null;
        transactionCachingInterceptor = null;
    }

    public void testGetConnectionInTransaction() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo1 = makeConnectionInfo();
        transactionCachingInterceptor.getConnection(connectionInfo1);
        assertTrue("Expected to get an initial connection", obtainedConnectionInfo != null);
        assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
        assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                connectionInfo1.getManagedConnectionInfo()
                == getSharedManagedConnectionInfo(transactionContext));
        obtainedConnectionInfo = null;
        ConnectionInfo connectionInfo2 = new ConnectionInfo();
        transactionCachingInterceptor.getConnection(connectionInfo2);
        assertTrue("Expected to not get a second connection", obtainedConnectionInfo == null);
        assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
        assertTrue("Expected the same ManagedConnectionInfo in both ConnectionInfos",
                connectionInfo1.getManagedConnectionInfo() == connectionInfo2.getManagedConnectionInfo());
        assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                connectionInfo1.getManagedConnectionInfo() == getSharedManagedConnectionInfo(transactionContext));
        //commit, see if connection returned.
        //we didn't create any handles, so the "ManagedConnection" should be returned.
        assertTrue("Expected TransactionContext to report active", transactionContext.isActive());
        transactionContext.commit();
        assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
        assertTrue("Expected TransactionContext to report inactive", !transactionContext.isActive());

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.