Search in sources :

Example 21 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class SelectQueryIT method testRouteQueryWithPrefetchesPrefetchExpressionPath.

/**
 * Test prefetching with qualifier on the root query being the path to the
 * prefetch.
 */
@Test
public void testRouteQueryWithPrefetchesPrefetchExpressionPath() {
    // find the painting not matching the artist (this is the case where
    // such prefetch
    // at least makes sense)
    Expression exp = ExpressionFactory.noMatchExp("toArtist", new Object());
    SelectQuery<Painting> q = new SelectQuery<>(Painting.class, exp);
    q.addPrefetch("toArtist");
    // test how prefetches are resolved in this case - this was a stumbling
    // block for
    // a while
    EntityResolver resolver = context.getEntityResolver();
    MockQueryRouter router = new MockQueryRouter();
    q.route(router, resolver, null);
    assertEquals(2, router.getQueryCount());
}
Also used : Expression(org.apache.cayenne.exp.Expression) EntityResolver(org.apache.cayenne.map.EntityResolver) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 22 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class LifecycleCallbackEventHandlerTest method testDefaultListeners.

@Test
public void testDefaultListeners() {
    LifecycleCallbackEventHandler map = new LifecycleCallbackEventHandler(new EntityResolver());
    L1 l1 = new L1();
    map.addDefaultListener(l1, "callback");
    C1 c1 = new C1();
    c1.setObjectId(new ObjectId("bogus"));
    assertEquals(0, l1.entities.size());
    map.performCallbacks(c1);
    assertEquals(1, l1.entities.size());
    assertTrue(l1.entities.contains(c1));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 23 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class LifecycleCallbackRegistryTest method createRegistry.

@Before
public void createRegistry() {
    EntityResolver entityResolver = mock(EntityResolver.class);
    registry = new LifecycleCallbackRegistry(entityResolver);
    for (LifecycleEvent event : LifecycleEvent.values()) {
        assertEquals(0, registry.getHandler(event).defaultListenersSize());
        assertEquals(0, registry.getHandler(event).listenersSize());
    }
}
Also used : LifecycleEvent(org.apache.cayenne.map.LifecycleEvent) EntityResolver(org.apache.cayenne.map.EntityResolver) Before(org.junit.Before)

Example 24 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class EJBQLQueryIT method testUniqueKeyEntity.

@Test
public void testUniqueKeyEntity() {
    // insertValue();
    EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
    String ejbql = "select a FROM Artist a";
    EJBQLQuery q1 = new EJBQLQuery(ejbql);
    q1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    EJBQLQuery q2 = new EJBQLQuery(ejbql);
    q2.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    assertEquals(q1.getMetaData(resolver).getCacheKey(), q2.getMetaData(resolver).getCacheKey());
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 25 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class EJBQLQueryIT method testGetMetadata.

@Test
public void testGetMetadata() {
    EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
    String ejbql = "select a FROM Artist a";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    QueryMetadata md = query.getMetaData(resolver);
    assertNotNull(md);
    assertNotNull(md.getClassDescriptor());
    assertSame(resolver.getClassDescriptor("Artist"), md.getClassDescriptor());
    assertNotNull(md.getObjEntity());
    assertSame(resolver.getObjEntity("Artist"), md.getObjEntity());
    assertFalse(md.isFetchingDataRows());
    assertTrue(md.isRefreshingObjects());
    assertEquals(QueryCacheStrategy.NO_CACHE, md.getCacheStrategy());
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)78 Test (org.junit.Test)53 ObjectId (org.apache.cayenne.ObjectId)13 ObjEntity (org.apache.cayenne.map.ObjEntity)13 DataMap (org.apache.cayenne.map.DataMap)11 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 DbEntity (org.apache.cayenne.map.DbEntity)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 QueryResponse (org.apache.cayenne.QueryResponse)5 MockEventManager (org.apache.cayenne.event.MockEventManager)5 SelectQuery (org.apache.cayenne.query.SelectQuery)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 List (java.util.List)3