Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE-595] fix merge AQL options #276

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
Expand Down