|
58 | 58 | * @author Geoffrey Deremetz
|
59 | 59 | * @author Yanming Zhou
|
60 | 60 | * @author Christoph Strobl
|
| 61 | + * @author Mark Paluch |
61 | 62 | * @since 2.7.0
|
62 | 63 | */
|
63 | 64 | public class JSqlParserQueryEnhancer implements QueryEnhancer {
|
@@ -119,7 +120,7 @@ public String applySorting(Sort sort, @Nullable String alias) {
|
119 | 120 |
|
120 | 121 | Select selectStatement = parseSelectStatement(queryString);
|
121 | 122 |
|
122 |
| - if (selectStatement instanceof SetOperationList setOperationList) { |
| 123 | + if (selectStatement instanceof SetOperationList setOperationList) { |
123 | 124 | return applySortingToSetOperationList(setOperationList, sort);
|
124 | 125 | }
|
125 | 126 |
|
@@ -217,7 +218,7 @@ private Set<String> getJoinAliases(String query) {
|
217 | 218 | }
|
218 | 219 |
|
219 | 220 | Select selectStatement = (Select) statement;
|
220 |
| - if (selectStatement instanceof PlainSelect selectBody) { |
| 221 | + if (selectStatement instanceof PlainSelect selectBody) { |
221 | 222 | return getJoinAliases(selectBody);
|
222 | 223 | }
|
223 | 224 |
|
@@ -315,7 +316,7 @@ private String detectAlias(String query) {
|
315 | 316 | * ValuesStatement has no alias
|
316 | 317 | * SetOperation can have multiple alias for each operation item
|
317 | 318 | */
|
318 |
| - if (!(selectStatement instanceof PlainSelect selectBody)) { |
| 319 | + if (!(selectStatement instanceof PlainSelect selectBody)) { |
319 | 320 | return null;
|
320 | 321 | }
|
321 | 322 |
|
@@ -370,7 +371,7 @@ public String createCountQueryFor(@Nullable String countProjection) {
|
370 | 371 | /*
|
371 | 372 | We only support count queries for {@link PlainSelect}.
|
372 | 373 | */
|
373 |
| - if (!(selectStatement instanceof PlainSelect selectBody)) { |
| 374 | + if (!(selectStatement instanceof PlainSelect selectBody)) { |
374 | 375 | return this.query.getQueryString();
|
375 | 376 | }
|
376 | 377 |
|
@@ -413,7 +414,7 @@ public String getProjection() {
|
413 | 414 |
|
414 | 415 | Select selectBody = selectStatement;
|
415 | 416 |
|
416 |
| - if (selectStatement instanceof SetOperationList setOperationList) { |
| 417 | + if (selectStatement instanceof SetOperationList setOperationList) { |
417 | 418 |
|
418 | 419 | // using the first one since for setoperations the projection has to be the same
|
419 | 420 | selectBody = setOperationList.getSelects().get(0);
|
@@ -491,7 +492,12 @@ private String countPropertyNameForSelection(List<SelectItem<?>> selectItems, bo
|
491 | 492 | return column.getFullyQualifiedName();
|
492 | 493 | }
|
493 | 494 |
|
494 |
| - return query.isNativeQuery() ? (distinct ? "*" : "1") : tableAlias == null ? "*" : tableAlias; |
| 495 | + // TODO: We should not handle JPQL here... |
| 496 | + if (!query.isNativeQuery()) { |
| 497 | + return tableAlias == null ? "*" : tableAlias; |
| 498 | + } |
| 499 | + |
| 500 | + return distinct ? ((tableAlias != null ? tableAlias + "." : "") + "*") : "1"; |
495 | 501 | }
|
496 | 502 |
|
497 | 503 | @Override
|
|
0 commit comments