use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl 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.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class SynchronizationTypeTest method testImplicitJoining.
@Test
public void testImplicitJoining() throws Exception {
// here the transaction is started beforeQuery the EM is opened. Because the SynchronizationType is UNSYNCHRONIZED
// though, it should not auto join the transaction
assertFalse("setup problem", JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertTrue("setup problem", JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
EntityManager entityManager = entityManagerFactory().createEntityManager(SynchronizationType.UNSYNCHRONIZED, null);
SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
assertFalse("EM was auto joined on creation", transactionCoordinator.isSynchronizationRegistered());
assertTrue("EM was auto joined on creation", transactionCoordinator.isActive());
assertFalse("EM was auto joined on creation", transactionCoordinator.isJoined());
session.getFlushMode();
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertTrue(transactionCoordinator.isActive());
assertFalse(transactionCoordinator.isJoined());
entityManager.joinTransaction();
assertTrue(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
assertTrue(transactionCoordinator.isActive());
assertTrue(transactionCoordinator.isSynchronizationRegistered());
assertTrue(transactionCoordinator.isActive());
assertTrue(transactionCoordinator.isJoined());
assertTrue(entityManager.isOpen());
assertTrue(session.isOpen());
entityManager.close();
assertFalse(entityManager.isOpen());
assertFalse(session.isOpen());
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse(entityManager.isOpen());
assertFalse(session.isOpen());
}
use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.
the class TransactionJoiningTest method testImplicitJoining.
@Test
public void testImplicitJoining() throws Exception {
// here the transaction is started beforeQuery the EM is opened...
assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
EntityManager entityManager = entityManagerFactory().createEntityManager();
SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
assertTrue(transactionCoordinator.isSynchronizationRegistered());
assertTrue(transactionCoordinator.isActive());
assertTrue(transactionCoordinator.isJoined());
assertTrue(entityManager.isOpen());
assertTrue(session.isOpen());
entityManager.close();
assertFalse(entityManager.isOpen());
assertFalse(session.isOpen());
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertFalse(entityManager.isOpen());
assertFalse(session.isOpen());
}
Aggregations