use of javax.transaction.RollbackException in project ignite by apache.
the class TestJtaTxServlet method doGet.
/** {@inheritDoc} */
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
final int key1 = 1;
final int key2 = 2;
final String correctVal1 = "correct_val1";
final String correctVal2 = "correct_val1";
final String incorrectVal1 = "incorrect_val2";
final String incorrectVal2 = "incorrect_val2";
final PrintWriter writer = res.getWriter();
try {
final Ignite ignite = Ignition.ignite();
final IgniteCache<Integer, String> cache = ignite.cache("tx");
TransactionManager tmMgr = TransactionManagerFactory.getTransactionManager();
tmMgr.begin();
cache.put(key1, correctVal1);
cache.put(key2, correctVal2);
writer.println("Transaction #1. Put values [key1=" + key1 + ", val1=" + cache.get(key1) + ", key2=" + key2 + ", val2=" + cache.get(key2) + "]");
writer.println();
tmMgr.commit();
try {
tmMgr.begin();
writer.println("Transaction #2. Current values [key1=" + key1 + ", val1=" + cache.get(key1) + ", key2=" + key2 + ", val2=" + cache.get(key2) + "]");
cache.put(key1, incorrectVal1);
cache.put(key2, incorrectVal2);
writer.println("Transaction #2. Put values [key1=" + key1 + ", val1=" + cache.get(key1) + ", key2=" + key2 + ", val2=" + cache.get(key2) + "]");
tmMgr.setRollbackOnly();
tmMgr.commit();
} catch (final RollbackException ignored) {
writer.println("Transaction #2. setRollbackOnly [key1=" + key1 + ", val1=" + cache.get(key1) + ", key2=" + key2 + ", val2=" + cache.get(key2) + "]");
}
writer.println();
tmMgr.begin();
writer.println("Transaction #2. Current values [key1=" + key1 + ", val1=" + cache.get(key1) + ", key2=" + key2 + ", val2=" + cache.get(key2) + "]");
tmMgr.commit();
} catch (final Throwable e) {
e.printStackTrace(writer);
}
}
use of javax.transaction.RollbackException in project jackrabbit by apache.
the class UserTransactionImpl method commit.
/**
* @see javax.transaction.UserTransaction#commit
*/
public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
if (status != Status.STATUS_ACTIVE) {
throw new IllegalStateException("Transaction not active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.end(xid, XAResource.TMSUCCESS);
}
status = Status.STATUS_PREPARING;
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.prepare(xid);
}
status = Status.STATUS_PREPARED;
status = Status.STATUS_COMMITTING;
if (distributedThreadAccess) {
Thread distributedThread = new Thread() {
public void run() {
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.commit(xid, false);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
};
distributedThread.start();
distributedThread.join(1000);
if (distributedThread.isAlive()) {
throw new SystemException("Commit from different thread but same XID must not block");
}
} else {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.commit(xid, false);
}
}
status = Status.STATUS_COMMITTED;
} catch (XAException e) {
if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) {
RollbackException re = new RollbackException("Transaction rolled back: XA_ERR=" + e.errorCode);
re.initCause(e.getCause());
throw re;
} else {
SystemException se = new SystemException("Unable to commit transaction: XA_ERR=" + e.errorCode);
se.initCause(e.getCause());
throw se;
}
} catch (InterruptedException e) {
throw new SystemException("Thread.join() interrupted");
}
}
use of javax.transaction.RollbackException in project jackrabbit by apache.
the class XATest method testConflictingCheckin.
/**
* Checkin from two sessions simultaneously should throw when committing.
* @throws Exception
*/
public void testConflictingCheckin() throws Exception {
// get user transaction object
UserTransaction utx = new UserTransactionImpl(superuser);
// add node and save
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
testRootNode.save();
// reference node in other session
Node nOther = otherSuperuser.getNodeByUUID(n.getUUID());
// start transaction
utx.begin();
// checkin node inside tx
n.checkin();
// checkin node outside tx
nOther.checkin();
// commit
try {
utx.commit();
fail("Commit failing with modified version history.");
} catch (RollbackException e) {
// expected
}
}
use of javax.transaction.RollbackException in project wildfly by wildfly.
the class WeldTransactionServices method registerSynchronization.
@Override
public void registerSynchronization(Synchronization synchronizedObserver) {
try {
final Synchronization synchronization;
if (!jtsEnabled) {
synchronization = synchronizedObserver;
} else {
synchronization = new JTSSynchronizationWrapper(synchronizedObserver);
}
injectedTransactionManager.getValue().getTransaction().registerSynchronization(synchronization);
} catch (IllegalStateException e) {
throw new RuntimeException(e);
} catch (RollbackException e) {
throw new RuntimeException(e);
} catch (SystemException e) {
throw new RuntimeException(e);
}
}
use of javax.transaction.RollbackException in project wildfly by wildfly.
the class MessageEndpointInvocationHandler method afterDelivery.
@Override
public void afterDelivery() throws ResourceException {
final TransactionManager tm = getTransactionManager();
try {
if (currentTx != null) {
if (currentTx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
tm.rollback();
else
tm.commit();
currentTx = null;
}
if (previousTx != null) {
tm.resume(previousTx);
previousTx = null;
}
} catch (InvalidTransactionException e) {
throw new LocalTransactionException(e);
} catch (HeuristicMixedException e) {
throw new LocalTransactionException(e);
} catch (SystemException e) {
throw new LocalTransactionException(e);
} catch (HeuristicRollbackException e) {
throw new LocalTransactionException(e);
} catch (RollbackException e) {
throw new LocalTransactionException(e);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previousClassLoader);
previousClassLoader = null;
}
}
Aggregations