Search in sources :

Example 1 with ObjectPagingAfterOid

use of com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid in project midpoint by Evolveum.

the class ObjectRetriever method searchObjectsIterativeByPagingStrictlySequential.

/**
     * Strictly-sequential version of paged search.
     *
     * Assumptions:
     *  - During processing of returned object(s), any objects can be added, deleted or modified.
     *
     * Guarantees:
     *  - We return each object that existed in the moment of search start:
     *     - exactly once if it was not deleted in the meanwhile,
     *     - at most once otherwise.
     *  - However, we may or may not return any objects that were added during the processing.
     *
     * Constraints:
     *  - There can be no ordering prescribed. We use our own ordering.
     *  - Moreover, for simplicity we disallow any explicit paging.
     *
     *  Implementation is very simple - we fetch objects ordered by OID, and remember last OID fetched.
     *  Obviously no object will be present in output more than once.
     *  Objects that are not deleted will be there exactly once, provided their oid is not changed.
     */
public <T extends ObjectType> void searchObjectsIterativeByPagingStrictlySequential(Class<T> type, ObjectQuery query, ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    try {
        ObjectQuery pagedQuery = query != null ? query.clone() : new ObjectQuery();
        String lastOid = "";
        final int batchSize = getConfiguration().getIterativeSearchByPagingBatchSize();
        if (pagedQuery.getPaging() != null) {
            throw new IllegalArgumentException("Externally specified paging is not supported on strictly sequential iterative search.");
        }
        ObjectPagingAfterOid paging = new ObjectPagingAfterOid();
        pagedQuery.setPaging(paging);
        main: for (; ; ) {
            paging.setOidGreaterThan(lastOid);
            paging.setMaxSize(batchSize);
            List<PrismObject<T>> objects = repositoryService.searchObjects(type, pagedQuery, options, result);
            for (PrismObject<T> object : objects) {
                lastOid = object.getOid();
                if (!handler.handle(object, result)) {
                    break main;
                }
            }
            if (objects.size() == 0) {
                break;
            }
        }
    } finally {
        if (result != null && result.isUnknown()) {
            result.computeStatus();
        }
    }
}
Also used : ObjectPagingAfterOid(com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 2 with ObjectPagingAfterOid

use of com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid in project midpoint by Evolveum.

the class QueryInterpreter2 method interpretPagingAndSorting.

private void interpretPagingAndSorting(InterpretationContext context, ObjectQuery query, boolean countingObjects) throws QueryException {
    RootHibernateQuery hibernateQuery = context.getHibernateQuery();
    String rootAlias = hibernateQuery.getPrimaryEntityAlias();
    if (query != null && query.getPaging() instanceof ObjectPagingAfterOid) {
        ObjectPagingAfterOid paging = (ObjectPagingAfterOid) query.getPaging();
        if (paging.getOidGreaterThan() != null) {
            Condition c = hibernateQuery.createSimpleComparisonCondition(rootAlias + ".oid", paging.getOidGreaterThan(), ">");
            hibernateQuery.addCondition(c);
        }
    }
    if (!countingObjects && query != null && query.getPaging() != null) {
        if (query.getPaging() instanceof ObjectPagingAfterOid) {
            // very special case - ascending ordering by OID (nothing more)
            updatePagingAndSortingByOid(hibernateQuery, (ObjectPagingAfterOid) query.getPaging());
        } else {
            updatePagingAndSorting(context, query.getPaging());
        }
    }
}
Also used : Condition(com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition) RootHibernateQuery(com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery) ObjectPagingAfterOid(com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RPolyString(com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)

Aggregations

ObjectPagingAfterOid (com.evolveum.midpoint.repo.sql.ObjectPagingAfterOid)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)1 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery)1 Condition (com.evolveum.midpoint.repo.sql.query2.hqm.condition.Condition)1