Search in sources :

Example 21 with ObjEntity

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

the class DataDomainIT method testEntityResolverRefresh.

@Test
public void testEntityResolverRefresh() throws Exception {
    DataDomain domain = new DataDomain("dom1");
    org.apache.cayenne.map.EntityResolver resolver = domain.getEntityResolver();
    assertNotNull(resolver);
    DataMap map = new DataMap("map");
    ObjEntity entity = new ObjEntity("TestEntity");
    map.addObjEntity(entity);
    domain.addDataMap(map);
    assertSame(entity, resolver.getObjEntity("TestEntity"));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 22 with ObjEntity

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

the class DeleteRulesIT method restoreReverse.

private void restoreReverse(ObjRelationship reverse) {
    ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
    ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
    relationship.getTargetEntity().addRelationship(reverse);
    context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatA");
    context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatB");
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship)

Example 23 with ObjEntity

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

the class DeleteRulesIT method changeDeleteRule.

private int changeDeleteRule(int deleteRule) {
    ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
    ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
    int oldRule = relationship.getDeleteRule();
    relationship.setDeleteRule(deleteRule);
    return oldRule;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship)

Example 24 with ObjEntity

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

the class FluentSelectPrefetchRouterActionQualifiedEntityIT method testPrefetchEmployee.

@Test
public void testPrefetchEmployee() {
    ObjEntity departmentEntity = resolver.getObjEntity(Department.class);
    ObjectSelect<Employee> query = ObjectSelect.query(Employee.class, Employee.NAME.eq("abc")).prefetch(Employee.TO_DEPARTMENT.disjoint());
    FluentSelectPrefetchRouterAction action = new FluentSelectPrefetchRouterAction();
    MockQueryRouter router = new MockQueryRouter();
    action.route(query, router, resolver);
    assertEquals(1, router.getQueryCount());
    PrefetchSelectQuery prefetch = (PrefetchSelectQuery) router.getQueries().get(0);
    assertEquals(departmentEntity.getName(), prefetch.getEntityName());
    assertEquals(ExpressionFactory.exp("db:employees.NAME = 'abc' and (db:employees.PERSON_TYPE = 'EE' " + "or db:employees.PERSON_TYPE = 'EM')"), prefetch.getWhere());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Test(org.junit.Test)

Example 25 with ObjEntity

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

the class FluentSelectPrefetchRouterActionIT method testPaintings1.

@Test
public void testPaintings1() {
    ObjEntity paintingEntity = resolver.getObjEntity(Painting.class);
    ObjectSelect<Artist> query = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("abc")).prefetch(Artist.PAINTING_ARRAY.disjoint());
    FluentSelectPrefetchRouterAction action = new FluentSelectPrefetchRouterAction();
    MockQueryRouter router = new MockQueryRouter();
    action.route(query, router, resolver);
    assertEquals(1, router.getQueryCount());
    PrefetchSelectQuery prefetch = (PrefetchSelectQuery) router.getQueries().get(0);
    assertEquals(paintingEntity.getName(), prefetch.entityName);
    assertEquals(ExpressionFactory.exp("db:toArtist.ARTIST_NAME = 'abc'"), prefetch.getWhere());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjEntity(org.apache.cayenne.map.ObjEntity) Test(org.junit.Test)

Aggregations

ObjEntity (org.apache.cayenne.map.ObjEntity)294 Test (org.junit.Test)110 DbEntity (org.apache.cayenne.map.DbEntity)72 ObjAttribute (org.apache.cayenne.map.ObjAttribute)68 ObjRelationship (org.apache.cayenne.map.ObjRelationship)62 DataMap (org.apache.cayenne.map.DataMap)57 DbAttribute (org.apache.cayenne.map.DbAttribute)37 DbRelationship (org.apache.cayenne.map.DbRelationship)29 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)27 ObjectId (org.apache.cayenne.ObjectId)26 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)22 ArrayList (java.util.ArrayList)19 Embeddable (org.apache.cayenne.map.Embeddable)18 EntityResolver (org.apache.cayenne.map.EntityResolver)17 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)16 Expression (org.apache.cayenne.exp.Expression)15 Persistent (org.apache.cayenne.Persistent)12 EntityEvent (org.apache.cayenne.map.event.EntityEvent)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Entity (org.apache.cayenne.map.Entity)11