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