Skip to content

ArangoDB: fix AQL query generation #290

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Contributors:
*
* Otavio Santana
* Michele Rastelli
*/
package org.eclipse.jnosql.databases.arangodb.communication;

Expand Down Expand Up @@ -38,6 +39,8 @@ final class QueryAQLConverter {
private static final String REMOVE = " REMOVE ";
private static final String RETURN = " RETURN ";
private static final String SEPARATOR = " ";
private static final String START_EXPRESSION = "(";
private static final String END_EXPRESSION = ")";
private static final String AND = " AND ";
private static final String OR = " OR ";
private static final String EQUALS = " == ";
Expand Down Expand Up @@ -157,7 +160,7 @@ private static void definesCondition(CriteriaCondition condition,
if (isFirstCondition(aql, counter)) {
aql.append(AND);
}
definesCondition(dc, aql, params, entity, counter +1);
definesCondition(dc, aql, params, entity, ++counter);
}
return;
case OR:
Expand All @@ -173,7 +176,9 @@ private static void definesCondition(CriteriaCondition condition,
case NOT:
CriteriaCondition documentCondition = document.get(CriteriaCondition.class);
aql.append(NOT);
aql.append(START_EXPRESSION);
definesCondition(documentCondition, aql, params, entity, ++counter);
aql.append(END_EXPRESSION);
return;
default:
throw new IllegalArgumentException("The condition does not support in AQL: " + condition.condition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@
* Contributors:
*
* Otavio Santana
* Michele Rastelli
*/
package org.eclipse.jnosql.databases.arangodb.communication;

import org.eclipse.jnosql.communication.semistructured.SelectQuery;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;

import java.util.List;
import java.util.Map;

import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
import static org.eclipse.jnosql.communication.semistructured.SelectQuery.select;
import static org.junit.jupiter.api.Assertions.assertEquals;

@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
public class QueryAQLConverterTest {

@Test
Expand Down Expand Up @@ -135,7 +133,7 @@ public void shouldRunEqualsQueryNot() {
String aql = convert.query();
Map<String, Object> values = convert.values();
assertEquals("value", values.get("name"));
assertEquals("FOR c IN collection FILTER NOT c.name == @name RETURN c", aql);
assertEquals("FOR c IN collection FILTER NOT ( c.name == @name) RETURN c", aql);

}

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

}

Expand Down