Skip to content

Commit a3dd07f

Browse files
christophstroblmp911de
authored andcommitted
Update Eclipselink grammar to support = & != for null comparison.
Eclipselink transforms = & and != in queries into IS and IS NOT. Closes #3314 Original pull request: #3316
1 parent fbf831c commit a3dd07f

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Eql.g4

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ like_expression
362362
;
363363

364364
null_comparison_expression
365-
: (single_valued_path_expression | input_parameter | nullif_expression) IS (NOT)? NULL
365+
: (single_valued_path_expression | input_parameter | nullif_expression) ((IS (NOT)?) | (op=(EQUAL | NOT_EQUAL))) NULL
366366
;
367367

368368
empty_collection_comparison_expression

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,13 @@ public List<JpaQueryParsingToken> visitNull_comparison_expression(EqlParser.Null
13151315
tokens.addAll(visit(ctx.nullif_expression()));
13161316
}
13171317

1318-
tokens.add(new JpaQueryParsingToken(ctx.IS()));
1319-
1320-
if (ctx.NOT() != null) {
1321-
tokens.add(new JpaQueryParsingToken(ctx.NOT()));
1318+
if (ctx.op != null) {
1319+
tokens.add(new JpaQueryParsingToken(ctx.op.getText()));
1320+
} else {
1321+
tokens.add(new JpaQueryParsingToken(ctx.IS()));
1322+
if (ctx.NOT() != null) {
1323+
tokens.add(new JpaQueryParsingToken(ctx.NOT()));
1324+
}
13221325
}
13231326
tokens.add(new JpaQueryParsingToken(ctx.NULL()));
13241327

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EqlComplianceTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,17 @@ void coalesceFunctions() {
401401
assertQuery("SELECT b FROM Bundle b WHERE coalesce(b.deleted, false) AND b.latestImport = true");
402402
assertQuery("SELECT b FROM Bundle b WHERE NOT coalesce(b.deleted, false) AND b.latestImport = true");
403403
}
404+
405+
@Test // GH-3314
406+
void isNullAndIsNotNull() {
407+
408+
assertQuery("SELECT e FROM Employee e WHERE (e.active = null OR e.active = true)");
409+
assertQuery("SELECT e FROM Employee e WHERE (e.active = NULL OR e.active = true)");
410+
assertQuery("SELECT e FROM Employee e WHERE (e.active IS null OR e.active = true)");
411+
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NULL OR e.active = true)");
412+
assertQuery("SELECT e FROM Employee e WHERE (e.active != null OR e.active = true)");
413+
assertQuery("SELECT e FROM Employee e WHERE (e.active != NULL OR e.active = true)");
414+
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NOT null OR e.active = true)");
415+
assertQuery("SELECT e FROM Employee e WHERE (e.active IS NOT NULL OR e.active = true)");
416+
}
404417
}

0 commit comments

Comments
 (0)