use of org.apache.openejb.core.CoreUserTransaction 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);
}
use of org.apache.openejb.core.CoreUserTransaction 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);
}
}
Aggregations