Search in sources :

Example 1 with TransactionSynchronizationRegistryWrapper

use of org.apache.openejb.core.TransactionSynchronizationRegistryWrapper 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)

Example 2 with TransactionSynchronizationRegistryWrapper

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

the class JndiEncBuilder method addSpecialCompBindings.

private void addSpecialCompBindings(final Map<String, Object> bindings) {
    // bind TransactionManager
    final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
    bindings.put("comp/TransactionManager", transactionManager);
    // bind TransactionSynchronizationRegistry
    bindings.put("comp/TransactionSynchronizationRegistry", new TransactionSynchronizationRegistryWrapper());
    try {
        bindings.put("comp/ORB", new SystemComponentReference(ParentClassLoaderFinder.Helper.get().loadClass("org.omg.CORBA.ORB")));
    } catch (final NoClassDefFoundError | ClassNotFoundException e) {
    // no corba, who does recall what it is today anyway :D
    }
    bindings.put("comp/HandleDelegate", new SystemComponentReference(HandleDelegate.class));
    // bind bean validation objects
    bindings.put("comp/ValidatorFactory", new IntraVmJndiReference(Assembler.VALIDATOR_FACTORY_NAMING_CONTEXT + uniqueId));
    bindings.put("comp/Validator", new IntraVmJndiReference(Assembler.VALIDATOR_NAMING_CONTEXT + uniqueId));
    // bind UserTransaction if bean managed transactions
    if (beanManagedTransactions) {
        final UserTransaction userTransaction = new CoreUserTransaction(transactionManager);
        bindings.put("comp/UserTransaction", userTransaction);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) CoreUserTransaction(org.apache.openejb.core.CoreUserTransaction) HandleDelegate(javax.ejb.spi.HandleDelegate) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) TransactionManager(javax.transaction.TransactionManager) CoreUserTransaction(org.apache.openejb.core.CoreUserTransaction) TransactionSynchronizationRegistryWrapper(org.apache.openejb.core.TransactionSynchronizationRegistryWrapper) SystemComponentReference(org.apache.openejb.core.ivm.naming.SystemComponentReference)

Aggregations

TransactionManager (javax.transaction.TransactionManager)2 CoreUserTransaction (org.apache.openejb.core.CoreUserTransaction)2 TransactionSynchronizationRegistryWrapper (org.apache.openejb.core.TransactionSynchronizationRegistryWrapper)2 HandleDelegate (javax.ejb.spi.HandleDelegate)1 NamingException (javax.naming.NamingException)1 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)1 UserTransaction (javax.transaction.UserTransaction)1 GeronimoTransactionManager (org.apache.geronimo.transaction.manager.GeronimoTransactionManager)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 SimpleTransactionSynchronizationRegistry (org.apache.openejb.core.SimpleTransactionSynchronizationRegistry)1 IntraVmJndiReference (org.apache.openejb.core.ivm.naming.IntraVmJndiReference)1 SystemComponentReference (org.apache.openejb.core.ivm.naming.SystemComponentReference)1 JtaEntityManagerRegistry (org.apache.openejb.persistence.JtaEntityManagerRegistry)1 ObjectRecipe (org.apache.xbean.recipe.ObjectRecipe)1