Search in sources :

Example 1 with DeepMergeOperation

use of org.apache.cayenne.util.DeepMergeOperation 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;
}
Also used : QueryMetadata(org.apache.cayenne.query.QueryMetadata) DeepMergeOperation(org.apache.cayenne.util.DeepMergeOperation) QueryResponse(org.apache.cayenne.QueryResponse) List(java.util.List) EntityResolver(org.apache.cayenne.map.EntityResolver) EntityResultSegment(org.apache.cayenne.query.EntityResultSegment)

Aggregations

List (java.util.List)1 QueryResponse (org.apache.cayenne.QueryResponse)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 EntityResultSegment (org.apache.cayenne.query.EntityResultSegment)1 QueryMetadata (org.apache.cayenne.query.QueryMetadata)1 DeepMergeOperation (org.apache.cayenne.util.DeepMergeOperation)1