use of javax.transaction.Synchronization in project datanucleus-core by datanucleus.
the class ResourcedTransaction method rollback.
public void rollback() {
if (completing) {
return;
}
try {
completing = true;
if (NucleusLogger.TRANSACTION.isDebugEnabled()) {
NucleusLogger.TRANSACTION.debug("Rolling back " + toString());
}
// Must be ACTIVE and MARKED ROLLBACK
if (status != STATUS_ACTIVE && status != STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException();
}
List failures = null;
status = STATUS_ROLLING_BACK;
Iterator<Map.Entry<Xid, XAResource>> branchesEntryIter = branches.entrySet().iterator();
while (branchesEntryIter.hasNext()) {
Map.Entry<Xid, XAResource> branchesEntry = branchesEntryIter.next();
Xid xid = branchesEntry.getKey();
XAResource resourceManager = branchesEntry.getValue();
try {
resourceManager.rollback(xid);
} catch (Throwable e) {
if (failures == null) {
// lazy instantiate this, because we only need on failures
failures = new ArrayList();
}
failures.add(e);
NucleusLogger.TRANSACTION.error(Localiser.msg("015038", "rollback", resourceManager, getXAErrorCode(e), toString(), StringUtils.getMessageFromRootCauseOfThrowable(e)));
}
}
status = STATUS_ROLLEDBACK;
// Synchronization.afterCompletion
if (synchronization != null) {
Iterator<Synchronization> syncIterator = synchronization.iterator();
while (syncIterator.hasNext()) {
syncIterator.next().afterCompletion(status);
}
}
} finally {
completing = false;
}
}
use of javax.transaction.Synchronization in project tests by datanucleus.
the class TransactionTest method testUpdateDuringBeforeCompletion.
/**
* JDO2 $13.4.3 Synchronization: "During the user's beforeCompletion method, fields in persistent and
* transactional instances might be changed, persistent instances might be deleted, and instances might be
* made persistent. These changes will be reflected in the current transaction."
*/
public void testUpdateDuringBeforeCompletion() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.setNontransactionalRead(true);
person = null;
tx.setSynchronization(new Synchronization() {
public void beforeCompletion() {
person.setEmailAddress(emailValueBeforeCompletion);
}
public void afterCompletion(int arg0) {
}
});
try {
// test on P_NEW object
tx.begin();
emailValueBeforeCompletion = "fred@jpox.org";
person = new Person(101, "Fred", "Flintstone", "fred.flintstone@warnerbros.com");
pm.makePersistent(person);
tx.commit();
verifyStringSetDuringBeforeCompletion(pm, person);
// test on HOLLOW object
emailValueBeforeCompletion = "fred.flintstone@aol.com";
tx.begin();
tx.commit();
verifyStringSetDuringBeforeCompletion(pm, person);
} finally {
tx.setSynchronization(null);
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(Person.class);
}
}
Aggregations