Search in sources :

Example 1 with MappedSelect

use of org.apache.cayenne.query.MappedSelect in project cayenne by apache.

the class CayenneContextNamedQueryCachingIT method testLocalCacheParameterized.

@Test
public void testLocalCacheParameterized() throws Exception {
    createThreeMtTable1sDataSet();
    final MappedSelect q1 = MappedSelect.query("ParameterizedMtQueryWithLocalCache").param("g", "g1");
    final MappedSelect q2 = MappedSelect.query("ParameterizedMtQueryWithLocalCache").param("g", "g2");
    final List<?> result1 = context.performQuery(q1);
    assertEquals(1, result1.size());
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> result2 = context.performQuery(q1);
            assertSame(result1, result2);
        }
    });
    final List<?> result3 = context.performQuery(q2);
    assertNotSame(result1, result3);
    assertEquals(1, result3.size());
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> result4 = context.performQuery(q2);
            assertSame(result3, result4);
            List<?> result5 = context.performQuery(q1);
            assertSame(result1, result5);
        }
    });
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) MappedSelect(org.apache.cayenne.query.MappedSelect) Test(org.junit.Test)

Example 2 with MappedSelect

use of org.apache.cayenne.query.MappedSelect in project cayenne by apache.

the class CayenneContextNamedQueryCachingIT method testLocalCache.

@Test
public void testLocalCache() throws Exception {
    createThreeMtTable1sDataSet();
    final MappedSelect q1 = MappedSelect.query("MtQueryWithLocalCache");
    final List<?> result1 = context.performQuery(q1);
    assertEquals(3, result1.size());
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> result2 = context.performQuery(q1);
            assertSame(result1, result2);
        }
    });
    // refresh
    q1.forceNoCache();
    List<?> result3 = context.performQuery(q1);
    assertNotSame(result1, result3);
    assertEquals(3, result3.size());
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) MappedSelect(org.apache.cayenne.query.MappedSelect) Test(org.junit.Test)

Aggregations

List (java.util.List)2 MappedSelect (org.apache.cayenne.query.MappedSelect)2 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)2 Test (org.junit.Test)2