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 182e580ad..926cb1570 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -792,7 +792,7 @@ public Filter sIndexFilter(Map qualifierMap) { MAP_VAL_NOT_EXISTS_BY_KEY { @Override public Exp filterExp(Map qualifierMap) { - return FilterOperation.findNotExistingByMapKey(qualifierMap); + return findNotExistingByMapKey(qualifierMap); } @Override @@ -832,7 +832,7 @@ public Exp filterExp(Map qualifierMap) { case JBLOB -> getConvertedValue1Exp(qualifierMap); case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "MAP_KEYS_CONTAIN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -857,7 +857,7 @@ public Exp filterExp(Map qualifierMap) { case JBLOB -> getConvertedValue1Exp(qualifierMap); case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "MAP_KEYS_CONTAIN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -884,7 +884,7 @@ public Exp filterExp(Map qualifierMap) { case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); case NULL -> Exp.nil(); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "MAP_VALUES_CONTAIN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -909,7 +909,7 @@ public Exp filterExp(Map qualifierMap) { case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); case NULL -> Exp.nil(); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "MAP_VALUES_CONTAIN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -943,7 +943,7 @@ public Exp filterExp(Map qualifierMap) { Exp.val((List) getValue2(qualifierMap).getObject())); case MAP -> Pair.of(Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)), Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue2))); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "MAP_KEYS_BETWEEN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -976,7 +976,7 @@ public Exp filterExp(Map qualifierMap) { Exp.val((List) getValue2(qualifierMap).getObject())); case MAP -> Pair.of(Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)), Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue2))); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "MAP_VAL_BETWEEN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1023,7 +1023,7 @@ public Exp filterExp(Map qualifierMap) { case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); case ParticleType.NULL -> Exp.nil(); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_CONTAINING FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1059,7 +1059,7 @@ public Exp filterExp(Map qualifierMap) { case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); case ParticleType.NULL -> Exp.nil(); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_CONTAINING FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1093,7 +1093,7 @@ public Exp filterExp(Map qualifierMap) { Exp.val((List) getValue2(qualifierMap).getObject())); case MAP -> Pair.of(Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)), Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue2))); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_BETWEEN FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1134,7 +1134,7 @@ public Exp filterExp(Map qualifierMap) { case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap); case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_GT FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1166,7 +1166,7 @@ public Exp filterExp(Map qualifierMap) { case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap); case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_GTEQ FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1192,7 +1192,7 @@ public Exp filterExp(Map qualifierMap) { Exp value = switch (getValue1(qualifierMap).getType()) { case INTEGER -> { if (getValue1(qualifierMap).toLong() == Long.MIN_VALUE) { - throw new IllegalArgumentException( + throw new UnsupportedOperationException( "LIST_VAL_LT FilterExpression unsupported value: expected [Long.MIN_VALUE+1.." + "Long.MAX_VALUE]"); } @@ -1203,7 +1203,7 @@ public Exp filterExp(Map qualifierMap) { case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap); case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_GTEQ FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1245,7 +1245,7 @@ public Exp filterExp(Map qualifierMap) { case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap); case LIST -> Exp.val((List) getValue1(qualifierMap).getObject()); case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( "LIST_VAL_LTEQ FilterExpression unsupported type: got " + getValue1(qualifierMap).getClass().getSimpleName()); }; @@ -1387,7 +1387,7 @@ private static Exp getFilterExpMapValOrFail(Map qualifierMap, Bi Exp.val((List) getValue1(qualifierMap).getObject())); case MAP -> operator.apply(getMapExp(qualifierMap, dotPathArr, Exp.Type.MAP), Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1))); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( opName + " FilterExpression unsupported type: " + getValue1(qualifierMap).getClass().getSimpleName()); }; } @@ -1430,7 +1430,7 @@ private static Exp getMapValEqOrFail(Map qualifierMap, BinaryOpe useCtx); case STRING -> { if (ignoreCase(qualifierMap)) { - throw new IllegalArgumentException( + throw new UnsupportedOperationException( opName + " FilterExpression: case insensitive comparison is not supported"); } yield getMapValEqExp(qualifierMap, Exp.Type.STRING, value1.toString(), dotPathArr, operator, @@ -1452,7 +1452,7 @@ yield getMapValEqExp(qualifierMap, expType, convertedValue, dotPathArr, operator dotPathArr, operator, useCtx); case ParticleType.NULL -> getMapValEqExp(qualifierMap, Exp.Type.NIL, value1, dotPathArr, operator, useCtx); - default -> throw new IllegalArgumentException( + default -> throw new UnsupportedOperationException( opName + " FilterExpression unsupported type: " + value1.getClass().getSimpleName()); }; } @@ -1576,7 +1576,7 @@ private static Exp toExp(Object value) { } else if (value instanceof Value.NullValue) { res = Exp.nil(); } else { - throw new IllegalArgumentException("Unsupported type for converting: " + value.getClass() + throw new UnsupportedOperationException("Unsupported type for converting: " + value.getClass() .getCanonicalName()); } 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 ec4422765..c98e11698 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 @@ -49,8 +49,6 @@ import static org.springframework.data.aerospike.query.FilterOperation.MAP_VALUES_NOT_CONTAIN; import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_CONTAINING_BY_KEY; import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_EQ_BY_KEY; -import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_EXISTS_BY_KEY; -import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_NOT_EXISTS_BY_KEY; /** * @author Peter Milne @@ -164,10 +162,6 @@ public AerospikeCriteria getCriteria(Part part, AerospikePersistentProperty prop switch (onMap) { case KEY -> op = MAP_KEYS_CONTAIN; case VALUE -> op = MAP_VALUES_CONTAIN; - case VALUE_EXISTS -> { - op = MAP_VAL_EXISTS_BY_KEY; - value2 = value1; - } } } else { op = FilterOperation.MAP_VAL_EQ_BY_KEY; @@ -179,10 +173,6 @@ public AerospikeCriteria getCriteria(Part part, AerospikePersistentProperty prop switch (onMap) { case KEY -> op = MAP_KEYS_NOT_CONTAIN; case VALUE -> op = MAP_VALUES_NOT_CONTAIN; - case VALUE_EXISTS -> { - op = MAP_VAL_NOT_EXISTS_BY_KEY; - value2 = value1; - } } } else { op = FilterOperation.MAP_VAL_NOTEQ_BY_KEY; diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/CriteriaDefinition.java b/src/main/java/org/springframework/data/aerospike/repository/query/CriteriaDefinition.java index 08696c13c..f90a9b81c 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/CriteriaDefinition.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/CriteriaDefinition.java @@ -37,6 +37,6 @@ public interface CriteriaDefinition { String getKey(); enum AerospikeMapCriteria { - KEY, VALUE, VALUE_CONTAINING, VALUE_EXISTS + KEY, VALUE, VALUE_CONTAINING } } 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 16793cf1b..aeb2d7f6b 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java @@ -37,7 +37,6 @@ import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.KEY; import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.VALUE; import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.VALUE_CONTAINING; -import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.VALUE_EXISTS; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests { @@ -580,7 +579,7 @@ void findByExists() { stringMap.put("key", null); stefan.setStringMap(stringMap); repository.save(stefan); - assertThat(repository.findByStringMapContaining("key", VALUE_EXISTS)).contains(stefan); + assertThat(repository.findByStringMapContaining("key", KEY)).contains(stefan); stefan.setAddress(null); // cleanup stefan.setStringMap(null); @@ -597,7 +596,7 @@ void findByIsNull() { stefan.setAddress(new Address(null, null, null, null)); repository.save(stefan); assertThat(repository.findByAddressIsNull()).doesNotContain(stefan); - assertThat(repository.findByAddressZipCodeIsNull()).contains(stefan); + assertThat(repository.findByAddressZipCodeIsNull()).contains(stefan).doesNotContain(carter, dave); assertThat(repository.findByAddressZipCode(null)).contains(stefan).doesNotContain(carter, dave); dave.setBestFriend(stefan); @@ -615,8 +614,8 @@ void findByIsNull() { stringMap.put("key", null); stefan.setStringMap(stringMap); repository.save(stefan); -// assertThat(repository.findByStringMapContaining("key", (String) null)).contains(stefan); // key-specific - assertThat(repository.findByStringMapContaining(null, VALUE)).contains(stefan); // among all values in map + assertThat(repository.findByStringMapContaining("key", (String) null)).contains(stefan); // key-specific + assertThat(repository.findByStringMapContaining(null, VALUE)).contains(stefan); // among all map values List strings = new ArrayList<>(); strings.add(null); @@ -655,12 +654,12 @@ void findByIsNotNull() { stringMap.put("key", "str"); stefan.setStringMap(stringMap); repository.save(stefan); - assertThat(repository.findByStringMapNotContaining(null, VALUE)).contains(stefan); // among all values + assertThat(repository.findByStringMapNotContaining(null, VALUE)).contains(stefan); // looks at all values // Currently only for a Map "IsNotNull" differs from "Exists" as map values can both exist and store null // Getting key-specific results requires post-processing: // firstly getting all entities with existing map key - List personsWithMapKeyExists = repository.findByStringMapContaining("key", VALUE_EXISTS); + List personsWithMapKeyExists = repository.findByStringMapContaining("key", KEY); // and then filtering those that have the key's value equal to null List personsWithMapValueNotNull = personsWithMapKeyExists.stream() .filter(person -> person.getStringMap().get("key") != null).toList(); @@ -671,7 +670,7 @@ void findByIsNotNull() { repository.save(stefan); assertThat(repository.findByStringMapNotContaining(null, VALUE)).doesNotContain(stefan); - personsWithMapKeyExists = repository.findByStringMapContaining("key", VALUE_EXISTS); + personsWithMapKeyExists = repository.findByStringMapContaining("key", KEY); personsWithMapValueNotNull = personsWithMapKeyExists.stream() .filter(person -> person.getStringMap().get("key") != null).toList(); assertThat(personsWithMapValueNotNull).doesNotContain(stefan); diff --git a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java index f4d6eca6a..f8fb80dea 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java +++ b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java @@ -171,7 +171,8 @@ public interface PersonRepository

extends AerospikeRepository< List

findByAddressZipCode(String zipCode); /** - * Find all entities that satisfy the condition "have address with zipCode which is not equal to the given argument" + * Find all entities that satisfy the condition "have address with zipCode which is not equal to the given + * argument" */ List

findByAddressZipCodeIsNot(String zipCode); @@ -343,20 +344,20 @@ public interface PersonRepository

extends AerospikeRepository< /** * Find all entities containing the given map element (key or value depending on the given criterion) * - * @param value map value + * @param element map value * @param criterion {@link CriteriaDefinition.AerospikeMapCriteria#KEY} or * {@link CriteriaDefinition.AerospikeMapCriteria#VALUE} */ - List

findByStringMapContaining(String value, CriteriaDefinition.AerospikeMapCriteria criterion); + List

findByStringMapContaining(String element, CriteriaDefinition.AerospikeMapCriteria criterion); /** * Find all entities that do not contain the given map element (key or value depending on the given criterion) * - * @param value map value + * @param element map value * @param criterion {@link CriteriaDefinition.AerospikeMapCriteria#KEY} or * {@link CriteriaDefinition.AerospikeMapCriteria#VALUE} */ - List

findByStringMapNotContaining(String value, CriteriaDefinition.AerospikeMapCriteria criterion); + List

findByStringMapNotContaining(String element, CriteriaDefinition.AerospikeMapCriteria criterion); /** * Find all entities that satisfy the condition "have the given map key and the value equal to the given string"