use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class QueryResultsRegionImpl method evictAll.
@Override
public void evictAll() throws CacheException {
transactionContext.clear();
final Transaction tx = suspend();
try {
// Invalidate the local region and then go remote
invalidateRegion();
Caches.broadcastEvictAll(cache);
} finally {
resume(tx);
}
}
use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class JtaAwareConnectionProviderImpl method getConnection.
@Override
public Connection getConnection() throws SQLException {
Transaction currentTransaction = findCurrentTransaction();
try {
if (currentTransaction == null) {
// this block handles non enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection connection = delegate.getConnection();
nonEnlistedConnections.add(connection);
return connection;
}
// this portion handles enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection connection = (Connection) TestingJtaPlatformImpl.synchronizationRegistry().getResource(CONNECTION_KEY);
if (connection == null) {
connection = delegate.getConnection();
TestingJtaPlatformImpl.synchronizationRegistry().putResource(CONNECTION_KEY, connection);
XAResourceWrapper xaResourceWrapper = new XAResourceWrapper(this, connection);
currentTransaction.enlistResource(xaResourceWrapper);
}
return connection;
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
}
use of javax.transaction.Transaction in project hazelcast by hazelcast.
the class HazelcastXATest method testRollback.
@Test
public void testRollback() throws Exception {
HazelcastInstance instance = createHazelcastInstance();
HazelcastXAResource xaResource = instance.getXAResource();
tm.begin();
Transaction transaction = tm.getTransaction();
transaction.enlistResource(xaResource);
TransactionContext context = xaResource.getTransactionContext();
boolean error = false;
try {
final TransactionalMap m = context.getMap("m");
m.put("key", "value");
throw new RuntimeException("Exception for rolling back");
} catch (Exception e) {
error = true;
} finally {
close(error, xaResource);
}
assertNull(instance.getMap("m").get("key"));
}
use of javax.transaction.Transaction in project hazelcast by hazelcast.
the class HazelcastXATest method txn.
private void txn(HazelcastInstance instance) throws Exception {
HazelcastXAResource xaResource = instance.getXAResource();
tm.begin();
Transaction transaction = tm.getTransaction();
transaction.enlistResource(xaResource);
boolean error = false;
try {
TransactionContext context = xaResource.getTransactionContext();
TransactionalMap m = context.getMap("m");
m.put(random.nextInt(10), "value");
} catch (Exception e) {
logger.severe("Exception during transaction", e);
error = true;
} finally {
close(error, xaResource);
}
}
use of javax.transaction.Transaction in project hazelcast by hazelcast.
the class ClientXATest 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();
}
Aggregations