Package org.apache.geronimo.transaction.context

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


        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

        startLatch.release();
        //Implementation note: we assume this is being called without an interesting TransactionContext,
        //and ignore/replace whatever is associated with the current thread.
        try {
            if (executionContext == null || executionContext.getXid() == null) {
                TransactionContext context = transactionContextManager.newUnspecifiedTransactionContext();
                try {
                    adaptee.run();
                } finally {
                    TransactionContext returningContext = transactionContextManager.getContext();
                    transactionContextManager.setContext(null);
                    if (context != returningContext) {
                        throw new WorkCompletedException("Wrong TransactionContext on return from work done");
                    }
                }
View Full Code Here

        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

        assertTrue("Expected TransactionContext to report inactive", !transactionContext.isActive());

    }

    public void testGetUnshareableConnectionsInTransaction() throws Exception {
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo1 = makeConnectionInfo();
        connectionInfo1.setUnshareable(true);
        transactionCachingInterceptor.getConnection(connectionInfo1);
        assertTrue("Expected to get an initial connection", obtainedConnectionInfo != null);
        assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
        assertTrue("Expected different ManagedConnectionInfo in the TransactionContext as was returned",
                connectionInfo1.getManagedConnectionInfo()
                != getSharedManagedConnectionInfo(transactionContext));
        //2nd is shared, modelling a call into another ejb
        obtainedConnectionInfo = null;
        ConnectionInfo connectionInfo2 = makeConnectionInfo();
        transactionCachingInterceptor.getConnection(connectionInfo2);
        assertTrue("Expected to 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",
                connectionInfo2.getManagedConnectionInfo() == getSharedManagedConnectionInfo(transactionContext));
        //3rd is unshared, modelling a call into a third ejb
        obtainedConnectionInfo = null;
        ConnectionInfo connectionInfo3 = makeConnectionInfo();
        connectionInfo3.setUnshareable(true);
        transactionCachingInterceptor.getConnection(connectionInfo3);
        assertTrue("Expected to get a third connection", obtainedConnectionInfo != null);
        assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
        assertTrue("Expected different ManagedConnectionInfo in both unshared ConnectionInfos",
                connectionInfo1.getManagedConnectionInfo() != connectionInfo3.getManagedConnectionInfo());
        assertTrue("Expected different ManagedConnectionInfo in the TransactionContext as was returned",
                connectionInfo3.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

        transactionCachingInterceptor.returnConnection(connectionInfo2, ConnectionReturnAction.RETURN_HANDLE);
        assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
    }

    public void testTransactionIndependence() throws Exception {
        TransactionContext transactionContext1 = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo1 = makeConnectionInfo();
        transactionCachingInterceptor.getConnection(connectionInfo1);
        obtainedConnectionInfo = null;

        //start a second transaction
        transactionContext1.suspend();
        TransactionContext transactionContext2 = transactionContextManager.newContainerTransactionContext();
        ConnectionInfo connectionInfo2 = makeConnectionInfo();
        transactionCachingInterceptor.getConnection(connectionInfo2);
        assertTrue("Expected to get a second connection", obtainedConnectionInfo != null);
        assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
        assertTrue("Expected different ManagedConnectionInfo in each ConnectionInfos",
                connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
        assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                connectionInfo2.getManagedConnectionInfo() == getSharedManagedConnectionInfo(transactionContext2));
        //commit 2nd transaction, see if connection returned.
        //we didn't create any handles, so the "ManagedConnection" should be returned.
        assertTrue("Expected TransactionContext to report active", transactionContext2.isActive());
        transactionContext2.commit();
        assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
        assertTrue("Expected TransactionContext to report inactive", !transactionContext2.isActive());
        returnedConnectionInfo = null;
        //resume first transaction
        transactionContext1.resume();
        transactionContext1.commit();
        assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
View Full Code Here

    }

    public void before(Object[] context, ServletRequest httpRequest,
            ServletResponse httpResponse) {
        TransactionContextHolder tch = new TransactionContextHolder();
        TransactionContext oldTransactionContext = transactionContextManager
                .getContext();
        TransactionContext newTransactionContext = null;
        if (oldTransactionContext == null
                || !oldTransactionContext.isInheritable()) {
            newTransactionContext = transactionContextManager
                    .newUnspecifiedTransactionContext();
        }
View Full Code Here

            if (next != null) {
                next.after(context, httpRequest, httpResponse);
            }
        } finally {
            TransactionContextHolder tch = (TransactionContextHolder) context[txIndex];
            TransactionContext oldTransactionContext = tch.getOldContext();
            TransactionContext newTransactionContext = tch.getNewContext();
            try {
                if (newTransactionContext != null) {
                    if (newTransactionContext != transactionContextManager
                            .getContext()) {
                        transactionContextManager.getContext().rollback();
                        newTransactionContext.rollback();
                        throw new RuntimeException(
                                "WRONG EXCEPTION! returned from servlet call with wrong tx context");
                    }
                    newTransactionContext.commit();

                } else {
                    if (oldTransactionContext != transactionContextManager
                            .getContext()) {
                        if (transactionContextManager.getContext() != null) {
View Full Code Here

        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

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.