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();
}
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();
}
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;
}
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
}
}
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;
}
Aggregations