Skip to content

Commit 6a31494

Browse files
authored
Merge pull request #290 from rashtao/bugfix/arangodb-logical-operator-precedence
ArangoDB: fix AQL query generation
2 parents 023315a + 2f7435f commit 6a31494

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Contributors:
1212
*
1313
* Otavio Santana
14+
* Michele Rastelli
1415
*/
1516
package org.eclipse.jnosql.databases.arangodb.communication;
1617

@@ -38,6 +39,8 @@ final class QueryAQLConverter {
3839
private static final String REMOVE = " REMOVE ";
3940
private static final String RETURN = " RETURN ";
4041
private static final String SEPARATOR = " ";
42+
private static final String START_EXPRESSION = "(";
43+
private static final String END_EXPRESSION = ")";
4144
private static final String AND = " AND ";
4245
private static final String OR = " OR ";
4346
private static final String EQUALS = " == ";
@@ -157,7 +160,7 @@ private static void definesCondition(CriteriaCondition condition,
157160
if (isFirstCondition(aql, counter)) {
158161
aql.append(AND);
159162
}
160-
definesCondition(dc, aql, params, entity, counter +1);
163+
definesCondition(dc, aql, params, entity, ++counter);
161164
}
162165
return;
163166
case OR:
@@ -173,7 +176,9 @@ private static void definesCondition(CriteriaCondition condition,
173176
case NOT:
174177
CriteriaCondition documentCondition = document.get(CriteriaCondition.class);
175178
aql.append(NOT);
179+
aql.append(START_EXPRESSION);
176180
definesCondition(documentCondition, aql, params, entity, ++counter);
181+
aql.append(END_EXPRESSION);
177182
return;
178183
default:
179184
throw new IllegalArgumentException("The condition does not support in AQL: " + condition.condition());

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
* Contributors:
1212
*
1313
* Otavio Santana
14+
* Michele Rastelli
1415
*/
1516
package org.eclipse.jnosql.databases.arangodb.communication;
1617

1718
import org.eclipse.jnosql.communication.semistructured.SelectQuery;
1819
import org.junit.jupiter.api.Test;
19-
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
2020

21+
import java.util.List;
2122
import java.util.Map;
2223

23-
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
24-
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
2524
import static org.eclipse.jnosql.communication.semistructured.SelectQuery.select;
2625
import static org.junit.jupiter.api.Assertions.assertEquals;
2726

28-
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
2927
public class QueryAQLConverterTest {
3028

3129
@Test
@@ -135,7 +133,7 @@ public void shouldRunEqualsQueryNot() {
135133
String aql = convert.query();
136134
Map<String, Object> values = convert.values();
137135
assertEquals("value", values.get("name"));
138-
assertEquals("FOR c IN collection FILTER NOT c.name == @name RETURN c", aql);
136+
assertEquals("FOR c IN collection FILTER NOT ( c.name == @name) RETURN c", aql);
139137

140138
}
141139

@@ -154,7 +152,7 @@ public void shouldNegate() {
154152
assertEquals("Assis", values.get("city"));
155153
assertEquals("Otavio", values.get("name"));
156154
assertEquals("Lucas", values.get("name_1"));
157-
assertEquals("FOR c IN collection FILTER NOT c.city == @city AND c.name == @name OR NOT c.name == @name_1 RETURN c", aql);
155+
assertEquals("FOR c IN collection FILTER NOT ( c.city == @city) AND c.name == @name OR NOT ( c.name == @name_1) RETURN c", aql);
158156

159157
}
160158

0 commit comments

Comments
 (0)