Package org.apache.cayenne.access

Examples of org.apache.cayenne.access.Transaction


public class ServerRuntimeTest extends TestCase {

    public void testPerformInTransaction() {

        final Transaction tx = mock(Transaction.class);
        final DataDomain domain = mock(DataDomain.class);
        when(domain.createTransaction()).thenReturn(tx);

        Module module = new Module() {
View Full Code Here


@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
public class DefaultTransactionManagerTest extends ServerCase {

    public void testPerformInTransaction_NoTx() {
       
        final Transaction tx = mock(Transaction.class);
        final DataDomain domain = mock(DataDomain.class);
        when(domain.createTransaction()).thenReturn(tx);
       
        DefaultTransactionManager txManager = new DefaultTransactionManager(domain);
View Full Code Here

        assertSame(expectedResult, result);
    }

    public void testPerformInTransaction_ExistingTx() {
       
        final Transaction tx1 = mock(Transaction.class);
        final DataDomain domain = mock(DataDomain.class);
        when(domain.createTransaction()).thenReturn(tx1);
       
        DefaultTransactionManager txManager = new DefaultTransactionManager(domain);

        final Transaction tx2 = mock(Transaction.class);
        Transaction.bindThreadTransaction(tx2);
        try {

            final Object expectedResult = new Object();
            Object result = txManager.performInTransaction(new TransactionalOperation<Object>() {
View Full Code Here

    public <T> T performInTransaction(TransactionalOperation<T> op) {

        // join existing tx if it is in progress... in such case do not try to
        // commit or roll it back
        Transaction currentTx = Transaction.getThreadTransaction();
        if (currentTx != null) {
            return op.perform();
        }

        // start a new tx and manage it till the end
        Transaction tx = dataDomain.createTransaction();
        Transaction.bindThreadTransaction(tx);
        try {

            T result = op.perform();

            tx.commit();

            return result;

        } catch (Exception ex) {
            tx.setRollbackOnly();
            throw new CayenneRuntimeException(ex);
        } finally {
            Transaction.bindThreadTransaction(null);

            if (tx.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) {
                try {
                    tx.rollback();
                } catch (Exception e) {
                }
            }
        }
    }
View Full Code Here

        // TODO (andrus, 7/6/2006) Note that this will still work in a pool with a single
        // connection, as PK generator is invoked early in the transaction, before the
        // connection is grabbed for commit... So maybe promote this to other adapters in
        // 3.0?

        Transaction transaction = Transaction.getThreadTransaction();
        Transaction.bindThreadTransaction(null);

        try {

            Connection connection = node.getDataSource().getConnection();
View Full Code Here

TOP

Related Classes of org.apache.cayenne.access.Transaction

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.