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; 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/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) { 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);