use of org.hibernate.resource.transaction.spi.TransactionCoordinator in project hibernate-orm by hibernate.
the class InaccessibleJtaPlatformTests method testInaccessibleUserTransactionHandling.
@Test
public void testInaccessibleUserTransactionHandling() {
// first, have JtaPlatform throw an exception
try {
final JtaPlatformInaccessibleImpl jtaPlatform = new JtaPlatformInaccessibleImpl(true);
final TransactionCoordinator transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, jtaPlatform, false, false);
transactionCoordinator.getTransactionDriverControl().begin();
fail("Expecting JtaPlatformInaccessibleException, but call succeeded");
} catch (JtaPlatformInaccessibleException expected) {
// expected condition
} catch (Exception e) {
fail("Expecting JtaPlatformInaccessibleException, but got " + e.getClass().getName());
}
// then, have it return null
try {
final JtaPlatformInaccessibleImpl jtaPlatform = new JtaPlatformInaccessibleImpl(false);
final TransactionCoordinator transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, jtaPlatform, false, false);
transactionCoordinator.getTransactionDriverControl().begin();
fail("Expecting JtaPlatformInaccessibleException, but call succeeded");
} catch (JtaPlatformInaccessibleException expected) {
// expected condition
} catch (Exception e) {
fail("Expecting JtaPlatformInaccessibleException, but got " + e.getClass().getName());
}
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinator in project hibernate-orm by hibernate.
the class BasicJdbcTransactionTests method testMarkRollbackOnly.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testMarkRollbackOnly() {
final TransactionCoordinatorOwnerTestingImpl owner = new TransactionCoordinatorOwnerTestingImpl();
final JdbcResourceLocalTransactionCoordinatorBuilderImpl transactionCoordinatorBuilder = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(owner, new TransactionCoordinatorBuilder.Options() {
@Override
public boolean shouldAutoJoinTransaction() {
return false;
}
});
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
assertEquals(TransactionStatus.MARKED_ROLLBACK, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (TransactionException expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinator in project hibernate-orm by hibernate.
the class InaccessibleJtaPlatformTests method testInaccessibleTransactionManagerHandling.
@Test
public void testInaccessibleTransactionManagerHandling() {
// first, have JtaPlatform throw an exception
try {
final JtaPlatformInaccessibleImpl jtaPlatform = new JtaPlatformInaccessibleImpl(true);
final TransactionCoordinator transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, jtaPlatform, false, false);
transactionCoordinator.getTransactionDriverControl().begin();
fail("Expecting JtaPlatformInaccessibleException, but call succeeded");
} catch (JtaPlatformInaccessibleException expected) {
// expected condition
} catch (Exception e) {
fail("Expecting JtaPlatformInaccessibleException, but got " + e.getClass().getName());
}
// then, have it return null
try {
final JtaPlatformInaccessibleImpl jtaPlatform = new JtaPlatformInaccessibleImpl(false);
final TransactionCoordinator transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, jtaPlatform, false, false);
transactionCoordinator.getTransactionDriverControl().begin();
fail("Expecting JtaPlatformInaccessibleException, but call succeeded");
} catch (JtaPlatformInaccessibleException expected) {
// expected condition
} catch (Exception e) {
fail("Expecting JtaPlatformInaccessibleException, but got " + e.getClass().getName());
}
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinator in project hibernate-orm by hibernate.
the class TombstoneAccessDelegate method write.
protected void write(SharedSessionContractImplementor session, Object key, Object value) {
TransactionCoordinator tc = session.getTransactionCoordinator();
FutureUpdateSynchronization sync = new FutureUpdateSynchronization(tc, asyncWriteCache, requiresTransaction, key, value, region, session.getTimestamp());
// The update will be invalidating all putFromLoads for the duration of expiration or until removed by the synchronization
Tombstone tombstone = new Tombstone(sync.getUuid(), region.nextTimestamp() + region.getTombstoneExpiration());
// The outcome of this operation is actually defined in TombstoneCallInterceptor
// Metadata in PKVC are cleared and set in the interceptor, too
writeCache.put(key, tombstone);
tc.getLocalSynchronizations().registerSynchronization(sync);
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinator in project hibernate-orm by hibernate.
the class QueryResultsRegionImpl method put.
@Override
@SuppressWarnings("unchecked")
public void put(SharedSessionContractImplementor session, Object key, Object value) throws CacheException {
if (checkValid()) {
// See HHH-7898: Even with FAIL_SILENTLY flag, failure to write in transaction
// fails the whole transaction. It is an Infinispan quirk that cannot be fixed
// ISPN-5356 tracks that. This is because if the transaction continued the
// value could be committed on backup owners, including the failed operation,
// and the result would not be consistent.
TransactionCoordinator tc = session.getTransactionCoordinator();
if (tc != null && tc.isJoined()) {
tc.getLocalSynchronizations().registerSynchronization(new PostTransactionQueryUpdate(tc, session, key, value));
// no need to synchronize as the transaction will be accessed by only one thread
Map map = transactionContext.get(session);
if (map == null) {
transactionContext.put(session, map = new HashMap());
}
map.put(key, value);
return;
}
// Here we don't want to suspend the tx. If we do:
// 1) We might be caching query results that reflect uncommitted
// changes. No tx == no WL on cache node, so other threads
// can prematurely see those query results
// 2) No tx == immediate replication. More overhead, plus we
// spread issue #1 above around the cluster
// Add a zero (or quite low) timeout option so we don't block.
// Ignore any TimeoutException. Basically we forego caching the
// query result in order to avoid blocking.
// Reads are done with suspended tx, so they should not hold the
// lock for long. Not caching the query result is OK, since
// any subsequent read will just see the old result with its
// out-of-date timestamp; that result will be discarded and the
// db query performed again.
putCache.put(key, value);
}
}
Aggregations