Skip to content

Commit bd58381

Browse files
authored
Merge pull request #303 from rashtao/feature/arangodb-between-operator
ArangoDB: between operator
2 parents f7c2977 + 98c40a6 commit bd58381

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

jnosql-arangodb/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,11 @@
4949
<artifactId>arangodb-java-driver-shaded</artifactId>
5050
<version>${arango.driver}</version>
5151
</dependency>
52+
<dependency>
53+
<groupId>org.slf4j</groupId>
54+
<artifactId>slf4j-simple</artifactId>
55+
<version>2.0.16</version>
56+
<scope>test</scope>
57+
</dependency>
5258
</dependencies>
5359
</project>

jnosql-arangodb/src/main/java/org/eclipse/jnosql/databases/arangodb/communication/QueryAQLConverter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private static AQLQueryResult convert(String documentCollection,
101101
.append(", ").append(maxResult);
102102
} else if (maxResult > 0) {
103103
aql.append(LIMIT).append(maxResult);
104-
} else if(firstResult > 0) {
104+
} else if (firstResult > 0) {
105105
aql.append(LIMIT).append(firstResult).append(", null");
106106
}
107107

@@ -180,6 +180,12 @@ private static void definesCondition(CriteriaCondition condition,
180180
definesCondition(documentCondition, aql, params, entity, ++localCounter);
181181
aql.append(END_EXPRESSION);
182182
return;
183+
case BETWEEN:
184+
List<Object> betweenList = ValueUtil.convertToList(document.value(), ArangoDBValueWriteDecorator.ARANGO_DB_VALUE_WRITER);
185+
appendCondition(aql, params, entity, Element.of(document.name(), betweenList.get(0)), GREATER_EQUALS_THAN);
186+
aql.append(AND);
187+
appendCondition(aql, params, entity, Element.of(document.name(), betweenList.get(1)), LESSER_EQUALS_THAN);
188+
return;
183189
default:
184190
throw new IllegalArgumentException("The condition does not support in AQL: " + condition.condition());
185191
}

jnosql-arangodb/src/test/java/org/eclipse/jnosql/databases/arangodb/communication/ArangoDBDocumentManagerTest.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,45 @@ void shouldInsertUUID() {
343343

344344
}
345345

346+
@Test
347+
void shouldFindBetween() {
348+
var deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
349+
entityManager.delete(deleteQuery);
350+
entityManager.insert(getEntitiesWithValues());
351+
352+
var query = select().from(COLLECTION_NAME)
353+
.where("age").between(22, 23)
354+
.build();
355+
356+
var result = entityManager.select(query).toList();
357+
358+
SoftAssertions.assertSoftly(softly -> {
359+
softly.assertThat(result).hasSize(2);
360+
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).contains(22, 23);
361+
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).doesNotContain(25);
362+
});
363+
}
364+
365+
@Test
366+
void shouldFindBetween2() {
367+
var deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
368+
entityManager.delete(deleteQuery);
369+
entityManager.insert(getEntitiesWithValues());
370+
371+
var query = select().from(COLLECTION_NAME)
372+
.where("age").between(22, 23)
373+
.and("type").eq("V")
374+
.build();
375+
376+
var result = entityManager.select(query).toList();
377+
378+
SoftAssertions.assertSoftly(softly -> {
379+
softly.assertThat(result).hasSize(2);
380+
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).contains(22, 23);
381+
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).doesNotContain(25);
382+
});
383+
}
384+
346385
private CommunicationEntity getEntity() {
347386
CommunicationEntity entity = CommunicationEntity.of(COLLECTION_NAME);
348387
Map<String, Object> map = new HashMap<>();
@@ -373,4 +412,27 @@ private CommunicationEntity createDocumentList() {
373412
return entity;
374413
}
375414

415+
private List<CommunicationEntity> getEntitiesWithValues() {
416+
var lucas = CommunicationEntity.of(COLLECTION_NAME);
417+
lucas.add(Element.of("name", "Lucas"));
418+
lucas.add(Element.of("age", 22));
419+
lucas.add(Element.of("location", "BR"));
420+
lucas.add(Element.of("type", "V"));
421+
422+
var luna = CommunicationEntity.of(COLLECTION_NAME);
423+
luna.add(Element.of("name", "Luna"));
424+
luna.add(Element.of("age", 23));
425+
luna.add(Element.of("location", "US"));
426+
luna.add(Element.of("type", "V"));
427+
428+
var otavio = CommunicationEntity.of(COLLECTION_NAME);
429+
otavio.add(Element.of("name", "Otavio"));
430+
otavio.add(Element.of("age", 25));
431+
otavio.add(Element.of("location", "BR"));
432+
otavio.add(Element.of("type", "V"));
433+
434+
435+
return asList(lucas, otavio, luna);
436+
}
437+
376438
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
org.slf4j.simpleLogger.logFile=System.out
2+
org.slf4j.simpleLogger.showDateTime=true
3+
org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS
4+
org.slf4j.simpleLogger.showThreadName=true
5+
org.slf4j.simpleLogger.showLogName=true
6+
org.slf4j.simpleLogger.showShortLogName=false
7+
8+
org.slf4j.simpleLogger.defaultLogLevel=info
9+
org.slf4j.simpleLogger.log.org.testcontainers=warn
10+
11+
## ArangoDB communication debug level
12+
#org.slf4j.simpleLogger.log.com.arangodb.internal.net.Communication=debug

0 commit comments

Comments
 (0)