use of javax.transaction.Transaction in project hazelcast by hazelcast.
the class ClientXATest method testWhenLockedOutOfTransaction.
@Test
public void testWhenLockedOutOfTransaction() throws Exception {
Hazelcast.newHazelcastInstance();
HazelcastInstance client = HazelcastClient.newHazelcastClient();
IMap<Object, Object> map = client.getMap("map");
map.put("key", "value");
HazelcastXAResource xaResource = client.getXAResource();
tm.begin();
Transaction transaction = tm.getTransaction();
transaction.enlistResource(xaResource);
TransactionContext context = xaResource.getTransactionContext();
TransactionalMap<Object, Object> transactionalMap = context.getMap("map");
if (map.tryLock("key")) {
transactionalMap.remove("key");
}
tm.commit();
}
use of javax.transaction.Transaction in project hazelcast by hazelcast.
the class HazelcastXATest method close.
private void close(boolean error, XAResource... xaResource) throws Exception {
int flag = XAResource.TMSUCCESS;
// get the current tx
Transaction tx = tm.getTransaction();
// closeConnection
if (error)
flag = XAResource.TMFAIL;
for (XAResource resource : xaResource) {
tx.delistResource(resource, flag);
}
if (error)
tm.rollback();
else
tm.commit();
}
use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class JTASessionContext method currentSession.
@Override
public Session currentSession() throws HibernateException {
final JtaPlatform jtaPlatform = factory().getServiceRegistry().getService(JtaPlatform.class);
final TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();
if (transactionManager == null) {
throw new HibernateException("No TransactionManagerLookup specified");
}
Transaction txn;
try {
txn = transactionManager.getTransaction();
if (txn == null) {
throw new HibernateException("Unable to locate current JTA transaction");
}
if (!JtaStatusHelper.isActive(txn.getStatus())) {
// entries cleaned up (aside from spawning threads).
throw new HibernateException("Current transaction is not in progress");
}
} catch (HibernateException e) {
throw e;
} catch (Throwable t) {
throw new HibernateException("Problem locating/validating JTA transaction", t);
}
final Object txnIdentifier = jtaPlatform.getTransactionIdentifier(txn);
Session currentSession = currentSessionMap.get(txnIdentifier);
if (currentSession == null) {
currentSession = buildOrObtainSession();
try {
txn.registerSynchronization(buildCleanupSynch(txnIdentifier));
} catch (Throwable t) {
try {
currentSession.close();
} catch (Throwable ignore) {
LOG.debug("Unable to release generated current-session on failed synch registration", ignore);
}
throw new HibernateException("Unable to register cleanup Synchronization with TransactionManager");
}
currentSessionMap.put(txnIdentifier, currentSession);
} else {
validateExistingSession(currentSession);
}
return currentSession;
}
use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class JtaIsolationDelegate method doInSuspendedTransaction.
private <T> T doInSuspendedTransaction(HibernateCallable<T> callable) {
try {
// First we suspend any current JTA transaction
Transaction surroundingTransaction = transactionManager.suspend();
LOG.debugf("Surrounding JTA transaction suspended [%s]", surroundingTransaction);
boolean hadProblems = false;
try {
return callable.call();
} catch (HibernateException e) {
hadProblems = true;
throw e;
} finally {
try {
transactionManager.resume(surroundingTransaction);
LOG.debugf("Surrounding JTA transaction resumed [%s]", surroundingTransaction);
} catch (Throwable t) {
// if the actually work had an error use that, otherwise error based on t
if (!hadProblems) {
//noinspection ThrowFromFinallyBlock
throw new HibernateException("Unable to resume previously suspended transaction", t);
}
}
}
} catch (SystemException e) {
throw new HibernateException("Unable to suspend current JTA transaction", e);
}
}
use of javax.transaction.Transaction in project Activiti by Activiti.
the class JtaTransactionContext method rollback.
public void rollback() {
// managed transaction, mark rollback-only if not done so already.
try {
Transaction transaction = getTransaction();
int status = transaction.getStatus();
if (status != Status.STATUS_NO_TRANSACTION && status != Status.STATUS_ROLLEDBACK) {
transaction.setRollbackOnly();
}
} catch (IllegalStateException e) {
throw new ActivitiException("Unexpected IllegalStateException while marking transaction rollback only");
} catch (SystemException e) {
throw new ActivitiException("SystemException while marking transaction rollback only");
}
}
Aggregations