use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class XaTransactionManagerImpl method suspend.
public Transaction suspend() throws SystemException {
Transaction suspended = currentTransaction.get();
currentTransaction.remove();
return suspended;
}
use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class DualNodeJtaTransactionManagerImpl method setRollbackOnly.
public void setRollbackOnly() throws IllegalStateException, SystemException {
Transaction tx = getCurrentTransaction();
if (tx == null) {
throw new IllegalStateException("no current transaction");
}
tx.setRollbackOnly();
}
use of javax.transaction.Transaction in project hibernate-orm by hibernate.
the class ClusteredTimestampsRegionImpl method evictAll.
@Override
public void evictAll() throws CacheException {
// TODO Is this a valid operation on a timestamps cache?
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 wildfly by wildfly.
the class InfinispanBatcherTestCase method resumeBatch.
@Test
public void resumeBatch() throws Exception {
TransactionBatch batch = mock(TransactionBatch.class);
Transaction tx = mock(Transaction.class);
when(batch.getTransaction()).thenReturn(tx);
try (BatchContext context = this.batcher.resumeBatch(batch)) {
verify(this.tm, never()).suspend();
verify(this.tm).resume(tx);
reset(this.tm);
assertSame(batch, InfinispanBatcher.CURRENT_BATCH.get());
}
verify(this.tm).suspend();
verify(this.tm, never()).resume(any());
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Transaction in project wildfly by wildfly.
the class InfinispanBatcher method resumeBatch.
@Override
public BatchContext resumeBatch(TransactionBatch batch) {
TransactionBatch existingBatch = CURRENT_BATCH.get();
// Trivial case - nothing to suspend/resume
if (batch == existingBatch)
return PASSIVE_BATCH_CONTEXT;
Transaction tx = (batch != null) ? batch.getTransaction() : null;
// Non-tx case, just swap thread local
if ((batch == null) || (tx == null)) {
CURRENT_BATCH.set(batch);
return () -> {
CURRENT_BATCH.set(existingBatch);
};
}
try {
if (existingBatch != null) {
Transaction existingTx = this.tm.suspend();
if (existingBatch.getTransaction() != existingTx) {
throw new IllegalStateException();
}
}
this.tm.resume(tx);
CURRENT_BATCH.set(batch);
return () -> {
try {
this.tm.suspend();
if (existingBatch != null) {
try {
this.tm.resume(existingBatch.getTransaction());
CURRENT_BATCH.set(existingBatch);
} catch (InvalidTransactionException e) {
throw new CacheException(e);
}
} else {
CURRENT_BATCH.remove();
}
} catch (SystemException e) {
throw new CacheException(e);
}
};
} catch (SystemException | InvalidTransactionException e) {
throw new CacheException(e);
}
}
Aggregations