Skip to content

Commit

Permalink
feat: handle multivalued in search by example in CB ORM #2297
Browse files Browse the repository at this point in the history
  • Loading branch information
yurem committed Sep 2, 2022
1 parent f770878 commit 35bb8c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.jans.orm.reflect.property.Setter;
import io.jans.orm.reflect.util.ReflectHelper;
import io.jans.orm.search.filter.Filter;
import io.jans.orm.search.filter.FilterProcessor;
import io.jans.orm.util.ArrayHelper;
import io.jans.orm.util.StringHelper;

Expand Down Expand Up @@ -108,6 +109,8 @@ public abstract class BaseEntryManager<O extends PersistenceOperationService> im
protected O operationService = null;
protected PersistenceExtension persistenceExtension = null;

protected FilterProcessor filterProcessor = new FilterProcessor();

@Override
public void persist(Object entry) {
if (entry == null) {
Expand Down Expand Up @@ -2234,6 +2237,10 @@ protected <T> Filter createFilterByEntry(Object entry, Class<T> entryClass, List
return addObjectClassFilter(attributesFilter, objectClasses);
}

protected Filter excludeObjectClassFilters(Filter genericFilter) {
return filterProcessor.excludeFilter(genericFilter, FilterProcessor.OBJECT_CLASS_EQUALITY_FILTER, FilterProcessor.OBJECT_CLASS_PRESENCE_FILTER);
}

protected Filter[] createAttributesFilter(List<AttributeData> attributes) {
if ((attributes == null) || (attributes.size() == 0)) {
return null;
Expand All @@ -2245,8 +2252,8 @@ protected Filter[] createAttributesFilter(List<AttributeData> attributes) {
String attributeName = attribute.getName();
for (Object value : attribute.getValues()) {
Filter filter = Filter.createEqualityFilter(attributeName, value);
if ((attribute.getMultiValued() != null) && attribute.getMultiValued()) {
filter.multiValued();
if (attribute.getMultiValued() != null) {
filter.multiValued(attribute.getMultiValued());
}

results.add(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ protected Filter addObjectClassFilter(Filter filter, String[] objectClasses) {
return filter;
}

// Make sure that there is only one objectClass in filter
filter = excludeObjectClassFilters(filter);

// In Couchbase implementation we need to use first one as entry type
Filter searchFilter = Filter.createEqualityFilter(OBJECT_CLASS, objectClasses[0]);
if (filter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class SqlEntryManager extends BaseEntryManager<SqlOperationService> imple
private Logger log;

private final SqlFilterConverter filterConverter;
private FilterProcessor filterProcessor;

private static final GenericKeyConverter KEY_CONVERTER = new GenericKeyConverter(false);

Expand All @@ -84,7 +83,6 @@ public class SqlEntryManager extends BaseEntryManager<SqlOperationService> imple
protected SqlEntryManager(SqlOperationService operationService) {
this.operationService = operationService;
this.filterConverter = new SqlFilterConverter(operationService);
this.filterProcessor = new FilterProcessor();
subscribers = new LinkedList<DeleteNotifier>();
}

Expand Down Expand Up @@ -800,10 +798,6 @@ private ConvertedExpression toSqlFilterWithEmptyAlias(Filter genericFilter, Map<
return filterConverter.convertToSqlFilter(excludeObjectClassFilters(genericFilter), propertiesAnnotationsMap, processor, true);
}

private Filter excludeObjectClassFilters(Filter genericFilter) {
return filterProcessor.excludeFilter(genericFilter, FilterProcessor.OBJECT_CLASS_EQUALITY_FILTER, FilterProcessor.OBJECT_CLASS_PRESENCE_FILTER);
}

private ParsedKey toSQLKey(String dn) {
return KEY_CONVERTER.convertToKey(dn);
}
Expand Down

0 comments on commit 35bb8c4

Please sign in to comment.