Search in sources :

Example 71 with ManagedConnection

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();
}
Also used : PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) Transaction(javax.transaction.Transaction) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) InvocationException(org.glassfish.api.invocation.InvocationException) RetryableUnavailableException(javax.resource.spi.RetryableUnavailableException)

Example 72 with ManagedConnection

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;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 73 with ManagedConnection

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;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Aggregations

ManagedConnection (javax.resource.spi.ManagedConnection)73 Test (org.junit.Test)24 ResourceException (javax.resource.ResourceException)20 XAResource (javax.transaction.xa.XAResource)17 Iterator (java.util.Iterator)16 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)13 SystemException (javax.transaction.SystemException)11 Subject (javax.security.auth.Subject)10 Xid (javax.transaction.xa.Xid)9 HashSet (java.util.HashSet)8 Transaction (javax.transaction.Transaction)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)6 RollbackException (javax.transaction.RollbackException)6 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)5 Connection (java.sql.Connection)5 NamingException (javax.naming.NamingException)5 ConnectionRequestInfo (javax.resource.spi.ConnectionRequestInfo)5 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)5 XAException (javax.transaction.xa.XAException)5 ArrayList (java.util.ArrayList)4