/ timeoutCommitEveryStatement;
Statement stm = getConnection().createStatement();
stm.execute("create table XATT (i int, text char(10))");
XADataSource xaDataSource = J2EEDataSource.getXADataSource();
XAConnection[] xaConn = new XAConnection[timeoutStatementsToExecute];
XAResource xaRes = null;
Connection conn = null;
for (int i=0; i < timeoutStatementsToExecute; i++) {
xaConn[i] = xaDataSource.getXAConnection();
xaRes = xaConn[i].getXAResource();
conn = xaConn[i].getConnection();
Xid xid = createXid(123, i);
xaRes.setTransactionTimeout(8);
xaRes.start(xid, XAResource.TMNOFLAGS);
stm = conn.createStatement();
stm.execute("insert into XATT values (" + i + ", 'Test_Entry')");
if (i % timeoutCommitEveryStatement == 0) {
stm.close();
xaRes.end(xid, XAResource.TMSUCCESS);
xaRes.prepare(xid);
xaRes.commit(xid, false);
} else if (i % 11 != 0) {
// check the tiemout for transactions disassociated
// with failure.
try {
xaRes.end(xid, XAResource.TMFAIL);
fail();
} catch (XAException ex) {
if (ex.errorCode < XAException.XA_RBBASE
|| ex.errorCode > XAException.XA_RBEND)
{
throw ex;
}
}
stm.close();
} else if (i % 2 == 0) {
// check the timeout for transactions disassociated
// with success.
xaRes.end(xid, XAResource.TMSUCCESS);
stm.close();
}
}
ResultSet rs = null;
stm = getConnection().createStatement();
rs = stm.executeQuery("select count(*) from XATT");
rs.next();
// Check whether the correct number of transactions
// was rolled back
assertTrue(rs.getInt(1) == timeoutStatementsCommitted);
// test the timeout during the statement run
XAConnection xaConn2 = xaDataSource.getXAConnection();
xaRes = xaConn2.getXAResource();
conn = xaConn2.getConnection();
Xid xid = createXid(124, 100);
xaRes.setTransactionTimeout(10);