From 078a12249d33a596b4a1d09c2c9afba429ea8092 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 13 Jun 2024 19:54:15 +0100 Subject: [PATCH 1/3] chore: include the contains, endswith, startswith keyword Signed-off-by: Otavio Santana --- antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4 b/antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4 index 5b06cc33e..835cbaff6 100644 --- a/antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4 +++ b/antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4 @@ -4,7 +4,7 @@ deleteBy: 'deleteBy' where? EOF; selectStart: 'find' limit 'By' | 'findBy' | 'countAll' | 'countBy' | 'existsBy'; where: condition (and condition| or condition)* ; -condition: eq | gt | gte | lt | lte | between | in | like | truth | untruth | nullable; +condition: eq | gt | gte | lt | lte | between | in | like | truth | untruth | nullable | contains | endsWith | startsWith; order: 'OrderBy' orderName (orderName)*; orderName: variable | variable asc | variable desc; limit : 'First' max?; @@ -22,6 +22,9 @@ lte: variable not? 'LessThanEqual'; between: variable not? 'Between'; in: variable not? 'In'; like: variable not? 'Like'; +contains: variable not? 'Contains'; +endsWith: variable not? 'EndsWith'; +startsWith: variable not? 'StartsWith'; nullable: variable not? 'Null'; not: 'Not'; variable: ANY_NAME; From 6d507a479b540e2553edc955a502a3f4240e480d Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 13 Jun 2024 19:58:06 +0100 Subject: [PATCH 2/3] feat: include token with contains Signed-off-by: Otavio Santana --- .../eclipse/jnosql/communication/query/method/MethodQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodQuery.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodQuery.java index e02901111..86c928831 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodQuery.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/MethodQuery.java @@ -23,7 +23,7 @@ public final class MethodQuery implements Supplier { private final String value; private static final Pattern PATTERN = Pattern.compile("findBy|deleteBy|countAll|countBy|existsBy|" + "OrderBy|First(?=\\d+By)|(?<=First\\d{1,})By|" - + "And|Or(?!der)|Null|Not|Equals|GreaterThanEqual|True|False|" + + + "And|Or(?!der)|Null|Not|Equals|GreaterThanEqual|True|False|Contains|EndsWith|StartsWith|" + "LessThanEqual|GreaterThan|LessThan|Between|In|Like|Asc|Desc"); private static final Map CACHE = Collections.synchronizedMap(new WeakHashMap<>()); private MethodQuery(String value) { From 8bcdd3aded04d4c678905a50ca4b425d9827c4dc Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Thu, 13 Jun 2024 20:03:52 +0100 Subject: [PATCH 3/3] feat: include UnsupportedOperationException Signed-off-by: Otavio Santana --- .../query/method/AbstractMethodQueryProvider.java | 15 +++++++++++++++ .../method/SelectMethodQueryProviderTest.java | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/AbstractMethodQueryProvider.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/AbstractMethodQueryProvider.java index 2045ec3bd..1f6144960 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/AbstractMethodQueryProvider.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/method/AbstractMethodQueryProvider.java @@ -183,6 +183,21 @@ public void exitOr(MethodParser.OrContext ctx) { this.and = false; } + @Override + public void exitContains(MethodParser.ContainsContext ctx) { + throw new UnsupportedOperationException("Contains is not supported in Eclipse JNoSQL method query"); + } + + @Override + public void exitEndsWith(MethodParser.EndsWithContext ctx) { + throw new UnsupportedOperationException("EndsWith is not supported in Eclipse JNoSQL method query"); + } + + @Override + public void exitStartsWith(MethodParser.StartsWithContext ctx) { + throw new UnsupportedOperationException("StartsWith is not supported in Eclipse JNoSQL method query"); + } + private void appendCondition(boolean hasNot, String variable, Condition operator) { ParamQueryValue queryValue = new MethodParamQueryValue(variable); checkCondition(new MethodCondition(variable, operator, queryValue), hasNot); diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/SelectMethodQueryProviderTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/SelectMethodQueryProviderTest.java index e29a1768d..fbb0c5e06 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/SelectMethodQueryProviderTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/SelectMethodQueryProviderTest.java @@ -538,6 +538,20 @@ void shouldReturnParserQuery37(String query) { assertNull(condition.value().get()); } + @ParameterizedTest(name = "Should parser the query {0}") + @ValueSource(strings = {"findByNameContains", "findByNameEndsWith", "findByNameStartsWith"}) + void shouldReturnUnsupportedOperationExceptionQuery(String query) { + String entity = "entity"; + Assertions.assertThrows(UnsupportedOperationException.class, () -> queryProvider.apply(query, entity)); + } + + @ParameterizedTest(name = "Should parser the query {0}") + @ValueSource(strings = {"findByNameNotContains", "findByNameNotEndsWith", "findByNameNotStartsWith"}) + void shouldReturnUnsupportedOperationExceptionQueryWithNegation(String query) { + String entity = "entity"; + Assertions.assertThrows(UnsupportedOperationException.class, () -> queryProvider.apply(query, entity)); + } + private void checkOrderBy(String query, Direction direction, Direction direction2) { String entity = "entity"; SelectQuery selectQuery = queryProvider.apply(query, entity);