Skip to content

Commit 31bc67b

Browse files
committed
Backoff JSqlParserQueryEnhancer if query type is not a supported query type.
We now backoff from enhancing queries if the query type is not supported (e.g. TRUNCATE). Closes #3038
1 parent 1cae1e8 commit 31bc67b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/org/springframework/data/jpa/repository/query/JSqlParserQueryEnhancer.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private ParsedType detectParsedType() {
9696
} else if (statement instanceof Merge) {
9797
return ParsedType.MERGE;
9898
} else {
99-
return ParsedType.SELECT;
99+
return ParsedType.OTHER;
100100
}
101101
} catch (JSQLParserException e) {
102102
throw new IllegalArgumentException("The query you provided is not a valid SQL Query!", e);
@@ -316,10 +316,10 @@ private String detectAlias(String query) {
316316
Select selectStatement = parseSelectStatement(query);
317317

318318
/*
319-
For all the other types ({@link ValuesStatement} and {@link SetOperationList}) it does not make sense to provide
320-
alias since:
321-
* ValuesStatement has no alias
322-
* SetOperation can have multiple alias for each operation item
319+
* For all the other types ({@link ValuesStatement} and {@link SetOperationList}) it does not make sense to provide
320+
* alias since:
321+
* ValuesStatement has no alias
322+
* SetOperation can have multiple alias for each operation item
323323
*/
324324
if (!(selectStatement.getSelectBody() instanceof PlainSelect)) {
325325
return null;
@@ -519,10 +519,11 @@ public DeclaredQuery getQuery() {
519519
* <li>{@code ParsedType.SELECT}: means the top level statement is {@link Select}</li>
520520
* <li>{@code ParsedType.INSERT}: means the top level statement is {@link Insert}</li>
521521
* <li>{@code ParsedType.MERGE}: means the top level statement is {@link Merge}</li>
522+
* <li>{@code ParsedType.OTHER}: means the top level statement is a different top-level type</li>
522523
* </ul>
523524
*/
524525
enum ParsedType {
525-
DELETE, UPDATE, SELECT, INSERT, MERGE;
526+
DELETE, UPDATE, SELECT, INSERT, MERGE, OTHER;
526527
}
527528

528529
}

0 commit comments

Comments
 (0)