Skip to content

Commit

Permalink
Merge branch 'feature/containers-iterative'
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Sep 3, 2023
2 parents a130e9c + aed364c commit 70423e2
Show file tree
Hide file tree
Showing 12 changed files with 903 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ public SearchResultMetadata searchReferencesIterative(
return null;
}

@Override
public <T extends Containerable> SearchResultMetadata searchContainersIterative(
Class<T> type, ObjectQuery query, ObjectHandler<T> handler,
Collection<SelectorOptions<GetOperationOptions>> options,
OperationResult parentResult) throws SchemaException {
return null;
}

@Override
public <O extends ObjectType> boolean isDescendant(
PrismObject<O> object, String ancestorOrgOid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import com.evolveum.midpoint.prism.query.ObjectOrdering;
import com.evolveum.midpoint.prism.query.OrderDirection;

import com.evolveum.midpoint.schema.query.TypedQuery;

import com.evolveum.midpoint.util.exception.SchemaException;

import org.jetbrains.annotations.Nullable;

import java.util.*;
Expand Down Expand Up @@ -95,10 +99,23 @@ public void orderBy(ResultItem resultItem, OrderDirection orderDirection) {

}

public AggregateQuery<T> filter(ObjectFilter filter) {
this.filter = filter;
return this;
}

public AggregateQuery<T> filter(String query) throws SchemaException {
return filter(TypedQuery.parse(root, query).toObjectQuery().getFilter());
}

public List<ObjectOrdering> getOrdering() {
return orderBy;
}

public ObjectFilter getFilter() {
return filter;
}

public abstract static class ResultItem {
private final ItemName name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public interface RepositoryService extends OrgTreeEvaluator, CaseSupportMixin, A
String OP_SEARCH_OBJECTS_ITERATIVE = "searchObjectsIterative";
String OP_SEARCH_OBJECTS_ITERATIVE_PAGE = "searchObjectsIterativePage";
String OP_SEARCH_CONTAINERS = "searchContainers";

String OP_SEARCH_CONTAINERS_ITERATIVE = "searchContainersIterative";
String OP_SEARCH_CONTAINERS_ITERATIVE_PAGE = "searchContainersIterativePage";
String OP_COUNT_CONTAINERS = "countContainers";
String OP_SEARCH_REFERENCES = "searchReferences";

Expand Down Expand Up @@ -511,6 +514,23 @@ <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<T> type
OperationResult parentResult)
throws SchemaException;

/**
* Executes iterative container search using the provided `handler` to process each container.
*
* @param query search query
* @param handler result handler
* @param options get options to use for the search
* @param parentResult parent OperationResult (in/out)
* @return summary information about the search result
*/
@Experimental
<T extends Containerable> SearchResultMetadata searchContainersIterative(
@NotNull Class<T> type,
@Nullable ObjectQuery query,
@NotNull ObjectHandler<T> handler,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult) throws SchemaException;

/**
* Executes iterative reference search using the provided `handler` to process each references.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public SearchResultMetadata searchReferencesIterative(
return searchOpHandler.searchReferencesIterative(query, handler, options, parentResult);
}

@Override
public <T extends Containerable> SearchResultMetadata searchContainersIterative(Class<T> type, ObjectQuery query, ObjectHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws SchemaException {
return searchOpHandler.searchContainersIterative(type, query, handler, options, parentResult);
}

@Override
public @NotNull <T extends Containerable> SearchResultList<T> searchContainers(
@NotNull Class<T> type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class SearchOpHandler extends CachedOpHandler {
private static final String OP_COUNT_REFERENCES = CLASS_NAME_WITH_DOT + "countReferences";
private static final String OP_SEARCH_REFERENCES_ITERATIVE = CLASS_NAME_WITH_DOT + "searchReferencesIterative";

private static final String OP_SEARCH_CONTAINERS_ITERATIVE = CLASS_NAME_WITH_DOT + "searchContainersIterative";


/**
* Queries resulting in more objects will not be cached "as such" - although individual objects/versions can be cached.
*/
Expand Down Expand Up @@ -438,6 +441,30 @@ public SearchResultMetadata searchReferencesIterative(
}
}

public <T extends Containerable> SearchResultMetadata searchContainersIterative(
@NotNull Class<T> type,
@Nullable ObjectQuery query,
@NotNull ObjectHandler<T> handler,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult) throws SchemaException {
OperationResult result = parentResult.subresult(OP_SEARCH_CONTAINERS_ITERATIVE)
.addQualifier(type.getSimpleName())
.addParam("type", type)
.addParam("query", query)
.addArbitraryObjectAsParam("options", options)
.build();
Long startTime = repoOpStart();
try {
return repositoryService.searchContainersIterative(type, query, handler, options, result);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
repoOpEnd(startTime);
result.computeStatusIfUnknown();
}
}

public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult)
throws SchemaException {
Expand All @@ -460,4 +487,6 @@ public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
result.computeStatusIfUnknown();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public AggregateSearchContext(AggregateQuery<?> query, SqaleQueryContext<? exten

public SearchResultList<PrismContainerValue<?>> search() throws SchemaException, RepositoryException {
computeMapping();
if (apiQuery.getFilter() != null) {
context.processFilter(apiQuery.getFilter());
}
context.beforeQuery();
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
var query = createQueryWithoutPaging(jdbcSession);
Expand All @@ -71,6 +74,9 @@ public SearchResultList<PrismContainerValue<?>> search() throws SchemaException,

public int count() throws SchemaException, RepositoryException {
computeMapping();
if (apiQuery.getFilter() != null) {
context.processFilter(apiQuery.getFilter());
}
context.beforeQuery();
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
return (int) createQueryWithoutPaging(jdbcSession).fetchCount();
Expand Down

0 comments on commit 70423e2

Please sign in to comment.