PrepareFailsXAResource failingXar = new PrepareFailsXAResource();
//Transaction Manager Setup
Transaction txT;
TransactionManager txM = new GenericTransactionManager();
txM.begin();
txT = txM.getTransaction();
txT.enlistResource(xar1);
txT.enlistResource(xar2);
txT.enlistResource(failingXar);
//Write on connection #1
checkAttach(fConn1, "out1.txt");
//Do file ops...
OutputStream ostream1 = fConn1.getOutputStream();
OutputStreamWriter writer1 = new OutputStreamWriter(ostream1, "UTF-8");
char[] data1 = "Data for the first file.\n".toCharArray();
writer1.write(data1);
writer1.close();
writer1 = null;
//Write on connection #2
checkAttach(fConn2, "out2.txt");
//Do file ops...
char[] data2 = "Data for the second file.\n".toCharArray();
fConn2.write(String.valueOf(data2));
//Wind up
fConn1.close();
fConn2.close();
//This should not succeed (prepare for 3rd XAR will fail)
try
{
txM.commit();
fail();
}
catch (RollbackException ex)
{
//Good