Skip to content

Commit

Permalink
repo-sqale: consistent log/simplify/skip for none search/count treatment
Browse files Browse the repository at this point in the history
Start of searchObjectsIterative() work, added logSearchInputParameters
and also adapted simplify logic from old repo (although differently).
  • Loading branch information
virgo47 committed Jul 27, 2021
1 parent 42eb3d4 commit fb78027
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.api.*;
import com.evolveum.midpoint.repo.api.perf.OperationRecord;
Expand Down Expand Up @@ -692,8 +691,7 @@ DeleteObjectResult deleteObjectAttempt(Class<T> type, UUID oid, JdbcSession jdbc
return new DeleteObjectResult(new String(fullObject, StandardCharsets.UTF_8));
}

// Counting/searching

// region Counting/searching
@Override
public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult)
Expand All @@ -708,6 +706,13 @@ public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
.build();

try {
logSearchInputParameters(type, query, "Count objects");

query = simplifyQuery(query);
if (isNoneQuery(query)) {
return 0;
}

return executeCountObject(type, query, options);
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
Expand Down Expand Up @@ -752,6 +757,13 @@ private <T extends ObjectType> int executeCountObject(
.build();

try {
logSearchInputParameters(type, query, "Search objects");

query = simplifyQuery(query);
if (isNoneQuery(query)) {
return new SearchResultList<>();
}

return executeSearchObject(type, query, options, OP_SEARCH_OBJECTS);
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
Expand Down Expand Up @@ -825,8 +837,32 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(
Class<T> type, ObjectQuery query, ResultHandler<T> handler,
Collection<SelectorOptions<GetOperationOptions>> options, boolean strictlySequential,
OperationResult parentResult) throws SchemaException {
// TODO
throw new UnsupportedOperationException();
Validate.notNull(type, "Object type must not be null.");
Validate.notNull(handler, "Result handler must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");

OperationResult operationResult = parentResult.subresult(SEARCH_OBJECTS_ITERATIVE)
.addQualifier(type.getSimpleName())
.addParam("type", type.getName())
.addParam("query", query)
.build();

try {
logSearchInputParameters(type, query, "Iterative search objects");

query = simplifyQuery(query);
if (isNoneQuery(query)) {
return null;
}

// TODO
throw new UnsupportedOperationException();
} catch (Throwable t) {
operationResult.recordFatalError(t);
throw t;
} finally {
operationResult.computeStatusIfUnknown();
}
}

@Override
Expand All @@ -842,6 +878,13 @@ public <T extends Containerable> int countContainers(Class<T> type, ObjectQuery
.addParam("query", query)
.build();
try {
logSearchInputParameters(type, query, "Count containers");

query = simplifyQuery(query);
if (isNoneQuery(query)) {
return 0;
}

return executeCountContainers(type, query, options);
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
Expand Down Expand Up @@ -885,6 +928,13 @@ public <T extends Containerable> SearchResultList<T> searchContainers(
.build();

try {
logSearchInputParameters(type, query, "Search containers");

query = simplifyQuery(query);
if (isNoneQuery(query)) {
return new SearchResultList<>();
}

SqaleQueryContext<T, FlexibleRelationalPathBase<Object>, Object> queryContext =
SqaleQueryContext.from(type, repositoryContext);
return sqlQueryExecutor.list(queryContext, query, options);
Expand All @@ -898,6 +948,34 @@ public <T extends Containerable> SearchResultList<T> searchContainers(
}
}

private <T> void logSearchInputParameters(Class<T> type, ObjectQuery query, String operation) {
ObjectPaging paging = query != null ? query.getPaging() : null;
LOGGER.debug(
"{} of type '{}', query on trace level, offset {}, limit {}.",
operation, type.getSimpleName(),
paging != null ? paging.getOffset() : "undefined",
paging != null ? paging.getMaxSize() : "undefined");

LOGGER.trace("Full query\n{}",
query == null ? "undefined" : query.debugDumpLazily());
}

private ObjectQuery simplifyQuery(ObjectQuery query) {
if (query != null) {
ObjectFilter filter = query.getFilter();
filter = ObjectQueryUtil.simplify(filter, repositoryContext.prismContext());
query = query.cloneEmpty();
query.setFilter(filter instanceof AllFilter ? null : filter);
}

return query;
}

private boolean isNoneQuery(ObjectQuery query) {
return query != null && query.getFilter() instanceof NoneFilter;
}
// endregion

@Override
public <O extends ObjectType> boolean isDescendant(
PrismObject<O> object, String ancestorOrgOid) {
Expand Down Expand Up @@ -1009,7 +1087,7 @@ public long advanceSequence(String oid, OperationResult parentResult)
.build();

try {
return executeAdvanceSequence(oidUuid, operationResult);
return executeAdvanceSequence(oidUuid);
} catch (RepositoryException | RuntimeException | SchemaException e) {
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
Expand All @@ -1020,9 +1098,9 @@ public long advanceSequence(String oid, OperationResult parentResult)
}
}

private long executeAdvanceSequence(UUID oid, OperationResult operationResult)
private long executeAdvanceSequence(UUID oid)
throws ObjectNotFoundException, SchemaException, RepositoryException {
// TODO executeAttempts
// TODO executeAttempts if any problems with further test, so far it looks good based on SequenceTestConcurrency
long opHandle = registerOperationStart(OP_ADVANCE_SEQUENCE, SequenceType.class);

try (JdbcSession jdbcSession = repositoryContext.newJdbcSession().startTransaction()) {
Expand Down Expand Up @@ -1100,7 +1178,7 @@ public void returnUnusedValuesToSequence(
}

try {
executeReturnUnusedValuesToSequence(oidUuid, unusedValues, operationResult);
executeReturnUnusedValuesToSequence(oidUuid, unusedValues);
} catch (RepositoryException | RuntimeException | SchemaException e) {
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
Expand All @@ -1111,8 +1189,7 @@ public void returnUnusedValuesToSequence(
}
}

private void executeReturnUnusedValuesToSequence(
UUID oid, Collection<Long> unusedValues, OperationResult operationResult)
private void executeReturnUnusedValuesToSequence(UUID oid, Collection<Long> unusedValues)
throws SchemaException, ObjectNotFoundException, RepositoryException {
// TODO executeAttempts
long opHandle = registerOperationStart(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ private void processOrdering(List<? extends ObjectOrdering> orderings)
* individual paths for extension columns, see {@code extensionColumns} in {@link QueryTableMapping}.
*/
public PageOf<Tuple> executeQuery(Connection conn) throws QueryException {
SQLQuery<?> query = this.sqlQuery.clone(conn);
SQLQuery<?> query = sqlQuery.clone(conn);
if (query.getMetadata().getModifiers().getLimit() == null) {
query.limit(NO_PAGINATION_LIMIT);
// TODO indicate incomplete result?
}

// see com.evolveum.midpoint.repo.sqlbase.querydsl.SqlLogger for logging details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* Component just under the service that orchestrates query transformation and execution.
* Sql query executor itself does hold the query state, it uses {@link SqlQueryContext} for that.
* This object manages configuration information and provides dataSource/connections for queries.
* <p>
* TODO: Not audit specific, should migrate to sqlbase when cleaned around BaseHelper/JdbcSession.
*/
public class SqlQueryExecutor {

Expand Down

0 comments on commit fb78027

Please sign in to comment.