Package org.apache.geronimo.transaction.context

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


        try {
            if (next != null) {
                next.after(context, httpRequest, httpResponse);
            }
        } finally {
            TransactionContext oldTransactionContext = (TransactionContext) context[oldTxIndex];
            TransactionContext newTransactionContext = (TransactionContext) context[newTxIndex];
            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) {
                            transactionContextManager.getContext().rollback();
View Full Code Here


        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

        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

        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

            }
        }
    }

    public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
        TransactionContext ctx = transactionContextManager.getContext();
        if (ctx instanceof BeanTransactionContext == false) {
            throw new IllegalStateException("Transaction has not been started");
        }
        BeanTransactionContext beanContext = (BeanTransactionContext) ctx;
        try {
View Full Code Here

            oldContext.resume();
        }
    }

    public void rollback() throws IllegalStateException, SecurityException, SystemException {
        TransactionContext ctx = transactionContextManager.getContext();
        if (ctx instanceof BeanTransactionContext == false) {
            throw new IllegalStateException("Transaction has not been started");
        }
        BeanTransactionContext beanContext = (BeanTransactionContext) ctx;
        try {
View Full Code Here

        this.next = next;
        this.transactionContextManager = transactionContextManager;
    }

    public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
        TransactionContext transactionContext = transactionContextManager.getContext();
        if (transactionContext == null) {
            next.getConnection(connectionInfo);
        } else {
        ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos) transactionContext.getManagedConnectionInfo(this);
        if (managedConnectionInfos == null) {
            managedConnectionInfos = new ManagedConnectionInfos();
            transactionContext.setManagedConnectionInfo(this, managedConnectionInfos);
        }
        if (connectionInfo.isUnshareable()) {
            if (!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo())) {
                next.getConnection(connectionInfo);
                managedConnectionInfos.addUnshared(connectionInfo.getManagedConnectionInfo());
View Full Code Here

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

        TransactionContext transactionContext = transactionContextManager.getContext();
        if (transactionContext != null && transactionContext.isActive()) {
            return;
        }
        if (connectionInfo.getManagedConnectionInfo().hasConnectionHandles()) {
            return;
        }
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

            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

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.