use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class CloseEntityManagerWithActiveTransactionTest method testUpdateThenCloseWithAnActiveTransaction.
@Test
@TestForIssue(jiraKey = "HHH-11166")
public void testUpdateThenCloseWithAnActiveTransaction() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
EntityManager em = getOrCreateEntityManager();
try {
Box box = new Box();
box.setColor("red-and-white");
em.persist(box);
em.close();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
em = getOrCreateEntityManager();
box = em.find(Box.class, box.getId());
Muffin muffin = new Muffin();
muffin.setKind("blueberry");
box.addMuffin(muffin);
em.close();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
} catch (Exception e) {
final TransactionManager transactionManager = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
if (transactionManager.getTransaction() != null && transactionManager.getTransaction().getStatus() == Status.STATUS_ACTIVE) {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
throw e;
} finally {
if (em.isOpen()) {
em.close();
}
}
em = getOrCreateEntityManager();
try {
final List<Box> boxes = em.createQuery("from Box").getResultList();
assertThat(boxes.size(), is(1));
assertThat(boxes.get(0).getMuffinSet().size(), is(1));
} finally {
em.close();
}
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class CloseEntityManagerWithActiveTransactionTest method testCommitReleasesLogicalConnection.
@Test
@TestForIssue(jiraKey = "HHH-11099")
public void testCommitReleasesLogicalConnection() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
EntityManager em = getOrCreateEntityManager();
try {
Box box = new Box();
box.setColor("red-and-white");
em.persist(box);
final SessionImpl session = (SessionImpl) em.unwrap(Session.class);
final JdbcCoordinatorImpl jdbcCoordinator = (JdbcCoordinatorImpl) session.getJdbcCoordinator();
em.close();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertThat("The logical connection is still open after commit", jdbcCoordinator.getLogicalConnection().isOpen(), is(false));
} catch (Exception e) {
final TransactionManager transactionManager = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
if (transactionManager.getTransaction() != null && transactionManager.getTransaction().getStatus() == Status.STATUS_ACTIVE) {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
}
throw e;
} finally {
if (em.isOpen()) {
em.close();
}
}
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class TxUtil method markRollbackOnly.
public static void markRollbackOnly(boolean useJta, Session s) {
if (useJta) {
JtaPlatform jtaPlatform = s.getSessionFactory().getSessionFactoryOptions().getServiceRegistry().getService(JtaPlatform.class);
TransactionManager tm = jtaPlatform.retrieveTransactionManager();
try {
tm.setRollbackOnly();
} catch (SystemException e) {
throw new RuntimeException(e);
}
} else {
s.getTransaction().markRollbackOnly();
}
}
use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.
the class MasterImpl method rollbackThisAndResumeOther.
void rollbackThisAndResumeOther(Transaction otherTx, SlaveContext txId) {
try {
TransactionManager txManager = graphDbConfig.getTxModule().getTxManager();
txManager.rollback();
transactions.remove(txId);
if (otherTx != null) {
txManager.resume(otherTx);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of javax.transaction.TransactionManager in project graphdb by neo4j-attic.
the class TestKernelPanic method panicTest.
@Test
public void panicTest() throws Exception {
String path = "target/var/testdb";
AbstractNeo4jTestCase.deleteFileOrDirectory(new File(path));
EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(path);
XaDataSourceManager xaDs = graphDb.getConfig().getTxModule().getXaDataSourceManager();
IllBehavingXaDataSource noob = new IllBehavingXaDataSource();
xaDs.registerDataSource("noob", noob, UTF8.encode("554342"));
Panic panic = new Panic();
graphDb.registerKernelEventHandler(panic);
org.neo4j.graphdb.Transaction gdbTx = graphDb.beginTx();
TransactionManager txMgr = graphDb.getConfig().getTxModule().getTxManager();
Transaction tx = txMgr.getTransaction();
graphDb.createNode();
tx.enlistResource(noob.getXaConnection().getXaResource());
try {
gdbTx.success();
gdbTx.finish();
fail("Should fail");
} catch (Throwable t) {
// ok
for (int i = 0; i < 10 && panic.panic == false; i++) {
Thread.sleep(1000);
}
} finally {
graphDb.unregisterKernelEventHandler(panic);
}
assertTrue(panic.panic);
graphDb.shutdown();
}
Aggregations