Skip to content

Commit

Permalink
cleanup, add @beta annotation to QualifierBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed May 26, 2024
1 parent 6ced1e0 commit d15e4a8
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.springframework.data.aerospike.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marks public API as potentially volatile, i.e. it may be a subject of incompatible changes in future releases.
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD})
public @interface Beta {

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static CTX toCtx(String singleCtx) {
private static CTX processSingleCtx(String singleCtx, AerospikeIndexResolver.CtxType ctxType) {
int length = singleCtx.length();
if (length < 3) {
throw new IllegalArgumentException("@Indexed annotation: context string '" + singleCtx +
throw new IllegalArgumentException("Context DSL: string '" + singleCtx +
"' has no content");
}
if (singleCtx.charAt(length - 1) != ctxType.closingChar) {
throw new IllegalArgumentException("@Indexed annotation: brackets mismatch, " +
throw new IllegalArgumentException("Context DSL: brackets mismatch, " +
"expecting '" + ctxType.closingChar + "', got '" + singleCtx.charAt(length - 1) + "' instead");
}

Expand Down Expand Up @@ -86,7 +86,7 @@ private static int parseIntOrFail(String substring, AerospikeIndexResolver.CtxTy
try {
return Integer.parseInt(substring);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("@Indexed annotation " + ctxType + " " + parameterName + ": " +
throw new IllegalArgumentException("Context DSL " + ctxType + " " + parameterName + ": " +
"expecting only integer values, got '" + substring + "' instead");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ public Exp filterExp(Map<QualifierKey, Object> qualifierMap) {
String path = String.join(".", getBinName(qualifierMap), pathPart);
Exp[] arrElementsExp = collection.stream().map(item ->
Qualifier.builder()
.setPath(getBinName(qualifierMap))
.setFilterOperation(FilterOperation.MAP_VAL_NOTEQ_BY_KEY)
.setPath(path)
.setValue(Value.get(item))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.springframework.data.aerospike.query.qualifier;

import org.springframework.data.aerospike.annotation.Beta;
import org.springframework.data.aerospike.query.FilterOperation;
import org.springframework.data.aerospike.repository.query.CriteriaDefinition;
import org.springframework.util.Assert;
Expand All @@ -11,6 +12,7 @@
import static org.springframework.data.aerospike.query.qualifier.QualifierKey.SECOND_VALUE;
import static org.springframework.data.aerospike.query.qualifier.QualifierKey.VALUE;

@Beta
public class MetadataQualifierBuilder extends BaseQualifierBuilder<MetadataQualifierBuilder> {

MetadataQualifierBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.aerospike.client.command.ParticleType;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.query.Filter;
import org.springframework.data.aerospike.annotation.Beta;
import org.springframework.data.aerospike.config.AerospikeDataSettings;
import org.springframework.data.aerospike.query.FilterOperation;
import org.springframework.data.aerospike.repository.query.CriteriaDefinition;
Expand Down Expand Up @@ -75,10 +76,12 @@ private Map<QualifierKey, Object> getImmutableMap() {
return Collections.unmodifiableMap(this.internalMap);
}

@Beta
public static QualifierBuilder builder() {
return new QualifierBuilder();
}

@Beta
public static MetadataQualifierBuilder metadataBuilder() {
return new MetadataQualifierBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.aerospike.client.Value;
import com.aerospike.client.cdt.CTX;
import org.springframework.data.aerospike.annotation.Beta;
import org.springframework.data.aerospike.index.AerospikeIndexResolverUtils;
import org.springframework.data.aerospike.query.FilterOperation;
import org.springframework.data.aerospike.repository.query.QueryQualifierBuilder;
Expand All @@ -22,6 +23,7 @@
import static org.springframework.data.aerospike.query.qualifier.QualifierKey.SECOND_VALUE;
import static org.springframework.data.aerospike.query.qualifier.QualifierKey.VALUE;

@Beta
public class QualifierBuilder extends BaseQualifierBuilder<QualifierBuilder> {

QualifierBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ void findPersonsByMetadata() {
.containsAll(repository.findUsingQuery(new Query(sinceUpdateTimeLt50Seconds)));
}

@Test
void findBySimplePropertyEquals_Enum() {
Qualifier genderEqFemale = Qualifier.builder()
.setPath("gender")
.setFilterOperation(FilterOperation.EQ)
.setValue(Value.get(Person.Gender.FEMALE))
.build();
assertThat(repository.findUsingQuery(new Query(genderEqFemale))).containsOnly(alicia);
}

@Test
void findBySimplePropertyEquals_String() {
String email = "[email protected]";
alicia.setEmailAddress(email);
repository.save(alicia);

Qualifier genderEqFemale = Qualifier.builder()
// custom bin name has been set to "email" via @Field annotation
.setPath("email")
.setFilterOperation(FilterOperation.EQ)
.setValue(Value.get(email))
.build();
assertThat(repository.findUsingQuery(new Query(genderEqFemale))).containsOnly(alicia);
}

@Test
void findPersonsByQuery() {
Iterable<Person> result;
Expand Down Expand Up @@ -266,20 +291,9 @@ void mapValuesTest() {
Qualifier intMapWithExactKeyAndValueLt100 = Qualifier.builder()
.setPath("intMap." + keyExactMatch) // Map bin name
.setFilterOperation(FilterOperation.MAP_VAL_LT_BY_KEY)
// .setKey(Value.get(keyExactMatch)) // Map key
.setValue(Value.get(valueToSearchLessThan)) // Map value to compare with
.build();
assertThat(repository.findUsingQuery(new Query(intMapWithExactKeyAndValueLt100))).containsOnly(carter);
}

@Test
void findBySimplePropertyEquals_Enum() {
Qualifier genderEqFemale = Qualifier.builder()
.setPath("gender")
.setFilterOperation(FilterOperation.EQ)
.setValue(Value.get(Person.Gender.FEMALE))
.build();
assertThat(repository.findUsingQuery(new Query(genderEqFemale))).containsOnly(alicia);
}
}

0 comments on commit d15e4a8

Please sign in to comment.