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;
}
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();
}
}
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();
}
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();
}
}
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();
}
}
Aggregations