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);
}
Aggregations