if (transactional) {
tran = getResourceManager(spec).getTransaction();
}
ResourceHandle handle =
getResourceFromPool(spec, alloc, info, tran);
if (!handle.supportsLazyAssociation()) {
spec.setLazyAssociatable(false);
}
if (spec.isLazyAssociatable() &&
spec.getConnectionToAssociate() != null) {
//If getConnectionToAssociate returns a connection that means
//we need to associate a new connection with it
try {
Object connection = spec.getConnectionToAssociate();
ManagedConnection dmc
= (ManagedConnection) handle.getResource();
dmc.associateConnection(connection);
} catch (ResourceException e) {
putbackDirectToPool(handle, spec.getPoolInfo());
PoolingException pe = new PoolingException(
e.getMessage());
pe.initCause(e);
throw pe;
}
}
//If the ResourceAdapter does not support lazy enlistment
//we cannot either
if (!handle.supportsLazyEnlistment()) {
spec.setLazyEnlistable(false);
}
handle.setResourceSpec(spec);
try {
if (handle.getResourceState().isUnenlisted()) {
//The spec being used here is the spec with the updated
//lazy enlistment info
//Here's the real place where we care about the correct
//resource manager (which in turn depends upon the ResourceSpec)
//and that's because if lazy enlistment needs to be done
//we need to get the LazyEnlistableResourceManager
getResourceManager(spec).enlistResource(handle);
}
} catch (Exception e) {
//In the rare cases where enlistResource throws exception, we
//should return the resource to the pool
putbackDirectToPool(handle, spec.getPoolInfo());
_logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn",
spec.getPoolInfo());
logFine("rm.enlistResource threw Exception. Returning resource to pool");
//and rethrow the exception
throw new PoolingException(e);
}
return handle.getUserConnection();
}