Search in sources :

Example 46 with ManagedConnection

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

the class TestFBXAResource method testStartXATrans.

@Test
public void testStartXATrans() 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.commit(xid, true);
    mc.destroy();
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 47 with ManagedConnection

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

the class TestFBXAResource method test2PCXATrans.

@Test
public void test2PCXATrans() 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.commit(xid, false);
    mc.destroy();
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 48 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project camunda-bpm-platform by camunda.

the class JcaExecutorServiceManagedConnectionFactory method matchManagedConnections.

@SuppressWarnings("rawtypes")
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 JcaExecutorServiceManagedConnection) {
            result = mc;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 49 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class JdbcAdminServiceImpl method getValidationTableNames.

/**
 * Get Validation table names list for the database that the jdbc
 * connection pool refers to. This is used for connection validation.
 * @param poolInfo
 * @return all validation table names.
 * @throws javax.resource.ResourceException
 * @throws javax.naming.NamingException
 */
public Set<String> getValidationTableNames(PoolInfo poolInfo) throws ResourceException {
    ManagedConnectionFactory mcf = null;
    ManagedConnection mc = null;
    java.sql.Connection con = null;
    try {
        mc = (ManagedConnection) ccPoolAdmService.getUnpooledConnection(poolInfo, null, false);
        mcf = ccPoolAdmService.obtainManagedConnectionFactory(poolInfo);
        if (mc != null) {
            con = (java.sql.Connection) mc.getConnection(null, null);
        }
        return getValidationTableNames(con, getDefaultDatabaseName(poolInfo, mcf));
    } catch (Exception re) {
        _logger.log(Level.WARNING, "pool.get_validation_table_names_failure", re.getMessage());
        throw new ResourceException(re);
    } finally {
        try {
            if (mc != null) {
                mc.destroy();
            }
        } catch (Exception ex) {
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, "pool.get_validation_table_names_mc_destroy", poolInfo);
            }
        }
    }
}
Also used : ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 50 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project Payara by payara.

the class JdbcRecoveryResourceHandler method closeConnections.

/**
 * {@inheritDoc}
 */
@Override
public void closeConnections(List connList) {
    for (Object obj : connList) {
        try {
            ManagedConnection con = (ManagedConnection) obj;
            con.destroy();
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "recovery.jdbc-resource.destroy-error", ex);
        }
    }
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException)

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