Skip to content

Commit

Permalink
fixed merge AQL options from @QueryOptions annotation and AqlQueryOpt…
Browse files Browse the repository at this point in the history
…ions parameter (#276)
rashtao authored May 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent edcb02b commit 85fc802
Showing 4 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -299,7 +299,7 @@
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver</artifactId>
<version>6.22.0</version>
<version>6.24.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Original file line number Diff line number Diff line change
@@ -132,39 +132,53 @@ protected AqlQueryOptions mergeQueryOptions(final AqlQueryOptions oldStatic, fin
if (newDynamic == null) {
return oldStatic;
}
final Integer batchSize = newDynamic.getBatchSize();
if (batchSize != null) {
oldStatic.batchSize(batchSize);

AqlQueryOptions mergedOptions = newDynamic.clone();

if (mergedOptions.getBatchSize() == null) {
mergedOptions.batchSize(oldStatic.getBatchSize());
}
final Integer maxPlans = newDynamic.getMaxPlans();
if (maxPlans != null) {
oldStatic.maxPlans(maxPlans);

if (mergedOptions.getCache() == null) {
mergedOptions.cache(oldStatic.getCache());
}
final Integer ttl = newDynamic.getTtl();
if (ttl != null) {
oldStatic.ttl(ttl);

if (mergedOptions.getCount() == null) {
mergedOptions.count(oldStatic.getCount());
}
final Boolean cache = newDynamic.getCache();
if (cache != null) {
oldStatic.cache(cache);

if (mergedOptions.getFullCount() == null) {
mergedOptions.fullCount(oldStatic.getFullCount());
}
final Boolean count = newDynamic.getCount();
if (count != null) {
oldStatic.count(count);

if (mergedOptions.getMaxPlans() == null) {
mergedOptions.maxPlans(oldStatic.getMaxPlans());
}
final Boolean fullCount = newDynamic.getFullCount();
if (fullCount != null) {
oldStatic.fullCount(fullCount);

if (mergedOptions.getProfile() == null) {
mergedOptions.profile(oldStatic.getProfile());
}
final Boolean profile = newDynamic.getProfile();
if (profile != null) {
oldStatic.profile(profile);
if (mergedOptions.getRules() == null) {
mergedOptions.rules(oldStatic.getRules());
}
final Collection<String> rules = newDynamic.getRules();
if (rules != null) {
oldStatic.rules(rules);

if (mergedOptions.getTtl() == null) {
mergedOptions.ttl(oldStatic.getTtl());
}
return oldStatic;

if (mergedOptions.getStream() == null) {
mergedOptions.stream(oldStatic.getStream());
}

if (mergedOptions.getMemoryLimit() == null) {
mergedOptions.memoryLimit(oldStatic.getMemoryLimit());
}

if (mergedOptions.getAllowDirtyRead() == null) {
mergedOptions.allowDirtyRead(oldStatic.getAllowDirtyRead());
}

return mergedOptions;
}

private Class<?> getTypeToRead(final ResultProcessor processor) {
Original file line number Diff line number Diff line change
@@ -51,6 +51,10 @@ public interface CustomerRepository extends ArangoRepository<Customer, String>,
@Query("FOR c IN #collection FILTER c._key == @id AND c.`customer-name` == @name RETURN c")
ArangoCursor<Customer> findOneByBindVarsAql(AqlQueryOptions options, @BindVars Map<String, Object> bindVars);

@QueryOptions(count = true)
@Query("for i in @n..10000 return 1/i")
ArangoCursor<Double> sequenceTo10K(@Param("n") Integer n, AqlQueryOptions options);

@Query("FOR c IN #collection FILTER c._key == @id AND c.`customer-name` == @name RETURN c")
Customer findOneByNameAndBindVarsAql(@Param("name") String name, @BindVars Map<String, Object> bindVars);

Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@
import static org.hamcrest.Matchers.*;
import static org.hamcrest.collection.IsIn.isOneOf;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import java.time.Instant;
import java.util.*;
@@ -92,6 +91,24 @@ public void findOneByBindVarsAqlTest() {
assertEquals(john, retrieved.next());
}

@Test
public void overrideQueryOptions() {
Integer countNotOverridden = repository.sequenceTo10K(1, new AqlQueryOptions()).getCount();
assertThat(countNotOverridden, is(10_000));

Integer countOverridden = repository.sequenceTo10K(1, new AqlQueryOptions().count(false)).getCount();
assertThat(countOverridden, nullValue());
}

@Test
public void mergeQueryOptions() {
List<Double> cursorNotMerged = repository.sequenceTo10K(0, new AqlQueryOptions()).asListRemaining();
assertThat(cursorNotMerged, hasSize(10_001));
assertThat(cursorNotMerged.get(0), nullValue());
assertThrows(ArangoDBException.class,
()-> repository.sequenceTo10K(0, new AqlQueryOptions().failOnWarning(true)));
}

@Test
public void findOneByComplementingNameAndBindVarsAqlTest() {
repository.saveAll(customers);

0 comments on commit 85fc802

Please sign in to comment.