use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.
the class TestTxSuspendResume method testMultipleTxSameThread.
@Test
public void testMultipleTxSameThread() throws Exception {
String storePath = getStorePath("test-neo2");
deleteFileOrDirectory(storePath);
EmbeddedGraphDatabase neo2 = new EmbeddedGraphDatabase(storePath);
TransactionManager tm = neo2.getConfig().getTxModule().getTxManager();
tm.begin();
Node refNode = neo2.getReferenceNode();
Transaction tx1 = tm.suspend();
tm.begin();
refNode.setProperty("test2", "test");
Transaction tx2 = tm.suspend();
tm.resume(tx1);
CommitThread thread = new CommitThread(tm, tx2);
thread.start();
// would wait for ever since tx2 has write lock but now we have other
// thread thread that will commit tx2
refNode.removeProperty("test2");
assertTrue(thread.success());
tm.commit();
neo2.shutdown();
}
use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.
the class EmbeddedGraphDbImpl method beginTx.
/**
* @throws TransactionFailureException if unable to start transaction
*/
public Transaction beginTx() {
if (graphDbInstance.transactionRunning()) {
if (placeboTransaction == null) {
placeboTransaction = new PlaceboTransaction(graphDbInstance.getTransactionManager());
}
return placeboTransaction;
}
TransactionManager txManager = graphDbInstance.getTransactionManager();
Transaction result = null;
try {
txManager.begin();
result = new TopLevelTransaction(txManager);
} catch (Exception e) {
throw new TransactionFailureException("Unable to begin transaction", e);
}
return result;
}
use of javax.transaction.TransactionManager in project spring-framework by spring-projects.
the class JndiJtaTransactionManagerTests method doTestJtaTransactionManagerWithDefaultJndiLookups.
private void doTestJtaTransactionManagerWithDefaultJndiLookups(String tmName, boolean tmFound, boolean defaultUt) throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
if (defaultUt) {
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
} else {
given(tm.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
}
JtaTransactionManager ptm = new JtaTransactionManager();
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
if (defaultUt) {
jndiTemplate.addObject("java:comp/UserTransaction", ut);
}
jndiTemplate.addObject(tmName, tm);
ptm.setJndiTemplate(jndiTemplate);
ptm.afterPropertiesSet();
if (tmFound) {
assertEquals(tm, ptm.getTransactionManager());
} else {
assertNull(ptm.getTransactionManager());
}
if (defaultUt) {
assertEquals(ut, ptm.getUserTransaction());
} else {
assertTrue(ptm.getUserTransaction() instanceof UserTransactionAdapter);
UserTransactionAdapter uta = (UserTransactionAdapter) ptm.getUserTransaction();
assertEquals(tm, uta.getTransactionManager());
}
TransactionTemplate tt = new TransactionTemplate(ptm);
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
});
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
if (defaultUt) {
verify(ut).begin();
verify(ut).commit();
} else {
verify(tm).begin();
verify(tm).commit();
}
}
use of javax.transaction.TransactionManager in project spring-framework by spring-projects.
the class JndiJtaTransactionManagerTests method jtaTransactionManagerWithCustomJndiLookups.
@Test
public void jtaTransactionManagerWithCustomJndiLookups() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
TransactionManager tm = mock(TransactionManager.class);
JtaTransactionManager ptm = new JtaTransactionManager();
ptm.setUserTransactionName("jndi-ut");
ptm.setTransactionManagerName("jndi-tm");
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
jndiTemplate.addObject("jndi-ut", ut);
jndiTemplate.addObject("jndi-tm", tm);
ptm.setJndiTemplate(jndiTemplate);
ptm.afterPropertiesSet();
assertEquals(ut, ptm.getUserTransaction());
assertEquals(tm, ptm.getTransactionManager());
TransactionTemplate tt = new TransactionTemplate(ptm);
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
});
assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
verify(ut).begin();
verify(ut).commit();
}
use of javax.transaction.TransactionManager in project spring-framework by spring-projects.
the class WebLogicJtaTransactionManager method retrieveTransactionManager.
@Override
protected TransactionManager retrieveTransactionManager() throws TransactionSystemException {
loadWebLogicTransactionHelper();
try {
logger.debug("Retrieving JTA TransactionManager from WebLogic TransactionHelper");
Method getTransactionManagerMethod = this.transactionHelper.getClass().getMethod("getTransactionManager");
return (TransactionManager) getTransactionManagerMethod.invoke(this.transactionHelper);
} catch (InvocationTargetException ex) {
throw new TransactionSystemException("WebLogic's TransactionHelper.getTransactionManager() method failed", ex.getTargetException());
} catch (Exception ex) {
throw new TransactionSystemException("Could not invoke WebLogic's TransactionHelper.getTransactionManager() method", ex);
}
}
Aggregations