Search in sources :

Example 31 with FetchPlan

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

the class CheckLoadedStateTest method testGetCurrentFetchPlan.

@Test
public void testGetCurrentFetchPlan() {
    DataManager dataManager = AppBeans.get(DataManager.class);
    EntityStates entityStates = AppBeans.get(EntityStates.class);
    User user = dataManager.load(User.class).id(userId).fetchPlan("user.edit").one();
    FetchPlan fetchPlan = entityStates.getCurrentFetchPlan(user);
    User user1 = dataManager.load(User.class).id(userId).fetchPlan(fetchPlan).one();
    entityStates.checkLoadedWithFetchPlan(user1, "user.edit");
}
Also used : User(com.haulmont.cuba.core.model.common.User) FetchPlan(io.jmix.core.FetchPlan) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 32 with FetchPlan

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

the class DataManagerCommit2Test method testViewAfterCommitModified.

@Test
public void testViewAfterCommitModified() throws Exception {
    Group group2 = dataManager.load(LoadContext.create(Group.class).setId(this.group2.getId()).setFetchPlan(FetchPlan.INSTANCE_NAME));
    assertFalse(entityStates.isLoaded(group2, "createTs"));
    LoadContext<User> loadContext = LoadContext.create(User.class).setId(userId).setView(view);
    User user = dataManager.load(loadContext);
    user.setName("testUser-changed");
    user.setGroup(group2);
    FetchPlan userView = new View(User.class, true).addProperty("login").addProperty("name").addProperty("group", new View(Group.class).addProperty("name").addProperty("createTs"));
    User committedUser = dataManager.commit(user, userView);
    assertTrue(entityStates.isLoaded(committedUser.getGroup(), "createTs"));
}
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 33 with FetchPlan

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

the class DataManagerCommit2Test method testViewAfterCommitNew.

@Test
public void testViewAfterCommitNew() throws Exception {
    Group group = dataManager.load(LoadContext.create(Group.class).setId(group1.getId()).setFetchPlan(FetchPlan.INSTANCE_NAME));
    assertFalse(entityStates.isLoaded(group, "createTs"));
    User user = metadata.create(User.class);
    try {
        user.setName("testUser");
        user.setLogin("login" + user.getId());
        user.setGroup(group);
        FetchPlan userView = new View(User.class, true).addProperty("login").addProperty("name").addProperty("group", new View(Group.class, false).addProperty("name").addProperty("createTs"));
        User committedUser = dataManager.commit(user, userView);
        assertTrue(entityStates.isLoaded(committedUser.getGroup(), "createTs"));
    } finally {
        testSupport.deleteRecord(user);
    }
}
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 34 with FetchPlan

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

the class EclipseLinkQueriesTest method testJoinOnWithParentReference.

// join on, view contains parent attribute
@Test
public void testJoinOnWithParentReference() throws Exception {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Group.class).addProperty("parent");
        TypedQuery<Group> query = em.createQuery("select g from test$Group g join test$QueryResult qr on qr.entityId = g.id where qr.queryKey = 1", Group.class);
        query.setView(view);
        List<Group> result = query.getResultList();
        tx.commit();
    }
}
Also used : Group(com.haulmont.cuba.core.model.common.Group) 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 35 with FetchPlan

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

the class FetchJoinTest method testLoadingJoinedInheritance.

@Test
public void testLoadingJoinedInheritance() throws Exception {
    FetchPlan typeLocalView = new View(JoinType.class).addProperty("name");
    FetchPlan classTypeView = new View(JoinClassType.class).addProperty("name").addProperty("types", typeLocalView);
    FetchPlan typeView = new View(JoinType.class).addProperty("name").addProperty("classType", classTypeView);
    FetchPlan userView = new View(JoinUser.class).addProperty("name").addProperty("type", typeView);
    DataManager dataManager = AppBeans.get(DataManager.class);
    JoinUser reloadedUser = dataManager.load(JoinUser.class).id(user.getId()).view(userView).one();
    assertNotNull(reloadedUser);
    assertEquals(type, reloadedUser.getType());
    assertEquals(classType, reloadedUser.getType().getClassType());
}
Also used : DataManager(com.haulmont.cuba.core.global.DataManager) 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