use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method testSynchronizationFailure.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testSynchronizationFailure() 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());
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getLocalSynchronizations().registerSynchronization(SynchronizationErrorImpl.forBefore());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (Exception expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
use of javax.transaction.TransactionManager in project geode by apache.
the class JNDIInvoker method doTransactionLookup.
/*
* Helps in locating TransactionManager in presence of application server scenario. Stores the
* value of TransactionManager for reference in GemFire system.
*/
private static void doTransactionLookup() throws NamingException {
Object jndiObject = null;
LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
for (int i = 0; i < knownJNDIManagers.length; i++) {
try {
jndiObject = ctx.lookup(knownJNDIManagers[i][0]);
} catch (NamingException e) {
String exception = "JNDIInvoker::doTransactionLookup::Couldn't lookup [" + knownJNDIManagers[i][0] + " (" + knownJNDIManagers[i][1] + ")]";
if (writer.finerEnabled())
writer.finer(exception);
}
if (jndiObject instanceof TransactionManager) {
transactionManager = (TransactionManager) jndiObject;
String exception = "JNDIInvoker::doTransactionLookup::Found TransactionManager for " + knownJNDIManagers[i][1];
if (writer.fineEnabled())
writer.fine(exception);
return;
} else {
String exception = "JNDIInvoker::doTransactionLookup::Found TransactionManager of class " + (jndiObject == null ? "null" : jndiObject.getClass()) + " but is not of type javax.transaction.TransactionManager";
if (writer.fineEnabled())
writer.fine(exception);
}
}
Class clazz;
try {
if (writer.finerEnabled())
writer.finer("JNDIInvoker::doTransactionLookup::Trying WebSphere 5.1: " + WS_FACTORY_CLASS_5_1);
clazz = ClassPathLoader.getLatest().forName(WS_FACTORY_CLASS_5_1);
if (writer.fineEnabled())
writer.fine("JNDIInvoker::doTransactionLookup::Found WebSphere 5.1: " + WS_FACTORY_CLASS_5_1);
} catch (ClassNotFoundException ex) {
try {
if (writer.finerEnabled())
writer.finer("JNDIInvoker::doTransactionLookup::Trying WebSphere 5.0: " + WS_FACTORY_CLASS_5_0);
clazz = ClassPathLoader.getLatest().forName(WS_FACTORY_CLASS_5_0);
if (writer.fineEnabled())
writer.fine("JNDIInvoker::doTransactionLookup::Found WebSphere 5.0: " + WS_FACTORY_CLASS_5_0);
} catch (ClassNotFoundException ex2) {
try {
clazz = ClassPathLoader.getLatest().forName(WS_FACTORY_CLASS_4);
String exception = "JNDIInvoker::doTransactionLookup::Found WebSphere 4: " + WS_FACTORY_CLASS_4;
if (writer.fineEnabled())
writer.fine(exception, ex);
} catch (ClassNotFoundException ex3) {
if (writer.finerEnabled())
writer.finer("JNDIInvoker::doTransactionLookup::Couldn't find any WebSphere TransactionManager factory class, neither for WebSphere version 5.1 nor 5.0 nor 4");
throw new NoInitialContextException();
}
}
}
try {
Method method = clazz.getMethod("getTransactionManager", (Class[]) null);
transactionManager = (TransactionManager) method.invoke(null, (Object[]) null);
} catch (Exception ex) {
writer.warning(LocalizedStrings.JNDIInvoker_JNDIINVOKER_DOTRANSACTIONLOOKUP_FOUND_WEBSPHERE_TRANSACTIONMANAGER_FACTORY_CLASS_0_BUT_COULDNT_INVOKE_ITS_STATIC_GETTRANSACTIONMANAGER_METHOD, clazz.getName(), ex);
throw new NameNotFoundException(LocalizedStrings.JNDIInvoker_JNDIINVOKER_DOTRANSACTIONLOOKUP_FOUND_WEBSPHERE_TRANSACTIONMANAGER_FACTORY_CLASS_0_BUT_COULDNT_INVOKE_ITS_STATIC_GETTRANSACTIONMANAGER_METHOD.toLocalizedString(new Object[] { clazz.getName() }));
}
}
use of javax.transaction.TransactionManager in project geode by apache.
the class RestartJUnitTest method testCleanUp.
@Test
public void testCleanUp() {
TransactionManager tm1 = null;
TransactionManager tm2 = null;
try {
props = new Properties();
props.setProperty(MCAST_PORT, "0");
String path = TestUtil.getResourcePath(RestartJUnitTest.class, "/jta/cachejta.xml");
props.setProperty(CACHE_XML_FILE, path);
ds1 = DistributedSystem.connect(props);
cache = CacheFactory.create(ds1);
tm1 = JNDIInvoker.getTransactionManager();
cache.close();
ds1.disconnect();
ds1 = DistributedSystem.connect(props);
cache = CacheFactory.create(ds1);
tm2 = JNDIInvoker.getTransactionManager();
assertNotSame("TransactionManager are same in before restart and after restart", tm1, tm2);
ds1.disconnect();
} catch (Exception e) {
fail("Failed in restarting the distributed system");
}
}
use of javax.transaction.TransactionManager in project ignite by apache.
the class CacheJtaManager method start0.
/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
super.start0();
if (cctx.txConfig() != null) {
tmFactory = cctx.txConfig().getTxManagerFactory();
if (tmFactory != null) {
cctx.kernalContext().resource().injectGeneric(tmFactory);
if (tmFactory instanceof LifecycleAware)
((LifecycleAware) tmFactory).start();
Object txMgr;
try {
txMgr = tmFactory.create();
} catch (Exception e) {
throw new IgniteCheckedException("Failed to create transaction manager [tmFactory=" + tmFactory + "]", e);
}
if (txMgr == null)
throw new IgniteCheckedException("Failed to create transaction manager (transaction manager " + "factory created null-value transaction manager) [tmFactory=" + tmFactory + "]");
if (!(txMgr instanceof TransactionManager))
throw new IgniteCheckedException("Failed to create transaction manager (transaction manager " + "factory created object that is not an instance of TransactionManager) [tmFactory=" + tmFactory + ", txMgr=" + txMgr + "]");
jtaTm = (TransactionManager) txMgr;
} else {
String txLookupClsName = cctx.txConfig().getTxManagerLookupClassName();
if (txLookupClsName != null)
tmLookupRef.set(createTmLookup(txLookupClsName));
}
useJtaSync = cctx.txConfig().isUseJtaSynchronization();
}
}
use of javax.transaction.TransactionManager in project ignite by apache.
the class CacheJndiTmFactorySelfTest method testFactoryException.
/**
* @throws Exception If failed.
*/
public void testFactoryException() throws Exception {
final CacheJndiTmFactory f = new CacheJndiTmFactory("wrongJndiName", NOT_TM_JNDI_NAME, "wrongJndiName2");
GridTestUtils.assertThrows(log, new Callable<TransactionManager>() {
@Override
public TransactionManager call() throws Exception {
return f.create();
}
}, IgniteException.class, "Failed to lookup TM by");
}
Aggregations