Search in sources :

Example 1 with SimpleTransactionSynchronizationRegistry

use of org.apache.openejb.core.SimpleTransactionSynchronizationRegistry in project tomee by apache.

the class Assembler method createTransactionManager.

public void createTransactionManager(final TransactionServiceInfo serviceInfo) throws OpenEJBException {
    Object service = SystemInstance.get().getComponent(TransactionManager.class);
    if (service == null) {
        final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
        service = serviceRecipe.create();
        logUnusedProperties(serviceRecipe, serviceInfo);
    } else {
        logger.info("Reusing provided TransactionManager " + service);
    }
    final Class interfce = serviceInterfaces.get(serviceInfo.service);
    checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);
    try {
        this.containerSystem.getJNDIContext().bind(JAVA_OPENEJB_NAMING_CONTEXT + serviceInfo.service, service);
        this.containerSystem.getJNDIContext().bind("comp/UserTransaction", new CoreUserTransaction((TransactionManager) service));
        this.containerSystem.getJNDIContext().bind("comp/TransactionManager", service);
    } catch (final NamingException e) {
        throw new OpenEJBException("Cannot bind " + serviceInfo.service + " with id " + serviceInfo.id, e);
    }
    setSystemInstanceComponent(interfce, service);
    getContext().put(interfce.getName(), service);
    props.put(interfce.getName(), service);
    props.put(serviceInfo.service, service);
    props.put(serviceInfo.id, service);
    this.transactionManager = (TransactionManager) service;
    // Update the config tree
    config.facilities.transactionService = serviceInfo;
    // todo find a better place for this
    // TransactionSynchronizationRegistry
    final TransactionSynchronizationRegistry synchronizationRegistry;
    if (transactionManager instanceof TransactionSynchronizationRegistry) {
        synchronizationRegistry = (TransactionSynchronizationRegistry) transactionManager;
    } else {
        // todo this should be built
        synchronizationRegistry = new SimpleTransactionSynchronizationRegistry(transactionManager);
    }
    Assembler.getContext().put(TransactionSynchronizationRegistry.class.getName(), synchronizationRegistry);
    SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, synchronizationRegistry);
    try {
        this.containerSystem.getJNDIContext().bind("comp/TransactionSynchronizationRegistry", new TransactionSynchronizationRegistryWrapper());
    } catch (final NamingException e) {
        throw new OpenEJBException("Cannot bind java:comp/TransactionSynchronizationRegistry", e);
    }
    // JtaEntityManagerRegistry
    // todo this should be built
    final JtaEntityManagerRegistry jtaEntityManagerRegistry = new JtaEntityManagerRegistry(synchronizationRegistry);
    Assembler.getContext().put(JtaEntityManagerRegistry.class.getName(), jtaEntityManagerRegistry);
    SystemInstance.get().setComponent(JtaEntityManagerRegistry.class, jtaEntityManagerRegistry);
    logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) JtaEntityManagerRegistry(org.apache.openejb.persistence.JtaEntityManagerRegistry) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) TransactionManager(javax.transaction.TransactionManager) SimpleTransactionSynchronizationRegistry(org.apache.openejb.core.SimpleTransactionSynchronizationRegistry) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) CoreUserTransaction(org.apache.openejb.core.CoreUserTransaction) NamingException(javax.naming.NamingException) SimpleTransactionSynchronizationRegistry(org.apache.openejb.core.SimpleTransactionSynchronizationRegistry) TransactionSynchronizationRegistryWrapper(org.apache.openejb.core.TransactionSynchronizationRegistryWrapper)

Aggregations

NamingException (javax.naming.NamingException)1 TransactionManager (javax.transaction.TransactionManager)1 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)1 GeronimoTransactionManager (org.apache.geronimo.transaction.manager.GeronimoTransactionManager)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 CoreUserTransaction (org.apache.openejb.core.CoreUserTransaction)1 SimpleTransactionSynchronizationRegistry (org.apache.openejb.core.SimpleTransactionSynchronizationRegistry)1 TransactionSynchronizationRegistryWrapper (org.apache.openejb.core.TransactionSynchronizationRegistryWrapper)1 JtaEntityManagerRegistry (org.apache.openejb.persistence.JtaEntityManagerRegistry)1 ObjectRecipe (org.apache.xbean.recipe.ObjectRecipe)1