transactionManager = (TransactionManager) props.get(TransactionManager.class.getName());
}
public Object allocateConnection(ManagedConnectionFactory factory, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
ConnectionCache connectionCache = null;
ManagedConnection conn = null;
if (!(factory instanceof JdbcManagedConnectionFactory) || !((JdbcManagedConnectionFactory) factory).isUnmanaged()) {
connectionCache = threadConnectionCache.get();
conn = connectionCache.getConnection(factory);
}
if (conn == null) {
conn = factory.matchManagedConnections(connSet, null, cxRequestInfo);
if (conn != null) {
connSet.remove(conn);
} else {
conn = factory.createManagedConnection(null, cxRequestInfo);
conn.addConnectionEventListener(this);
}
conn.getLocalTransaction().begin();
try {
/*
* The transaction manager has a wrapper that ensures that any Synchronization
* objects are handled after the EntityBean.ejbStore and SessionSynchronization methods of beans.
* In the StatefulContainer and EntityContainer enterprise beans are wrapped
* Synchronization wrappers, which must be handled
* before the LocalTransaction objects in this connection manager.
*/
Transaction tx = getTransactionManager().getTransaction();
if (tx != null) {
tx.registerSynchronization(new Synchronizer(conn.getLocalTransaction()));
}
} catch (SystemException se) {
throw new ApplicationServerInternalException("Can not obtain a Transaction object from TransactionManager. " + se.getMessage(), se);
} catch (RollbackException re) {
throw new ApplicationServerInternalException("Can not register org.apache.openejb.resource.LocalTransacton with transaciton manager. Transaction has already been rolled back" + re.getMessage(), re);
}
if (connectionCache != null) {
connectionCache.putConnection(factory, conn);
}
}
Object handle = conn.getConnection(null, cxRequestInfo);
return handle;
}