Examples of TransactionPolicy


Examples of org.apache.openejb.core.transaction.TransactionPolicy

            if (di.isBeanManagedTransaction()) {
                throw new IllegalStateException("bean-managed transaction beans can not access the setRollbackOnly() method");
            }

            TransactionPolicy txPolicy = threadContext.getTransactionPolicy();
            if (txPolicy == null) {
                throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
            }
            if (!txPolicy.isTransactionActive()) {
                // this would be true for Supports tx attribute where no tx was propagated
                throw new IllegalStateException("No current transaction");
            }
            txPolicy.setRollbackOnly();
        }
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

            if (di.isBeanManagedTransaction()) {
                throw new IllegalStateException("bean-managed transaction beans can not access the getRollbackOnly() method: deploymentId=" + di.getDeploymentID());
            }

            TransactionPolicy transactionPolicy = threadContext.getTransactionPolicy();
            if (transactionPolicy == null) {
                throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
            }
            if (!transactionPolicy.isTransactionActive()) {
                // this would be true for Supports tx attribute where no tx was propagated
                throw new IllegalStateException("No current transaction");
            }
            return transactionPolicy.isRollbackOnly();
        }
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

        return instanceManager;
    }

    protected Object invoke(Method callMethod, Method runMethod, Object [] args, ThreadContext callContext) throws OpenEJBException {
        CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
        TransactionPolicy txPolicy = createTransactionPolicy(deploymentInfo.getTransactionType(callMethod), callContext);

        EntityBean bean = null;

        Object returnValue = null;
        entrancyTracker.enter(callContext.getDeploymentInfo(), callContext.getPrimaryKey());
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

    public void ejbLoad_If_No_Transaction(ThreadContext callContext, EntityBean bean) throws Exception {
        Operation orginalOperation = callContext.getCurrentOperation();
        BaseContext.State[] originalAllowedStates = callContext.getCurrentAllowedStates();
        if (orginalOperation == Operation.BUSINESS || orginalOperation == Operation.REMOVE) {

            TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
            if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
                return;
            }

            CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
            TransactionPolicy txPolicy = deploymentInfo.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
            try {
                // double check we don't have an active transaction
                if (!txPolicy.isTransactionActive()) {
                    callContext.setCurrentOperation(Operation.LOAD);
                    callContext.setCurrentAllowedStates(EntityContext.getStates());
                    bean.ejbLoad();
                }
            } catch (NoSuchEntityException e) {
                instanceManager.discardInstance(callContext, bean);
                throw new ApplicationException(new NoSuchObjectException("Entity not found: " + callContext.getPrimaryKey())/*.initCause(e)*/);
            } catch (Exception e) {
                instanceManager.discardInstance(callContext, bean);
                throw e;
            } finally {
                callContext.setCurrentOperation(orginalOperation);
                callContext.setCurrentAllowedStates(originalAllowedStates);
                txPolicy.commit();
            }

        }
    }
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

    public void ejbStore_If_No_Transaction(ThreadContext callContext, EntityBean bean) throws Exception {
        Operation currentOp = callContext.getCurrentOperation();
        BaseContext.State[] originalAllowedStates = callContext.getCurrentAllowedStates();
        if (currentOp == Operation.BUSINESS) {

            TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
            if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
                return;
            }

            CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
            TransactionPolicy txPolicy = deploymentInfo.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
            try {
                // double check we don't have an active transaction
                if (!txPolicy.isTransactionActive()) {
                    callContext.setCurrentOperation(Operation.STORE);
                    callContext.setCurrentAllowedStates(EntityContext.getStates());
                    bean.ejbStore();
                }
            } catch (Exception e) {
                instanceManager.discardInstance(callContext, bean);
                throw e;
            } finally {
                callContext.setCurrentOperation(currentOp);
                callContext.setCurrentAllowedStates(originalAllowedStates);
                txPolicy.commit();
            }
        }
    }
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

                    throw new EJBException(e);
                }
            }

            // Start transaction
            TransactionPolicy txPolicy = createTransactionPolicy(createContext.getDeploymentInfo().getTransactionType(callMethod), createContext);

            Instance instance = null;
            try {
                // Create new instance
                instance = newInstance(primaryKey, deploymentInfo.getBeanClass(), entityManagers);
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

                    throw new ApplicationException(new RemoveException("A stateful EJB enrolled in a bean-managed transaction can not be removed"));
                }
            }

            // Start transaction
            TransactionPolicy txPolicy = createTransactionPolicy(callContext.getDeploymentInfo().getTransactionType(callMethod), callContext);

            Object returnValue = null;
            boolean retain = false;
            Instance instance = null;
            Method runMethod = null;
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

        try {
            // Security check
            checkAuthorization(deploymentInfo, callMethod, callInterface);

            // Start transaction
            TransactionPolicy txPolicy = createTransactionPolicy(callContext.getDeploymentInfo().getTransactionType(callMethod), callContext);

            Object returnValue = null;
            Instance instance = null;
            try {
                // Obtain instance
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

        entityManagerRegistry.removeEntityManagers((String) deploymentInfo.getDeploymentID(), instance.primaryKey);
    }


    private void registerSessionSynchronization(Instance instance, ThreadContext callContext)  {
        TransactionPolicy txPolicy = callContext.getTransactionPolicy();
        if (txPolicy == null) {
            throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
        }

        SessionSynchronizationCoordinator coordinator = (SessionSynchronizationCoordinator) txPolicy.getResource(SessionSynchronizationCoordinator.class);
        if (coordinator == null) {
            coordinator = new SessionSynchronizationCoordinator(txPolicy);
            txPolicy.registerSynchronization(coordinator);
            txPolicy.putResource(SessionSynchronizationCoordinator.class, coordinator);
        }

        // SessionSynchronization are only enabled for beans after CREATE that are not bean-managed and implement the SessionSynchronization interface
        boolean sessionSynchronization = callContext.getCurrentOperation() != Operation.CREATE &&
                callContext.getDeploymentInfo().isBeanManagedTransaction() &&
                instance.bean instanceof SessionSynchronization &&
                txPolicy.isTransactionActive();

        coordinator.registerSessionSynchronization(instance, callContext.getDeploymentInfo(), callContext.getPrimaryKey(), sessionSynchronization);
    }
View Full Code Here

Examples of org.apache.openejb.core.transaction.TransactionPolicy

        * the TransactionScopeManager would attempt to commit the transaction immediately after the ejbCreate
        * and before the ejbPostCreate had a chance to execute.  Once the ejbPostCreate method execute the
        * super classes afterInvoke( ) method will be executed committing the transaction if its a CMT.
        */

        TransactionPolicy txPolicy = createTransactionPolicy(deploymentInfo.getTransactionType(callMethod), callContext);

        EntityBean bean = null;
        Object primaryKey = null;
        try {
            // Get new ready instance
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.