use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method basicThreadCheckingUsage.
@Test
public void basicThreadCheckingUsage() throws Exception {
JtaTransactionCoordinatorImpl transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, JtaPlatformStandardTestingImpl.INSTANCE, preferUserTransactions(), true);
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
// begin the transaction
tm.begin();
transactionCoordinator.explicitJoin();
assertEquals(SynchronizationCallbackCoordinatorTrackingImpl.class, transactionCoordinator.getSynchronizationCallbackCoordinator().getClass());
tm.commit();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isJoined());
tm.begin();
transactionCoordinator.explicitJoin();
assertEquals(SynchronizationCallbackCoordinatorTrackingImpl.class, transactionCoordinator.getSynchronizationCallbackCoordinator().getClass());
tm.rollback();
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method rollbackCmtUsageTest.
@Test
public void rollbackCmtUsageTest() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
// begin the transaction
tm.begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(true);
// NOTE : because of auto-join
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// rollback the transaction
tm.rollback();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(0, localSync.getBeforeCompletionCount());
assertEquals(0, localSync.getSuccessfulCompletionCount());
assertEquals(1, localSync.getFailedCompletionCount());
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class DdlInWildFlyUsingBmtAndEmfTest method testCreateThenDrop.
@Test
public void testCreateThenDrop() throws Exception {
URL persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource(PERSISTENCE_XML_RESOURCE_NAME);
if (persistenceXmlUrl == null) {
persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource('/' + PERSISTENCE_XML_RESOURCE_NAME);
}
assertNotNull(persistenceXmlUrl);
ParsedPersistenceXmlDescriptor persistenceUnit = PersistenceXmlParser.locateIndividualPersistenceUnit(persistenceXmlUrl);
// creating the EMF causes SchemaCreator to be run...
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, Collections.emptyMap()).build();
// closing the EMF causes the delayed SchemaDropper to be run...
// wrap in a transaction just to see if we can get this to fail in the way the WF report says;
// in my experience however this succeeds with or without the transaction
final TransactionManager tm = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(JtaPlatform.class).retrieveTransactionManager();
tm.begin();
Transaction txn = tm.getTransaction();
emf.close();
txn.commit();
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class JOTMJtaPlatform method locateTransactionManager.
@Override
protected TransactionManager locateTransactionManager() {
try {
final Class tmClass = serviceRegistry().getService(ClassLoaderService.class).classForName(TM_CLASS_NAME);
final Method getTransactionManagerMethod = tmClass.getMethod("getTransactionManager");
return (TransactionManager) getTransactionManagerMethod.invoke(null, (Object[]) null);
} catch (Exception e) {
throw new JtaPlatformException("Could not obtain JOTM transaction manager instance", e);
}
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class JOnASJtaPlatform method locateTransactionManager.
@Override
protected TransactionManager locateTransactionManager() {
try {
final Class clazz = Class.forName(TM_CLASS_NAME);
final Method getTransactionManagerMethod = clazz.getMethod("getTransactionManager");
return (TransactionManager) getTransactionManagerMethod.invoke(null);
} catch (Exception e) {
throw new JtaPlatformException("Could not obtain JOnAS transaction manager instance", e);
}
}
Aggregations