Skip to content
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

Unsupported contains ends with #525

Merged
merged 3 commits into from
Jun 13, 2024
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
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