use of javax.transaction.RollbackException in project geode by apache.
the class ClientServerTransactionDUnitTest method doJTATx1.
private void doJTATx1(String regionName, CountDownLatch latch1, CountDownLatch latch2) {
TransactionManagerImpl tm = TransactionManagerImpl.getTransactionManager();
Region r = getClientRegion(regionName);
try {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
latch1.await();
r.put(key1, "value2");
utx.commit();
fail("Do not get expected RollbackException");
} catch (Exception e) {
if (e instanceof RollbackException) {
// expected exception.
} else {
Assert.fail("Unexpected exception while doing JTA Transaction1 ", e);
}
} finally {
latch2.countDown();
}
}
use of javax.transaction.RollbackException in project ignite by apache.
the class CacheJtaManager method checkJta.
/** {@inheritDoc} */
@Override
public void checkJta() throws IgniteCheckedException {
if (jtaTm == null) {
try {
CacheTmLookup tmLookup = tmLookupRef.get();
if (tmLookup == null)
return;
jtaTm = tmLookup.getTm();
} catch (Exception e) {
throw new IgniteCheckedException("Failed to get transaction manager: " + e, e);
}
}
if (jtaTm != null) {
CacheJtaResource rsrc = this.rsrc.get();
if (rsrc == null || rsrc.isFinished()) {
try {
Transaction jtaTx = jtaTm.getTransaction();
if (jtaTx != null) {
GridNearTxLocal tx = cctx.tm().userTx();
if (tx == null) {
TransactionConfiguration tCfg = cctx.kernalContext().config().getTransactionConfiguration();
tx = cctx.tm().newTx(/*implicit*/
false, /*implicit single*/
false, null, tCfg.getDefaultTxConcurrency(), tCfg.getDefaultTxIsolation(), tCfg.getDefaultTxTimeout(), /*store enabled*/
true, /*tx size*/
0);
}
rsrc = new CacheJtaResource(tx, cctx.kernalContext());
if (useJtaSync)
jtaTx.registerSynchronization(rsrc);
else if (!jtaTx.enlistResource(rsrc))
throw new IgniteCheckedException("Failed to enlist XA resource to JTA user transaction.");
this.rsrc.set(rsrc);
}
} catch (SystemException e) {
throw new IgniteCheckedException("Failed to obtain JTA transaction.", e);
} catch (RollbackException e) {
throw new IgniteCheckedException("Failed to enlist XAResource to JTA transaction.", e);
}
}
}
}
use of javax.transaction.RollbackException in project jackrabbit by apache.
the class XATest method testLockTwice.
/**
* Test locking a node inside a transaction that has been locked in another
* session, which leads to a failure when committing.
* @throws Exception
*/
public void testLockTwice() throws Exception {
Session other = getHelper().getSuperuserSession();
try {
// add node that is both lockable and referenceable, save
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixLockable);
n.addMixin(mixReferenceable);
testRootNode.save();
// reference node in second session
Node nOther = other.getNodeByUUID(n.getUUID());
// verify node is not locked in either session
assertFalse("Node not locked in session 1", n.isLocked());
assertFalse("Node not locked in session 2", nOther.isLocked());
// get user transaction object, start and lock node
UserTransaction utx = new UserTransactionImpl(superuser);
utx.begin();
n.lock(false, true);
// lock node in non-transactional session, too
nOther.lock(false, true);
// verify node is locked in both sessions
assertTrue("Node locked in session 1", n.isLocked());
assertTrue("Node locked in session 2", nOther.isLocked());
assertTrue("Node locked in session 2", nOther.hasProperty(jcrLockOwner));
// assertion: commit must fail since node has already been locked
try {
utx.commit();
fail("Commit succeeds with double locking");
} catch (RollbackException e) {
/* expected */
}
// verify node is locked in both sessions
assertTrue("Node locked in session 1", n.isLocked());
assertTrue("Node locked in session 2", nOther.isLocked());
assertTrue("Node locked in session 2", nOther.hasProperty(jcrlockIsDeep));
} finally {
// logout
other.logout();
}
}
use of javax.transaction.RollbackException in project jackrabbit by apache.
the class XATest method testAddReference.
/**
* Add reference to some node in one session while removing
* the node in another.
* @throws Exception
*/
public void testAddReference() throws Exception {
// add two nodes, second one referenceable
Node n1 = testRootNode.addNode(nodeName1);
Node n2 = testRootNode.addNode(nodeName2);
n2.addMixin(mixReferenceable);
testRootNode.save();
// get user transaction object
UserTransaction utx = new UserTransactionImpl(superuser);
// start transaction
utx.begin();
// add reference and save
n1.setProperty(propertyName1, n2);
testRootNode.save();
// remove referenced node in other session
Session otherSuperuser = getHelper().getSuperuserSession();
Node otherRootNode = otherSuperuser.getRootNode().getNode(testPath);
otherSuperuser.getNodeByUUID(n2.getUUID()).remove();
otherRootNode.save();
// assertion: commit must fail since integrity violated
try {
utx.commit();
fail("Commit succeeds with violated integrity");
} catch (RollbackException e) {
/* expected */
}
// logout
otherSuperuser.logout();
}
use of javax.transaction.RollbackException in project tomee by apache.
the class BaseEjbProxyHandler method getLiveHandleRegistry.
public ConcurrentMap getLiveHandleRegistry() {
final BeanContext beanContext = getBeanContext();
final ThreadContext tc = ThreadContext.getThreadContext();
if (tc != null && tc.getBeanContext() != beanContext && /* parent bean */
tc.getCurrentOperation() == Operation.BUSINESS) {
ProxyRegistry registry = tc.get(ProxyRegistry.class);
if (registry == null) {
registry = new ProxyRegistry();
tc.set(ProxyRegistry.class, registry);
}
return registry.liveHandleRegistry;
} else {
// use the tx if there
final SystemInstance systemInstance = SystemInstance.get();
final TransactionManager txMgr = systemInstance.getComponent(TransactionManager.class);
try {
final Transaction tx = txMgr.getTransaction();
if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
final TransactionSynchronizationRegistry registry = systemInstance.getComponent(TransactionSynchronizationRegistry.class);
final String resourceKey = ProxyRegistry.class.getName();
ConcurrentMap map = ConcurrentMap.class.cast(registry.getResource(resourceKey));
if (map == null) {
map = new ConcurrentHashMap();
registry.putResource(resourceKey, map);
try {
final ConcurrentMap tmp = map;
tx.registerSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// no-op
}
@Override
public void afterCompletion(final int status) {
tmp.clear();
}
});
} catch (final RollbackException e) {
// not really possible since we check the status
// let it go to default
}
}
return map;
}
} catch (final SystemException e) {
// let it go to default
}
// back to default but it doesnt release the memory
ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
if (proxyRegistry == null) {
proxyRegistry = new ProxyRegistry();
beanContext.set(ProxyRegistry.class, proxyRegistry);
}
return proxyRegistry.liveHandleRegistry;
}
}
Aggregations