Search in sources :

Example 6 with EntityResultSegment

use of org.apache.cayenne.query.EntityResultSegment in project cayenne by apache.

the class DataContextQueryAction method interceptPaginatedQuery.

@Override
protected boolean interceptPaginatedQuery() {
    if (metadata.getPageSize() > 0) {
        Integer maxIdQualifierSize = actingDataContext.getParentDataDomain().getMaxIdQualifierSize();
        List<?> paginatedList;
        List<Object> rsMapping = metadata.getResultSetMapping();
        boolean mixedResults = false;
        if (rsMapping != null) {
            if (rsMapping.size() > 1) {
                mixedResults = true;
            } else if (rsMapping.size() == 1) {
                mixedResults = !(rsMapping.get(0) instanceof EntityResultSegment) || !metadata.isSingleResultSetMapping();
            }
        }
        if (mixedResults) {
            paginatedList = new MixedResultIncrementalFaultList<>(actingDataContext, query, maxIdQualifierSize);
        } else {
            DbEntity dbEntity = metadata.getDbEntity();
            if (dbEntity != null && dbEntity.getPrimaryKeys().size() == 1) {
                paginatedList = new SimpleIdIncrementalFaultList<>(actingDataContext, query, maxIdQualifierSize);
            } else {
                paginatedList = new IncrementalFaultList<>(actingDataContext, query, maxIdQualifierSize);
            }
        }
        response = new ListResponse(paginatedList);
        return DONE;
    }
    return !DONE;
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) ListResponse(org.apache.cayenne.util.ListResponse) EntityResultSegment(org.apache.cayenne.query.EntityResultSegment)

Example 7 with EntityResultSegment

use of org.apache.cayenne.query.EntityResultSegment in project cayenne by apache.

the class ClientServerChannelQueryAction method processMixedResult.

private List<Object[]> processMixedResult(List<Object[]> serverObjects, List<Object> rsMapping) {
    // must clone the list to ensure we do not mess up the server list that can be
    // used elsewhere (e.g. it can be cached).
    List<Object[]> clientObjects = new ArrayList<>(serverObjects.size());
    ObjectDetachOperation op = new ObjectDetachOperation(serverResolver.getClientEntityResolver());
    int width = rsMapping.size();
    for (Object[] serverObject : serverObjects) {
        Object[] clientObject = new Object[width];
        for (int i = 0; i < width; i++) {
            if (rsMapping.get(i) instanceof EntityResultSegment) {
                clientObject[i] = convertSingleObject(serverMetadata.getPrefetchTree(), op, serverObject[i]);
            } else {
                clientObject[i] = serverObject[i];
            }
        }
        clientObjects.add(clientObject);
    }
    return clientObjects;
}
Also used : ObjectDetachOperation(org.apache.cayenne.util.ObjectDetachOperation) ArrayList(java.util.ArrayList) EntityResultSegment(org.apache.cayenne.query.EntityResultSegment)

Aggregations

EntityResultSegment (org.apache.cayenne.query.EntityResultSegment)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EmbeddableObject (org.apache.cayenne.EmbeddableObject)1 Persistent (org.apache.cayenne.Persistent)1 QueryResponse (org.apache.cayenne.QueryResponse)1 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 EmbeddableResultSegment (org.apache.cayenne.query.EmbeddableResultSegment)1 QueryMetadata (org.apache.cayenne.query.QueryMetadata)1 CayenneMapEntry (org.apache.cayenne.util.CayenneMapEntry)1 DeepMergeOperation (org.apache.cayenne.util.DeepMergeOperation)1 ListResponse (org.apache.cayenne.util.ListResponse)1 ObjectDetachOperation (org.apache.cayenne.util.ObjectDetachOperation)1