Skip to content

Commit

Permalink
Merge pull request #525 from eclipse/unsupported-contains-ends-with
Browse files Browse the repository at this point in the history
Unsupported contains ends with
  • Loading branch information
otaviojava authored Jun 13, 2024
2 parents 5910b70 + 8bcdd3a commit 3a982dd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion antlr4/org/eclipse/jnosql/query/grammar/method/Method.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class MethodQuery implements Supplier<String> {
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<String, String> CACHE = Collections.synchronizedMap(new WeakHashMap<>());
private MethodQuery(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3a982dd

Please sign in to comment.