use of com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyTwo in project jmix by jmix-framework.
the class EntityCacheTestClass method setUp.
@BeforeEach
public void setUp() throws Exception {
try (Transaction tx = persistence.createTransaction()) {
EntityManagerFactory emf = persistence.getEntityManager().getDelegate().getEntityManagerFactory();
assertTrue(metadataTools.isCacheable(metadata.getClass(User.class)));
assertFalse(metadataTools.isCacheable(metadata.getClass(UserSubstitution.class)));
ServerSession serverSession = ((EntityManagerFactoryDelegate) emf).getServerSession();
ClassDescriptor descriptor = serverSession.getDescriptor(User.class);
assertEquals(500, descriptor.getCachePolicy().getIdentityMapSize());
this.cache = (JpaCache) emf.getCache();
group = metadata.create(Group.class);
group.setName("group-" + group.getId());
persistence.getEntityManager().persist(group);
user = metadata.create(User.class);
user.setLogin("ECTest-" + user.getId());
user.setPassword("111");
user.setGroup(group);
persistence.getEntityManager().persist(user);
user2 = metadata.create(User.class);
user2.setLogin("ECTest-" + user2.getId());
user2.setPassword("111");
user2.setGroup(group);
persistence.getEntityManager().persist(user2);
role = metadata.create(Role.class);
role.setName("Test role");
role.setDescription("Test role descr");
persistence.getEntityManager().persist(role);
userRole = metadata.create(UserRole.class);
userRole.setRole(role);
userRole.setUser(user);
persistence.getEntityManager().persist(userRole);
userSetting = metadata.create(UserSetting.class);
userSetting.setUser(user);
persistence.getEntityManager().persist(userSetting);
userSubstitution = metadata.create(UserSubstitution.class);
userSubstitution.setUser(user);
userSubstitution.setSubstitutedUser(user2);
persistence.getEntityManager().persist(userSubstitution);
compositeOne = metadata.create(CompositeOne.class);
compositeOne.setName("compositeOne");
persistence.getEntityManager().persist(compositeOne);
compositeTwo = metadata.create(CompositeTwo.class);
compositeTwo.setName("compositeTwo");
persistence.getEntityManager().persist(compositeTwo);
compositePropertyOne = metadata.create(CompositePropertyOne.class);
compositePropertyOne.setName("compositePropertyOne");
compositePropertyOne.setCompositeOne(compositeOne);
compositePropertyOne.setCompositeTwo(compositeTwo);
persistence.getEntityManager().persist(compositePropertyOne);
compositePropertyTwo = metadata.create(CompositePropertyTwo.class);
compositePropertyTwo.setName("compositePropertyTwo");
compositePropertyTwo.setCompositeTwo(compositeTwo);
persistence.getEntityManager().persist(compositePropertyTwo);
cachedParent = metadata.create(ParentCachedEntity.class);
cachedParent.setTitle("parent one");
cachedParent.setTestAdditional("ONE");
persistence.getEntityManager().persist(cachedParent);
cachedChild = metadata.create(ChildCachedEntity.class);
cachedChild.setSimpleProperty("simple value");
cachedChild.setTestAdditional("ONE");
cachedChild.setParent(cachedParent);
persistence.getEntityManager().persist(cachedChild);
tx.commit();
}
cache.clear();
}
use of com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyTwo in project jmix by jmix-framework.
the class EntityCacheTestClass method testNonCachedOneToManyFromCache.
@Test
public void testNonCachedOneToManyFromCache() {
appender.clearMessages();
DataManager dataManager = AppBeans.get(DataManager.class);
LoadContext<CompositeOne> loadContextList = new LoadContext<>(CompositeOne.class).setFetchPlan("compositeOne-view");
loadContextList.setQueryString("select e from test$CompositeOne e where e.name = 'compositeOne'").setMaxResults(1);
List<CompositeOne> results = dataManager.loadList(loadContextList);
Assertions.assertEquals(1, results.size());
CompositeOne compositeOne = results.get(0);
Assertions.assertEquals(1, compositeOne.getCompositePropertyOne().size());
CompositePropertyOne compositePropertyOne = compositeOne.getCompositePropertyOne().get(0);
CompositeTwo compositeTwo = compositePropertyOne.getCompositeTwo();
Assertions.assertNotNull(compositeTwo);
Assertions.assertEquals(1, compositeTwo.getCompositePropertyTwo().size());
CompositePropertyTwo compositePropertyTwo = compositeTwo.getCompositePropertyTwo().get(0);
Assertions.assertEquals("compositePropertyTwo", compositePropertyTwo.getName());
// UserSubstitution, User, User
assertEquals(4, appender.filterMessages(s -> s.contains("> SELECT") && !s.contains("DYNAT_CATEGORY")).count());
appender.clearMessages();
LoadContext<CompositeOne> loadContextOne = new LoadContext<>(CompositeOne.class).setId(compositeOne.getId()).setFetchPlan("compositeOne-view");
CompositeOne result = dataManager.load(loadContextOne);
// UserSubstitution only, User is cached
assertEquals(3, appender.filterMessages(selectsOnly).count());
}
Aggregations