use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class FetchJoinTest method testNotLoadingCustomer.
@Test
public void testNotLoadingCustomer() throws Exception {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
FetchPlan partyView = new View(Party.class).addProperty("name");
FetchPlan productView = new View(Product.class).addProperty("name");
FetchPlan customerView = new View(Customer.class).addProperty("customerNumber").addProperty("party", partyView);
FetchPlan salesPersonView = new View(SalesPerson.class).addProperty("salespersonNumber").addProperty("party", partyView);
FetchPlan orderView = new View(Order.class).addProperty("orderNumber").addProperty("customer", customerView).addProperty("salesPerson", salesPersonView);
FetchPlan orderLineView = new View(OrderLine.class).addProperty("order", orderView).addProperty("product", productView);
OrderLine reloadedOrderLine = em.find(OrderLine.class, orderLine.getId(), orderLineView);
assertNotNull(reloadedOrderLine);
assertNotNull(reloadedOrderLine.getOrder().getCustomer());
assertEquals(partyCustomer, reloadedOrderLine.getOrder().getCustomer().getParty());
assertNotNull(reloadedOrderLine.getOrder().getSalesPerson());
assertEquals(partyPerson, reloadedOrderLine.getOrder().getSalesPerson().getParty());
tx.commit();
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class DataManagerCommit2Test method testViewOnSecondLevelAfterCommitNew.
@Test
public void testViewOnSecondLevelAfterCommitNew() throws Exception {
FetchPlan groupView = new View(Group.class, false).addProperty("createTs").addProperty("constraints", new View(Constraint.class, false).addProperty("createTs")).setLoadPartialEntities(true);
Group group = dataManager.load(LoadContext.create(Group.class).setId(this.group2.getId()).setView(groupView));
assertNotNull(group);
assertFalse(entityStates.isLoaded(group.getConstraints().iterator().next(), "entityName"));
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("createTs").addProperty("constraints", new View(Constraint.class, false).addProperty("entityName")));
User committedUser = dataManager.commit(user, userView);
assertTrue(entityStates.isLoaded(committedUser.getGroup(), "createTs"));
assertTrue(entityStates.isLoaded(committedUser.getGroup().getConstraints().iterator().next(), "entityName"));
} finally {
testSupport.deleteRecord(user);
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class EclipseLinkDetachedTest method testSerializedFetchGroup.
@Test
public void testSerializedFetchGroup() throws Exception {
Transaction tx;
EntityManager em;
User user;
tx = persistence.createTransaction();
try {
em = persistence.getEntityManager();
FetchPlan view = new View(User.class).addProperty("login").setLoadPartialEntities(true);
user = em.find(User.class, userId, view);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
user = testSupport.reserialize(user);
assertEquals("testLogin", user.getLogin());
// exception on getting not loaded references
try {
user.getName();
fail();
} catch (Exception ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "group"));
user.getGroup();
} catch (Exception ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "userRoles"));
user.getUserRoles().size();
} catch (Exception ignored) {
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class EclipseLinkQueriesTest method testJoinOnWithToManyView.
// join on, view contains ToMany attribute
@Test
public void testJoinOnWithToManyView() throws Exception {
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 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 testCrossJoinViewParentReference.
// cross join, view with the reference to the parent entity
@Test
public void testCrossJoinViewParentReference() throws Exception {
List<Group> result;
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, test$User u where u.group = g", Group.class);
query.setView(view);
result = query.getResultList();
tx.commit();
}
for (Group g : result) {
g = testSupport.reserialize(g);
if (g.equals(rootGroup))
assertNull(g.getParent());
else if (g.equals(group))
assertEquals(rootGroup, g.getParent());
}
}
Aggregations