Search in sources :

Example 1 with XidImpl

use of org.firebirdsql.jaybird.xca.TestXABase.XidImpl in project jaybird by FirebirdSQL.

the class TestFBXADataSource method testInDistributed_rollback.

/**
 * Test if calling rollback throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
 */
@Test
public void testInDistributed_rollback() throws Exception {
    XAConnection pc = getXAConnection();
    XAResource xa = pc.getXAResource();
    Xid xid = new XidImpl();
    try (Connection con = pc.getConnection()) {
        con.setAutoCommit(false);
        xa.start(xid, XAResource.TMNOFLAGS);
        expectedException.expect(SQLException.class);
        expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
        con.rollback();
    } finally {
        xa.end(xid, XAResource.TMSUCCESS);
        xa.rollback(xid);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TestFBXAResource(org.firebirdsql.jaybird.xca.TestFBXAResource) Xid(javax.transaction.xa.Xid) XidImpl(org.firebirdsql.jaybird.xca.TestXABase.XidImpl) XAConnection(javax.sql.XAConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) XAConnection(javax.sql.XAConnection)

Example 2 with XidImpl

use of org.firebirdsql.jaybird.xca.TestXABase.XidImpl in project jaybird by FirebirdSQL.

the class TestFBXADataSource method testInDistributed_rollback_savepoint.

/**
 * Test if calling rollback for savepoint throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
 */
@Test
public void testInDistributed_rollback_savepoint() throws Exception {
    XAConnection pc = getXAConnection();
    XAResource xa = pc.getXAResource();
    try (Connection con = pc.getConnection()) {
        assumeTrue("Test requires SAVEPOINT support", supportInfoFor(con).supportsSavepoint());
        Xid xid = new XidImpl();
        try {
            con.setAutoCommit(false);
            // Just to create one
            Savepoint savepoint = con.setSavepoint();
            // Required to make sure start() works.
            con.rollback();
            xa.start(xid, XAResource.TMNOFLAGS);
            expectedException.expect(SQLException.class);
            expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
            con.rollback(savepoint);
        } finally {
            xa.end(xid, XAResource.TMSUCCESS);
            xa.rollback(xid);
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TestFBXAResource(org.firebirdsql.jaybird.xca.TestFBXAResource) Xid(javax.transaction.xa.Xid) XidImpl(org.firebirdsql.jaybird.xca.TestXABase.XidImpl) XAConnection(javax.sql.XAConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) XAConnection(javax.sql.XAConnection)

Example 3 with XidImpl

use of org.firebirdsql.jaybird.xca.TestXABase.XidImpl in project jaybird by FirebirdSQL.

the class TestFBXADataSource method testInDistributed_setAutoCommit_true_notInAutoCommit.

/**
 * Tests if setting autoCommit(true) when autoCommit is false throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
 */
@Test
public void testInDistributed_setAutoCommit_true_notInAutoCommit() throws Exception {
    XAConnection pc = getXAConnection();
    XAResource xa = pc.getXAResource();
    Xid xid = new XidImpl();
    try (Connection con = pc.getConnection()) {
        con.setAutoCommit(false);
        xa.start(xid, XAResource.TMNOFLAGS);
        expectedException.expect(SQLException.class);
        expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
        con.setAutoCommit(true);
    } finally {
        xa.end(xid, XAResource.TMSUCCESS);
        xa.rollback(xid);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TestFBXAResource(org.firebirdsql.jaybird.xca.TestFBXAResource) Xid(javax.transaction.xa.Xid) XidImpl(org.firebirdsql.jaybird.xca.TestXABase.XidImpl) XAConnection(javax.sql.XAConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) XAConnection(javax.sql.XAConnection)

Example 4 with XidImpl

use of org.firebirdsql.jaybird.xca.TestXABase.XidImpl in project jaybird by FirebirdSQL.

the class TestFBXADataSource method testInDistributed_setSavepoint_named.

/**
 * Test if calling setSavePoint (named) throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
 */
@Test
public void testInDistributed_setSavepoint_named() throws Exception {
    XAConnection pc = getXAConnection();
    XAResource xa = pc.getXAResource();
    Xid xid = new XidImpl();
    try (Connection con = pc.getConnection()) {
        con.setAutoCommit(false);
        xa.start(xid, XAResource.TMNOFLAGS);
        expectedException.expect(SQLException.class);
        expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
        con.setSavepoint("test_sp");
    } finally {
        xa.end(xid, XAResource.TMSUCCESS);
        xa.rollback(xid);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TestFBXAResource(org.firebirdsql.jaybird.xca.TestFBXAResource) Xid(javax.transaction.xa.Xid) XidImpl(org.firebirdsql.jaybird.xca.TestXABase.XidImpl) XAConnection(javax.sql.XAConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) XAConnection(javax.sql.XAConnection)

Example 5 with XidImpl

use of org.firebirdsql.jaybird.xca.TestXABase.XidImpl in project jaybird by FirebirdSQL.

the class TestFBXADataSource method testInDistributed_setSavepoint.

/**
 * Test if calling setSavePoint (no param) throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
 */
@Test
public void testInDistributed_setSavepoint() throws Exception {
    XAConnection pc = getXAConnection();
    XAResource xa = pc.getXAResource();
    Xid xid = new XidImpl();
    try (Connection con = pc.getConnection()) {
        con.setAutoCommit(false);
        xa.start(xid, XAResource.TMNOFLAGS);
        expectedException.expect(SQLException.class);
        expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
        con.setSavepoint();
    } finally {
        xa.end(xid, XAResource.TMSUCCESS);
        xa.rollback(xid);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TestFBXAResource(org.firebirdsql.jaybird.xca.TestFBXAResource) Xid(javax.transaction.xa.Xid) XidImpl(org.firebirdsql.jaybird.xca.TestXABase.XidImpl) XAConnection(javax.sql.XAConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) XAConnection(javax.sql.XAConnection)

Aggregations

XAConnection (javax.sql.XAConnection)7 XAResource (javax.transaction.xa.XAResource)7 Xid (javax.transaction.xa.Xid)7 TestFBXAResource (org.firebirdsql.jaybird.xca.TestFBXAResource)7 XidImpl (org.firebirdsql.jaybird.xca.TestXABase.XidImpl)7 FirebirdConnection (org.firebirdsql.jdbc.FirebirdConnection)7