Search in sources :

Example 21 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class ViewBuilderTest method testRefView.

@Test
public void testRefView() {
    FetchPlan view = ViewBuilder.of(Pet.class).add("owner", builder -> builder.add("name")).build();
    assertFalse(containsSystemProperties(view));
    assertNotNull(view.getProperty("owner"));
    FetchPlan ownerView = view.getProperty("owner").getFetchPlan();
    assertNotNull(ownerView);
    assertFalse(containsSystemProperties(ownerView));
    assertTrue(ownerView.containsProperty("name"));
}
Also used : Pet(com.haulmont.cuba.core.model.Pet) Test(org.junit.jupiter.api.Test) ViewBuilder(com.haulmont.cuba.core.global.ViewBuilder) List(java.util.List) FetchPlanProperty(io.jmix.core.FetchPlanProperty) FetchPlan(io.jmix.core.FetchPlan) Owner(com.haulmont.cuba.core.model.Owner) Assertions(org.junit.jupiter.api.Assertions) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) MetadataTools(io.jmix.core.MetadataTools) FetchPlan(io.jmix.core.FetchPlan) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Example 22 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class ViewBuilderTest method testBuild.

@Test
public void testBuild() {
    FetchPlan view = ViewBuilder.of(Pet.class).build();
    assertNotNull(view);
    assertFalse(containsSystemProperties(view));
    assertFalse(view.containsProperty("name"));
}
Also used : FetchPlan(io.jmix.core.FetchPlan) Pet(com.haulmont.cuba.core.model.Pet) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Example 23 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class SoftDeleteTest method testReferenceToDeletedEntityOneToManyThroughManyToOne.

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

Example 24 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class SoftDeleteTest method testManyToOne_InnerJoinOnClause.

@Test
public void testManyToOne_InnerJoinOnClause() throws SQLException {
    System.out.println("===================== BEGIN testManyToOne =====================");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(persistence.getDataSource());
    jdbcTemplate.update("update TEST_GROUP set DELETE_TS = current_timestamp, DELETED_BY = 'admin' where ID = ?", groupId.toString());
    // test without view
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
        Group group = null;
        try {
            User user = em.find(User.class, userId);
            group = user.getGroup();
        } finally {
            setPrintInnerJoinInWhereClause(em, prevValue);
        }
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    FetchPlan view;
    // test fetchMode = AUTO (JOIN is used)
    view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"));
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
        Group group;
        try {
            User user = em.find(User.class, userId, view);
            group = user.getGroup();
        } finally {
            setPrintInnerJoinInWhereClause(em, prevValue);
        }
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    // test fetchMode = UNDEFINED
    view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.UNDEFINED);
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
        Group group;
        try {
            User user = em.find(User.class, userId, view);
            group = user.getGroup();
        } finally {
            setPrintInnerJoinInWhereClause(em, prevValue);
        }
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    // test fetchMode = BATCH
    view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.BATCH);
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        boolean prevValue = setPrintInnerJoinInWhereClause(em, false);
        Group group;
        try {
            User user = em.find(User.class, userId, view);
            group = user.getGroup();
        } finally {
            setPrintInnerJoinInWhereClause(em, prevValue);
        }
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    System.out.println("===================== END testManyToOne =====================");
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 25 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class SoftDeleteTest method testManyToOne.

@Test
public void testManyToOne() throws SQLException {
    System.out.println("===================== BEGIN testManyToOne =====================");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(persistence.getDataSource());
    jdbcTemplate.update("update TEST_GROUP set DELETE_TS = current_timestamp, DELETED_BY = 'admin' where ID = ?", groupId.toString());
    // test without view
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        User user = em.find(User.class, userId);
        Group group = user.getGroup();
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    FetchPlan view;
    // test fetchMode = AUTO (JOIN is used)
    view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"));
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        User user = em.find(User.class, userId, view);
        Group group = user.getGroup();
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    // test fetchMode = UNDEFINED
    view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.UNDEFINED);
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        User user = em.find(User.class, userId, view);
        Group group = user.getGroup();
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    // test fetchMode = BATCH
    view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("group", new View(Group.class).addProperty("name"), FetchMode.BATCH);
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        User user = em.find(User.class, userId, view);
        Group group = user.getGroup();
        tx.commit();
        assertNotNull(group);
        assertTrue(group.isDeleted());
    }
    System.out.println("===================== END testManyToOne =====================");
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Aggregations

FetchPlan (io.jmix.core.FetchPlan)61 Test (org.junit.jupiter.api.Test)48 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)45 View (com.haulmont.cuba.core.global.View)35 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)10 Pet (com.haulmont.cuba.core.model.Pet)5 SoftDeleteOneToOneA (com.haulmont.cuba.core.model.SoftDeleteOneToOneA)5 Group (com.haulmont.cuba.core.model.common.Group)5 User (com.haulmont.cuba.core.model.common.User)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 DataManager (com.haulmont.cuba.core.global.DataManager)3 LoadContext (com.haulmont.cuba.core.global.LoadContext)3 FetchPlanProperty (io.jmix.core.FetchPlanProperty)3 Metadata (io.jmix.core.Metadata)3 MetadataTools (io.jmix.core.MetadataTools)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 SoftDeleteOneToOneB (com.haulmont.cuba.core.model.SoftDeleteOneToOneB)2 Permission (com.haulmont.cuba.core.model.common.Permission)2 QueryImpl (com.haulmont.cuba.core.sys.QueryImpl)2 Entity (io.jmix.core.Entity)2