Search in sources :

Example 31 with Server

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();
    }
}
Also used : Server(com.haulmont.cuba.core.entity.Server) Test(org.junit.Test)

Example 32 with Server

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);
    });
}
Also used : Server(com.haulmont.cuba.core.entity.Server) UUID(java.util.UUID) Test(org.junit.Test)

Example 33 with Server

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();
    }
}
Also used : Server(com.haulmont.cuba.core.entity.Server) UUID(java.util.UUID)

Aggregations

Server (com.haulmont.cuba.core.entity.Server)33 Test (org.junit.Test)25 UUID (java.util.UUID)10 Entity (com.haulmont.cuba.core.entity.Entity)8 Before (org.junit.Before)4 UserSession (com.haulmont.cuba.security.global.UserSession)3 TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)3 Date (java.util.Date)3 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)2 User (com.haulmont.cuba.security.entity.User)2 QueryRunner (com.haulmont.bali.db.QueryRunner)1 Instance (com.haulmont.chile.core.model.Instance)1 DataService (com.haulmont.cuba.core.app.DataService)1 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)1 EntitySnapshot (com.haulmont.cuba.core.entity.EntitySnapshot)1 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 EntityDiff (com.haulmont.cuba.core.entity.diff.EntityDiff)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1