Search in sources :

Example 36 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SoftDeleteDataManagerTest method setUp.

@Before
public void setUp() throws Exception {
    persistence = cont.persistence();
    metadata = cont.metadata();
    try (Transaction tx = persistence.createTransaction()) {
        user = metadata.create(User.class);
        user.setGroup(persistence.getEntityManager().find(Group.class, TestSupport.COMPANY_GROUP_ID));
        user.setLogin("user-" + user.getId());
        persistence.getEntityManager().persist(user);
        tx.commit();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) Transaction(com.haulmont.cuba.core.Transaction) Before(org.junit.Before)

Example 37 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SoftDeleteMany2ManyTest method test_PL_3452.

/**
 * @see <a href="https://youtrack.haulmont.com/issue/PL-3452">PL-3452</a>
 */
@Test
public void test_PL_3452() throws Exception {
    Many2ManyA a1;
    Many2ManyA a2;
    Many2ManyB b1;
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        a1 = em.find(Many2ManyA.class, this.a1.getId());
        assertNotNull(a1);
        assertEquals(2, a1.getCollectionOfB().size());
        a2 = em.find(Many2ManyA.class, this.a2.getId());
        assertNotNull(a2);
        assertEquals(1, a2.getCollectionOfB().size());
        tx.commitRetaining();
        em = cont.entityManager();
        b1 = em.find(Many2ManyB.class, this.b1.getId());
        em.remove(b1);
        tx.commitRetaining();
        em = cont.entityManager();
        a1 = em.find(Many2ManyA.class, this.a1.getId());
        assertNotNull(a1);
        assertEquals(1, a1.getCollectionOfB().size());
        tx.commit();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Many2ManyB(com.haulmont.cuba.testmodel.many2many.Many2ManyB) Many2ManyA(com.haulmont.cuba.testmodel.many2many.Many2ManyA) Test(org.junit.Test)

Example 38 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SoftDeleteMany2ManyTest method testMany2ManyUnlink.

@Test
public void testMany2ManyUnlink() throws Exception {
    try (Transaction tx = cont.persistence().createTransaction()) {
        Many2ManyA a = cont.entityManager().find(Many2ManyA.class, this.many2ManyA.getId());
        assertNotNull(a);
        assertFalse(a.getCollectionOfB().isEmpty());
        assertEquals(many2ManyB, a.getCollectionOfB().iterator().next());
        tx.commit();
    }
    try (Transaction tx = cont.persistence().createTransaction()) {
        Many2ManyB b = cont.entityManager().find(Many2ManyB.class, this.many2ManyB.getId());
        cont.entityManager().remove(b);
        tx.commit();
    }
    try (Transaction tx = cont.persistence().createTransaction()) {
        Many2ManyA a = cont.entityManager().find(Many2ManyA.class, this.many2ManyA.getId());
        assertNotNull(a);
        assertTrue(a.getCollectionOfB().isEmpty());
        tx.commit();
    }
}
Also used : Transaction(com.haulmont.cuba.core.Transaction) Many2ManyB(com.haulmont.cuba.testmodel.many2many.Many2ManyB) Many2ManyA(com.haulmont.cuba.testmodel.many2many.Many2ManyA) Test(org.junit.Test)

Example 39 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SoftDeleteNotFoundDeletedTest method setUp.

@Before
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        SoftDelete_Service service = new SoftDelete_Service();
        serviceId = service.getId();
        service.setName("service");
        service.setCode("serviceCode");
        em.persist(service);
        SoftDelete_Task task = new SoftDelete_Task();
        taskId = task.getId();
        task.setMessage("message");
        task.setService(service);
        em.persist(task);
        SoftDelete_TaskValue taskValue = new SoftDelete_TaskValue();
        taskValueId = taskValue.getId();
        taskValue.setTask(task);
        em.persist(taskValue);
        SoftDelete_Project project = new SoftDelete_Project();
        projectId = project.getId();
        project.setName("project");
        project.setAValue(taskValue);
        project.setTask(task);
        em.persist(project);
        tx.commitRetaining();
        em = cont.persistence().getEntityManager();
        task = em.find(SoftDelete_Task.class, taskId);
        em.remove(task);
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : SoftDelete_Task(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Task) EntityManager(com.haulmont.cuba.core.EntityManager) SoftDelete_Service(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Service) SoftDelete_TaskValue(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_TaskValue) Transaction(com.haulmont.cuba.core.Transaction) DataManager(com.haulmont.cuba.core.global.DataManager) SoftDelete_Project(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Project)

Example 40 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SoftDeleteTest method testQuery_CleanupMode.

@Test
public void testQuery_CleanupMode() {
    System.out.println("===================== BEGIN testQuery_CleanupMode =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        em.setSoftDeletion(false);
        Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
        query.setParameter(1, "roleToBeDeleted");
        List<Role> list = query.getResultList();
        assertTrue(!list.isEmpty());
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testQuery_CleanupMode =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)211 EntityManager (com.haulmont.cuba.core.EntityManager)138 Test (org.junit.Test)44 User (com.haulmont.cuba.security.entity.User)30 Query (com.haulmont.cuba.core.Query)26 View (com.haulmont.cuba.core.global.View)21 Before (org.junit.Before)15 Group (com.haulmont.cuba.security.entity.Group)13 TypedQuery (com.haulmont.cuba.core.TypedQuery)11 MetaClass (com.haulmont.chile.core.model.MetaClass)9 SendingMessage (com.haulmont.cuba.core.entity.SendingMessage)8 Entity (com.haulmont.cuba.core.entity.Entity)7 List (java.util.List)6 Role (com.haulmont.cuba.security.entity.Role)5 UserRole (com.haulmont.cuba.security.entity.UserRole)5 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)5 UUID (java.util.UUID)5 Nullable (javax.annotation.Nullable)5 AppFolder (com.haulmont.cuba.core.entity.AppFolder)4 IdentityEntity (com.haulmont.cuba.testmodel.primary_keys.IdentityEntity)4