Search in sources :

Example 36 with FetchPlan

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

the class AbstractTable method getInstanceContainer.

@SuppressWarnings("unchecked")
@Override
public InstanceContainer<E> getInstanceContainer(E item) {
    if (fieldDatasources == null) {
        fieldDatasources = new WeakHashMap<>();
    }
    Object fieldDatasource = fieldDatasources.get(item);
    if (fieldDatasource instanceof InstanceContainer) {
        return (InstanceContainer<E>) fieldDatasource;
    }
    EntityTableItems containerTableItems = (EntityTableItems) getItems();
    if (containerTableItems == null) {
        throw new IllegalStateException("Table is not bound to items");
    }
    InstanceContainer<E> instanceContainer;
    MetaClass metaClass = containerTableItems.getEntityMetaClass();
    if (metaClass instanceof KeyValueMetaClass) {
        instanceContainer = (InstanceContainer<E>) dataComponents.createKeyValueContainer(metaClass);
    } else {
        instanceContainer = dataComponents.createInstanceContainer(metaClass.getJavaClass());
    }
    FetchPlan view = viewRepository.getFetchPlan(metaClass, FetchPlan.LOCAL);
    instanceContainer.setFetchPlan(view);
    instanceContainer.setItem(item);
    fieldDatasources.put(item, instanceContainer);
    return instanceContainer;
}
Also used : KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) InstanceContainer(io.jmix.ui.model.InstanceContainer) FetchPlan(io.jmix.core.FetchPlan)

Example 37 with FetchPlan

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

the class FetchJoinTest method testNotLoadingJoinB.

@Test
public void testNotLoadingJoinB() throws Exception {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        FetchPlan fView = new View(JoinF.class).addProperty("name");
        FetchPlan eView = new View(JoinE.class).addProperty("name").addProperty("f", fView, FetchMode.JOIN);
        FetchPlan dView = new View(JoinD.class).addProperty("name");
        FetchPlan cView = new View(JoinC.class).addProperty("name").addProperty("d", dView, FetchMode.JOIN).addProperty("e", eView, FetchMode.JOIN);
        FetchPlan bView = new View(JoinB.class).addProperty("name").addProperty("c", cView, FetchMode.JOIN);
        FetchPlan aView = new View(JoinA.class).addProperty("name").addProperty("b", bView, FetchMode.JOIN);
        JoinA loadedA = em.find(JoinA.class, joinA.getId(), aView);
        assertNotNull(loadedA);
        assertNotNull(loadedA.getB().getC().getD());
        assertNotNull(loadedA.getB().getC().getE());
        assertNotNull(loadedA.getB().getC().getE().getF());
        tx.commit();
    }
}
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 38 with FetchPlan

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

the class FetchSameEntityTest method testUnFetched.

@Test
public void testUnFetched() throws Exception {
    DataManager dataManager = AppBeans.get(DataManager.class);
    FetchPlan a1View = new View(FetchSameLinkAEntity.class).addProperty("name").addProperty("mainEntity", new View(FetchSameMainEntity.class));
    FetchPlan a2View = new View(FetchSameLinkAEntity.class).addProperty("description");
    FetchPlan bView = new View(FetchSameLinkBEntity.class).addProperty("name").addProperty("linkAEntity", a2View);
    FetchPlan mainView = new View(FetchSameMainEntity.class).addProperty("description").addProperty("linkAEntities", a1View).addProperty("linkBEntities", bView);
    LoadContext<FetchSameMainEntity> lc = new LoadContext<>(FetchSameMainEntity.class).setId(mainEntity.getId()).setView(mainView);
    FetchSameMainEntity reloaded = dataManager.load(lc);
    assertEquals(1, reloaded.getLinkAEntities().size());
    // no exception should be thrown
    reloaded.getLinkAEntities().get(0).getMainEntity();
}
Also used : LoadContext(com.haulmont.cuba.core.global.LoadContext) DataManager(com.haulmont.cuba.core.global.DataManager) FetchSameMainEntity(com.haulmont.cuba.core.model.FetchSameMainEntity) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) FetchSameLinkAEntity(com.haulmont.cuba.core.model.FetchSameLinkAEntity) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 39 with FetchPlan

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

the class EclipseLinkQueriesTest method testJoinOnWithToManyView2.

// join on, view contains ToMany attribute, fetch = JOIN
@Test
public void testJoinOnWithToManyView2() throws Exception {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Group.class).addProperty("constraints", new View(Constraint.class, FetchPlan.LOCAL), FetchMode.JOIN);
        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) Constraint(com.haulmont.cuba.core.model.common.Constraint) 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 40 with FetchPlan

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

the class EclipseLinkQueriesTest method testCrossJoinWithToManyView.

// cross join, view has ToMany reference
@Test
public void testCrossJoinWithToManyView() throws Exception {
    List<Group> result;
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Group.class).addProperty("constraints");
        TypedQuery<Group> query = em.createQuery("select g from test$Group g, test$User u where u.group = g", Group.class);
        query.setView(view);
        result = query.getResultList();
        tx.commit();
    }
    for (Group group : result) {
        group = testSupport.reserialize(group);
        group.getConstraints().size();
    }
}
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)

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