Search in sources :

Example 1 with AbstractSearchExpressionEvaluatorCache

use of com.evolveum.midpoint.model.common.expression.evaluator.caching.AbstractSearchExpressionEvaluatorCache in project midpoint by Evolveum.

the class AbstractSearchExpressionEvaluator method executeSearchUsingCache.

private <O extends ObjectType> List<V> executeSearchUsingCache(Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    ObjectSearchStrategyType searchStrategy = getSearchStrategy();
    AbstractSearchExpressionEvaluatorCache cache = getCache();
    if (cache == null) {
        return executeSearch(null, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
    }
    List<V> list = cache.getQueryResult(targetTypeClass, query, searchStrategy, params, prismContext);
    if (list != null) {
        LOGGER.trace("Cache: HIT {} ({})", query, targetTypeClass.getSimpleName());
        return CloneUtil.clone(list);
    }
    LOGGER.trace("Cache: MISS {} ({})", query, targetTypeClass.getSimpleName());
    List<PrismObject> rawResult = new ArrayList<>();
    list = executeSearch(rawResult, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
    if (list != null && !list.isEmpty()) {
        // we don't want to cache negative results (e.g. if used with focal objects it might mean that they would be attempted to create multiple times)
        cache.putQueryResult(targetTypeClass, query, searchStrategy, params, list, rawResult, prismContext);
    }
    return list;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) AbstractSearchExpressionEvaluatorCache(com.evolveum.midpoint.model.common.expression.evaluator.caching.AbstractSearchExpressionEvaluatorCache) ObjectSearchStrategyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSearchStrategyType) ArrayList(java.util.ArrayList)

Aggregations

AbstractSearchExpressionEvaluatorCache (com.evolveum.midpoint.model.common.expression.evaluator.caching.AbstractSearchExpressionEvaluatorCache)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectSearchStrategyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSearchStrategyType)1 ArrayList (java.util.ArrayList)1