// Setup the JtaTransactionmanager
Environment env = createEnvironment(context);
//TransactionManager txm = (TransactionManager) env.get( EnvironmentName.TRANSACTION_MANAGER );
javax.transaction.TransactionManager tm = (javax.transaction.TransactionManager) env.get( EnvironmentName.TRANSACTION_MANAGER );
TransactionManager txm = new JtaTransactionManager( env.get( EnvironmentName.TRANSACTION ),
env.get( EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY ),
tm );
// Create linked transactionTestObjects
TransactionTestObject mainObject = new TransactionTestObject();
mainObject.setName("main" + testName);
TransactionTestObject subObject = new TransactionTestObject();
subObject.setName("sub" + testName);
mainObject.setSubObject(subObject);
// Commit the mainObject after "commiting" the subObject
Cache<Serializable, Object> cache = cm.getCache("jbpm-configured-cache");
try {
// Begin the real trasnaction
boolean txOwner = txm.begin();
// Do the "sub" transaction
// - the txm doesn't really commit,
// because we keep track of who's the tx owner.
boolean notTxOwner = txm.begin();
Serializable s = generateId(mainObject);
mainObject.setId(Long.valueOf(s.toString()));
cache.put(s, mainObject);
txm.commit(notTxOwner);
// Finish the transaction off
Serializable s2 = generateId(subObject);
subObject.setId(Long.valueOf(s2.toString()));
cache.put(s2, subObject);
txm.commit(txOwner);
}
catch( Throwable t ) {
fail( "No exception should have been thrown: " + t.getMessage() );
}
}