Search in sources :

Example 1 with CompositeTwo

use of com.haulmont.cuba.core.model.entitycache_unfetched.CompositeTwo 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();
}
Also used : ServerSession(org.eclipse.persistence.sessions.server.ServerSession) EntityManagerFactoryDelegate(org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ParentCachedEntity(com.haulmont.cuba.core.model.entity_cache.ParentCachedEntity) CompositePropertyTwo(com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyTwo) CompositeTwo(com.haulmont.cuba.core.model.entitycache_unfetched.CompositeTwo) CompositePropertyOne(com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyOne) CompositeOne(com.haulmont.cuba.core.model.entitycache_unfetched.CompositeOne) ChildCachedEntity(com.haulmont.cuba.core.model.entity_cache.ChildCachedEntity) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 2 with CompositeTwo

use of com.haulmont.cuba.core.model.entitycache_unfetched.CompositeTwo 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());
}
Also used : CompositePropertyOne(com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyOne) CompositeOne(com.haulmont.cuba.core.model.entitycache_unfetched.CompositeOne) LoadContext(com.haulmont.cuba.core.global.LoadContext) DataManager(com.haulmont.cuba.core.global.DataManager) CompositePropertyTwo(com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyTwo) CompositeTwo(com.haulmont.cuba.core.model.entitycache_unfetched.CompositeTwo)

Aggregations

CompositeOne (com.haulmont.cuba.core.model.entitycache_unfetched.CompositeOne)2 CompositePropertyOne (com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyOne)2 CompositePropertyTwo (com.haulmont.cuba.core.model.entitycache_unfetched.CompositePropertyTwo)2 CompositeTwo (com.haulmont.cuba.core.model.entitycache_unfetched.CompositeTwo)2 DataManager (com.haulmont.cuba.core.global.DataManager)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 ChildCachedEntity (com.haulmont.cuba.core.model.entity_cache.ChildCachedEntity)1 ParentCachedEntity (com.haulmont.cuba.core.model.entity_cache.ParentCachedEntity)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 EntityManagerFactoryDelegate (org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate)1 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)1