use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class EntityCacheTestClass method testLoadingRelatedEntityFromCache.
@Test
public void testLoadingRelatedEntityFromCache() {
appender.clearMessages();
FetchPlanRepository viewRepository = AppBeans.get(FetchPlanRepository.class);
FetchPlan view = viewRepository.getFetchPlan(metadata.getClass(UserSubstitution.class), "usersubst.edit");
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().find(UserSubstitution.class, this.userSubstitution.getId(), view);
tx.commit();
}
// UserSubstitution, User, User
assertEquals(3, appender.filterMessages(selectsOnly).count());
// User must not be joined because it is cached
assertTrue(appender.filterMessages(selectsOnly).noneMatch(s -> s.contains("JOIN TEST_USER")));
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().find(UserSubstitution.class, this.userSubstitution.getId(), view);
tx.commit();
}
// UserSubstitution only, User is cached
assertEquals(1, appender.filterMessages(selectsOnly).count());
// User must not be joined because it is cached
assertTrue(appender.filterMessages(selectsOnly).noneMatch(s -> s.contains("JOIN TEST_USER")));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class EntityCacheTestClass method loadUserSetting.
private UserSetting loadUserSetting() throws Exception {
UserSetting us;
FetchPlan usView = new View(UserSetting.class).addProperty("name").addProperty("user", new View(User.class).addProperty("login"));
try (Transaction tx = persistence.createTransaction()) {
us = persistence.getEntityManager().find(UserSetting.class, this.userSetting.getId(), usView);
assertNotNull(us);
tx.commit();
}
us = testSupport.reserialize(us);
assertEquals(userSetting, us);
assertEquals(user, us.getUser());
return us;
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class QueryCacheTestClass method testLoadingWithPartialView.
@Test
public void testLoadingWithPartialView() throws Exception {
appender.clearMessages();
User user;
List<User> resultList;
// load with view: one parameter login
FetchPlan userLoginView = new View(User.class).addProperty("login").setLoadPartialEntities(true);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<User> query = em.createQuery("select u from test$User u where u.login like 'ECTest-%' order by u.name asc", User.class);
query.setCacheable(true);
query.setView(userLoginView);
resultList = query.getResultList();
assertEquals(resultList.size(), 2);
tx.commit();
}
user = testSupport.reserialize(resultList.get(0));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
user = testSupport.reserialize(resultList.get(1));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
// user
assertEquals(1, appender.filterMessages(m -> m.contains("> SELECT")).count());
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<User> query = em.createQuery("select u from test$User u where u.login like 'ECTest-%' order by u.name asc", User.class);
query.setCacheable(true);
query.setView(userLoginView);
resultList = query.getResultList();
assertEquals(resultList.size(), 2);
tx.commit();
}
user = testSupport.reserialize(resultList.get(0));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
user = testSupport.reserialize(resultList.get(1));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
// user
assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
appender.clearMessages();
// load with view: group
FetchPlan groupView = new View(Group.class, false).addProperty("name").setLoadPartialEntities(true);
FetchPlan userGroupView = new View(User.class).addProperty("group", groupView).setLoadPartialEntities(true);
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<User> query = em.createQuery("select u from test$User u where u.login like 'ECTest-%' order by u.name asc", User.class);
query.setCacheable(true);
query.setView(userGroupView);
resultList = query.getResultList();
assertEquals(resultList.size(), 2);
tx.commit();
}
user = testSupport.reserialize(resultList.get(0));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertEquals(user.getGroup(), group);
assertEquals(user.getGroup().getName(), group.getName());
user = testSupport.reserialize(resultList.get(1));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertEquals(user.getGroup(), group);
assertEquals(user.getGroup().getName(), group.getName());
assertEquals(1, appender.filterMessages(m -> m.contains("> SELECT") && m.contains("TEST_GROUP")).count());
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<User> query = em.createQuery("select u from test$User u where u.login like 'ECTest-%' order by u.name asc", User.class);
query.setCacheable(true);
query.setView(userGroupView);
resultList = query.getResultList();
assertEquals(resultList.size(), 2);
tx.commit();
}
user = testSupport.reserialize(resultList.get(0));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertEquals(user.getGroup(), group);
assertEquals(user.getGroup().getName(), group.getName());
user = testSupport.reserialize(resultList.get(1));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertEquals(user.getGroup(), group);
assertEquals(user.getGroup().getName(), group.getName());
assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<User> query = em.createQuery("select u from test$User u where u.login like 'ECTest-%' order by u.name asc", User.class);
query.setCacheable(true);
query.setView(userLoginView);
resultList = query.getResultList();
assertEquals(resultList.size(), 2);
tx.commit();
}
user = testSupport.reserialize(resultList.get(0));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertFail(user::getGroup);
user = testSupport.reserialize(resultList.get(1));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertFail(user::getGroup);
assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<User> query = em.createQuery("select u from test$User u where u.login like 'ECTest-%' order by u.name asc", User.class);
query.setCacheable(true);
query.setView(userGroupView);
resultList = query.getResultList();
assertEquals(resultList.size(), 2);
tx.commit();
}
user = testSupport.reserialize(resultList.get(0));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertEquals(user.getGroup(), group);
assertEquals(user.getGroup().getName(), group.getName());
user = testSupport.reserialize(resultList.get(1));
assertNotNull(user.getLogin());
assertNotNull(user.getName());
assertEquals(user.getGroup(), group);
assertEquals(user.getGroup().getName(), group.getName());
assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class SoftDeleteNotFoundDeletedTest method testLoadDeletedObject.
@Test
public void testLoadDeletedObject() {
FetchPlan taskView_Message = new View(SoftDelete_Task.class).addProperty("message");
FetchPlan taskView_Service = new View(SoftDelete_Task.class).addProperty("service", new View(SoftDelete_Service.class).addProperty("code"));
FetchPlan taskValueView = new View(SoftDelete_TaskValue.class).addProperty("task", taskView_Message);
FetchPlan projectView = new View(SoftDelete_Project.class).addProperty("name").addProperty("aValue", taskValueView).addProperty("task", taskView_Service);
LoadContext<SoftDelete_Project> loadContext = new LoadContext<>(SoftDelete_Project.class).setView(projectView).setId(projectId);
SoftDelete_Project project = dataManager.load(loadContext);
Assertions.assertNotNull(project);
Assertions.assertNotNull(project.getTask());
Assertions.assertTrue(project.getTask().isDeleted());
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testLocal.
@Test
public void testLocal() {
FetchPlan petView = ViewBuilder.of(Pet.class).addView(FetchPlan.LOCAL).build();
assertTrue(containsSystemProperties(petView));
assertTrue(petView.containsProperty("name"));
FetchPlan ownerView = ViewBuilder.of(Owner.class).addView(FetchPlan.LOCAL).build();
assertTrue(containsSystemProperties(ownerView));
assertTrue(ownerView.containsProperty("name"));
assertFalse(ownerView.containsProperty("address"));
}
Aggregations