Search in sources :

Example 61 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.

the class DistributedManagedConnectionFactory1 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 {
    ManagedConnection result = null;
    Iterator it = connectionSet.iterator();
    while (result == null && it.hasNext()) {
        ManagedConnection mc = (ManagedConnection) it.next();
        if (mc instanceof DistributedManagedConnection1) {
            result = mc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 62 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.

the class MultipleManagedConnectionFactory2 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 MultipleManagedConnection2) {
            result = mc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 63 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.

the class HelloWorldManagedConnectionFactory 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
 * @throws  ResourceException     generic exception
 * @return  ManagedConnection if resource adapter finds an acceptable match otherwise null
 */
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    ManagedConnection result = null;
    Iterator it = connectionSet.iterator();
    while (result == null && it.hasNext()) {
        ManagedConnection mc = (ManagedConnection) it.next();
        if (mc instanceof HelloWorldManagedConnection) {
            HelloWorldManagedConnection hwmc = (HelloWorldManagedConnection) mc;
            result = hwmc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 64 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project wildfly by wildfly.

the class MultipleManagedConnectionFactory2 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 MultipleManagedConnection2) {
            result = mc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 65 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project jackrabbit by apache.

the class ConnectionFactoryTest method testMatching.

/**
 * Test the connection matching.
 */
public void testMatching() throws Exception {
    // Create connection request infos
    JCAConnectionRequestInfo cri1 = new JCAConnectionRequestInfo(JCR_SUPERUSER, JCR_WORKSPACE);
    JCAConnectionRequestInfo cri2 = new JCAConnectionRequestInfo(JCR_ANONUSER, JCR_WORKSPACE);
    // Check if not same
    assertNotSame(cri1, cri2);
    // Create the connection factory
    mcf.createConnectionFactory();
    // Allocate connections
    ManagedConnection mc1 = mcf.createManagedConnection(null, cri1);
    ManagedConnection mc2 = mcf.createManagedConnection(null, cri2);
    // Check if not same
    assertTrue(mc1 != mc2);
    // Create a sef of connections
    HashSet connectionSet = new HashSet();
    connectionSet.add(mc1);
    connectionSet.add(mc2);
    // Match the first connection
    JCAConnectionRequestInfo cri3 = new JCAConnectionRequestInfo(cri1);
    assertTrue((cri1 != cri3) && cri1.equals(cri3));
    ManagedConnection mc3 = mcf.matchManagedConnections(connectionSet, null, cri3);
    assertTrue(mc1 == mc3);
    // Match the second connection
    JCAConnectionRequestInfo cri4 = new JCAConnectionRequestInfo(cri2);
    assertTrue((cri2 != cri4) && cri2.equals(cri4));
    ManagedConnection mc4 = mcf.matchManagedConnections(connectionSet, null, cri4);
    assertTrue(mc2 == mc4);
}
Also used : JCAConnectionRequestInfo(org.apache.jackrabbit.jca.JCAConnectionRequestInfo) ManagedConnection(javax.resource.spi.ManagedConnection) HashSet(java.util.HashSet)

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