use of io.jmix.core.FetchPlanRepository in project jmix by jmix-framework.
the class EntityCacheTestClass method testAccessConnectionWithCacheInvalidation.
@Test
@Disabled
public void testAccessConnectionWithCacheInvalidation() {
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().getConnection();
FetchPlanRepository viewRepository = AppBeans.get(FetchPlanRepository.class);
FetchPlan view = viewRepository.getFetchPlan(metadata.getClass(User.class), "user.browse");
persistence.getEntityManager().find(User.class, this.user.getId(), view);
tx.commit();
}
// User, Group
assertEquals(2, appender.filterMessages(m -> m.contains("> SELECT")).count());
appender.clearMessages();
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().getConnection();
FetchPlanRepository viewRepository = AppBeans.get(FetchPlanRepository.class);
FetchPlan view = viewRepository.getFetchPlan(metadata.getClass(User.class), "user.browse");
persistence.getEntityManager().find(User.class, this.user.getId(), view);
tx.commit();
}
// User, Group
assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
appender.clearMessages();
try (Transaction tx = persistence.createTransaction(new TransactionParams().setReadOnly(true))) {
try (Transaction tx1 = persistence.getTransaction()) {
persistence.getEntityManager().getConnection();
tx1.commit();
}
FetchPlanRepository fetchPlanRepository = AppBeans.get(FetchPlanRepository.class);
FetchPlan fetchPlan = fetchPlanRepository.getFetchPlan(metadata.getClass(User.class), "user.browse");
Query query = persistence.getEntityManager().createQuery("select u from test$User u where u.id = :id").setParameter("id", user.getId());
query.setView(View.copy((View) fetchPlan).setLoadPartialEntities(true));
((QueryImpl) query).setSingleResultExpected(true);
User userL = (User) query.getSingleResult();
// User userL = persistence.getEntityManager().find(User.class, user.getId(), view);
assertNotNull(userL);
tx.commit();
}
// User, Group
assertEquals(0, appender.filterMessages(m -> m.contains("> SELECT")).count());
}
use of io.jmix.core.FetchPlanRepository 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")));
}
Aggregations