Search in sources :

Example 31 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project jaybird by FirebirdSQL.

the class TestFBXAResource method testRollback2PCXATrans.

@Test
public void testRollback2PCXATrans() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    ManagedConnection mc = mcf.createManagedConnection(null, null);
    FBManagedConnection fbmc = (FBManagedConnection) mc;
    XAResource xa = mc.getXAResource();
    Xid xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    assertNotNull("no db handle after start xid", fbmc.getGDSHelper().getCurrentDatabase());
    xa.end(xid, XAResource.TMSUCCESS);
    xa.prepare(xid);
    xa.rollback(xid);
    mc.destroy();
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 32 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project jaybird by FirebirdSQL.

the class TestFBXAResource method testDo2XATrans.

@Test
public void testDo2XATrans() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    ManagedConnection mc1 = mcf.createManagedConnection(null, null);
    FBManagedConnection fbmc1 = (FBManagedConnection) mc1;
    XAResource xa1 = mc1.getXAResource();
    Xid xid1 = new XidImpl();
    xa1.start(xid1, XAResource.TMNOFLAGS);
    assertNotNull("no db handle after start xid", fbmc1.getGDSHelper().getCurrentDatabase());
    ManagedConnection mc2 = mcf.createManagedConnection(null, null);
    FBManagedConnection fbmc2 = (FBManagedConnection) mc2;
    XAResource xa2 = mc2.getXAResource();
    Xid xid2 = new XidImpl();
    xa2.start(xid2, XAResource.TMNOFLAGS);
    assertNotNull("no db handle after start xid", fbmc2.getGDSHelper().getCurrentDatabase());
    // commit each tr on other xares
    xa1.end(xid1, XAResource.TMSUCCESS);
    xa2.commit(xid1, true);
    xa2.end(xid2, XAResource.TMSUCCESS);
    xa1.commit(xid2, true);
    mc1.destroy();
    mc2.destroy();
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 33 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project activemq-artemis by apache.

the class ActiveMQRAConnectionManager method allocateConnection.

/**
 * Allocates a connection
 *
 * @param mcf           The managed connection factory
 * @param cxRequestInfo The connection request information
 * @return The connection
 * @throws ResourceException Thrown if there is a problem obtaining the connection
 */
@Override
public Object allocateConnection(final ManagedConnectionFactory mcf, final ConnectionRequestInfo cxRequestInfo) throws ResourceException {
    if (ActiveMQRAConnectionManager.trace) {
        ActiveMQRALogger.LOGGER.trace("allocateConnection(" + mcf + ", " + cxRequestInfo + ")");
    }
    ManagedConnection mc = mcf.createManagedConnection(null, cxRequestInfo);
    Object c = mc.getConnection(null, cxRequestInfo);
    if (ActiveMQRAConnectionManager.trace) {
        ActiveMQRALogger.LOGGER.trace("Allocated connection: " + c + ", with managed connection: " + mc);
    }
    connections.add(mc);
    return c;
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection)

Example 34 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project activemq-artemis by apache.

the class OutgoingConnectionTest method testConnectionCredentialsFail.

@Test
public void testConnectionCredentialsFail() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection();
    queueConnection.close();
    mc.destroy();
    try {
        queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
        queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
        fail("should throw esxception");
    } catch (JMSException e) {
    // pass
    }
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) ManagedConnection(javax.resource.spi.ManagedConnection) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) JMSException(javax.jms.JMSException) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) QueueSession(javax.jms.QueueSession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 35 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)

Aggregations

ManagedConnection (javax.resource.spi.ManagedConnection)70 Test (org.junit.Test)24 ResourceException (javax.resource.ResourceException)20 XAResource (javax.transaction.xa.XAResource)17 Iterator (java.util.Iterator)15 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 SystemException (javax.transaction.SystemException)12 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 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)6 RollbackException (javax.transaction.RollbackException)6 XAException (javax.transaction.xa.XAException)6 Connection (java.sql.Connection)5 NamingException (javax.naming.NamingException)5 ConnectionRequestInfo (javax.resource.spi.ConnectionRequestInfo)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4