Search in sources :

Example 36 with EntityResolver

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

the class RelationshipFault method updateReverse.

// see if reverse relationship is to-one and we can connect source to
// results....
protected void updateReverse(List<E> resolved) {
    EntityResolver resolver = relationshipOwner.getObjectContext().getEntityResolver();
    ObjEntity sourceEntity = resolver.getObjEntity(relationshipOwner.getObjectId().getEntityName());
    ObjRelationship relationship = sourceEntity.getRelationship(relationshipName);
    ObjRelationship reverse = relationship.getReverseRelationship();
    if (reverse != null && !reverse.isToMany()) {
        PropertyDescriptor property = resolver.getClassDescriptor(reverse.getSourceEntity().getName()).getProperty(reverse.getName());
        for (Object o : resolved) {
            property.writePropertyDirectly(o, null, relationshipOwner);
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) PropertyDescriptor(org.apache.cayenne.reflect.PropertyDescriptor) EntityResolver(org.apache.cayenne.map.EntityResolver)

Example 37 with EntityResolver

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

the class ServerRuntimeTest method testGetDataChannel_CustomModule.

@Test
public void testGetDataChannel_CustomModule() {
    final DataChannel channel = new DataChannel() {

        public EntityResolver getEntityResolver() {
            return null;
        }

        public EventManager getEventManager() {
            return null;
        }

        public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
            return null;
        }

        public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
            return null;
        }
    };
    Module module = binder -> binder.bind(DataChannel.class).toInstance(channel);
    ServerRuntime runtime = new ServerRuntime(Collections.singleton(module));
    assertSame(channel, runtime.getChannel());
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) Arrays(java.util.Arrays) DataContext(org.apache.cayenne.access.DataContext) Collection(java.util.Collection) Constants(org.apache.cayenne.configuration.Constants) Module(org.apache.cayenne.di.Module) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DataChannel(org.apache.cayenne.DataChannel) Query(org.apache.cayenne.query.Query) BaseTransaction(org.apache.cayenne.tx.BaseTransaction) List(java.util.List) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) EventManager(org.apache.cayenne.event.EventManager) Arrays.asList(java.util.Arrays.asList) GraphDiff(org.apache.cayenne.graph.GraphDiff) QueryResponse(org.apache.cayenne.QueryResponse) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) TransactionalOperation(org.apache.cayenne.tx.TransactionalOperation) Assert(org.junit.Assert) Collections(java.util.Collections) Key(org.apache.cayenne.di.Key) Mockito.mock(org.mockito.Mockito.mock) DataChannel(org.apache.cayenne.DataChannel) Query(org.apache.cayenne.query.Query) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 38 with EntityResolver

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

the class BatchActionGeneratedIT method testHasGeneratedKeys1.

@Test
public void testHasGeneratedKeys1() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that supports keys
    JdbcAdapter adapter = buildAdapter(true);
    InsertBatchQuery batch1 = new InsertBatchQuery(resolver.getObjEntity(GeneratedColumnTestEntity.class).getDbEntity(), 5);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    assertTrue(new BatchAction(batch1, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 39 with EntityResolver

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

the class BatchActionIT method testHasGeneratedKeys1.

@Test
public void testHasGeneratedKeys1() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that supports keys
    JdbcAdapter adapter = buildAdapter(true);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
    assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 40 with EntityResolver

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

the class BatchActionIT method testHasGeneratedKeys2.

@Test
public void testHasGeneratedKeys2() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that does not support keys...
    JdbcAdapter adapter = buildAdapter(false);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
    assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) 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