-
Notifications
You must be signed in to change notification settings - Fork 174
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
Fix for JPQL queries where identifier clashes with function #2218
Merged
lukasj
merged 11 commits into
eclipse-ee4j:master
from
OmniFish-EE:ondromih-fix-identifier-clashes-with-function
Aug 2, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e7f1fba
(#2217) Fix when an unnamed entity has a field with name as a function
OndroMih 5d1620a
(#2217) Test for length field in an expression
OndroMih e07df3a
(#2217) Support implicit variable this in UPDATE
OndroMih a0c5fa1
(#2217) Support implicit variable this in DELETE. Add tests
OndroMih 20fa01a
(#2217) Fixing failed tests
OndroMih a09bfc9
(#2217) Fix copyright headers
OndroMih 6221df4
(#2217) Removed usage of Hamcrest
OndroMih 4b7b8f9
(#2217) Apply fix for all functions, not only length
OndroMih 87fad3c
(#2217) Revert moving isNumericLiteral method
OndroMih 5a0a76b
(#2217) Moved tests to jpa.test.jpql
OndroMih ec20853
(#2217) Removed failing test currently out of scope
OndroMih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2006, 2024 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
|
@@ -15,6 +16,7 @@ | |
// | ||
package org.eclipse.persistence.jpa.jpql.parser; | ||
|
||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.security.AccessController; | ||
|
@@ -516,6 +518,22 @@ public final JPQLExpression getRoot() { | |
return (parent == null) ? (JPQLExpression) this : parent.getRoot(); | ||
} | ||
|
||
/** | ||
* Returns closest nested expression that encapsulates this expression, | ||
* or the root expression if not inside a nested expression. | ||
* | ||
* @return Parent expression | ||
*/ | ||
public final ParentExpression getParentExpression() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a query "SELECT e Employee e WHERE (SELECT COUNT(m) FROM managedEmployees m) > 0)", it will return root expression for subexpressions related to the |
||
if (this instanceof ParentExpression parentExpression) { | ||
return parentExpression; | ||
} else if (parent == null) { | ||
return null; | ||
} else { | ||
return parent.getParentExpression(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the encapsulated text of this {@link AbstractExpression}, which can be used in various | ||
* ways, it can be a keyword, a literal, etc. | ||
|
@@ -769,6 +787,9 @@ tolerant && isParsingComplete(wordParser, word, expression)) { | |
if (factory != null) { | ||
child = factory.buildExpression(this, wordParser, word, queryBNF, expression, tolerant); | ||
|
||
// if an invalid expression came from the factory, ignore it and try fallback | ||
child = revertExpressionIfInvalid(child, wordParser, word); | ||
|
||
if (child != null) { | ||
|
||
// The new expression is a child of the previous expression, | ||
|
@@ -988,6 +1009,14 @@ else if (currentInfo != null) { | |
); | ||
} | ||
|
||
static AbstractExpression revertExpressionIfInvalid(AbstractExpression expression, WordParser wordParser, String word) { | ||
if (expression != null && expression.isInvalid()) { | ||
wordParser.moveBackward(word); | ||
return null; | ||
} | ||
return expression; | ||
} | ||
|
||
/** | ||
* Right away parses the text by retrieving the {@link ExpressionFactory} for the first word that | ||
* is extracted from {@link WordParser} at the current location. | ||
|
@@ -1133,6 +1162,17 @@ public String toParsedText() { | |
*/ | ||
protected abstract void toParsedText(StringBuilder writer, boolean actual); | ||
|
||
/** | ||
* Whether this expression is not valid and should be discarded. If it returns true, | ||
* the parser will be reverted to the state before this expression was parsed | ||
* and it will attempt to parse a different expression. | ||
* | ||
* @return True if this expression is invalid and should be discarded, otherwise false. By default returns false, should be overriden if expression should be reverted. | ||
*/ | ||
protected boolean isInvalid() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
// toString() should only be called during debugging, thus the cached parsed text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to reset the word parser