diff --git a/src/main/java/org/springframework/data/aerospike/query/ExpiryQualifier.java b/src/main/java/org/springframework/data/aerospike/query/ExpiryQualifier.java index 866763b94..8bd1786ca 100644 --- a/src/main/java/org/springframework/data/aerospike/query/ExpiryQualifier.java +++ b/src/main/java/org/springframework/data/aerospike/query/ExpiryQualifier.java @@ -33,7 +33,7 @@ public class ExpiryQualifier extends Qualifier { private static final long serialVersionUID = 13172814137477042L; public ExpiryQualifier(FilterOperation op, Value value) { - super(new QualifierBuilder() + super(Qualifier.builder() .setField(QueryEngine.Meta.EXPIRATION.toString()) .setFilterOperation(op) .setValue1(value) diff --git a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java index 4e00f09d2..05ee4c2bb 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -75,12 +75,12 @@ public Exp filterExp(Map qualifierMap) { Value value1 = getValue1AsCollectionOrFail(qualifierMap); Collection collection = (Collection) value1.getObject(); Exp[] arrElementsExp = collection.stream().map(item -> - new Qualifier( - new QualifierBuilder() - .setField(getField(qualifierMap)) - .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(item)) - ).toFilterExp() + Qualifier.builder() + .setField(getField(qualifierMap)) + .setFilterOperation(FilterOperation.EQ) + .setValue1(Value.get(item)) + .build() + .toFilterExp() ).toArray(Exp[]::new); return Exp.or(arrElementsExp); @@ -100,12 +100,12 @@ public Exp filterExp(Map qualifierMap) { Value value1 = getValue1AsCollectionOrFail(qualifierMap); Collection collection = (Collection) value1.getObject(); Exp[] arrElementsExp = collection.stream().map(item -> - new Qualifier( - new QualifierBuilder() - .setField(getField(qualifierMap)) - .setFilterOperation(FilterOperation.NOTEQ) - .setValue1(Value.get(item)) - ).toFilterExp() + Qualifier.builder() + .setField(getField(qualifierMap)) + .setFilterOperation(FilterOperation.NOTEQ) + .setValue1(Value.get(item)) + .build() + .toFilterExp() ).toArray(Exp[]::new); return Exp.and(arrElementsExp); @@ -587,7 +587,8 @@ public Exp filterExp(Map qualifierMap) { validateEquality(getValue1(qualifierMap).getType(), getValue3(qualifierMap).getType(), qualifierMap, "MAP_VAL_BETWEEN_BY_KEY"); - Exp value1, value2; + Exp value1; + Exp value2; Exp.Type type; switch (getValue1(qualifierMap).getType()) { case INTEGER -> { @@ -1212,11 +1213,12 @@ public Filter sIndexFilter(Map qualifierMap) { /** * FilterOperations that require both sIndexFilter and FilterExpression */ - public static final List dualFilterOperations = Arrays.asList( + protected static final List dualFilterOperations = Arrays.asList( MAP_VAL_EQ_BY_KEY, MAP_VAL_GT_BY_KEY, MAP_VAL_GTEQ_BY_KEY, MAP_VAL_LT_BY_KEY, MAP_VAL_LTEQ_BY_KEY, MAP_VAL_BETWEEN_BY_KEY ); + @SuppressWarnings("unchecked") private static Exp processMetadataFieldInOrNot(Map qualifierMap, boolean notIn) { FilterOperation filterOperation = notIn ? NOTEQ : EQ; Object value1 = getValue1Object(qualifierMap); @@ -1230,12 +1232,12 @@ private static Exp processMetadataFieldInOrNot(Map qualifierMap, "type List"); } Exp[] listElementsExp = listOfLongs.stream().map(item -> - new Qualifier( - new MetadataQualifierBuilder() - .setMetadataField(getMetadataField(qualifierMap)) - .setFilterOperation(filterOperation) - .setValue1AsObj(item) - ).toFilterExp() + Qualifier.metadataBuilder() + .setMetadataField(getMetadataField(qualifierMap)) + .setFilterOperation(filterOperation) + .setValue1AsObj(item) + .build() + .toFilterExp() ).toArray(Exp[]::new); return notIn ? Exp.and(listElementsExp) : Exp.or(listElementsExp); diff --git a/src/main/java/org/springframework/data/aerospike/query/KeyQualifier.java b/src/main/java/org/springframework/data/aerospike/query/KeyQualifier.java index 3d8dddb92..5f5e4f46e 100644 --- a/src/main/java/org/springframework/data/aerospike/query/KeyQualifier.java +++ b/src/main/java/org/springframework/data/aerospike/query/KeyQualifier.java @@ -35,7 +35,7 @@ public class KeyQualifier extends Qualifier { boolean hasDigest = false; public KeyQualifier(Value value) { - super(new QualifierBuilder() + super(Qualifier.builder() .setField(QueryEngine.Meta.KEY.toString()) .setFilterOperation(FilterOperation.EQ) .setValue1(value) @@ -43,7 +43,7 @@ public KeyQualifier(Value value) { } public KeyQualifier(byte[] digest) { - super(new QualifierBuilder() + super(Qualifier.builder() .setField(QueryEngine.Meta.KEY.toString()) .setFilterOperation(FilterOperation.EQ) .setValue1(null) diff --git a/src/main/java/org/springframework/data/aerospike/query/LatestUpdateQualifier.java b/src/main/java/org/springframework/data/aerospike/query/LatestUpdateQualifier.java index 050ac683b..88cd0bd62 100644 --- a/src/main/java/org/springframework/data/aerospike/query/LatestUpdateQualifier.java +++ b/src/main/java/org/springframework/data/aerospike/query/LatestUpdateQualifier.java @@ -33,7 +33,7 @@ public class LatestUpdateQualifier extends Qualifier { private static final long serialVersionUID = -8767573059309320133L; public LatestUpdateQualifier(FilterOperation op, Value value) { - super(new QualifierBuilder() + super(Qualifier.builder() .setField("latest_update_time") .setFilterOperation(op) .setValue1(value) diff --git a/src/main/java/org/springframework/data/aerospike/query/MetadataQualifierBuilder.java b/src/main/java/org/springframework/data/aerospike/query/MetadataQualifierBuilder.java deleted file mode 100644 index b9d57e639..000000000 --- a/src/main/java/org/springframework/data/aerospike/query/MetadataQualifierBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.springframework.data.aerospike.query; - -import org.springframework.data.aerospike.repository.query.CriteriaDefinition; -import org.springframework.util.Assert; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import static org.springframework.data.aerospike.query.Qualifier.FIELD; -import static org.springframework.data.aerospike.query.Qualifier.METADATA_FIELD; -import static org.springframework.data.aerospike.query.Qualifier.OPERATION; -import static org.springframework.data.aerospike.query.Qualifier.QUALIFIERS; -import static org.springframework.data.aerospike.query.Qualifier.VALUE1; -import static org.springframework.data.aerospike.query.Qualifier.VALUE2; - -public class MetadataQualifierBuilder implements QualifierMapBuilder { - - private final Map map = new HashMap<>(); - - public MetadataQualifierBuilder setFilterOperation(FilterOperation filterOperation) { - this.map.put(OPERATION, filterOperation); - return this; - } - - public FilterOperation getFilterOperation() { - return (FilterOperation) this.map.get(OPERATION); - } - - public MetadataQualifierBuilder setQualifiers(Qualifier... qualifiers) { - this.map.put(QUALIFIERS, qualifiers); - return this; - } - - public MetadataQualifierBuilder setMetadataField(CriteriaDefinition.AerospikeMetadata metadataField) { - this.map.put(METADATA_FIELD, metadataField); - return this; - } - - public CriteriaDefinition.AerospikeMetadata getMetadataField() { - return (CriteriaDefinition.AerospikeMetadata) map.get(METADATA_FIELD); - } - - public String getField() { - return (String) this.map.get(FIELD); - } - - public MetadataQualifierBuilder setValue1AsObj(Object object) { - this.map.put(VALUE1, object); - return this; - } - - public Object getValue1AsObj() { - return this.map.get(VALUE1); - } - - public MetadataQualifierBuilder setValue2AsObj(Object object) { - this.map.put(VALUE2, object); - return this; - } - - public Object getValue2AsObj() { - return this.map.get(VALUE2); - } - - public Qualifier build() { - validate(); - return new Qualifier(this); - } - - public Map buildMap() { - return this.map; - } - - @SuppressWarnings("unchecked") - protected void validate() { - // metadata query - if (this.getMetadataField() != null) { - if (this.getField() == null) { - FilterOperation operation = this.getFilterOperation(); - switch (operation) { - case EQ, NOTEQ, LT, LTEQ, GT, GTEQ -> Assert.isTrue(this.getValue1AsObj() instanceof Long, - operation.name() + ": value1 is expected to be set as Long"); - case BETWEEN -> { - Assert.isTrue(this.getValue1AsObj() instanceof Long, - "BETWEEN: value1 is expected to be set as Long"); - Assert.isTrue(this.getValue2AsObj() instanceof Long, - "BETWEEN: value2 is expected to be set as Long"); - } - case NOT_IN, IN -> Assert.isTrue(this.getValue1AsObj() instanceof Collection - && (!((Collection) this.getValue1AsObj()).isEmpty()) - && ((Collection) this.getValue1AsObj()).toArray()[0] instanceof Long, - operation.name() + ": value1 is expected to be a non-empty Collection"); - default -> throw new IllegalArgumentException("Operation " + operation + " cannot be applied to " + - "metadataField"); - } - } else { - throw new IllegalArgumentException("Either a field or a metadataField must be set, not both"); - } - } - } -} diff --git a/src/main/java/org/springframework/data/aerospike/query/Qualifier.java b/src/main/java/org/springframework/data/aerospike/query/Qualifier.java index 6e46bd9e7..43c281186 100644 --- a/src/main/java/org/springframework/data/aerospike/query/Qualifier.java +++ b/src/main/java/org/springframework/data/aerospike/query/Qualifier.java @@ -20,7 +20,9 @@ import com.aerospike.client.command.ParticleType; import com.aerospike.client.exp.Exp; import com.aerospike.client.query.Filter; +import org.springframework.data.aerospike.convert.MappingAerospikeConverter; import org.springframework.data.aerospike.repository.query.CriteriaDefinition; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; import java.io.Serial; @@ -55,7 +57,7 @@ public class Qualifier implements Map, Serializable { private static final long serialVersionUID = -2689196529952712849L; protected final Map internalMap; - public Qualifier(QualifierMapBuilder builder) { + protected Qualifier(Builder builder) { internalMap = new HashMap<>(); if (!builder.buildMap().isEmpty()) { @@ -63,6 +65,26 @@ public Qualifier(QualifierMapBuilder builder) { } } + public static void validateQualifiers(Qualifier... qualifiers) { + boolean haveInternalQualifiers = qualifiers.length > 1; + for (Qualifier qualifier : qualifiers) { + haveInternalQualifiers = haveInternalQualifiers || qualifier.hasQualifiers(); + // excludeFilter in the upmost parent qualifier is set to true + // if there are multiple qualifiers + // must not build secondary index filter based on any of them + // as it might conflict with the combination of qualifiers + qualifier.setExcludeFilter(haveInternalQualifiers); + } + } + + public static QualifierBuilder builder() { + return new QualifierBuilder(); + } + + public static MetadataQualifierBuilder metadataBuilder() { + return new MetadataQualifierBuilder(); + } + public FilterOperation getOperation() { return (FilterOperation) internalMap.get(OPERATION); } @@ -124,28 +146,12 @@ protected String luaFieldString(String field) { } protected String luaValueString(Value value) { - String res = null; - if (null == value) return res; + if (null == value) return null; int type = value.getType(); - switch (type) { - // case ParticleType.LIST: - // res = value.toString(); - // break; - // case ParticleType.MAP: - // res = value.toString(); - // break; - // case ParticleType.DOUBLE: - // res = value.toString(); - // break; - case ParticleType.STRING: - case ParticleType.GEOJSON: - res = String.format("'%s'", value); - break; - default: - res = value.toString(); - break; - } - return res; + return switch (type) { + case ParticleType.STRING, ParticleType.GEOJSON -> String.format("'%s'", value); + default -> value.toString(); + }; } @Override @@ -217,6 +223,13 @@ public String toString() { getOperation(), getValue1(), getValue2()); } + public interface Builder { + + Map buildMap(); + + Qualifier build(); + } + public static class QualifierRegexpBuilder { private static final Character BACKSLASH = '\\'; @@ -226,6 +239,9 @@ public static class QualifierRegexpBuilder { private static final Character OPEN_BRACKET = '['; private static final Character CIRCUMFLEX = '^'; + private QualifierRegexpBuilder() { + } + public static String escapeBRERegexp(String base) { StringBuilder builder = new StringBuilder(); for (char stringChar : base.toCharArray()) { @@ -277,15 +293,164 @@ public static String getStringEquals(String base) { } } - public static void validateQualifiers(Qualifier... qualifiers) { - boolean haveInternalQualifiers = qualifiers.length > 1; - for (Qualifier qualifier : qualifiers) { - haveInternalQualifiers = haveInternalQualifiers || qualifier.hasQualifiers(); - // excludeFilter in the upmost parent qualifier is set to true - // if there are multiple qualifiers - // must not build secondary index filter based on any of them - // as it might conflict with the combination of qualifiers - qualifier.setExcludeFilter(haveInternalQualifiers); + public static class QualifierBuilder extends BaseQualifierBuilder { + + private QualifierBuilder() { + } + + public QualifierBuilder setIgnoreCase(boolean ignoreCase) { + this.map.put(IGNORE_CASE, ignoreCase); + return this; + } + + public QualifierBuilder setExcludeFilter(boolean excludeFilter) { + this.map.put(EXCLUDE_FILTER, excludeFilter); + return this; + } + + public QualifierBuilder setValue1(Value value1) { + this.map.put(VALUE1, value1); + return this; + } + + public QualifierBuilder setValue2(Value value2) { + this.map.put(VALUE2, value2); + return this; + } + + public QualifierBuilder setValue3(Value value3) { + this.map.put(VALUE3, value3); + return this; + } + + public void setDotPath(String dotPath) { + this.map.put(DOT_PATH, dotPath); + } + + public QualifierBuilder setConverter(MappingAerospikeConverter converter) { + this.map.put(CONVERTER, converter); + return this; + } + } + + public static class MetadataQualifierBuilder extends BaseQualifierBuilder { + + private MetadataQualifierBuilder() { + } + + public CriteriaDefinition.AerospikeMetadata getMetadataField() { + return (CriteriaDefinition.AerospikeMetadata) map.get(METADATA_FIELD); + } + + public MetadataQualifierBuilder setMetadataField(CriteriaDefinition.AerospikeMetadata metadataField) { + this.map.put(METADATA_FIELD, metadataField); + return this; + } + + public Object getValue1AsObj() { + return this.map.get(VALUE1); + } + + public MetadataQualifierBuilder setValue1AsObj(Object object) { + this.map.put(VALUE1, object); + return this; + } + + public Object getValue2AsObj() { + return this.map.get(VALUE2); + } + + public MetadataQualifierBuilder setValue2AsObj(Object object) { + this.map.put(VALUE2, object); + return this; + } + + @SuppressWarnings("unchecked") + @Override + protected void validate() { + // metadata query + if (this.getMetadataField() != null) { + if (this.getField() == null) { + FilterOperation operation = this.getFilterOperation(); + switch (operation) { + case EQ, NOTEQ, LT, LTEQ, GT, GTEQ -> Assert.isTrue(this.getValue1AsObj() instanceof Long, + operation.name() + ": value1 is expected to be set as Long"); + case BETWEEN -> { + Assert.isTrue(this.getValue1AsObj() instanceof Long, + "BETWEEN: value1 is expected to be set as Long"); + Assert.isTrue(this.getValue2AsObj() instanceof Long, + "BETWEEN: value2 is expected to be set as Long"); + } + case NOT_IN, IN -> Assert.isTrue(this.getValue1AsObj() instanceof Collection + && (!((Collection) this.getValue1AsObj()).isEmpty()) + && ((Collection) this.getValue1AsObj()).toArray()[0] instanceof Long, + operation.name() + ": value1 is expected to be a non-empty Collection"); + default -> + throw new IllegalArgumentException("Operation " + operation + " cannot be applied to " + + "metadataField"); + } + } else { + throw new IllegalArgumentException("Either a field or a metadataField must be set, not both"); + } + } + } + } + + @SuppressWarnings("unchecked") + protected abstract static class BaseQualifierBuilder> implements Builder { + + protected final Map map = new HashMap<>(); + + public FilterOperation getFilterOperation() { + return (FilterOperation) this.map.get(OPERATION); + } + + public T setFilterOperation(FilterOperation filterOperation) { + this.map.put(OPERATION, filterOperation); + return (T) this; + } + + public T setQualifiers(Qualifier... qualifiers) { + this.map.put(QUALIFIERS, qualifiers); + return (T) this; + } + + public String getField() { + return (String) this.map.get(FIELD); + } + + public T setField(String field) { + this.map.put(FIELD, field); + return (T) this; + } + + public boolean hasValue1() { + return this.map.get(VALUE1) != null; + } + + public boolean hasValue2() { + return this.map.get(VALUE2) != null; + } + + public boolean hasValue3() { + return this.map.get(VALUE3) != null; + } + + public boolean hasDotPath() { + return this.map.get(DOT_PATH) != null; + } + + public Qualifier build() { + validate(); + return new Qualifier(this); + } + + public Map buildMap() { + return this.map; + } + + protected void validate() { + // do nothing } } } diff --git a/src/main/java/org/springframework/data/aerospike/query/QualifierBuilder.java b/src/main/java/org/springframework/data/aerospike/query/QualifierBuilder.java deleted file mode 100644 index 55c8c3a7d..000000000 --- a/src/main/java/org/springframework/data/aerospike/query/QualifierBuilder.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.springframework.data.aerospike.query; - -import com.aerospike.client.Value; -import org.springframework.data.aerospike.convert.MappingAerospikeConverter; - -import java.util.HashMap; -import java.util.Map; - -import static org.springframework.data.aerospike.query.Qualifier.*; - -public class QualifierBuilder implements QualifierMapBuilder { - - private final Map map = new HashMap<>(); - - public QualifierBuilder setField(String field) { - this.map.put(FIELD, field); - return this; - } - - public String getField() { - return (String) this.map.get(FIELD); - } - - public QualifierBuilder setIgnoreCase(boolean ignoreCase) { - this.map.put(IGNORE_CASE, ignoreCase); - return this; - } - - public QualifierBuilder setFilterOperation(FilterOperation filterOperation) { - this.map.put(OPERATION, filterOperation); - return this; - } - - public FilterOperation getFilterOperation() { - return (FilterOperation) this.map.get(OPERATION); - } - - public QualifierBuilder setQualifiers(Qualifier... qualifiers) { - this.map.put(QUALIFIERS, qualifiers); - return this; - } - - public QualifierBuilder setExcludeFilter(boolean excludeFilter) { - this.map.put(EXCLUDE_FILTER, excludeFilter); - return this; - } - - public QualifierBuilder setValue1(Value value1) { - this.map.put(VALUE1, value1); - return this; - } - - public QualifierBuilder setValue2(Value value2) { - this.map.put(VALUE2, value2); - return this; - } - - @SuppressWarnings("UnusedReturnValue") - public QualifierBuilder setValue3(Value value3) { - this.map.put(VALUE3, value3); - return this; - } - - public void setDotPath(String dotPath) { - this.map.put(DOT_PATH, dotPath); - } - - public QualifierBuilder setConverter(MappingAerospikeConverter converter) { - this.map.put(CONVERTER, converter); - return this; - } - - public boolean hasValue1() { - return this.map.get(VALUE1) != null; - } - - public boolean hasValue2() { - return this.map.get(VALUE2) != null; - } - - public boolean hasValue3() { - return this.map.get(VALUE3) != null; - } - - public boolean hasDotPath() { - return this.map.get(DOT_PATH) != null; - } - - public Qualifier build() { - return new Qualifier(this); - } - - public Map buildMap() { - return this.map; - } -} diff --git a/src/main/java/org/springframework/data/aerospike/query/QualifierMapBuilder.java b/src/main/java/org/springframework/data/aerospike/query/QualifierMapBuilder.java deleted file mode 100644 index 199dd50ee..000000000 --- a/src/main/java/org/springframework/data/aerospike/query/QualifierMapBuilder.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.springframework.data.aerospike.query; - -import java.util.Map; - -public interface QualifierMapBuilder { - - Map buildMap(); -} diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeCriteria.java b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeCriteria.java index 3b39baafb..3b2e397c8 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeCriteria.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeCriteria.java @@ -17,7 +17,6 @@ package org.springframework.data.aerospike.repository.query; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; /** * @author Michael Zhang diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java index 75ef10e01..5ad85fe1a 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java @@ -25,7 +25,6 @@ import org.springframework.data.aerospike.mapping.AerospikePersistentProperty; import org.springframework.data.aerospike.query.FilterOperation; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria; import org.springframework.data.domain.Sort; import org.springframework.data.mapping.PersistentPropertyPath; @@ -142,7 +141,7 @@ private Object convertIfNecessary(Object obj) { public AerospikeCriteria getCriteria(Part part, AerospikePersistentProperty property, Object value1, Object value2, Iterator parameters, FilterOperation op) { - QualifierBuilder qb = new QualifierBuilder(); + Qualifier.QualifierBuilder qb = Qualifier.builder(); String fieldName = getFieldName(part.getProperty().getSegment(), property); String dotPath = null; Object value3 = null; @@ -284,13 +283,13 @@ private String getFieldName(String segmentName, AerospikePersistentProperty prop return segmentName; } - private AerospikeCriteria aerospikeCriteriaAndConcatenated(List params, QualifierBuilder qb, + private AerospikeCriteria aerospikeCriteriaAndConcatenated(List params, Qualifier.QualifierBuilder qb, Part part, String fieldName, FilterOperation op, String dotPath) { return aerospikeCriteriaAndConcatenated(params, qb, part, fieldName, op, dotPath, false); } - private AerospikeCriteria aerospikeCriteriaAndConcatenated(List params, QualifierBuilder qb, + private AerospikeCriteria aerospikeCriteriaAndConcatenated(List params, Qualifier.QualifierBuilder qb, Part part, String fieldName, FilterOperation op, String dotPath, boolean containingMapKeyValuePairs) { Qualifier[] qualifiers; @@ -298,13 +297,12 @@ private AerospikeCriteria aerospikeCriteriaAndConcatenated(List params, qualifiers = new Qualifier[params.size() / 2]; // keys/values qty must be even for (int i = 0, j = 0; i < params.size(); i += 2) { setQbValuesForMapByKey(qb, params.get(i), params.get(i + 1)); - Qualifier qualifier = setQualifierBuilderValues(qb, fieldName, op, part, params.get(i), + qualifiers[j++] = setQualifierBuilderValues(qb, fieldName, op, part, params.get(i), null, null, dotPath).build(); - qualifiers[j++] = qualifier; } return new AerospikeCriteria( - new QualifierBuilder() + Qualifier.builder() .setQualifiers(qualifiers) .setFilterOperation(FilterOperation.AND) ); @@ -312,20 +310,19 @@ private AerospikeCriteria aerospikeCriteriaAndConcatenated(List params, qualifiers = new Qualifier[params.size()]; for (int i = 0; i < params.size(); i++) { setQbValuesForMapByKey(qb, params.get(i), params.get(i)); - Qualifier qualifier = setQualifierBuilderValues(qb, fieldName, op, part, params.get(i), + qualifiers[i] = setQualifierBuilderValues(qb, fieldName, op, part, params.get(i), null, null, dotPath).build(); - qualifiers[i] = qualifier; } } return new AerospikeCriteria( - new QualifierBuilder() + Qualifier.builder() .setQualifiers(qualifiers) .setFilterOperation(FilterOperation.AND) ); } - private QualifierBuilder setQualifierBuilderValues(QualifierBuilder qb, String fieldName, + private Qualifier.QualifierBuilder setQualifierBuilderValues(Qualifier.QualifierBuilder qb, String fieldName, FilterOperation op, Part part, Object value1, Object value2, Object value3, String dotPath) { qb.setField(fieldName) @@ -354,14 +351,14 @@ private FilterOperation getCorrespondingListFilterOperationOrFail(FilterOperatio } } - private void setNotNullQbValues(QualifierBuilder qb, Object v1, Object v2, Object v3, String dotPath) { + private void setNotNullQbValues(Qualifier.QualifierBuilder qb, Object v1, Object v2, Object v3, String dotPath) { if (v1 != null && !qb.hasValue1()) qb.setValue1(Value.get(v1)); if (v2 != null && !qb.hasValue2()) qb.setValue2(Value.get(v2)); if (v3 != null && !qb.hasValue3()) qb.setValue3(Value.get(v3)); if (dotPath != null && !qb.hasDotPath()) qb.setDotPath(dotPath); } - private void setQbValuesForMapByKey(QualifierBuilder qb, Object key, Object value) { + private void setQbValuesForMapByKey(Qualifier.QualifierBuilder qb, Object key, Object value) { qb.setValue1(Value.get(value)); // contains value qb.setValue2(Value.get(key)); // contains key } @@ -382,7 +379,7 @@ protected AerospikeCriteria and(Part part, AerospikeCriteria base, Iterator reactiveTemplate.count(null, (Class) null).block()) .isInstanceOf(IllegalArgumentException.class); } @Test - public void count_shouldCountAllByPassingEntityClass() { + void count_shouldCountAllByPassingEntityClass() { String id1 = nextId(); reactiveTemplate.insert(new Person(id1, "vasili", 50)).subscribeOn(Schedulers.parallel()).block(); String id2 = nextId(); diff --git a/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java b/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java index a40dc3e8e..5366dce55 100644 --- a/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java +++ b/src/test/java/org/springframework/data/aerospike/logging/LoggingTests.java @@ -11,7 +11,6 @@ import org.springframework.data.aerospike.mapping.AerospikeMappingContext; import org.springframework.data.aerospike.query.FilterOperation; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import org.springframework.data.aerospike.query.StatementBuilder; import org.springframework.data.aerospike.query.cache.IndexesCache; import org.springframework.data.aerospike.repository.query.AerospikeQueryCreator; @@ -38,13 +37,14 @@ public static void setup() { } @Test - public void binIsIndexed() { + void binIsIndexed() { IndexesCache indexesCacheMock = Mockito.mock(IndexesCache.class); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("testField") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get("testValue1")) - ); + .build(); + StatementBuilder statementBuilder = new StatementBuilder(indexesCacheMock); statementBuilder.build("TEST", "testSet", null, new Qualifier[]{qualifier}); @@ -55,13 +55,13 @@ public void binIsIndexed() { } @Test - public void queryIsCreated() { + void queryIsCreated() { AerospikeMappingContext context = new AerospikeMappingContext(); PartTree tree = new PartTree("findByFirstName", Person.class); AerospikeQueryCreator creator = new AerospikeQueryCreator(tree, new StubParameterAccessor("TestName"), context); creator.createQuery(); - assertThat(memoryAppender.countEventsForLogger(LOGGER_NAME)).isGreaterThan(0); + assertThat(memoryAppender.countEventsForLogger(LOGGER_NAME)).isPositive(); String msg = "Created query: firstName EQ TestName"; assertThat(memoryAppender.search(msg, Level.DEBUG).size()).isEqualTo(1); assertThat(memoryAppender.contains(msg, Level.INFO)).isFalse(); diff --git a/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java index 08005b503..07e0595b7 100644 --- a/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/IndexedQualifierTests.java @@ -39,7 +39,7 @@ /* * These tests generate qualifiers on indexed bins. */ -public class IndexedQualifierTests extends BaseQueryEngineTests { +class IndexedQualifierTests extends BaseQueryEngineTests { @AfterEach public void assertNoScans() { @@ -47,14 +47,15 @@ public void assertNoScans() { } @Test - public void selectOnIndexedLTQualifier() { + void selectOnIndexedLTQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age < 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.LT) .setValue1(Value.get(26)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); assertThat(iterator) @@ -66,14 +67,15 @@ public void selectOnIndexedLTQualifier() { } @Test - public void selectOnIndexedLTEQQualifier() { + void selectOnIndexedLTEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.LTEQ) .setValue1(Value.get(26)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(iterator) @@ -88,14 +90,15 @@ public void selectOnIndexedLTEQQualifier() { } @Test - public void selectOnIndexedNumericEQQualifier() { + void selectOnIndexedNumericEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(26)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); assertThat(iterator) @@ -107,14 +110,15 @@ public void selectOnIndexedNumericEQQualifier() { } @Test - public void selectOnIndexWithQualifiers() { + void selectOnIndexWithQualifiers() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { Filter filter = Filter.range("age", 25, 29); - Qualifier qual1 = new Qualifier(new QualifierBuilder() + Qualifier qual1 = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(BLUE)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, filter, qual1); assertThat(it) @@ -126,14 +130,15 @@ public void selectOnIndexWithQualifiers() { } @Test - public void selectOnIndexedGTEQQualifier() { + void selectOnIndexedGTEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.GTEQ) .setValue1(Value.get(28)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(iterator) @@ -148,13 +153,14 @@ public void selectOnIndexedGTEQQualifier() { } @Test - public void selectOnIndexedGTQualifier() { + void selectOnIndexedGTQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.GT) .setValue1(Value.get(28)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); assertThat(iterator) @@ -166,13 +172,14 @@ public void selectOnIndexedGTQualifier() { } @Test - public void selectOnIndexedStringEQQualifier() { + void selectOnIndexedStringEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING, () -> { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(ORANGE)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); assertThat(iterator) @@ -184,7 +191,7 @@ public void selectOnIndexedStringEQQualifier() { } @Test - public void selectWithGeoWithin() { + void selectWithGeoWithin() { if (ServerVersionUtils.isDropCreateBehaviorUpdated(client)) { withIndex(namespace, INDEXED_GEO_SET, "geo_index", GEO_BIN_NAME, IndexType.GEO2DSPHERE, () -> { double lon = -122.0; @@ -194,23 +201,24 @@ public void selectWithGeoWithin() { + "\"coordinates\": [[%.8f, %.8f], %f] }", lon, lat, radius); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(GEO_BIN_NAME) .setFilterOperation(FilterOperation.GEO_WITHIN) .setValue1(Value.getAsGeoJSON(rgnstr)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, INDEXED_GEO_SET, null, qualifier); assertThat(iterator).toIterable() .isNotEmpty() - .allSatisfy(rec -> assertThat(rec.record.generation).isGreaterThanOrEqualTo(1)); + .allSatisfy(rec -> assertThat(rec.record.generation).isPositive()); additionalAerospikeTestOperations.assertNoScansForSet(INDEXED_GEO_SET); }); } } @Test - public void selectOnIndexFilter() { + void selectOnIndexFilter() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { Filter filter = Filter.range("age", 28, 29); KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, filter); @@ -227,7 +235,7 @@ public void selectOnIndexFilter() { } @Test - public void selectOnIndexFilterNonExistingKeys() { + void selectOnIndexFilterNonExistingKeys() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { Filter filter = Filter.range("age", 30, 35); KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, filter); @@ -237,20 +245,20 @@ public void selectOnIndexFilterNonExistingKeys() { } @Test - public void selectWithQualifiersOnly() { - QualifierBuilder qb1 = new QualifierBuilder() + void selectWithQualifiersOnly() { + Qualifier qual1 = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(GREEN)); - QualifierBuilder qb2 = new QualifierBuilder() + .setValue1(Value.get(GREEN)) + .build(); + Qualifier qual2 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(29)); + .setValue2(Value.get(29)) + .build(); withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qual1 = new Qualifier(qb1); - Qualifier qual2 = new Qualifier(qb2); KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, null, qual1, qual2); assertThat(it).toIterable() @@ -261,27 +269,26 @@ public void selectWithQualifiersOnly() { } @Test - public void selectWithAndQualifier() { - QualifierBuilder qb1 = new QualifierBuilder() + void selectWithAndQualifier() { + Qualifier colorIsGreen = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(GREEN)); - QualifierBuilder qb2 = new QualifierBuilder() + .setValue1(Value.get(GREEN)) + .build(); + Qualifier ageBetween28And29 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(29)); + .setValue2(Value.get(29)) + .build(); tryCreateIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC); tryCreateIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING); try { - Qualifier colorIsGreen = new Qualifier(qb1); - Qualifier ageBetween28And29 = new Qualifier(qb2); - - QualifierBuilder qbAnd = new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setFilterOperation(FilterOperation.AND) - .setQualifiers(colorIsGreen, ageBetween28And29); - Qualifier qualifier = new Qualifier(qbAnd); + .setQualifiers(colorIsGreen, ageBetween28And29) + .build(); KeyRecordIterator it = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); diff --git a/src/test/java/org/springframework/data/aerospike/query/QualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/QualifierTests.java index e913a96f1..5afbef7ed 100644 --- a/src/test/java/org/springframework/data/aerospike/query/QualifierTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/QualifierTests.java @@ -42,7 +42,7 @@ * Tests to ensure that Qualifiers are built successfully for non indexed bins. */ @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class QualifierTests extends BaseQueryEngineTests { +class QualifierTests extends BaseQueryEngineTests { /* * These bins should not be indexed. @@ -57,11 +57,11 @@ public void dropIndexes() { void throwsExceptionWhenScansDisabled() { queryEngine.setScansEnabled(false); try { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(LT) - .setValue1(Value.get(26)) - ); + .setValue1(Value.get(26)).build(); + //noinspection resource assertThatThrownBy(() -> queryEngine.select(namespace, SET_NAME, null, qualifier)) .isInstanceOf(IllegalStateException.class) @@ -72,7 +72,7 @@ void throwsExceptionWhenScansDisabled() { } @Test - public void selectOneWitKey() { + void selectOneWitKey() { KeyQualifier kq = new KeyQualifier(Value.get("selector-test:3")); KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, kq); @@ -81,7 +81,7 @@ public void selectOneWitKey() { } @Test - public void selectOneWitKeyNonExisting() { + void selectOneWitKeyNonExisting() { KeyQualifier kq = new KeyQualifier(Value.get("selector-test:unknown")); KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, kq); @@ -90,20 +90,21 @@ public void selectOneWitKeyNonExisting() { } @Test - public void selectAll() { + void selectAll() { KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null); assertThat(iterator).toIterable().hasSize(RECORD_COUNT); } @Test - public void lTQualifier() { + void lTQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age < 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.LT) .setValue1(Value.get(26)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -114,13 +115,14 @@ public void lTQualifier() { } @Test - public void numericLTEQQualifier() { + void numericLTEQQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.LTEQ) .setValue1(Value.get(26)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(it) @@ -134,13 +136,14 @@ public void numericLTEQQualifier() { } @Test - public void numericEQQualifier() { + void numericEQQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(26)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(iterator) @@ -151,13 +154,14 @@ public void numericEQQualifier() { } @Test - public void numericGTEQQualifier() { + void numericGTEQQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.GTEQ) .setValue1(Value.get(28)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(it) @@ -171,13 +175,14 @@ public void numericGTEQQualifier() { } @Test - public void numericGTQualifier() { + void numericGTQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age > 28 or equivalently == 29 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.GT) .setValue1(Value.get(28)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -188,28 +193,30 @@ public void numericGTQualifier() { } @Test - public void metadataSinceUpdateEQQualifier() { - Qualifier qualifier = new Qualifier(new MetadataQualifierBuilder() + void metadataSinceUpdateEQQualifier() { + Qualifier qualifier = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.GT) .setValue1AsObj(1L) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(iterator) .toIterable() .isNotEmpty() - .allSatisfy(item -> assertThat(item.record.getInt("age")).isGreaterThan(0)) + .allSatisfy(item -> assertThat(item.record.getInt("age")).isPositive()) .hasSize(RECORD_COUNT); } @Test - public void stringEQQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void stringEQQualifier() { + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(ORANGE)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -220,14 +227,14 @@ public void stringEQQualifier() { } @Test - public void stringEQIgnoreCaseQualifier() { - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(true) - .setValue1(Value.get(ORANGE.toUpperCase())) - ); + void stringEQIgnoreCaseQualifier() { + Qualifier qualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(true) + .setValue1(Value.get(ORANGE.toUpperCase())) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -238,15 +245,15 @@ public void stringEQIgnoreCaseQualifier() { } @Test - public void stringEqualIgnoreCaseWorksOnUnindexedBin() { + void stringEqualIgnoreCaseWorksOnUnindexedBin() { boolean ignoreCase = true; - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("BlUe")) - ); + Qualifier qualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("BlUe")) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -257,16 +264,16 @@ public void stringEqualIgnoreCaseWorksOnUnindexedBin() { } @Test - public void stringEqualIgnoreCaseWorksOnIndexedBin() { + void stringEqualIgnoreCaseWorksOnIndexedBin() { withIndex(namespace, SET_NAME, "color_index_selector", "color", IndexType.STRING, () -> { boolean ignoreCase = true; - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("BlUe")) - ); + Qualifier qualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("BlUe")) + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(iterator) @@ -281,27 +288,28 @@ public void stringEqualIgnoreCaseWorksOnIndexedBin() { } @Test - public void stringEqualIgnoreCaseWorksRequiresFullMatch() { + void stringEqualIgnoreCaseWorksRequiresFullMatch() { boolean ignoreCase = true; - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("lue")) - ); + Qualifier qualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("lue")) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it).toIterable().isEmpty(); } @Test - public void stringStartWithQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void stringStartWithQualifier() { + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.STARTS_WITH) .setValue1(Value.get(BLUE.substring(0, 2))) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -312,12 +320,13 @@ public void stringStartWithQualifier() { } @Test - public void stringStartWithEntireWordQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void stringStartWithEntireWordQualifier() { + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.STARTS_WITH) .setValue1(Value.get(BLUE)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -328,14 +337,14 @@ public void stringStartWithEntireWordQualifier() { } @Test - public void stringStartWithICASEQualifier() { - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.STARTS_WITH) - .setIgnoreCase(true) - .setValue1(Value.get("BLU")) - ); + void stringStartWithICASEQualifier() { + Qualifier qualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.STARTS_WITH) + .setIgnoreCase(true) + .setValue1(Value.get("BLU")) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -346,12 +355,13 @@ public void stringStartWithICASEQualifier() { } @Test - public void stringEndsWithQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void stringEndsWithQualifier() { + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.ENDS_WITH) .setValue1(Value.get(GREEN.substring(2))) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -362,12 +372,13 @@ public void stringEndsWithQualifier() { } @Test - public void selectEndsWith() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void selectEndsWith() { + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.ENDS_WITH) .setValue1(Value.get("e")) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -378,12 +389,13 @@ public void selectEndsWith() { } @Test - public void stringEndsWithEntireWordQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void stringEndsWithEntireWordQualifier() { + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.ENDS_WITH) .setValue1(Value.get(GREEN)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it) @@ -394,15 +406,15 @@ public void stringEndsWithEntireWordQualifier() { } @Test - public void betweenQualifier() { + void betweenQualifier() { // Ages range from 25 -> 29. Get back age between 26 and 28 inclusive - QualifierBuilder qb = new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(26)) - .setValue2(Value.get(29)); // + 1 as upper limit is exclusive + .setValue2(Value.get(29)) // + 1 as upper limit is exclusive + .build(); - Qualifier qualifier = new Qualifier(qb); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(it) @@ -417,16 +429,17 @@ public void betweenQualifier() { } @Test - public void containingQualifier() { + void containingQualifier() { Map expectedCounts = Arrays.stream(COLOURS) .filter(c -> c.contains("l")) .collect(Collectors.toMap(color -> color, color -> queryEngineTestDataPopulator.colourCounts.get(color))); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.CONTAINING) .setValue1(Value.get("l")) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map colorCount = CollectionUtils.toStream(it) @@ -436,16 +449,17 @@ public void containingQualifier() { } @Test - public void inQualifier() { + void inQualifier() { List inColors = Arrays.asList(COLOURS[0], COLOURS[2]); Map expectedCounts = inColors.stream() .collect(Collectors.toMap(color -> color, color -> queryEngineTestDataPopulator.colourCounts.get(color))); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.IN) .setValue1(Value.get(inColors)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map colorCount = CollectionUtils.toStream(it) @@ -455,15 +469,16 @@ public void inQualifier() { } @Test - public void listContainsQualifier() { + void listContainsQualifier() { String searchColor = COLOURS[0]; String binName = "colorList"; - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(binName) .setFilterOperation(FilterOperation.LIST_VAL_CONTAINING) .setValue1(Value.get(searchColor)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it).toIterable() @@ -478,17 +493,17 @@ public void listContainsQualifier() { } @Test - public void listBetweenQualifier() { + void listBetweenQualifier() { long ageStart = AGES[0]; // 25 long ageEnd = AGES[2]; // 27 String binName = "longList"; - QualifierBuilder qb = new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(binName) .setFilterOperation(FilterOperation.LIST_VAL_BETWEEN) .setValue1(Value.get(ageStart)) - .setValue2(Value.get(ageEnd + 1L)); - Qualifier qualifier = new Qualifier(qb); + .setValue2(Value.get(ageEnd + 1L)) + .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); @@ -507,15 +522,16 @@ public void listBetweenQualifier() { } @Test - public void mapKeysContainsQualifier() { + void mapKeysContainsQualifier() { String searchColor = COLOURS[0]; String binName = "colorAgeMap"; - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(binName) .setFilterOperation(FilterOperation.MAP_KEYS_CONTAIN) .setValue1(Value.get(searchColor)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it).toIterable() @@ -529,15 +545,16 @@ public void mapKeysContainsQualifier() { } @Test - public void mapValuesContainsQualifier() { + void mapValuesContainsQualifier() { String searchColor = COLOURS[0]; String binName = "ageColorMap"; - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(binName) .setFilterOperation(FilterOperation.MAP_VALUES_CONTAIN) .setValue1(Value.get(searchColor)) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it).toIterable() @@ -551,17 +568,18 @@ public void mapValuesContainsQualifier() { } @Test - public void mapKeysBetweenQualifier() { + void mapKeysBetweenQualifier() { long ageStart = AGES[0]; // 25 long ageEnd = AGES[2]; // 27 String binName = "ageColorMap"; - QualifierBuilder qb = new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(binName) .setFilterOperation(FilterOperation.MAP_KEYS_BETWEEN) .setValue1(Value.get(ageStart)) - .setValue2(Value.get(ageEnd + 1L)); - Qualifier qualifier = new Qualifier(qb); + .setValue2(Value.get(ageEnd + 1L)) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(it) @@ -582,17 +600,18 @@ public void mapKeysBetweenQualifier() { } @Test - public void mapValuesBetweenQualifier() { + void mapValuesBetweenQualifier() { long ageStart = AGES[0]; // 25 long ageEnd = AGES[2]; // 27 String binName = "colorAgeMap"; - QualifierBuilder qb = new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(binName) .setFilterOperation(FilterOperation.MAP_VAL_BETWEEN) .setValue1(Value.get(ageStart)) - .setValue2(Value.get(ageEnd + 1L)); - Qualifier qualifier = new Qualifier(qb); + .setValue2(Value.get(ageEnd + 1L)) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); Map ageCount = CollectionUtils.toStream(it) @@ -613,12 +632,13 @@ public void mapValuesBetweenQualifier() { } @Test - public void containingDoesNotUseSpecialCharacterQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void containingDoesNotUseSpecialCharacterQualifier() { + Qualifier qualifier = Qualifier.builder() .setField(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.CONTAINING) .setValue1(Value.get(".*")) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, qualifier); assertThat(it).toIterable() @@ -628,12 +648,13 @@ public void containingDoesNotUseSpecialCharacterQualifier() { } @Test - public void startWithDoesNotUseSpecialCharacterQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void startWithDoesNotUseSpecialCharacterQualifier() { + Qualifier qualifier = Qualifier.builder() .setField(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.STARTS_WITH) .setValue1(Value.get(".*")) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, qualifier); assertThat(it).toIterable() @@ -643,12 +664,13 @@ public void startWithDoesNotUseSpecialCharacterQualifier() { } @Test - public void endWithDoesNotUseSpecialCharacterQualifier() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void endWithDoesNotUseSpecialCharacterQualifier() { + Qualifier qualifier = Qualifier.builder() .setField(SPECIAL_CHAR_BIN) .setFilterOperation(FilterOperation.ENDS_WITH) .setValue1(Value.get(".*")) - ); + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, qualifier); assertThat(it).toIterable() @@ -658,14 +680,14 @@ public void endWithDoesNotUseSpecialCharacterQualifier() { } @Test - public void eQIcaseDoesNotUseSpecialCharacter() { - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField(SPECIAL_CHAR_BIN) - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(true) - .setValue1(Value.get(".*")) - ); + void eQIcaseDoesNotUseSpecialCharacter() { + Qualifier qualifier = Qualifier.builder() + .setField(SPECIAL_CHAR_BIN) + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(true) + .setValue1(Value.get(".*")) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, qualifier); assertThat(it).toIterable().isEmpty(); @@ -673,14 +695,14 @@ public void eQIcaseDoesNotUseSpecialCharacter() { @ParameterizedTest @ValueSource(strings = {"[", "$", "\\", "^"}) - public void containingFindsSquareBracket(String specialString) { - Qualifier qualifier = new Qualifier( - new QualifierBuilder() - .setField(SPECIAL_CHAR_BIN) - .setFilterOperation(FilterOperation.CONTAINING) - .setIgnoreCase(true) - .setValue1(Value.get(specialString)) - ); + void containingFindsSquareBracket(String specialString) { + Qualifier qualifier = Qualifier.builder() + .setField(SPECIAL_CHAR_BIN) + .setFilterOperation(FilterOperation.CONTAINING) + .setIgnoreCase(true) + .setValue1(Value.get(specialString)) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, qualifier); assertThat(it).toIterable() @@ -690,18 +712,19 @@ public void containingFindsSquareBracket(String specialString) { } @Test - public void selectWithGeoWithin() { + void selectWithGeoWithin() { double lon = -122.0; double lat = 37.5; double radius = 50000.0; String rgnstr = String.format("{ \"type\": \"AeroCircle\", " + "\"coordinates\": [[%.8f, %.8f], %f] }", lon, lat, radius); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(GEO_BIN_NAME) .setFilterOperation(FilterOperation.GEO_WITHIN) .setValue1(Value.getAsGeoJSON(rgnstr)) - ); + .build(); + KeyRecordIterator iterator = queryEngine.select(namespace, GEO_SET, null, qualifier); assertThat(iterator).toIterable() @@ -710,22 +733,21 @@ public void selectWithGeoWithin() { } @Test - public void startWithAndEqualIgnoreCaseReturnsAllItems() { + void startWithAndEqualIgnoreCaseReturnsAllItems() { boolean ignoreCase = true; - Qualifier qual1 = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get(BLUE.toUpperCase())) - ); - Qualifier qual2 = new Qualifier( - new QualifierBuilder() - .setField("name") - .setFilterOperation(FilterOperation.STARTS_WITH) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("NA")) - ); + Qualifier qual1 = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get(BLUE.toUpperCase())) + .build(); + + Qualifier qual2 = Qualifier.builder() + .setField("name") + .setFilterOperation(FilterOperation.STARTS_WITH) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("NA")) + .build(); KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qual1, qual2); @@ -736,72 +758,73 @@ public void startWithAndEqualIgnoreCaseReturnsAllItems() { } @Test - public void equalIgnoreCaseReturnsNoItemsIfNoneMatched() { + void equalIgnoreCaseReturnsNoItemsIfNoneMatched() { boolean ignoreCase = false; - Qualifier qual1 = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get(BLUE.toUpperCase())) - ); + Qualifier qual1 = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get(BLUE.toUpperCase())) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qual1); assertThat(it).toIterable().isEmpty(); } @Test - public void startWithIgnoreCaseReturnsNoItemsIfNoneMatched() { + void startWithIgnoreCaseReturnsNoItemsIfNoneMatched() { boolean ignoreCase = false; - Qualifier qual1 = new Qualifier( - new QualifierBuilder() - .setField("name") - .setFilterOperation(FilterOperation.STARTS_WITH) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("NA")) - ); + Qualifier qual1 = Qualifier.builder() + .setField("name") + .setFilterOperation(FilterOperation.STARTS_WITH) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("NA")) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qual1); assertThat(it).toIterable().isEmpty(); } @Test - public void selectWithBetweenAndOrQualifiers() { - QualifierBuilder qbColorIsGreen = new QualifierBuilder() + void selectWithBetweenAndOrQualifiers() { + Qualifier colorIsGreen = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(GREEN)); - QualifierBuilder qbAgeBetween28And29 = new QualifierBuilder() + .setValue1(Value.get(GREEN)) + .build(); + Qualifier ageBetween28And29 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(29)); - QualifierBuilder qbAgeIs25 = new QualifierBuilder() + .setValue2(Value.get(29)) + .build(); + Qualifier ageIs25 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(25)); - QualifierBuilder qbNameIs696 = new QualifierBuilder() + .setValue1(Value.get(25)) + .build(); + Qualifier nameIs696 = Qualifier.builder() .setField("name") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get("name:696")); - Qualifier colorIsGreen = new Qualifier(qbColorIsGreen); - Qualifier ageBetween28And29 = new Qualifier(qbAgeBetween28And29); - Qualifier ageIs25 = new Qualifier(qbAgeIs25); - Qualifier nameIs696 = new Qualifier(qbNameIs696); + .setValue1(Value.get("name:696")) + .build(); - QualifierBuilder qbOr = new QualifierBuilder() + Qualifier or = Qualifier.builder() .setFilterOperation(FilterOperation.OR) - .setQualifiers(ageIs25, ageBetween28And29, nameIs696); - QualifierBuilder qbOr2 = new QualifierBuilder() + .setQualifiers(ageIs25, ageBetween28And29, nameIs696) + .build(); + Qualifier or2 = Qualifier.builder() .setFilterOperation(FilterOperation.OR) - .setQualifiers(colorIsGreen, nameIs696); - Qualifier or = new Qualifier(qbOr); - Qualifier or2 = new Qualifier(qbOr2); + .setQualifiers(colorIsGreen, nameIs696) + .build(); - QualifierBuilder qbAnd = new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setFilterOperation(FilterOperation.AND) - .setQualifiers(or, or2); - Qualifier qualifier = new Qualifier(qbAnd); + .setQualifiers(or, or2) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, qualifier); assertThat(it).toIterable().isNotEmpty() @@ -823,24 +846,25 @@ public void selectWithBetweenAndOrQualifiers() { } @Test - public void selectWithOrQualifiers() { + void selectWithOrQualifiers() { // We are expecting to get back all records where color == blue or (age == 28 || age == 29) - QualifierBuilder qbColorIsBlue = new QualifierBuilder() + Qualifier colorIsBlue = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(BLUE)); - QualifierBuilder qbAgeBetween28And29 = new QualifierBuilder() + .setValue1(Value.get(BLUE)) + .build(); + Qualifier ageBetween28And29 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(30)); // + 1 as upper limit is exclusive - Qualifier colorIsBlue = new Qualifier(qbColorIsBlue); - Qualifier ageBetween28And29 = new Qualifier(qbAgeBetween28And29); + .setValue2(Value.get(30)) // + 1 as upper limit is exclusive + .build(); - QualifierBuilder qbOr = new QualifierBuilder() + Qualifier or = Qualifier.builder() .setFilterOperation(FilterOperation.OR) - .setQualifiers(colorIsBlue, ageBetween28And29); - Qualifier or = new Qualifier(qbOr); + .setQualifiers(colorIsBlue, ageBetween28And29) + .build(); + KeyRecordIterator it = queryEngine.select(namespace, SET_NAME, null, or); List result = CollectionUtils.toStream(it).collect(Collectors.toList()); diff --git a/src/test/java/org/springframework/data/aerospike/query/UsersTests.java b/src/test/java/org/springframework/data/aerospike/query/UsersTests.java index 9860f5a4d..a358c5a55 100644 --- a/src/test/java/org/springframework/data/aerospike/query/UsersTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/UsersTests.java @@ -7,17 +7,17 @@ import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.RECORD_COUNT; import static org.springframework.data.aerospike.query.QueryEngineTestDataPopulator.USERS_SET; -public class UsersTests extends BaseQueryEngineTests { +class UsersTests extends BaseQueryEngineTests { @Test - public void allUsers() { + void allUsers() { KeyRecordIterator it = queryEngine.select(namespace, USERS_SET, null); assertThat(it).toIterable().hasSize(RECORD_COUNT); } @Test - public void usersInterrupted() { + void usersInterrupted() { try (KeyRecordIterator it = queryEngine.select(namespace, USERS_SET, null)) { int counter = 0; while (it.hasNext()) { @@ -30,12 +30,12 @@ public void usersInterrupted() { } @Test - public void usersInNorthRegion() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + void usersInNorthRegion() { + Qualifier qualifier = Qualifier.builder() .setField("region") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get("n")) - ); + .build(); KeyRecordIterator it = queryEngine.select(namespace, USERS_SET, null, qualifier); diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedPersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedPersonRepositoryQueryTests.java index abe571a73..d3e8421ce 100644 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedPersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedPersonRepositoryQueryTests.java @@ -11,9 +11,7 @@ import org.springframework.data.aerospike.BaseReactiveIntegrationTests; import org.springframework.data.aerospike.ReactiveBlockingAerospikeTestOperations; import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.MetadataQualifierBuilder; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import org.springframework.data.aerospike.repository.query.CriteriaDefinition; import org.springframework.data.aerospike.sample.Address; import org.springframework.data.aerospike.sample.IndexedPerson; @@ -33,8 +31,6 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class ReactiveIndexedPersonRepositoryQueryTests extends BaseReactiveIntegrationTests { - @Autowired - ReactiveIndexedPersonRepository reactiveRepository; static final IndexedPerson alain = IndexedPerson.builder().id(nextId()).firstName("Alain").lastName("Sebastian") .age(42).strings(Arrays.asList("str1", "str2")) .address(new Address("Foo Street 1", 1, "C0123", "Bar")).build(); @@ -55,6 +51,8 @@ public class ReactiveIndexedPersonRepositoryQueryTests extends BaseReactiveInteg public static final List allIndexedPersons = Arrays.asList(alain, luc, lilly, daniel, petra, emilien); @Autowired + ReactiveIndexedPersonRepository reactiveRepository; + @Autowired ReactiveBlockingAerospikeTestOperations reactiveBlockingAerospikeTestOperations; @BeforeAll @@ -246,9 +244,9 @@ public void findPersonsByAddressZipCode() { @Test public void findByMapKeyValueContainingInt() { assertThat(emilien.getIntMap().containsKey("key1")).isTrue(); - assertThat(emilien.getIntMap().get("key1") == 0).isTrue(); + assertThat(emilien.getIntMap().get("key1")).isZero(); assertThat(lilly.getIntMap().containsKey("key1")).isTrue(); - assertThat(lilly.getIntMap().get("key1") == 0).isFalse(); + assertThat(lilly.getIntMap().get("key1")).isNotZero(); List results = reactiveRepository.findByIntMapContaining("key1", 0) .subscribeOn(Schedulers.parallel()).collectList().block(); @@ -259,9 +257,9 @@ public void findByMapKeyValueContainingInt() { @Test public void findByMapKeyValueGreaterThan() { assertThat(emilien.getIntMap().containsKey("key2")).isTrue(); - assertThat(emilien.getIntMap().get("key2") > 0).isTrue(); + assertThat(emilien.getIntMap().get("key2")).isPositive(); assertThat(lilly.getIntMap().containsKey("key2")).isTrue(); - assertThat(lilly.getIntMap().get("key2") > 0).isTrue(); + assertThat(lilly.getIntMap().get("key2")).isPositive(); List results = reactiveRepository.findByIntMapGreaterThan("key2", 0) .subscribeOn(Schedulers.parallel()).collectList().block(); @@ -272,9 +270,9 @@ public void findByMapKeyValueGreaterThan() { @Test public void findByMapKeyValueLessThanOrEqual() { assertThat(emilien.getIntMap().containsKey("key2")).isTrue(); - assertThat(emilien.getIntMap().get("key2") <= 1).isTrue(); + assertThat(emilien.getIntMap().get("key2")).isLessThanOrEqualTo(1); assertThat(lilly.getIntMap().containsKey("key2")).isTrue(); - assertThat(lilly.getIntMap().get("key2") <= 1).isFalse(); + assertThat(lilly.getIntMap().get("key2")).isGreaterThan(1); List results = reactiveRepository.findByIntMapLessThanEqual("key2", 1) .subscribeOn(Schedulers.parallel()).collectList().block(); @@ -285,8 +283,8 @@ public void findByMapKeyValueLessThanOrEqual() { public void findByMapKeyValueBetween() { assertThat(lilly.getIntMap().containsKey("key2")).isTrue(); assertThat(emilien.getIntMap().containsKey("key2")).isTrue(); - assertThat(lilly.getIntMap().get("key2") >= 0).isTrue(); - assertThat(emilien.getIntMap().get("key2") >= 0).isTrue(); + assertThat(lilly.getIntMap().get("key2")).isNotNegative(); + assertThat(emilien.getIntMap().get("key2")).isNotNegative(); List results = reactiveRepository.findByIntMapBetween("key2", 0, 1) .subscribeOn(Schedulers.parallel()).collectList().block(); @@ -297,7 +295,7 @@ public void findByMapKeyValueBetween() { @Test public void findPersonsByMetadata() { // creating a condition "since_update_time metadata value is less than 50 seconds" - Qualifier sinceUpdateTimeLt10Seconds = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeLt10Seconds = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LT) .setValue1AsObj(50000L) @@ -306,7 +304,7 @@ public void findPersonsByMetadata() { .containsAll(allIndexedPersons); // creating a condition "since_update_time metadata value is between 1 millisecond and 50 seconds" - Qualifier sinceUpdateTimeBetween1And50000 = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeBetween1And50000 = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.BETWEEN) .setValue1AsObj(1L) @@ -321,14 +319,14 @@ public void findPersonsByQualifiers() { Iterable result; // creating a condition "since_update_time metadata value is greater than 1 millisecond" - Qualifier sinceUpdateTimeGt1 = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeGt1 = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.GT) .setValue1AsObj(1L) .build(); // creating a condition "since_update_time metadata value is less than 50 seconds" - Qualifier sinceUpdateTimeLt50Seconds = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeLt50Seconds = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LT) .setValue1AsObj(50000L) @@ -337,7 +335,7 @@ public void findPersonsByQualifiers() { .containsAll(allIndexedPersons); // creating a condition "since_update_time metadata value is between 1 and 50 seconds" - Qualifier sinceUpdateTimeBetween1And50000 = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeBetween1And50000 = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.BETWEEN) .setValue1AsObj(1L) @@ -345,14 +343,14 @@ public void findPersonsByQualifiers() { .build(); // creating a condition "firsName is equal to Petra" - Qualifier firstNameEqPetra = new QualifierBuilder() + Qualifier firstNameEqPetra = Qualifier.builder() .setField("firstName") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get("Petra")) .build(); // creating a condition "age is equal to 34" - Qualifier ageEq34 = new QualifierBuilder() + Qualifier ageEq34 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(34)) @@ -361,7 +359,7 @@ public void findPersonsByQualifiers() { assertThat(result).containsOnly(petra); // creating a condition "age is greater than 34" - Qualifier ageGt34 = new QualifierBuilder() + Qualifier ageGt34 = Qualifier.builder() .setFilterOperation(FilterOperation.GT) .setField("age") .setValue1(Value.get(34)) @@ -377,7 +375,7 @@ public void findPersonsByQualifiers() { // conditions "age == 34", "firstName is Petra" and "since_update_time metadata value is less than 50 seconds" // are combined with OR - Qualifier orWide = new QualifierBuilder() + Qualifier orWide = Qualifier.builder() .setFilterOperation(FilterOperation.OR) .setQualifiers(ageEq34, firstNameEqPetra, sinceUpdateTimeLt50Seconds) .build(); @@ -385,14 +383,14 @@ public void findPersonsByQualifiers() { assertThat(result).containsAll(allIndexedPersons); // conditions "age == 34" and "firstName is Petra" are combined with OR - Qualifier orNarrow = new QualifierBuilder() + Qualifier orNarrow = Qualifier.builder() .setFilterOperation(FilterOperation.OR) .setQualifiers(ageEq34, firstNameEqPetra) .build(); result = reactiveRepository.findByQualifiers(orNarrow).collectList().block(); assertThat(result).containsOnly(petra); - result = reactiveRepository.findByQualifiers(new QualifierBuilder() + result = reactiveRepository.findByQualifiers(Qualifier.builder() .setFilterOperation(FilterOperation.AND) .setQualifiers(ageEq34, ageGt34) .build()).collectList().block(); @@ -404,7 +402,7 @@ public void findPersonsByQualifiers() { assertThat(result).isEmpty(); // conditions "age == 34" and "age > 34" are combined with OR - Qualifier ageEqOrGt34 = new QualifierBuilder() + Qualifier ageEqOrGt34 = Qualifier.builder() .setFilterOperation(FilterOperation.OR) .setQualifiers(ageEq34, ageGt34) .build(); @@ -420,7 +418,7 @@ public void findPersonsByQualifiers() { // a condition that returns all entities and a condition that returns one entity are combined using AND // another way of running the same query - Qualifier orCombinedWithAnd = new QualifierBuilder() + Qualifier orCombinedWithAnd = Qualifier.builder() .setFilterOperation(FilterOperation.AND) .setQualifiers(orWide, orNarrow) .build(); diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java index e5a082f73..28b9f6ca1 100644 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveIndexedQualifierTests.java @@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.query.FilterOperation; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -61,11 +60,12 @@ public void assertNoScans() { public void selectOnIndexedLTQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age < 26 withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(LT) .setValue1(Value.get(26)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) @@ -92,11 +92,12 @@ public void selectOnIndexedLTQualifier() { public void selectOnIndexedLTEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(LTEQ) .setValue1(Value.get(26)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) @@ -126,11 +127,12 @@ public void selectOnIndexedNumericEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(EQ) .setValue1(Value.get(26)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -149,11 +151,12 @@ public void selectOnIndexedGTEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(GTEQ) .setValue1(Value.get(28)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) @@ -183,11 +186,12 @@ public void selectOnIndexedGTQualifier() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { // Ages range from 25 -> 29. We expected to only get back values with age > 28 or equivalently == 29 - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(GT) .setValue1(Value.get(28)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) @@ -205,11 +209,12 @@ public void selectOnIndexedGTQualifier() { @Test public void selectOnIndexedStringEQQualifier() { withIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING, () -> { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(EQ) .setValue1(Value.get(ORANGE)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) @@ -260,11 +265,12 @@ void selectOnIndexFilterNonExistingKeys() { public void selectOnIndexWithQualifiers() { withIndex(namespace, INDEXED_SET_NAME, "age_index", "age", IndexType.NUMERIC, () -> { Filter filter = Filter.range("age", 25, 29); - Qualifier qual1 = new Qualifier(new QualifierBuilder() + Qualifier qual1 = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(BLUE)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, filter, qual1); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -283,17 +289,18 @@ public void selectOnIndexWithQualifiers() { @Test public void selectWithQualifiersOnly() { withIndex(namespace, INDEXED_SET_NAME, "color_index", "color", IndexType.STRING, () -> { - QualifierBuilder qb1 = new QualifierBuilder() + Qualifier qual1 = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(GREEN)); - QualifierBuilder qb2 = new QualifierBuilder() + .setValue1(Value.get(GREEN)) + .build(); + Qualifier qual2 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(29)); - Qualifier qual1 = new Qualifier(qb1); - Qualifier qual2 = new Qualifier(qb2); + .setValue2(Value.get(29)) + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_SET_NAME, null, qual1, qual2); StepVerifier.create(flux.collectList()) @@ -318,11 +325,12 @@ public void selectWithGeoWithin() { String rgnstr = String.format("{ \"type\": \"AeroCircle\", " + "\"coordinates\": [[%.8f, %.8f], %f] }", lon, lat, radius); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField(GEO_BIN_NAME) .setFilterOperation(GEO_WITHIN) .setValue1(Value.getAsGeoJSON(rgnstr)) - ); + .build(); + Flux flux = queryEngine.select(namespace, INDEXED_GEO_SET, null, qualifier); StepVerifier.create(flux.collectList()) diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java index e73b9bbe4..6be4004b2 100644 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveQualifierTests.java @@ -24,7 +24,6 @@ import org.junit.jupiter.api.TestInstance; import org.springframework.data.aerospike.query.FilterOperation; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -68,11 +67,12 @@ public void dropIndexes() { void throwsExceptionWhenScansDisabled() { queryEngine.setScansEnabled(false); try { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("age") .setFilterOperation(LT) .setValue1(Value.get(26)) - ); + .build(); + StepVerifier.create(queryEngine.select(namespace, SET_NAME, null, qualifier)) .expectErrorSatisfies(e -> assertThat(e) .isInstanceOf(IllegalStateException.class) @@ -86,11 +86,12 @@ void throwsExceptionWhenScansDisabled() { @Test public void lTQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age < 26 - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("age") .setFilterOperation(LT) .setValue1(Value.get(26)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -109,11 +110,12 @@ public void lTQualifier() { @Test public void numericLTEQQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age <= 26 - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("age") .setFilterOperation(LTEQ) .setValue1(Value.get(26)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -139,11 +141,12 @@ public void numericLTEQQualifier() { @Test public void numericEQQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age == 26 - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("age") .setFilterOperation(EQ) .setValue1(Value.get(26)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) @@ -159,11 +162,12 @@ public void numericEQQualifier() { @Test public void numericGTEQQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age >= 28 - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("age") .setFilterOperation(GTEQ) .setValue1(Value.get(28)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -189,11 +193,12 @@ public void numericGTEQQualifier() { @Test public void numericGTQualifier() { // Ages range from 25 -> 29. We expected to only get back values with age > 28 or equivalently == 29 - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("age") .setFilterOperation(GT) .setValue1(Value.get(28)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -207,11 +212,12 @@ public void numericGTQualifier() { @Test public void stringEQQualifier() { - Qualifier stringEqQualifier = new Qualifier(new QualifierBuilder() + Qualifier stringEqQualifier = Qualifier.builder() .setField("color") .setFilterOperation(EQ) .setValue1(Value.get(ORANGE)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -225,13 +231,13 @@ public void stringEQQualifier() { @Test public void stringEQQualifierCaseSensitive() { - Qualifier stringEqQualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(EQ) - .setIgnoreCase(true) - .setValue1(Value.get(ORANGE.toUpperCase())) - ); + Qualifier stringEqQualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(EQ) + .setIgnoreCase(true) + .setValue1(Value.get(ORANGE.toUpperCase())) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -247,11 +253,12 @@ public void stringEQQualifierCaseSensitive() { public void stringStartWithQualifier() { String bluePrefix = "blu"; - Qualifier stringEqQualifier = new Qualifier(new QualifierBuilder() + Qualifier stringEqQualifier = Qualifier.builder() .setField("color") .setFilterOperation(STARTS_WITH) .setValue1(Value.get("blu")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -265,11 +272,12 @@ public void stringStartWithQualifier() { @Test public void stringStartWithEntireWordQualifier() { - Qualifier stringEqQualifier = new Qualifier(new QualifierBuilder() + Qualifier stringEqQualifier = Qualifier.builder() .setField("color") .setFilterOperation(STARTS_WITH) .setValue1(Value.get(BLUE)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -285,13 +293,13 @@ public void stringStartWithEntireWordQualifier() { public void stringStartWithICASEQualifier() { String blue = "blu"; - Qualifier stringEqQualifier = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(STARTS_WITH) - .setIgnoreCase(true) - .setValue1(Value.get("BLU")) - ); + Qualifier stringEqQualifier = Qualifier.builder() + .setField("color") + .setFilterOperation(STARTS_WITH) + .setIgnoreCase(true) + .setValue1(Value.get("BLU")) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -307,11 +315,12 @@ public void stringStartWithICASEQualifier() { public void stringEndsWithQualifier() { String greenEnding = GREEN.substring(2); - Qualifier stringEqQualifier = new Qualifier(new QualifierBuilder() + Qualifier stringEqQualifier = Qualifier.builder() .setField("color") .setFilterOperation(ENDS_WITH) .setValue1(Value.get(greenEnding)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -325,11 +334,12 @@ public void stringEndsWithQualifier() { @Test public void stringEndsWithEntireWordQualifier() { - Qualifier stringEqQualifier = new Qualifier(new QualifierBuilder() + Qualifier stringEqQualifier = Qualifier.builder() .setField("color") .setFilterOperation(ENDS_WITH) .setValue1(Value.get(GREEN)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, stringEqQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -344,12 +354,13 @@ public void stringEndsWithEntireWordQualifier() { @Test public void betweenQualifier() { // Ages range from 25 -> 29. Get back age between 26 and 28 inclusive - QualifierBuilder qb = new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("age") .setFilterOperation(BETWEEN) .setValue1(Value.get(26)) - .setValue2(Value.get(29)); // + 1 as upper limit is exclusive - Qualifier AgeRangeQualifier = new Qualifier(qb); + .setValue2(Value.get(29)) // + 1 as upper limit is exclusive + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -381,11 +392,12 @@ public void containingQualifier() { .filter(c -> c.contains("l")) .collect(Collectors.toMap(c -> c, color -> queryEngineTestDataPopulator.colourCounts.get(color))); - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField("color") .setFilterOperation(CONTAINING) .setValue1(Value.get("l")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -404,11 +416,12 @@ public void inQualifier() { Map expectedColorCounts = inColours.stream() .collect(Collectors.toMap(c -> c, color -> queryEngineTestDataPopulator.colourCounts.get(color))); - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("color") .setFilterOperation(IN) .setValue1(Value.get(inColours)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, qualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -427,11 +440,12 @@ public void listContainsQualifier() { String binName = "colorList"; - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(binName) .setFilterOperation(LIST_VAL_CONTAINING) .setValue1(Value.get(searchColor)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -457,12 +471,13 @@ public void listBetweenQualifier() { String binName = "longList"; - QualifierBuilder qb = new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(binName) .setFilterOperation(LIST_VAL_BETWEEN) .setValue1(Value.get(ageStart)) - .setValue2(Value.get(ageEnd)); - Qualifier AgeRangeQualifier = new Qualifier(qb); + .setValue2(Value.get(ageEnd)) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -494,11 +509,12 @@ public void mapKeysContainsQualifier() { String binName = "colorAgeMap"; - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(binName) .setFilterOperation(MAP_KEYS_CONTAIN) .setValue1(Value.get(searchColor)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -522,11 +538,12 @@ public void testMapValuesContainsQualifier() { String binName = "ageColorMap"; - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(binName) .setFilterOperation(MAP_VALUES_CONTAIN) .setValue1(Value.get(searchColor)) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -551,13 +568,14 @@ public void testMapKeysBetweenQualifier() { String binName = "ageColorMap"; - QualifierBuilder qb = new QualifierBuilder() + Qualifier ageRangeQualifier = Qualifier.builder() .setField(binName) .setFilterOperation(MAP_KEYS_BETWEEN) .setValue1(Value.get(ageStart)) - .setValue2(Value.get(ageEnd)); - Qualifier AgeRangeQualifier = new Qualifier(qb); - Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); + .setValue2(Value.get(ageEnd)) + .build(); + + Flux flux = queryEngine.select(namespace, SET_NAME, null, ageRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { AtomicInteger age25Count = new AtomicInteger(); @@ -596,13 +614,14 @@ public void testMapValuesBetweenQualifier() { String binName = "colorAgeMap"; - QualifierBuilder qb = new QualifierBuilder() + Qualifier ageRangeQualifier = Qualifier.builder() .setField(binName) .setFilterOperation(MAP_VAL_BETWEEN) .setValue1(Value.get(ageStart)) - .setValue2(Value.get(ageEnd)); - Qualifier AgeRangeQualifier = new Qualifier(qb); - Flux flux = queryEngine.select(namespace, SET_NAME, null, AgeRangeQualifier); + .setValue2(Value.get(ageEnd)) + .build(); + + Flux flux = queryEngine.select(namespace, SET_NAME, null, ageRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { AtomicInteger age25Count = new AtomicInteger(); @@ -636,11 +655,12 @@ public void testMapValuesBetweenQualifier() { @Test public void testContainingDoesNotUseSpecialCharacterQualifier() { - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(SPECIAL_CHAR_BIN) .setFilterOperation(CONTAINING) .setValue1(Value.get(".*")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -654,11 +674,12 @@ public void testContainingDoesNotUseSpecialCharacterQualifier() { @Test public void testStartWithDoesNotUseSpecialCharacterQualifier() { - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(SPECIAL_CHAR_BIN) .setFilterOperation(STARTS_WITH) .setValue1(Value.get(".*")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -675,11 +696,12 @@ public void testStartWithDoesNotUseSpecialCharacterQualifier() { @Test public void testEndWithDoesNotUseSpecialCharacterQualifier() { - Qualifier AgeRangeQualifier = new Qualifier(new QualifierBuilder() + Qualifier AgeRangeQualifier = Qualifier.builder() .setField(SPECIAL_CHAR_BIN) .setFilterOperation(ENDS_WITH) .setValue1(Value.get(".*")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, AgeRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -696,13 +718,13 @@ public void testEndWithDoesNotUseSpecialCharacterQualifier() { @Test public void testEQIcaseDoesNotUseSpecialCharacter() { - Qualifier AgeRangeQualifier = new Qualifier( - new QualifierBuilder() - .setField(SPECIAL_CHAR_BIN) - .setFilterOperation(EQ) - .setIgnoreCase(true) - .setValue1(Value.get(".*")) - ); + Qualifier AgeRangeQualifier = Qualifier.builder() + .setField(SPECIAL_CHAR_BIN) + .setFilterOperation(EQ) + .setIgnoreCase(true) + .setValue1(Value.get(".*")) + .build(); + Flux flux = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, AgeRangeQualifier); StepVerifier.create(flux) .verifyComplete(); @@ -712,14 +734,14 @@ public void testEQIcaseDoesNotUseSpecialCharacter() { public void testContainingFindsSquareBracket() { String[] specialStrings = new String[]{"[", "$", "\\", "^"}; for (String specialString : specialStrings) { - Qualifier AgeRangeQualifier = new Qualifier( - new QualifierBuilder() - .setField(SPECIAL_CHAR_BIN) - .setFilterOperation(CONTAINING) - .setIgnoreCase(true) - .setValue1(Value.get(specialString)) - ); - Flux flux = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, AgeRangeQualifier); + Qualifier ageRangeQualifier = Qualifier.builder() + .setField(SPECIAL_CHAR_BIN) + .setFilterOperation(CONTAINING) + .setIgnoreCase(true) + .setValue1(Value.get(specialString)) + .build(); + + Flux flux = queryEngine.select(namespace, SPECIAL_CHAR_SET, null, ageRangeQualifier); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { assertThat(results) @@ -741,13 +763,13 @@ public void stringEqualIgnoreCaseWorksOnIndexedBin() { boolean ignoreCase = true; String expectedColor = "blue"; - Qualifier caseInsensitiveQual = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(FilterOperation.EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("BlUe")) - ); + Qualifier caseInsensitiveQual = Qualifier.builder() + .setField("color") + .setFilterOperation(FilterOperation.EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("BlUe")) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, caseInsensitiveQual); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -767,22 +789,23 @@ public void selectWithOrQualifiers() { String expectedColor = BLUE; // We are expecting to get back all records where color == blue or (age == 28 || age == 29) - QualifierBuilder qb1 = new QualifierBuilder() + Qualifier qual1 = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(expectedColor)); - QualifierBuilder qb2 = new QualifierBuilder() + .setValue1(Value.get(expectedColor)) + .build(); + Qualifier qual2 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(30)); // + 1 as upper limit is exclusive - Qualifier qual1 = new Qualifier(qb1); - Qualifier qual2 = new Qualifier(qb2); + .setValue2(Value.get(30)) // + 1 as upper limit is exclusive + .build(); - QualifierBuilder qbOr = new QualifierBuilder() + Qualifier or = Qualifier.builder() .setFilterOperation(FilterOperation.OR) - .setQualifiers(qual1, qual2); - Qualifier or = new Qualifier(qbOr); + .setQualifiers(qual1, qual2) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, or); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -802,7 +825,8 @@ public void selectWithOrQualifiers() { }); assertThat(colorMatched.get()).isEqualTo(queryEngineTestDataPopulator.colourCounts.get(expectedColor)); - assertThat(ageMatched.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(28) + queryEngineTestDataPopulator.ageCount.get(29)); + assertThat(ageMatched.get()).isEqualTo(queryEngineTestDataPopulator.ageCount.get(28) + + queryEngineTestDataPopulator.ageCount.get(29)); return true; }) @@ -811,56 +835,53 @@ public void selectWithOrQualifiers() { @Test public void selectWithBetweenAndOrQualifiers() { - QualifierBuilder qbColorIsGreen = new QualifierBuilder() + Qualifier qualColorIsGreen = Qualifier.builder() .setField("color") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get("green")); - QualifierBuilder qbAgeBetween28And29 = new QualifierBuilder() + .setValue1(Value.get("green")) + .build(); + Qualifier qualAgeBetween28And29 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.BETWEEN) .setValue1(Value.get(28)) - .setValue2(Value.get(30)); // + 1 as upper limit is exclusive - QualifierBuilder qbAgeIs25 = new QualifierBuilder() + .setValue2(Value.get(30)) // + 1 as upper limit is exclusive + .build(); + Qualifier qualAgeIs25 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get(25)); - QualifierBuilder qbNameIs696 = new QualifierBuilder() + .setValue1(Value.get(25)) + .build(); + Qualifier qualNameIs696 = Qualifier.builder() .setField("name") .setFilterOperation(FilterOperation.EQ) - .setValue1(Value.get("name:696")); - Qualifier qualColorIsGreen = new Qualifier(qbColorIsGreen); - Qualifier qualAgeBetween28And29 = new Qualifier(qbAgeBetween28And29); - Qualifier qualAgeIs25 = new Qualifier(qbAgeIs25); - Qualifier qualNameIs696 = new Qualifier(qbNameIs696); + .setValue1(Value.get("name:696")) + .build(); - QualifierBuilder qbOr = new QualifierBuilder() + Qualifier or = Qualifier.builder() .setFilterOperation(FilterOperation.OR) - .setQualifiers(qualAgeIs25, qualAgeBetween28And29, qualNameIs696); - QualifierBuilder qbOr2 = new QualifierBuilder() + .setQualifiers(qualAgeIs25, qualAgeBetween28And29, qualNameIs696) + .build(); + Qualifier or2 = Qualifier.builder() .setFilterOperation(FilterOperation.OR) - .setQualifiers(qualColorIsGreen, qualNameIs696); - Qualifier or = new Qualifier(qbOr); - Qualifier or2 = new Qualifier(qbOr2); + .setQualifiers(qualColorIsGreen, qualNameIs696) + .build(); - QualifierBuilder qbAnd = new QualifierBuilder() + Qualifier and = Qualifier.builder() .setFilterOperation(FilterOperation.AND) - .setQualifiers(or, or2); - Qualifier and = new Qualifier(qbAnd); + .setQualifiers(or, or2) + .build(); Flux flux = queryEngine.select(namespace, SET_NAME, null, and); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { AtomicBoolean has25 = new AtomicBoolean(false); results.forEach(keyRecord -> { - int age = keyRecord.record.getInt("age"); if (age == 25) has25.set(true); - else assertTrue("green".equals(keyRecord.record.getString("color")) && age >= 28 && age <= 29); - + else assertTrue("green".equals(keyRecord.record.getString("color")) + && age >= 28 && age <= 29); }); - assertTrue(has25.get()); - return true; }) .verifyComplete(); diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java index dfbc8d7a1..21b14608d 100644 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveSelectorTests.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.query.KeyQualifier; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -54,11 +53,12 @@ public void selectAll() { @Test public void selectEndssWith() { - Qualifier qual1 = new Qualifier(new QualifierBuilder() + Qualifier qual1 = Qualifier.builder() .setField("color") .setFilterOperation(ENDS_WITH) .setValue1(Value.get("e")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, qual1); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -72,11 +72,12 @@ public void selectEndssWith() { @Test public void selectStartsWith() { - Qualifier startsWithQual = new Qualifier(new QualifierBuilder() + Qualifier startsWithQual = Qualifier.builder() .setField("color") .setFilterOperation(STARTS_WITH) .setValue1(Value.get("bl")) - ); + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, startsWithQual); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -91,20 +92,19 @@ public void selectStartsWith() { @Test public void startWithAndEqualIgnoreCaseReturnsAllItems() { boolean ignoreCase = true; - Qualifier qual1 = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("BLUE")) - ); - Qualifier qual2 = new Qualifier( - new QualifierBuilder() - .setField("name") - .setFilterOperation(STARTS_WITH) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("NA")) - ); + Qualifier qual1 = Qualifier.builder() + .setField("color") + .setFilterOperation(EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("BLUE")) + .build(); + + Qualifier qual2 = Qualifier.builder() + .setField("name") + .setFilterOperation(STARTS_WITH) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("NA")) + .build(); Flux flux = queryEngine.select(namespace, SET_NAME, null, qual1, qual2); StepVerifier.create(flux) @@ -115,13 +115,13 @@ public void startWithAndEqualIgnoreCaseReturnsAllItems() { @Test public void equalIgnoreCaseReturnsNoItemsIfNoneMatched() { boolean ignoreCase = false; - Qualifier qual1 = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("BLUE")) - ); + Qualifier qual1 = Qualifier.builder() + .setField("color") + .setFilterOperation(EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("BLUE")) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, qual1); StepVerifier.create(flux) .expectNextCount(0) @@ -131,13 +131,13 @@ public void equalIgnoreCaseReturnsNoItemsIfNoneMatched() { @Test public void startWithIgnoreCaseReturnsNoItemsIfNoneMatched() { boolean ignoreCase = false; - Qualifier qual1 = new Qualifier( - new QualifierBuilder() - .setField("name") - .setFilterOperation(STARTS_WITH) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("NA")) - ); + Qualifier qual1 = Qualifier.builder() + .setField("name") + .setFilterOperation(STARTS_WITH) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("NA")) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, qual1); StepVerifier.create(flux) .expectNextCount(0) @@ -149,13 +149,13 @@ public void stringEqualIgnoreCaseWorksOnUnindexedBin() { boolean ignoreCase = true; String expectedColor = "blue"; - Qualifier caseInsensitiveQual = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("BlUe")) - ); + Qualifier caseInsensitiveQual = Qualifier.builder() + .setField("color") + .setFilterOperation(EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("BlUe")) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, caseInsensitiveQual); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { @@ -170,13 +170,13 @@ public void stringEqualIgnoreCaseWorksOnUnindexedBin() { @Test public void stringEqualIgnoreCaseWorksRequiresFullMatch() { boolean ignoreCase = true; - Qualifier caseInsensitiveQual = new Qualifier( - new QualifierBuilder() - .setField("color") - .setFilterOperation(EQ) - .setIgnoreCase(ignoreCase) - .setValue1(Value.get("lue")) - ); + Qualifier caseInsensitiveQual = Qualifier.builder() + .setField("color") + .setFilterOperation(EQ) + .setIgnoreCase(ignoreCase) + .setValue1(Value.get("lue")) + .build(); + Flux flux = queryEngine.select(namespace, SET_NAME, null, caseInsensitiveQual); StepVerifier.create(flux) @@ -192,16 +192,17 @@ public void selectWithGeoWithin() { String rgnstr = String.format("{ \"type\": \"AeroCircle\", " + "\"coordinates\": [[%.8f, %.8f], %f] }", lon, lat, radius); - Qualifier qual1 = new Qualifier(new QualifierBuilder() + Qualifier qual1 = Qualifier.builder() .setField(GEO_BIN_NAME) .setFilterOperation(GEO_WITHIN) .setValue1(Value.getAsGeoJSON(rgnstr)) - ); + .build(); + Flux flux = queryEngine.select(namespace, GEO_SET, null, qual1); StepVerifier.create(flux.collectList()) .expectNextMatches(results -> { assertThat(results) - .allSatisfy(rec -> assertThat(rec.record.generation).isGreaterThanOrEqualTo(1)) + .allSatisfy(rec -> assertThat(rec.record.generation).isPositive()) .isNotEmpty(); return true; }) diff --git a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java index 991c467fd..99e0d6aa0 100644 --- a/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java +++ b/src/test/java/org/springframework/data/aerospike/query/reactive/ReactiveUsersTests.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import org.springframework.data.aerospike.query.FilterOperation; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -16,11 +15,12 @@ public class ReactiveUsersTests extends BaseReactiveQueryEngineTests { @Test public void usersInNorthRegion() { - Qualifier qualifier = new Qualifier(new QualifierBuilder() + Qualifier qualifier = Qualifier.builder() .setField("region") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get("n")) - ); + .build(); + Flux flux = queryEngine.select(namespace, USERS_SET, null, qualifier); StepVerifier.create(flux.collectList()) diff --git a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java index a246dafa1..ba2db0bc6 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java @@ -8,9 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.aerospike.BaseBlockingIntegrationTests; import org.springframework.data.aerospike.query.FilterOperation; -import org.springframework.data.aerospike.query.MetadataQualifierBuilder; import org.springframework.data.aerospike.query.Qualifier; -import org.springframework.data.aerospike.query.QualifierBuilder; import org.springframework.data.aerospike.sample.Address; import org.springframework.data.aerospike.sample.Person; import org.springframework.data.aerospike.sample.PersonRepository; @@ -1220,7 +1218,7 @@ public void findPersonsByEmail() { @Test public void findPersonsByMetadata() { // creating a condition "since_update_time metadata value is less than 50 seconds" - Qualifier sinceUpdateTimeLt10Seconds = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeLt10Seconds = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LT) .setValue1AsObj(50000L) @@ -1228,7 +1226,7 @@ public void findPersonsByMetadata() { assertThat(repository.findByQualifiers(sinceUpdateTimeLt10Seconds)).containsAll(allPersons); // creating a condition "since_update_time metadata value is between 1 millisecond and 50 seconds" - Qualifier sinceUpdateTimeBetween1And50000 = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeBetween1And50000 = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.BETWEEN) .setValue1AsObj(1L) @@ -1243,14 +1241,14 @@ public void findPersonsByQualifiers() { Iterable result; // creating a condition "since_update_time metadata value is greater than 1 millisecond" - Qualifier sinceUpdateTimeGt1 = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeGt1 = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.GT) .setValue1AsObj(1L) .build(); // creating a condition "since_update_time metadata value is less than 50 seconds" - Qualifier sinceUpdateTimeLt50Seconds = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeLt50Seconds = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LT) .setValue1AsObj(50000L) @@ -1258,7 +1256,7 @@ public void findPersonsByQualifiers() { assertThat(repository.findByQualifiers(sinceUpdateTimeLt50Seconds)).containsAll(allPersons); // creating a condition "since_update_time metadata value is between 1 millisecond and 50 seconds" - Qualifier sinceUpdateTimeBetween1And50000 = new MetadataQualifierBuilder() + Qualifier sinceUpdateTimeBetween1And50000 = Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.BETWEEN) .setValue1AsObj(1L) @@ -1266,14 +1264,14 @@ public void findPersonsByQualifiers() { .build(); // creating a condition "firsName is equal to Carter" - Qualifier firstNameEqCarter = new QualifierBuilder() + Qualifier firstNameEqCarter = Qualifier.builder() .setField("firstName") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get("Carter")) .build(); // creating a condition "age is equal to 49" - Qualifier ageEq49 = new QualifierBuilder() + Qualifier ageEq49 = Qualifier.builder() .setField("age") .setFilterOperation(FilterOperation.EQ) .setValue1(Value.get(49)) @@ -1282,7 +1280,7 @@ public void findPersonsByQualifiers() { assertThat(result).containsOnly(carter); // creating a condition "age is greater than 49" - Qualifier ageGt49 = new QualifierBuilder() + Qualifier ageGt49 = Qualifier.builder() .setFilterOperation(FilterOperation.GT) .setField("age") .setValue1(Value.get(49)) @@ -1297,7 +1295,7 @@ public void findPersonsByQualifiers() { // conditions "age == 49", "firstName is Carter" and "since_update_time metadata value is less than 50 seconds" // are combined with OR - Qualifier orWide = new QualifierBuilder() + Qualifier orWide = Qualifier.builder() .setFilterOperation(FilterOperation.OR) .setQualifiers(ageEq49, firstNameEqCarter, sinceUpdateTimeLt50Seconds) .build(); @@ -1305,7 +1303,7 @@ public void findPersonsByQualifiers() { assertThat(result).containsAll(allPersons); // conditions "age == 49" and "firstName is Carter" are combined with OR - Qualifier orNarrow = new QualifierBuilder() + Qualifier orNarrow = Qualifier.builder() .setFilterOperation(FilterOperation.OR) .setQualifiers(ageEq49, firstNameEqCarter) .build(); @@ -1318,7 +1316,7 @@ public void findPersonsByQualifiers() { assertThat(result).isEmpty(); // conditions "age == 49" and "age > 49" are combined with OR - Qualifier ageEqOrGt49 = new QualifierBuilder() + Qualifier ageEqOrGt49 = Qualifier.builder() .setFilterOperation(FilterOperation.OR) .setQualifiers(ageEq49, ageGt49) .build(); @@ -1333,7 +1331,7 @@ public void findPersonsByQualifiers() { // a condition that returns all entities and a condition that returns one entity are combined using AND // another way of running the same query - Qualifier orCombinedWithAnd = new QualifierBuilder() + Qualifier orCombinedWithAnd = Qualifier.builder() .setFilterOperation(FilterOperation.AND) .setQualifiers(orWide, orNarrow) .build(); @@ -1343,7 +1341,7 @@ public void findPersonsByQualifiers() { @Test public void findPersonsByQualifiersMustBeValid() { - assertThatThrownBy(() -> repository.findByQualifiers(new MetadataQualifierBuilder() + assertThatThrownBy(() -> repository.findByQualifiers(Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.BETWEEN) .setValue1AsObj(1L) @@ -1351,7 +1349,7 @@ public void findPersonsByQualifiersMustBeValid() { .isInstanceOf(IllegalArgumentException.class) .hasMessage("BETWEEN: value2 is expected to be set as Long"); - assertThatThrownBy(() -> repository.findByQualifiers(new MetadataQualifierBuilder() + assertThatThrownBy(() -> repository.findByQualifiers(Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.BETWEEN) .setValue2AsObj(1L) @@ -1359,7 +1357,7 @@ public void findPersonsByQualifiersMustBeValid() { .isInstanceOf(IllegalArgumentException.class) .hasMessage("BETWEEN: value1 is expected to be set as Long"); - assertThatThrownBy(() -> repository.findByQualifiers(new MetadataQualifierBuilder() + assertThatThrownBy(() -> repository.findByQualifiers(Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.GT) .setValue1AsObj(1) @@ -1367,7 +1365,7 @@ public void findPersonsByQualifiersMustBeValid() { .isInstanceOf(IllegalArgumentException.class) .hasMessage("GT: value1 is expected to be set as Long"); - assertThatThrownBy(() -> repository.findByQualifiers(new MetadataQualifierBuilder() + assertThatThrownBy(() -> repository.findByQualifiers(Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LT) .setValue1AsObj(1) @@ -1375,7 +1373,7 @@ public void findPersonsByQualifiersMustBeValid() { .isInstanceOf(IllegalArgumentException.class) .hasMessage("LT: value1 is expected to be set as Long"); - assertThatThrownBy(() -> repository.findByQualifiers(new MetadataQualifierBuilder() + assertThatThrownBy(() -> repository.findByQualifiers(Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.LTEQ) .setValue1AsObj(Value.get(1)) @@ -1383,7 +1381,7 @@ public void findPersonsByQualifiersMustBeValid() { .isInstanceOf(IllegalArgumentException.class) .hasMessage("LTEQ: value1 is expected to be set as Long"); - assertThatThrownBy(() -> repository.findByQualifiers(new MetadataQualifierBuilder() + assertThatThrownBy(() -> repository.findByQualifiers(Qualifier.metadataBuilder() .setMetadataField(SINCE_UPDATE_TIME) .setFilterOperation(FilterOperation.STARTS_WITH) .setValue1AsObj(1L)