use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class StringIdQueryTest method testPerformQuery_SingleEntity.
@Test
public void testPerformQuery_SingleEntity() throws Exception {
e1Helper.deleteAll();
e1Helper.insert(3).insert(4);
StringIdQuery query = new StringIdQuery("E1:3", "E1:4", "E1:5");
QueryResponse response = runtime.newContext().performGenericQuery(query);
assertEquals(1, response.size());
assertEquals(2, response.firstList().size());
Set<Number> ids = new HashSet<>();
DataRow r1 = (DataRow) response.firstList().get(0);
ids.add((Number) r1.get("ID"));
DataRow r2 = (DataRow) response.firstList().get(1);
ids.add((Number) r2.get("ID"));
assertTrue(ids.contains(3L));
assertTrue(ids.contains(4L));
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class ClientChannel method onQuery.
@SuppressWarnings("unchecked")
public QueryResponse onQuery(ObjectContext context, Query query) {
QueryResponse response = send(new QueryMessage(query), QueryResponse.class);
if (context != null) {
EntityResolver resolver = context.getEntityResolver();
QueryMetadata info = query.getMetaData(resolver);
if (!info.isFetchingDataRows()) {
response.reset();
while (response.next()) {
if (response.isList()) {
List objects = response.currentList();
if (!objects.isEmpty()) {
DeepMergeOperation merger = new DeepMergeOperation(context);
List<Object> rsMapping = info.getResultSetMapping();
if (rsMapping == null) {
convertSingleObjects(objects, merger);
} else {
if (rsMapping.size() == 1) {
if (rsMapping.get(0) instanceof EntityResultSegment) {
convertSingleObjects(objects, merger);
}
} else {
processMixedResult(objects, merger, rsMapping);
}
}
}
}
}
}
}
return response;
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DeletedDiffProcessor method nodeRemoved.
@Override
public void nodeRemoved(Object nodeId) {
ObjectId id = (ObjectId) nodeId;
final MutableObjectChange objectChangeSet = changeSet.getOrCreate(id, ObjectChangeType.DELETE);
// TODO: rewrite with SelectById query after Cayenne upgrade
ObjectIdQuery query = new ObjectIdQuery(id, true, ObjectIdQuery.CACHE);
QueryResponse result = channel.onQuery(null, query);
@SuppressWarnings("unchecked") List<DataRow> rows = result.firstList();
if (rows.isEmpty()) {
LOGGER.warn("No DB snapshot for object to be deleted, no changes will be recorded. ID: " + id);
return;
}
final DataRow row = rows.get(0);
ClassDescriptor descriptor = channel.getEntityResolver().getClassDescriptor(id.getEntityName());
final CommitLogEntity entity = entityFactory.getEntity(id);
descriptor.visitProperties(new PropertyVisitor() {
@Override
public boolean visitAttribute(AttributeProperty property) {
if (!entity.isIncluded(property.getName())) {
return true;
}
Object value;
if (entity.isConfidential(property.getName())) {
value = Confidential.getInstance();
} else {
String key = property.getAttribute().getDbAttributeName();
value = row.get(key);
}
if (value != null) {
objectChangeSet.attributeChanged(property.getName(), value, null);
}
return true;
}
@Override
public boolean visitToOne(ToOneProperty property) {
// TODO record FK changes?
return true;
}
@Override
public boolean visitToMany(ToManyProperty property) {
return true;
}
});
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class ClientServerChannelIT method testPerformQueryObjectIDInjection.
@Test
public void testPerformQueryObjectIDInjection() throws Exception {
tMtTable1.insert(55, "g1", "s1");
Query query = new SelectQuery("MtTable1");
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 instanceof ClientMtTable1);
ClientMtTable1 clientObject = (ClientMtTable1) result;
assertNotNull(clientObject.getObjectId());
assertEquals(new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 55), clientObject.getObjectId());
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class ClientServerChannelIT method testPerformQueryValuePropagation.
@Test
public void testPerformQueryValuePropagation() throws Exception {
byte[] bytes = new byte[] { 1, 2, 3 };
tMtTable3.insert(1, bytes, "abc", 4);
Query query = new SelectQuery("MtTable3");
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 ClientMtTable3);
ClientMtTable3 clientObject = (ClientMtTable3) result;
assertEquals("abc", clientObject.getCharColumn());
assertEquals(new Integer(4), clientObject.getIntColumn());
assertTrue(new EqualsBuilder().append(clientObject.getBinaryColumn(), bytes).isEquals());
}
Aggregations