Search in sources :

Example 46 with View

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

the class SoftDeleteNotFoundDeletedTest method testLoadDeletedObject.

@Test
public void testLoadDeletedObject() {
    View taskView_Message = new View(SoftDelete_Task.class).addProperty("message");
    View taskView_Service = new View(SoftDelete_Task.class).addProperty("service", new View(SoftDelete_Service.class).addProperty("code"));
    View taskValueView = new View(SoftDelete_TaskValue.class).addProperty("task", taskView_Message);
    View projectView = new View(SoftDelete_Project.class).addProperty("name").addProperty("aValue", taskValueView).addProperty("task", taskView_Service);
    LoadContext<SoftDelete_Project> loadContext = new LoadContext<>(SoftDelete_Project.class).setView(projectView).setId(projectId);
    SoftDelete_Project project = dataManager.load(loadContext);
    Assert.assertNotNull(project);
    Assert.assertNotNull(project.getTask());
    Assert.assertTrue(project.getTask().isDeleted());
}
Also used : SoftDelete_Task(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Task) SoftDelete_TaskValue(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_TaskValue) LoadContext(com.haulmont.cuba.core.global.LoadContext) SoftDelete_Project(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Project) View(com.haulmont.cuba.core.global.View)

Example 47 with View

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

the class SoftDeleteTest method testReferenceToDeletedEntityOneToManyThroughManyToOne.

@Test
public void testReferenceToDeletedEntityOneToManyThroughManyToOne() {
    View constraintView = new View(Constraint.class).addProperty("code");
    View groupView = new View(Group.class).addProperty("name").addProperty("constraints", constraintView, FetchMode.BATCH);
    View groupHierarchyView = new View(GroupHierarchy.class).addProperty("group", groupView, FetchMode.BATCH);
    GroupHierarchy groupHierarchy = cont.persistence().callInTransaction((em) -> em.find(GroupHierarchy.class, groupHierarchyId, groupHierarchyView));
    assertNotNull(groupHierarchy);
    assertNotNull(groupHierarchy.getGroup());
    assertEquals(1, groupHierarchy.getGroup().getConstraints().size());
}
Also used : View(com.haulmont.cuba.core.global.View)

Example 48 with View

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

the class SoftDeleteTest method testOneToOneQuery.

@Test
public void testOneToOneQuery() {
    System.out.println("===================== BEGIN testOneToOneQuery =====================");
    // test fetchMode = AUTO
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneA.class, "testView").addProperty("name").addProperty("b", new View(SoftDeleteOneToOneB.class, "testView").addProperty("name"));
        List<SoftDeleteOneToOneA> r = em.createQuery("select a from test$SoftDeleteOneToOneA a where a.name = :name", SoftDeleteOneToOneA.class).setParameter("name", "oneToOneA2").setView(view).getResultList();
        assertEquals(1, r.size());
        assertEquals(r.get(0).getB().getId(), oneToOneB2Id);
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOneQuery =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) SoftDeleteOneToOneA(com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA) View(com.haulmont.cuba.core.global.View)

Example 49 with View

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

the class SoftDeleteTest method testOneToOneMappedByQuery.

@Test
public void testOneToOneMappedByQuery() {
    System.out.println("===================== BEGIN testOneToOneMappedByQuery =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        SoftDeleteOneToOneA oneToOneA3 = cont.metadata().create(SoftDeleteOneToOneA.class);
        oneToOneA3.setName("oneToOneA3");
        oneToOneA3.setB(em.find(SoftDeleteOneToOneB.class, oneToOneB1Id));
        em.persist(oneToOneA3);
        oneToOneA3Id = oneToOneA3.getId();
        tx.commit();
    } finally {
        tx.end();
    }
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"));
        List<SoftDeleteOneToOneB> r = em.createQuery("select b from test$SoftDeleteOneToOneB b where b.name = :name", SoftDeleteOneToOneB.class).setParameter("name", "oneToOneB1").setView(view).getResultList();
        assertEquals(1, r.size());
        assertEquals(r.get(0).getA().getId(), oneToOneA3Id);
        assertEquals(r.get(0).getA().getName(), "oneToOneA3");
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOneMappedByQuery =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) SoftDeleteOneToOneA(com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA) SoftDeleteOneToOneB(com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB) View(com.haulmont.cuba.core.global.View)

Example 50 with View

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

the class SoftDeleteTest method testOneToMany.

@Test
public void testOneToMany() {
    System.out.println("===================== BEGIN testOneToMany =====================");
    // test fetchMode = AUTO
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView").addProperty("role", new View(Role.class, "testView").addProperty("name")));
        User user = em.find(User.class, userId, view);
        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = JOIN
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        View view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView"), FetchMode.JOIN);
        User user = em.find(User.class, userId, view);
        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToMany =====================");
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) View(com.haulmont.cuba.core.global.View)

Aggregations

View (com.haulmont.cuba.core.global.View)55 Test (org.junit.Test)24 EntityManager (com.haulmont.cuba.core.EntityManager)22 Transaction (com.haulmont.cuba.core.Transaction)21 User (com.haulmont.cuba.security.entity.User)19 Group (com.haulmont.cuba.security.entity.Group)10 MetaClass (com.haulmont.chile.core.model.MetaClass)5 ViewProperty (com.haulmont.cuba.core.global.ViewProperty)5 UserRole (com.haulmont.cuba.security.entity.UserRole)5 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 Entity (com.haulmont.cuba.core.entity.Entity)2 ViewRepository (com.haulmont.cuba.core.global.ViewRepository)2 Role (com.haulmont.cuba.security.entity.Role)2 SoftDeleteOneToOneB (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneB)2 QueryRunner (com.haulmont.bali.db.QueryRunner)1 MetadataObject (com.haulmont.chile.core.model.MetadataObject)1 DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)1 QueryResult (com.haulmont.cuba.core.entity.QueryResult)1 Server (com.haulmont.cuba.core.entity.Server)1