use of javax.resource.spi.ManagedConnection in project Payara by payara.
the class PoolManagerImpl method getResource.
// invoked by DataSource objects to obtain a connection
public Object getResource(ResourceSpec spec, ResourceAllocator alloc, ClientSecurityInfo info) throws PoolingException, RetryableUnavailableException {
Transaction tran = null;
boolean transactional = alloc.isTransactional();
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) {
// 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;
}
}
// 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 throw the resource away
putbackBadResourceToPool(handle);
_logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn", spec.getPoolInfo());
logFine("rm.enlistResource threw Exception. Evicting resource from pool");
// and rethrow the exception
throw new PoolingException(e);
}
return handle.getUserConnection();
}
use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.
the class AnnoManagedConnectionFactory method matchManagedConnections.
/**
* Returns a matched connection from the candidate set of connections.
*
* @param connectionSet Candidate connection set
* @param subject Caller's security information
* @param cxRequestInfo Additional resource adapter specific connection request
* information
* @return ManagedConnection if resource adapter finds an acceptable match
* otherwise null
* @throws ResourceException generic exception
*/
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
log.trace("matchManagedConnections()");
ManagedConnection result = null;
Iterator it = connectionSet.iterator();
while (result == null && it.hasNext()) {
ManagedConnection mc = (ManagedConnection) it.next();
if (mc instanceof AnnoManagedConnection) {
result = mc;
}
}
return result;
}
use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.
the class LazyManagedConnectionFactory method matchManagedConnections.
@Override
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
logger.trace("#LazyManagedConnectionFactory.matchManagedConnections");
ManagedConnection result = null;
Iterator it = connectionSet.iterator();
while (result == null && it.hasNext()) {
ManagedConnection mc = (ManagedConnection) it.next();
if (mc instanceof LazyManagedConnection) {
result = mc;
}
}
return result;
}
Aggregations