Package org.apache.openejb.core.transaction

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


        }
    }

    public Object createBean(EntityBean bean, ThreadContext callContext) throws CreateException {
        // TODO verify that extract primary key requires a flush followed by a merge
        TransactionPolicy txPolicy = startTransaction("persist", callContext);
        creating.get().add(bean);
        try {
            BeanContext beanContext = callContext.getBeanContext();
            EntityManager entityManager = getEntityManager(beanContext);
View Full Code Here


            commitTransaction("persist", callContext, txPolicy);
        }
    }

    public Object loadBean(ThreadContext callContext, Object primaryKey) {
        TransactionPolicy txPolicy = startTransaction("load", callContext);
        try {
            BeanContext beanContext = callContext.getBeanContext();
            Class<?> beanClass = beanContext.getCmpImplClass();

            // Try to load it from the entity manager
View Full Code Here

            commitTransaction("load", callContext, txPolicy);
        }
    }

    public void storeBeanIfNoTx(ThreadContext callContext, Object bean) {
        TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
        if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
            return;
        }

        TransactionPolicy txPolicy = startTransaction("store", callContext);
        try {
            // only store if we started a new transaction
            if (txPolicy.isNewTransaction()) {
                EntityManager entityManager = getEntityManager(callContext.getBeanContext());
                entityManager.merge(bean);
            }
        } finally {
            commitTransaction("store", callContext, txPolicy);
View Full Code Here

            commitTransaction("store", callContext, txPolicy);
        }
    }

    public void removeBean(ThreadContext callContext) {
        TransactionPolicy txPolicy = startTransaction("remove", callContext);
        try {
            BeanContext deploymentInfo = callContext.getBeanContext();
            Class<?> beanClass = deploymentInfo.getCmpImplClass();

            EntityManager entityManager = getEntityManager(deploymentInfo);
View Full Code Here

        }
    }

    private TransactionPolicy startTransaction(String operation, ThreadContext callContext) {
        try {
            TransactionPolicy txPolicy = createTransactionPolicy(TransactionType.Required, callContext);
            return txPolicy;
        } catch (Exception e) {
            throw new EJBException("Unable to start transaction for " + operation + " operation", e);
        }
    }
View Full Code Here

            createContext.setCurrentOperation(Operation.CREATE);
            createContext.setCurrentAllowedStates(null);

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

            Instance instance = null;
            try {
                // Create new instance
View Full Code Here

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

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

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

        try {
            // Security check
            checkAuthorization(callMethod, interfaceType);

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

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

            return instance;
        }
    }

    private Transaction getTransaction(ThreadContext callContext) {
        TransactionPolicy policy = callContext.getTransactionPolicy();

        Transaction currentTransaction = null;
        if (policy instanceof JtaTransactionPolicy) {
            JtaTransactionPolicy jtaPolicy = (JtaTransactionPolicy) policy;
View Full Code Here

        entityManagerRegistry.removeEntityManagers((String) beanContext.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 synchronize = callContext.getCurrentOperation() != Operation.CREATE &&
                callContext.getBeanContext().isSessionSynchronized() &&
                txPolicy.isTransactionActive();

        coordinator.registerSessionSynchronization(instance, callContext.getBeanContext(), callContext.getPrimaryKey(), synchronize);
    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.core.transaction.TransactionPolicy

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.