Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 23, 2022
2 parents 10d1d65 + 92d0dda commit f006ff1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit;
import com.evolveum.midpoint.prism.query.builder.S_ConditionEntry;
import com.evolveum.midpoint.prism.util.PrismUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
Expand Down Expand Up @@ -1094,23 +1093,53 @@ private <T extends ObjectType> ObjectFilter lastOidCondition(
// "By default, null values sort as if larger than any non-null value; that is,
// NULLS FIRST is the default for DESC order, and NULLS LAST otherwise."
} else {
// see MID-7860
/*
IMPL NOTE: Compare this code with SqaleAuditService.iterativeSearchCondition, there are couple of differences.
This one seems bloated, but each branch is simple; on the other hand it's not obvious what is different in each.
Also, audit version does not require polystring treatment.
Finally, this works for a single provided ordering, but not for multiple (unsupported commented code lower).
*/
boolean isPolyString = QNameUtil.match(
PolyStringType.COMPLEX_TYPE, item.getDefinition().getTypeName());

Object realValue = item.getRealValue();
S_AtomicFilterExit subfilter = asc
? (isPolyString ? filter.gt(realValue).matchingOrig() : filter.gt(realValue))
: (isPolyString ? filter.lt(realValue).matchingOrig() : filter.lt(realValue));
S_ConditionEntry subfilter2 = subfilter.or()
.block()
.item(orderByPath);
filter = (isPolyString ? subfilter2.eq(realValue).matchingOrig() : subfilter2.eq(realValue))
.and()
.item(OID_PATH);
return (asc ? filter.gt(lastProcessedOid) : filter.lt(lastProcessedOid))
.endBlock()
.buildFilter();
if (isPolyString) {
// We need to use matchingOrig for polystring, see MID-7860
if (asc) {
return filter.gt(realValue).matchingOrig().or()
.block()
.item(orderByPath).eq(realValue).matchingOrig()
.and()
.item(OID_PATH).gt(lastProcessedOid)
.endBlock()
.buildFilter();
} else {
return filter.lt(realValue).matchingOrig().or()
.block()
.item(orderByPath).eq(realValue).matchingOrig()
.and()
.item(OID_PATH).lt(lastProcessedOid)
.endBlock()
.buildFilter();
}
} else {
if (asc) {
return filter.gt(realValue).or()
.block()
.item(orderByPath).eq(realValue)
.and()
.item(OID_PATH).gt(lastProcessedOid)
.endBlock()
.buildFilter();
} else {
return filter.lt(realValue).or()
.block()
.item(orderByPath).eq(realValue)
.and()
.item(OID_PATH).lt(lastProcessedOid)
.endBlock()
.buildFilter();
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
import static com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.datatype.DatatypeFactory;
Expand All @@ -39,7 +36,6 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrderDirection;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.repo.sqlbase.QueryException;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ResultHandler;
Expand Down Expand Up @@ -747,17 +743,6 @@ public void test700FullTextSearch() throws Exception {

@Test
public void test710FulltextSearchNestedInOwnedBy() throws Exception {
// TODO remove this debug output when tests are finished
try (JdbcSession session = createJdbcSession()) {
Connection conn = session.connection();
try (PreparedStatement stmt = conn.prepareStatement("select owner_oid, text from m_object_text_info")) {
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("owner_oid") + ": " + rs.getString("text"));
}
}
}

given("query for assignments owned by role matching given fulltext search");
ObjectQuery query = prismContext.queryFor(AssignmentType.class)
.ownedBy(AbstractRoleType.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.query.ExistsFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.repo.sql.data.common.RObjectReference;
import com.evolveum.midpoint.repo.sql.data.common.any.ROExtReference;
import com.evolveum.midpoint.repo.sql.query.InterpretationContext;
import com.evolveum.midpoint.repo.sql.query.QueryInterpreter;
import com.evolveum.midpoint.repo.sql.query.definition.JpaAnyReferenceDefinition;
import com.evolveum.midpoint.repo.sql.query.definition.JpaEntityDefinition;
import com.evolveum.midpoint.repo.sql.query.definition.JpaLinkDefinition;
Expand Down Expand Up @@ -181,17 +179,12 @@ private Condition handleEqInOrNull(HibernateQuery hibernateQuery, String propert
}

private Condition targetFilterCondition() throws QueryException {
ObjectFilter targetFilter = Objects.requireNonNull(filter.getFilter());
ObjectFilter existsFilter = context.getPrismContext().queryFor(context.getType())
.exists(filter.getFullPath().append(T_OBJECT_REFERENCE))
.filter(Objects.requireNonNull(filter.getFilter()))
.buildFilter();

//noinspection deprecation
ExistsFilter existsFilter = context.getPrismContext().queryFactory().createExists(
filter.getFullPath().append(T_OBJECT_REFERENCE),
context.getType(), // source type (start of the path), not the target type
context.getPrismContext(),
targetFilter);

QueryInterpreter interpreter = context.getInterpreter();
return interpreter.interpretFilter(context, existsFilter, this);
return context.getInterpreter().interpretFilter(context, existsFilter, this);
}

private Condition refCondition(Condition condition) throws QueryException {
Expand Down

0 comments on commit f006ff1

Please sign in to comment.