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);
}
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations