Search in sources :

Example 26 with ManagedConnection

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

the class TestFBConnection method testAssociateC.

@Test
public void testAssociateC() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    ManagedConnection mc1 = mcf.createManagedConnection(null, null);
    Connection c1 = (Connection) mc1.getConnection(null, null);
    ManagedConnection mc2 = mcf.createManagedConnection(null, null);
    Connection c2 = (Connection) mc2.getConnection(null, null);
    mc1.associateConnection(c2);
    mc2.associateConnection(c1);
    mc1.destroy();
    mc2.destroy();
}
Also used : Connection(java.sql.Connection) ManagedConnection(javax.resource.spi.ManagedConnection) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 27 with ManagedConnection

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

the class TestFBConnection method testCreateC.

@Test
public void testCreateC() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    assertNotNull("Could not get FBManagedConnectionFactory", mcf);
    ManagedConnection mc = mcf.createManagedConnection(null, null);
    assertNotNull("Could not get ManagedConnection", mc);
    Connection c = (Connection) mc.getConnection(null, null);
    assertNotNull("Could not get Connection", c);
    mc.destroy();
}
Also used : Connection(java.sql.Connection) ManagedConnection(javax.resource.spi.ManagedConnection) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 28 with ManagedConnection

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

the class TestFBResultSet method testUseResultSetMore.

@Test
public void testUseResultSetMore() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    ManagedConnection mc = mcf.createManagedConnection(null, null);
    Connection c = (Connection) mc.getConnection(null, null);
    Statement s = c.createStatement();
    XAResource xa = mc.getXAResource();
    Exception ex = null;
    Xid xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    try {
        s.execute("CREATE TABLE T1 ( C1 INTEGER not null primary key, C2 SMALLINT, C3 DECIMAL(18,0), C4 FLOAT, C5 DOUBLE PRECISION, C6 CHAR(10), C7 VARCHAR(20), C8 TIME, C9 DATE, C10 TIMESTAMP)");
    } catch (Exception e) {
        ex = e;
    }
    xa.end(xid, XAResource.TMSUCCESS);
    xa.commit(xid, true);
    xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    assertFalse("execute returned true for insert statement", s.execute("insert into T1 values (1, 1, 1, 1.0, 1.0, 'one', 'one', '8:00:03.1234', '2002-JAN-11', '2001-JAN-6:8:00:03.1223')"));
    assertTrue("execute returned false for select statement", s.execute("select C1, C2, C3,  C4, C5, C6, C7, C8, C9, C10 from T1"));
    ResultSet rs = s.getResultSet();
    while (rs.next()) {
        if (log != null)
            log.info("C1: " + rs.getInt(1) + " C2: " + rs.getShort(2) + " C3: " + rs.getLong(3) + " C4: " + rs.getFloat(4) + " C5: " + rs.getDouble(5) + " C6: " + rs.getString(6) + " C7: " + rs.getString(7) + " C8: " + rs.getTime(8) + " C9: " + rs.getDate(9) + " C10: " + rs.getTimestamp(10));
        if (log != null)
            log.info("C1: " + rs.getInt("C1") + " C2: " + rs.getShort("C2") + " C3: " + rs.getLong("C3") + " C4: " + rs.getFloat("C4") + " C5: " + rs.getDouble("C5") + " C6: " + rs.getString("C6") + " C7: " + rs.getString("C7"));
    }
    rs.close();
    xa.end(xid, XAResource.TMSUCCESS);
    xa.commit(xid, true);
    xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    s.execute("DROP TABLE T1");
    s.close();
    xa.end(xid, XAResource.TMSUCCESS);
    xa.commit(xid, true);
    mc.destroy();
    if (ex != null) {
        throw ex;
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ManagedConnection(javax.resource.spi.ManagedConnection) FBConnection(org.firebirdsql.jdbc.FBConnection) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 29 with ManagedConnection

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

the class TestFBResultSet method testUseResultSet.

@Test
public void testUseResultSet() throws Exception {
    FBManagedConnectionFactory mcf = initMcf();
    ManagedConnection mc = mcf.createManagedConnection(null, null);
    Connection c = (Connection) mc.getConnection(null, null);
    Statement s = c.createStatement();
    XAResource xa = mc.getXAResource();
    Exception ex = null;
    Xid xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    try {
        s.execute("CREATE TABLE T1 ( C1 SMALLINT, C2 SMALLINT)");
    } catch (Exception e) {
        ex = e;
    }
    xa.end(xid, XAResource.TMSUCCESS);
    xa.commit(xid, true);
    xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    assertFalse("execute returned true for insert statement", s.execute("insert into T1 values (1, 1)"));
    assertEquals("executeUpdate did not return 1 for single row insert", 1, s.executeUpdate("insert into T1 values (2, 2)"));
    assertTrue("execute returned false for select statement", s.execute("select C1, C2 from T1"));
    ResultSet rs = s.getResultSet();
    while (rs.next()) {
        if (log != null)
            log.info("C1: " + rs.getShort(1) + " C2: " + rs.getShort(2));
    }
    rs.close();
    xa.end(xid, XAResource.TMSUCCESS);
    xa.commit(xid, true);
    xid = new XidImpl();
    xa.start(xid, XAResource.TMNOFLAGS);
    s.execute("DROP TABLE T1");
    s.close();
    xa.end(xid, XAResource.TMSUCCESS);
    xa.commit(xid, true);
    mc.destroy();
    if (ex != null) {
        throw ex;
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ManagedConnection(javax.resource.spi.ManagedConnection) FBConnection(org.firebirdsql.jdbc.FBConnection) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

Example 30 with ManagedConnection

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

the class TestFBXAResource method testIsSameRM.

@Test
public void testIsSameRM() throws Exception {
    FBManagedConnectionFactory mcf1 = initMcf();
    ManagedConnection mc1 = mcf1.createManagedConnection(null, null);
    XAResource xa1 = mc1.getXAResource();
    ManagedConnection mc2 = mcf1.createManagedConnection(null, null);
    XAResource xa2 = mc2.getXAResource();
    FBManagedConnectionFactory mcf3 = initMcf();
    ManagedConnection mc3 = mcf3.createManagedConnection(null, null);
    XAResource xa3 = mc3.getXAResource();
    if (xa1.isSameRM(xa2)) {
        fail("isSameRM reports no difference from same mcf");
    }
    if (xa1.isSameRM(xa3)) {
        fail("isSameRM reports no difference from different mcf");
    }
    mc1.destroy();
    mc2.destroy();
    mc3.destroy();
}
Also used : XAResource(javax.transaction.xa.XAResource) ManagedConnection(javax.resource.spi.ManagedConnection) Test(org.junit.Test)

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