Skip to content

Commit

Permalink
sqale: Added support for orderBy by nested items
Browse files Browse the repository at this point in the history
Added preliminary support for nested ordering (contained containers)
such as metadata/*
  • Loading branch information
tonydamage committed Aug 10, 2021
1 parent 4c88564 commit aad7afc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,15 @@ public void test502SearchObjectWithoutExtensionStringItem() throws SchemaExcepti
creatorOid, modifierOid, user3Oid, user4Oid);
}

@Test
public void test504SearchObjectOrderedByMetadataTimestamp() throws SchemaException {
searchUsersTest("with extension string item with any value ordered by that item",
f -> f.not()
.item(UserType.F_EXTENSION, new QName("string")).isNull()
.asc(UserType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP),
user2Oid, user1Oid);
}

@Test(enabled = false) // TODO missing feature order by complex paths, see SqlQueryContext.processOrdering
public void test503SearchObjectWithAnyValueForExtensionItemOrderedByIt() throws SchemaException {
searchUsersTest("with extension string item with any value ordered by that item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import com.evolveum.midpoint.repo.sqlbase.filtering.NaryLogicalFilterProcessor;
import com.evolveum.midpoint.repo.sqlbase.filtering.NotFilterProcessor;
import com.evolveum.midpoint.repo.sqlbase.filtering.ValueFilterProcessor;
import com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver;
import com.evolveum.midpoint.repo.sqlbase.mapping.ItemSqlMapper;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping;
import com.evolveum.midpoint.repo.sqlbase.mapping.RepositoryMappingException;
import com.evolveum.midpoint.repo.sqlbase.mapping.SqlDetailFetchMapper;
Expand Down Expand Up @@ -202,14 +205,7 @@ private void processOrdering(List<? extends ObjectOrdering> orderings)
throws RepositoryException {
for (ObjectOrdering ordering : orderings) {
ItemPath orderByItemPath = ordering.getOrderBy();
// TODO to support ordering by ext/something we need to implement this.
// That may not even require cache for JOIN because it should be allowed only for
// single-value containers embedded in the object.
if (orderByItemPath.size() > 1) {
throw new QueryException(
"ORDER BY is not possible for complex paths: " + orderByItemPath);
}
Path<?> path = entityPathMapping.primarySqlPath(orderByItemPath.firstToQName(), this);
Path<?> path = orderingPath(orderByItemPath);
if (!(path instanceof ComparableExpressionBase)) {
throw new QueryException(
"ORDER BY is not possible for non-comparable path: " + orderByItemPath);
Expand All @@ -223,6 +219,22 @@ private void processOrdering(List<? extends ObjectOrdering> orderings)
}
}

private Path<?> orderingPath(ItemPath orderByItemPath) throws RepositoryException {
ItemPath path = orderByItemPath;
QueryModelMapping<?, ?, ?> current = entityPathMapping;
// TODO to support ordering by ext/something we need to implement correctly itemPrimaryPath in ExtensionMapping
// That may not even require cache for JOIN because it should be allowed only for
// single-value containers embedded in the object.
while (path.size() > 1) {
ItemRelationResolver resolver = current.relationResolver(path);
ItemRelationResolver.ResolutionResult<?, ?> resolution = resolver.resolve(this);
current = resolution.mapping;
path = path.rest();
}
ItemSqlMapper mapper = current.itemMapper(path.firstToName());
return mapper.itemPrimaryPath(entityPath);
}

/**
* Returns page of results with each row represented by a Tuple containing {@link R} and then
* individual paths for extension columns, see {@code extensionColumns} in {@link QueryTableMapping}.
Expand Down

0 comments on commit aad7afc

Please sign in to comment.