Search in sources :

Example 1 with E2

use of org.apache.cayenne.cache.invalidation.db.E2 in project cayenne by apache.

the class CacheInvalidationCacheGroupsHandlerIT method invalidateE2.

@Test
public void invalidateE2() throws Exception {
    ObjectContext context = runtime.newContext();
    ObjectSelect<E2> g0 = ObjectSelect.query(E2.class).localCache();
    ObjectSelect<E2> g1 = ObjectSelect.query(E2.class).localCache("g1");
    ObjectSelect<E2> g2 = ObjectSelect.query(E2.class).localCache("g2");
    ObjectSelect<E2> g3 = ObjectSelect.query(E2.class).localCache("g3");
    ObjectSelect<E2> g5 = ObjectSelect.query(E2.class).localCache("g5");
    assertEquals(0, g0.selectCount(context));
    assertEquals(0, g1.selectCount(context));
    assertEquals(0, g2.selectCount(context));
    assertEquals(0, g3.selectCount(context));
    assertEquals(0, g5.selectCount(context));
    e2.insert(1).insert(2);
    // inserted via SQL... query results are still cached...
    assertEquals(0, g0.selectCount(context));
    assertEquals(0, g1.selectCount(context));
    assertEquals(0, g2.selectCount(context));
    assertEquals(0, g3.selectCount(context));
    assertEquals(0, g5.selectCount(context));
    context.newObject(E2.class);
    context.commitChanges();
    // Typed remove will actually call untyped version, thus 4 + 2
    assertEquals(4 + 2, removeGroupUntypedCounter.get());
    assertEquals(2, removeGroupTypedCounter.get());
    // inserted via Cayenne... "g1" and "g2" should get auto refreshed...
    assertEquals(0, g0.selectCount(context));
    assertEquals(3, g1.selectCount(context));
    assertEquals(3, g2.selectCount(context));
    assertEquals(3, g3.selectCount(context));
    assertEquals(3, g5.selectCount(context));
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) E2(org.apache.cayenne.cache.invalidation.db.E2) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)1 E2 (org.apache.cayenne.cache.invalidation.db.E2)1 Test (org.junit.Test)1