diff --git a/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java b/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java index fba2dab05..f1dacf81a 100644 --- a/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java +++ b/src/main/java/org/springframework/data/aerospike/core/AerospikeOperations.java @@ -26,11 +26,9 @@ import com.aerospike.client.query.ResultSet; import org.springframework.data.aerospike.core.model.GroupedEntities; import org.springframework.data.aerospike.core.model.GroupedKeys; -import org.springframework.data.aerospike.query.Qualifier; import org.springframework.data.aerospike.repository.query.Query; import org.springframework.data.domain.Sort; import org.springframework.data.mapping.context.MappingContext; -import org.springframework.lang.Nullable; import java.util.Collection; import java.util.List; @@ -794,49 +792,6 @@ List findByIdsUsingQuery(Collection ids, Class entityClass, Clas */ Stream find(Query query, Class targetClass, String setName); - /** - * Find all documents in the given entityClass's set using provided {@link Query}. - * - * @param query The {@link Query} to filter results. Constructed using a {@link Qualifier} that can contain - * other qualifiers. Must not be {@literal null}. If filter param is null and qualifier has - * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the - * first processed qualifier. - * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be - * {@literal null}. - * @param filter Secondary index filter. - * @return Stream of entities. - */ - Stream find(Query query, Class entityClass, @Nullable Filter filter); - - /** - * Find all documents in the given entityClass's set using provided {@link Query}. - * - * @param query The {@link Query} to filter results. Constructed using a {@link Qualifier} that can contain - * other qualifiers. Must not be {@literal null}. If filter param is null and qualifier has - * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the - * first processed qualifier. - * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be - * {@literal null}. - * @param targetClass The class to map the entity to. Must not be {@literal null}. - * @param filter Secondary index filter. - * @return Stream of entities. - */ - Stream find(Query query, Class entityClass, Class targetClass, @Nullable Filter filter); - - /** - * Find all documents in the given set using provided {@link Query}. - * - * @param query The {@link Query} to filter results. Constructed using a {@link Qualifier} that can contain - * other qualifiers. Must not be {@literal null}. If filter param is null and qualifier has - * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the - * first processed qualifier. - * @param targetClass The class to map the entity to. Must not be {@literal null}. - * @param setName Set name to find the documents in. - * @param filter Secondary index filter. - * @return Stream of entities. - */ - Stream find(Query query, Class targetClass, String setName, @Nullable Filter filter); - /** * Find all documents in the given entityClass's set and map them to the given class type. * diff --git a/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java b/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java index 021c7824b..66239234e 100644 --- a/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java +++ b/src/main/java/org/springframework/data/aerospike/core/AerospikeTemplate.java @@ -74,7 +74,6 @@ import static org.springframework.data.aerospike.core.TemplateUtils.queryCriteriaIsNotNull; import static org.springframework.data.aerospike.query.QualifierUtils.getOneIdQualifier; import static org.springframework.data.aerospike.query.QualifierUtils.validateQualifiers; -import static org.springframework.data.aerospike.utility.Utils.allArrayElementsAreNull; /** * Primary implementation of {@link AerospikeOperations}. @@ -668,13 +667,13 @@ public S findById(Object id, Class entityClass, Class targetClass, return (S) findByIdUsingQuery(id, entityClass, targetClass, setName, null); } - private Record getRecord(AerospikePersistentEntity entity, Key key, Qualifier criteria) { + private Record getRecord(AerospikePersistentEntity entity, Key key, Qualifier qualifier) { Record aeroRecord; if (entity.isTouchOnRead()) { Assert.state(!entity.hasExpirationProperty(), "Touch on read is not supported for expiration property"); - aeroRecord = getAndTouch(key, entity.getExpiration(), null); + aeroRecord = getAndTouch(key, entity.getExpiration(), null, null); } else { - Policy policy = getPolicyFilterExp(criteria); + Policy policy = getPolicyFilterExp(qualifier); aeroRecord = getAerospikeClient().get(policy, key); } return aeroRecord; @@ -696,14 +695,14 @@ private Key[] getKeys(Collection ids, String setName) { } private Object getRecordMapToTargetClass(AerospikePersistentEntity entity, Key key, Class targetClass, - Qualifier criteria) { + Qualifier qualifier) { Record aeroRecord; String[] binNames = getBinNamesFromTargetClass(targetClass); if (entity.isTouchOnRead()) { Assert.state(!entity.hasExpirationProperty(), "Touch on read is not supported for expiration property"); - aeroRecord = getAndTouch(key, entity.getExpiration(), binNames, criteria); + aeroRecord = getAndTouch(key, entity.getExpiration(), binNames, qualifier); } else { - Policy policy = getPolicyFilterExp(criteria); + Policy policy = getPolicyFilterExp(qualifier); aeroRecord = getAerospikeClient().get(policy, key, binNames); } return mapToEntity(key, targetClass, aeroRecord); @@ -729,12 +728,12 @@ private Policy getPolicyFilterExp(Qualifier... qualifiers) { return null; } - private Record getAndTouch(Key key, int expiration, String[] binNames, Qualifier... qualifiers) { + private Record getAndTouch(Key key, int expiration, String[] binNames, Qualifier qualifier) { WritePolicyBuilder writePolicyBuilder = WritePolicyBuilder.builder(client.getWritePolicyDefault()) .expiration(expiration); - if (qualifiers != null && qualifiers.length > 0) { - writePolicyBuilder.filterExp(queryEngine.getFilterExpressionsBuilder().build(qualifiers)); + if (qualifier != null) { + writePolicyBuilder.filterExp(queryEngine.getFilterExpressionsBuilder().build(new Qualifier[]{qualifier})); } WritePolicy writePolicy = writePolicyBuilder.build(); @@ -816,15 +815,15 @@ public Object findByIdUsingQuery(Object id, Class entityClass, Class entity = mappingContext.getRequiredPersistentEntity(entityClass); Key key = getKey(id, setName); if (targetClass != null && targetClass != entityClass) { - return getRecordMapToTargetClass(entity, key, targetClass, criteria); + return getRecordMapToTargetClass(entity, key, targetClass, qualifier); } - return mapToEntity(key, entityClass, getRecord(entity, key, criteria)); + return mapToEntity(key, entityClass, getRecord(entity, key, qualifier)); } catch (AerospikeException e) { throw translateError(e); } @@ -895,21 +894,9 @@ public Stream find(Query query, Class targetClass, String setName) { return findUsingQueryWithPostProcessing(setName, targetClass, query); } - @Override - public Stream find(Query query, Class entityClass, Filter filter) { - return find(query, entityClass, getSetName(entityClass), filter); - } - - @Override - public Stream find(Query query, Class entityClass, Class targetClass, Filter filter) { - return findRecordsUsingQualifiers(getSetName(entityClass), targetClass, filter) - .map(keyRecord -> mapToEntity(keyRecord, targetClass)); - } - - @Override - public Stream find(Query query, Class targetClass, String setName, Filter filter) { - Qualifier criteria = queryCriteriaIsNotNull(query) ? query.getCriteria().getCriteriaObject() : null; - return findRecordsUsingQualifiers(setName, targetClass, filter, criteria) + private Stream find(Query query, Class targetClass, String setName, Filter filter) { + Qualifier qualifier = queryCriteriaIsNotNull(query) ? query.getCriteria().getCriteriaObject() : null; + return findRecordsUsingQualifier(setName, targetClass, filter, qualifier) .map(keyRecord -> mapToEntity(keyRecord, targetClass)); } @@ -951,21 +938,20 @@ public Stream findAll(Sort sort, long offset, long limit, Class target Assert.notNull(setName, "Set name must not be null!"); Assert.notNull(targetClass, "Target class must not be null!"); - return findUsingQualifierWithPostProcessing(setName, targetClass, sort, offset, limit, - null, null); + return findUsingQualifierWithPostProcessing(setName, targetClass, sort, offset, limit, null); } private Stream findUsingQueryWithPostProcessing(String setName, Class targetClass, Query query) { verifyUnsortedWithOffset(query.getSort(), query.getOffset()); - Stream results = findUsingQualifiersWithDistinctPredicate(setName, targetClass, + Stream results = findUsingQueryWithDistinctPredicate(setName, targetClass, getDistinctPredicate(query), query); return applyPostProcessingOnResults(results, query); } - private Stream findUsingQualifiersWithDistinctPredicate(String setName, Class targetClass, - Predicate distinctPredicate, - Query query) { - return findRecordsUsingQualifiers(setName, targetClass, null, query.getCriteria().getCriteriaObject()) + private Stream findUsingQueryWithDistinctPredicate(String setName, Class targetClass, + Predicate distinctPredicate, + Query query) { + return findRecordsUsingQualifier(setName, targetClass, null, query.getCriteria().getCriteriaObject()) .filter(distinctPredicate) .map(keyRecord -> mapToEntity(keyRecord, targetClass)); } @@ -988,8 +974,7 @@ public Stream findInRange(long offset, long limit, Sort sort, Assert.notNull(targetClass, "Target class must not be null!"); Assert.notNull(setName, "Set name must not be null!"); - return findUsingQualifierWithPostProcessing(setName, targetClass, sort, offset, limit, - null, null); + return findUsingQualifierWithPostProcessing(setName, targetClass, sort, offset, limit, null); } @Override @@ -1072,7 +1057,7 @@ private Stream findRecordsUsingQuery(String setName, Query query) { Assert.notNull(setName, "Set name must not be null!"); Qualifier qualifier = query.getCriteria().getCriteriaObject(); - return findRecordsUsingQualifiers(setName, null, null, qualifier); + return findRecordsUsingQualifier(setName, null, null, qualifier); } @Override @@ -1255,11 +1240,10 @@ private Record putAndGetHeader(AerospikeWriteData data, WritePolicy policy, bool @SuppressWarnings("SameParameterValue") private Stream findUsingQualifierWithPostProcessing(String setName, Class targetClass, Sort sort, - long offset, long limit, Filter filter, - Qualifier qualifier) { + long offset, long limit, Qualifier qualifier) { verifyUnsortedWithOffset(sort, offset); Query query = qualifier != null ? new Query(qualifier) : null; - Stream results = find(query, targetClass, setName, filter); + Stream results = find(query, targetClass, setName, null); return applyPostProcessingOnResults(results, sort, offset, limit); } @@ -1294,16 +1278,16 @@ private Stream applyPostProcessingOnResults(Stream results, Sort sort, return results; } - private Stream findRecordsUsingQualifiers(String setName, Class targetClass, Filter filter, - Qualifier... qualifiers) { - if (qualifiers != null && qualifiers.length > 0 && !allArrayElementsAreNull(qualifiers)) { - validateQualifiers(qualifiers); + private Stream findRecordsUsingQualifier(String setName, Class targetClass, Filter filter, + Qualifier qualifier) { + if (qualifier != null) { + validateQualifiers(qualifier); - Qualifier idQualifier = getOneIdQualifier(qualifiers); + Qualifier idQualifier = getOneIdQualifier(qualifier); if (idQualifier != null) { // a special flow if there is id given return findByIdsWithoutMapping(getIdValue(idQualifier), setName, targetClass, - excludeIdQualifier(qualifiers)).stream(); + excludeIdQualifier(qualifier)).stream(); } } @@ -1311,9 +1295,9 @@ private Stream findRecordsUsingQualifiers(String setName, Class Flux findByIdsUsingQuery(Collection ids, Class entityClass, Clas */ Flux find(Query query, Class targetClass, String setName); - /** - * Find all documents in the given entityClass's set using provided {@link Query}. - * - * @param query The {@link Query} to filter results. Constructed using a {@link Qualifier} that can contain - * other qualifiers. Must not be {@literal null}. If filter param is null and qualifier has - * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the - * first processed qualifier. - * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be - * {@literal null}. - * @param filter Secondary index filter. - * @return Stream of entities. - */ - Flux find(Query query, Class entityClass, @Nullable Filter filter); - - /** - * Find all documents in the given entityClass's set using provided {@link Query}. - * - * @param query The {@link Query} to filter results. Constructed using a {@link Qualifier} that can contain - * other qualifiers. Must not be {@literal null}. If filter param is null and qualifier has - * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the - * first processed qualifier. - * @param entityClass The class to extract the Aerospike set from and to map the entity to. Must not be - * {@literal null}. - * @param targetClass The class to map the entity to. Must not be {@literal null}. - * @param filter Secondary index filter. - * @return Stream of entities. - */ - Flux find(Query query, Class entityClass, Class targetClass, @Nullable Filter filter); - - /** - * Find all documents in the given set using provided {@link Query}. - * - * @param query The {@link Query} to filter results. Constructed using a {@link Qualifier} that can contain - * other qualifiers. Must not be {@literal null}. If filter param is null and qualifier has - * {@link Qualifier#getExcludeFilter()} == false, secondary index filter is built based on the - * first processed qualifier. - * @param targetClass The class to map the entity to. Must not be {@literal null}. - * @param setName Set name to find the documents in. - * @param filter Secondary index filter. - * @return Stream of entities. - */ - Flux find(Query query, Class targetClass, String setName, @Nullable Filter filter); - /** * Reactively find all documents in the given entityClass's set and map them to the given class type. * diff --git a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java index 7f9f2c422..1e0c84137 100644 --- a/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java +++ b/src/main/java/org/springframework/data/aerospike/core/ReactiveAerospikeTemplate.java @@ -71,7 +71,6 @@ import static org.springframework.data.aerospike.core.TemplateUtils.queryCriteriaIsNotNull; import static org.springframework.data.aerospike.query.QualifierUtils.getOneIdQualifier; import static org.springframework.data.aerospike.query.QualifierUtils.validateQualifiers; -import static org.springframework.data.aerospike.utility.Utils.allArrayElementsAreNull; /** * Primary implementation of {@link ReactiveAerospikeOperations}. @@ -623,7 +622,7 @@ public Mono findById(Object id, Class entityClass, String setName) { if (entity.isTouchOnRead()) { Assert.state(!entity.hasExpirationProperty(), "Touch on read is not supported for entity without expiration property"); - return getAndTouch(key, entity.getExpiration(), null) + return getAndTouch(key, entity.getExpiration(), null, null) .filter(keyRecord -> Objects.nonNull(keyRecord.record)) .map(keyRecord -> mapToEntity(keyRecord.key, entityClass, keyRecord.record)) .onErrorResume( @@ -654,7 +653,7 @@ public Mono findById(Object id, Class entityClass, Class targetC if (entity.isTouchOnRead()) { Assert.state(!entity.hasExpirationProperty(), "Touch on read is not supported for entity without expiration property"); - return getAndTouch(key, entity.getExpiration(), binNames) + return getAndTouch(key, entity.getExpiration(), binNames, null) .filter(keyRecord -> Objects.nonNull(keyRecord.record)) .map(keyRecord -> mapToEntity(keyRecord.key, targetClass, keyRecord.record)) .onErrorResume( @@ -735,12 +734,11 @@ public Mono findByIdUsingQuery(Object id, Class entityClass, Class< target = entityClass; } - Qualifier[] qualifiers = queryCriteriaIsNotNull(query) ? - new Qualifier[]{query.getCriteria().getCriteriaObject()} : null; + Qualifier qualifier = queryCriteriaIsNotNull(query) ? query.getCriteria().getCriteriaObject() : null; if (entity.isTouchOnRead()) { Assert.state(!entity.hasExpirationProperty(), "Touch on read is not supported for entity without expiration property"); - return getAndTouch(key, entity.getExpiration(), binNames, qualifiers) + return getAndTouch(key, entity.getExpiration(), binNames, qualifier) .filter(keyRecord -> Objects.nonNull(keyRecord.record)) .map(keyRecord -> mapToEntity(keyRecord.key, target, keyRecord.record)) .onErrorResume( @@ -750,9 +748,9 @@ public Mono findByIdUsingQuery(Object id, Class entityClass, Class< .onErrorMap(this::translateError); } else { Policy policy = null; - if (qualifiers != null && qualifiers.length > 0) { + if (qualifier != null) { policy = new Policy(reactorClient.getReadPolicyDefault()); - policy.filterExp = reactorQueryEngine.getFilterExpressionsBuilder().build(qualifiers); + policy.filterExp = reactorQueryEngine.getFilterExpressionsBuilder().build(new Qualifier[]{qualifier}); } return reactorClient.get(policy, key, binNames) .filter(keyRecord -> Objects.nonNull(keyRecord.record)) @@ -817,24 +815,6 @@ public Flux find(Query query, Class targetClass, String setName) { return findUsingQueryWithPostProcessing(setName, targetClass, query); } - @Override - public Flux find(Query query, Class entityClass, Filter filter) { - return find(query, entityClass, getSetName(entityClass), filter); - } - - @Override - public Flux find(Query query, Class entityClass, Class targetClass, Filter filter) { - return findRecordsUsingQualifiers(getSetName(entityClass), targetClass, filter) - .map(keyRecord -> mapToEntity(keyRecord, targetClass)); - } - - @Override - public Flux find(Query query, Class targetClass, String setName, Filter filter) { - Qualifier criteria = queryCriteriaIsNotNull(query) ? query.getCriteria().getCriteriaObject() : null; - return findRecordsUsingQualifiers(setName, targetClass, filter, criteria) - .map(keyRecord -> mapToEntity(keyRecord, targetClass)); - } - @Override public Flux findAll(Class entityClass) { Assert.notNull(entityClass, "Entity class must not be null!"); @@ -855,7 +835,7 @@ public Flux findAll(Class targetClass, String setName) { Assert.notNull(targetClass, "Target class must not be null!"); Assert.notNull(setName, "Set name must not be null!"); - return findUsingQualifiers(setName, targetClass, null, (Qualifier[]) null); + return findUsingQualifier(setName, targetClass, null, null); } @Override @@ -878,8 +858,7 @@ public Flux findAll(Sort sort, long offset, long limit, Class targetCl Assert.notNull(targetClass, "Target class must not be null!"); Assert.notNull(setName, "Set name must not be null!"); - return findUsingQualifiersWithPostProcessing(setName, targetClass, sort, offset, limit, - null, (Qualifier[]) null); + return findUsingQualifierWithPostProcessing(setName, targetClass, sort, offset, limit, null); } @Override @@ -902,8 +881,7 @@ public Flux findInRange(long offset, long limit, Sort sort, Class targ Assert.notNull(targetClass, "Target Class must not be null!"); Assert.notNull(setName, "Set name must not be null!"); - return findUsingQualifiersWithPostProcessing(setName, targetClass, sort, offset, limit, - null, (Qualifier[]) null); + return findUsingQualifierWithPostProcessing(setName, targetClass, sort, offset, limit, null); } private BatchPolicy getBatchPolicyFilterExp(Qualifier[] qualifiers) { @@ -1009,7 +987,7 @@ private Flux findRecordsUsingQuery(String setName, Query query) { Assert.notNull(setName, "Set name must not be null!"); Qualifier qualifier = query.getCriteria().getCriteriaObject(); - return findRecordsUsingQualifiers(setName, null, null, qualifier); + return findRecordsUsingQualifier(setName, null, null, qualifier); } @Override @@ -1149,12 +1127,13 @@ private Mono putAndGetHeader(AerospikeWriteData data, WritePolicy policy .map(keyRecord -> keyRecord.record); } - private Mono getAndTouch(Key key, int expiration, String[] binNames, Qualifier... qualifiers) { + private Mono getAndTouch(Key key, int expiration, String[] binNames, Qualifier qualifiers) { WritePolicyBuilder writePolicyBuilder = WritePolicyBuilder.builder(this.writePolicyDefault) .expiration(expiration); - if (qualifiers != null && qualifiers.length > 0) { - writePolicyBuilder.filterExp(reactorQueryEngine.getFilterExpressionsBuilder().build(qualifiers)); + if (qualifiers != null) { + writePolicyBuilder.filterExp(reactorQueryEngine.getFilterExpressionsBuilder() + .build(new Qualifier[]{qualifiers})); } WritePolicy writePolicy = writePolicyBuilder.build(); @@ -1191,18 +1170,17 @@ private Throwable translateError(Throwable e) { private Flux findUsingQueryWithPostProcessing(String setName, Class targetClass, Query query) { verifyUnsortedWithOffset(query.getSort(), query.getOffset()); Qualifier qualifier = query.getCriteria().getCriteriaObject(); - Flux results = findUsingQualifiersWithDistinctPredicate(setName, targetClass, + Flux results = findUsingQualifierWithDistinctPredicate(setName, targetClass, getDistinctPredicate(query), qualifier); results = applyPostProcessingOnResults(results, query); return results; } @SuppressWarnings("SameParameterValue") - private Flux findUsingQualifiersWithPostProcessing(String setName, Class targetClass, Sort sort, - long offset, long limit, Filter filter, - Qualifier... qualifiers) { + private Flux findUsingQualifierWithPostProcessing(String setName, Class targetClass, Sort sort, + long offset, long limit, Qualifier qualifier) { verifyUnsortedWithOffset(sort, offset); - Flux results = findUsingQualifiers(setName, targetClass, filter, qualifiers); + Flux results = findUsingQualifier(setName, targetClass, null, qualifier); results = applyPostProcessingOnResults(results, sort, offset, limit); return results; } @@ -1246,44 +1224,44 @@ private Flux applyPostProcessingOnResults(Flux results, Sort sort, lon return results; } - private Flux findUsingQualifiers(String setName, Class targetClass, Filter filter, - Qualifier... qualifiers) { - return findRecordsUsingQualifiers(setName, targetClass, filter, qualifiers) + private Flux findUsingQualifier(String setName, Class targetClass, Filter filter, + Qualifier qualifier) { + return findRecordsUsingQualifier(setName, targetClass, filter, qualifier) .map(keyRecord -> mapToEntity(keyRecord, targetClass)); } - private Flux findUsingQualifiersWithDistinctPredicate(String setName, Class targetClass, - Predicate distinctPredicate, - Qualifier... qualifiers) { - return findRecordsUsingQualifiers(setName, targetClass, null, qualifiers) + private Flux findUsingQualifierWithDistinctPredicate(String setName, Class targetClass, + Predicate distinctPredicate, + Qualifier qualifier) { + return findRecordsUsingQualifier(setName, targetClass, null, qualifier) .filter(distinctPredicate) .map(keyRecord -> mapToEntity(keyRecord, targetClass)); } - private Flux findRecordsUsingQualifiers(String setName, Class targetClass, Filter filter, - Qualifier... qualifiers) { - if (qualifiers != null && qualifiers.length > 0 && !allArrayElementsAreNull(qualifiers)) { - validateQualifiers(qualifiers); + private Flux findRecordsUsingQualifier(String setName, Class targetClass, Filter filter, + Qualifier qualifier) { + if (qualifier != null) { + validateQualifiers(qualifier); - Qualifier idQualifier = getOneIdQualifier(qualifiers); + Qualifier idQualifier = getOneIdQualifier(qualifier); if (idQualifier != null) { // a special flow if there is id given return findByIdsWithoutMapping(getIdValue(idQualifier), setName, targetClass, - excludeIdQualifier(qualifiers)); + excludeIdQualifier(qualifier)); } } if (targetClass != null) { String[] binNames = getBinNamesFromTargetClass(targetClass); - return this.reactorQueryEngine.select(this.namespace, setName, binNames, filter, qualifiers); + return this.reactorQueryEngine.select(this.namespace, setName, binNames, filter, qualifier); } else { - return this.reactorQueryEngine.select(this.namespace, setName, filter, qualifiers); + return this.reactorQueryEngine.select(this.namespace, setName, filter, qualifier); } } private Flux findByIdsWithoutMapping(Collection ids, String setName, Class targetClass, - Qualifier... qualifiers) { + Qualifier qualifier) { Assert.notNull(ids, "List of ids must not be null!"); Assert.notNull(setName, "Set name must not be null!"); @@ -1291,7 +1269,7 @@ private Flux findByIdsWithoutMapping(Collection ids, String se return Flux.empty(); } - BatchPolicy policy = getBatchPolicyFilterExp(qualifiers); + BatchPolicy policy = getBatchPolicyFilterExp(new Qualifier[]{qualifier}); return Flux.fromIterable(ids) .map(id -> getKey(id, setName)) diff --git a/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java b/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java index ab133f0ee..712d41a96 100644 --- a/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java +++ b/src/main/java/org/springframework/data/aerospike/core/TemplateUtils.java @@ -59,23 +59,23 @@ public static Qualifier[] excludeIdQualifier(Qualifier[] qualifiers) { return null; } - public static Qualifier excludeIdQualifier(Qualifier criteria) { + public static Qualifier excludeIdQualifier(Qualifier qualifier) { List qualifiersWithoutId = new ArrayList<>(); - if (criteria != null && criteria.hasQualifiers()) { - for (Qualifier qualifier : criteria.getQualifiers()) { - if (qualifier.hasQualifiers()) { - Qualifier[] internalQuals = excludeIdQualifier(qualifier.getQualifiers()); - qualifiersWithoutId.add(combineMultipleQualifiers(qualifier.getOperation(), internalQuals)); - } else if (!qualifier.hasId()) { - qualifiersWithoutId.add(qualifier); + if (qualifier != null && qualifier.hasQualifiers()) { + for (Qualifier innerQual : qualifier.getQualifiers()) { + if (innerQual.hasQualifiers()) { + Qualifier[] internalQuals = excludeIdQualifier(innerQual.getQualifiers()); + qualifiersWithoutId.add(combineMultipleQualifiers(innerQual.getOperation(), internalQuals)); + } else if (!innerQual.hasId()) { + qualifiersWithoutId.add(innerQual); } } - return combineMultipleQualifiers(criteria.getOperation() != null ? criteria.getOperation() : + return combineMultipleQualifiers(qualifier.getOperation() != null ? qualifier.getOperation() : FilterOperation.AND, qualifiersWithoutId.toArray(Qualifier[]::new)); - } else if (criteria.hasId()) { + } else if (qualifier.hasId()) { return null; } - return criteria; + return qualifier; } private static Qualifier combineMultipleQualifiers(FilterOperation operation, Qualifier[] qualifiers) { diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java b/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java index 46dace238..722046f54 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateFindByQueryTests.java @@ -536,23 +536,17 @@ public void findAllUsingQuery_shouldRunWithDifferentArgumentsCombinations() { additionalAerospikeTestOperations.createIndex(SampleClasses.CustomCollectionClass.class, "CustomCollectionClass_field", fieldName, IndexType.STRING); - // find by qualifiers, no predefined secondary index filter + // find by query Qualifier qualifier = Qualifier.builder() .setField(fieldName) .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(fieldValue1)) .build(); Stream result1 = - template.find(new Query(qualifier), SampleClasses.CustomCollectionClass.class, (Filter) null); + template.find(new Query(qualifier), SampleClasses.CustomCollectionClass.class); assertThat(result1).containsOnly(doc1); - // find by a predefined secondary index filter, no qualifiers - Filter filter = Filter.equal(fieldName, fieldValue1); - Stream result2 = - template.find(null, SampleClasses.CustomCollectionClass.class, filter); - assertThat(result2).containsOnly(doc1); - - // find by a complex qualifier + // find by query with a complex qualifier Qualifier dataEqFieldValue1 = Qualifier.builder() .setFilterOperation(FilterOperation.EQ) .setField(fieldName) @@ -565,12 +559,12 @@ public void findAllUsingQuery_shouldRunWithDifferentArgumentsCombinations() { .build(); Qualifier qualifierOr = Qualifier.or(dataEqFieldValue1, dataEqFieldValue2); Stream result3 = - template.find(new Query(qualifierOr), SampleClasses.CustomCollectionClass.class, (Filter) null); + template.find(new Query(qualifierOr), SampleClasses.CustomCollectionClass.class); assertThat(result3).containsOnly(doc1, doc2); // no secondary index filter and no qualifiers Stream result4 = - template.find(null, SampleClasses.CustomCollectionClass.class, (Filter) null); + template.find(null, SampleClasses.CustomCollectionClass.class); assertThat(result4).contains(doc1, doc2); additionalAerospikeTestOperations.dropIndex(SampleClasses.CustomCollectionClass.class,