use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
the class TransactionTest method testSuspendRollback.
@Test
public void testSuspendRollback() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Server server = new Server();
server.setName("localhost");
server.setRunning(true);
em.persist(server);
Transaction tx1 = cont.persistence().createTransaction();
try {
EntityManager em1 = cont.persistence().getEntityManager();
assertTrue(em != em1);
Server server1 = em1.find(Server.class, server.getId());
assertNull(server1);
throwException();
tx1.commit();
} catch (Exception e) {
//
} finally {
tx1.end();
}
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
the class TransactionTest method testRunInTransaction.
@Test
public void testRunInTransaction() throws Exception {
UUID id = cont.persistence().callInTransaction(em -> {
assertNotNull(em);
Server server = new Server();
server.setName("localhost");
server.setRunning(true);
em.persist(server);
return server.getId();
});
cont.persistence().runInTransaction(em -> {
Server server = em.find(Server.class, id);
assertNotNull(server);
assertEquals(id, server.getId());
server.setRunning(false);
});
}
use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
the class TransactionTest method __testCommitRetainingAndRollback.
private void __testCommitRetainingAndRollback() {
UUID id;
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
assertNotNull(em);
Server server = new Server();
id = server.getId();
server.setName("localhost");
server.setRunning(true);
em.persist(server);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
server = em.find(Server.class, id);
assertEquals(id, server.getId());
server.setRunning(false);
throwException();
tx.commit();
} finally {
tx.end();
}
}
Aggregations