use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class ChildDiffLoader method findObject.
protected Persistent findObject(Object nodeId) {
// first do a lookup in ObjectStore; if even a hollow object is found,
// return it;
// if not - fetch.
Persistent object = (Persistent) context.getGraphManager().getNode(nodeId);
if (object != null) {
return object;
}
ObjectId id = (ObjectId) nodeId;
// modified
if (id.isTemporary()) {
return null;
}
// skip context cache lookup, go directly to its channel
Query query = new ObjectIdQuery((ObjectId) nodeId);
QueryResponse response = context.getChannel().onQuery(context, query);
List<?> objects = response.firstList();
if (objects.size() == 0) {
throw new CayenneRuntimeException("No object for ID exists: %s", nodeId);
} else if (objects.size() > 1) {
throw new CayenneRuntimeException("Expected zero or one object, instead query matched: %d", objects.size());
}
return (Persistent) objects.get(0);
}
use of org.apache.cayenne.QueryResponse 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.QueryResponse in project cayenne by apache.
the class StringIdQueryTest method testPerformQuery_MultipleEntities.
@Test
public void testPerformQuery_MultipleEntities() throws Exception {
e1Helper.deleteAll();
e1Helper.insert(3).insert(4);
e2Helper.deleteAll();
e2Helper.insert(5).insert(6).insert(7);
StringIdQuery query = new StringIdQuery("E1:3", "E1:4", "E2:6", "E1:5");
QueryResponse response = runtime.newContext().performGenericQuery(query);
assertEquals(2, response.size());
Set<String> ids = new HashSet<>();
while (response.next()) {
@SuppressWarnings("unchecked") List<DataRow> list = (List<DataRow>) response.currentList();
for (DataRow row : list) {
ids.add(row.getEntityName() + ":" + row.get("ID"));
}
}
assertEquals(3, ids.size());
assertTrue(ids.contains("E1:3"));
assertTrue(ids.contains("E1:4"));
assertTrue(ids.contains("E2:6"));
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class AshwoodEntitySorter method findReflexiveMaster.
protected Object findReflexiveMaster(Persistent object, ObjRelationship toOneRel, String targetEntityName) {
DbRelationship finalRel = toOneRel.getDbRelationships().get(0);
ObjectContext context = object.getObjectContext();
// the method
if (object.getObjectId().isTemporary()) {
return null;
}
ObjectIdQuery query = new ObjectIdQuery(object.getObjectId(), true, ObjectIdQuery.CACHE);
QueryResponse response = context.getChannel().onQuery(null, query);
List<?> result = response.firstList();
if (result == null || result.size() == 0) {
return null;
}
DataRow snapshot = (DataRow) result.get(0);
ObjectId id = snapshot.createTargetObjectId(targetEntityName, finalRel);
// hollow objects
return (id != null) ? context.getGraphManager().getNode(id) : null;
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class ClientServerChannelIT method testPerformQueryPropagationInheritance.
@Test
public void testPerformQueryPropagationInheritance() throws Exception {
tMtTable1.insert(65, "sub1", "xyz");
SelectQuery query = new SelectQuery(ClientMtTable1.class);
QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
Object result = results.get(0);
assertTrue("Result is of wrong type: " + result, result instanceof ClientMtTable1Subclass1);
ClientMtTable1Subclass1 clientObject = (ClientMtTable1Subclass1) result;
assertEquals("sub1", clientObject.getGlobalAttribute1());
}
Aggregations