Skip to content

Commit 19571e4

Browse files
committed
Polishing.
Refine JOIN and function keyword rendering. See #3692
1 parent 2e58485 commit 19571e4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public QueryRendererBuilder visitJoin(HqlParser.JoinContext ctx) {
168168

169169
QueryRendererBuilder builder = QueryRenderer.builder();
170170

171+
builder.append(TOKEN_SPACE);
171172
builder.appendExpression(visit(ctx.joinType()));
172173
builder.append(QueryTokens.expression(ctx.JOIN()));
173174

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ public QueryTokenStream visitEntityWithJoins(HqlParser.EntityWithJoinsContext ct
329329

330330
QueryRendererBuilder builder = QueryRenderer.builder();
331331

332-
builder.appendExpression(visit(ctx.fromRoot()));
333-
builder.appendInline(QueryTokenStream.concat(ctx.joinSpecifier(), this::visit, TOKEN_SPACE));
332+
builder.appendInline(visit(ctx.fromRoot()));
333+
builder.appendInline(QueryTokenStream.concat(ctx.joinSpecifier(), this::visit, EMPTY_TOKEN));
334334

335335
return builder;
336336
}
@@ -389,6 +389,7 @@ public QueryTokenStream visitJoin(HqlParser.JoinContext ctx) {
389389

390390
QueryRendererBuilder builder = QueryRenderer.builder();
391391

392+
builder.append(TOKEN_SPACE);
392393
builder.append(visit(ctx.joinType()));
393394
builder.append(QueryTokens.expression(ctx.JOIN()));
394395

@@ -746,7 +747,7 @@ public QueryTokenStream visitOffsetClause(HqlParser.OffsetClauseContext ctx) {
746747
QueryRendererBuilder builder = QueryRenderer.builder();
747748

748749
builder.append(QueryTokens.expression(ctx.OFFSET()));
749-
builder.append(visit(ctx.parameterOrIntegerLiteral()));
750+
builder.appendExpression(visit(ctx.parameterOrIntegerLiteral()));
750751

751752
if (ctx.ROW() != null) {
752753
builder.append(QueryTokens.expression(ctx.ROW()));
@@ -3377,7 +3378,7 @@ public QueryTokenStream visitEveryFunction(HqlParser.EveryFunctionContext ctx) {
33773378
builder.append(TOKEN_CLOSE_PAREN);
33783379
} else {
33793380

3380-
builder.appendExpression(visit(ctx.collectionQuantifier()));
3381+
builder.append(visit(ctx.collectionQuantifier()));
33813382

33823383
builder.append(TOKEN_OPEN_PAREN);
33833384
builder.appendInline(visit(ctx.simplePath()));
@@ -3412,7 +3413,7 @@ public QueryTokenStream visitAnyFunction(HqlParser.AnyFunctionContext ctx) {
34123413
builder.append(TOKEN_CLOSE_PAREN);
34133414
} else {
34143415

3415-
builder.appendExpression(visit(ctx.collectionQuantifier()));
3416+
builder.append(visit(ctx.collectionQuantifier()));
34163417

34173418
builder.append(TOKEN_OPEN_PAREN);
34183419
builder.appendInline(visit(ctx.simplePath()));
@@ -3801,9 +3802,9 @@ public QueryTokenStream visitInList(HqlParser.InListContext ctx) {
38013802
if (ctx.simplePath() != null) {
38023803

38033804
if (ctx.ELEMENTS() != null) {
3804-
builder.append(QueryTokens.expression(ctx.ELEMENTS()));
3805+
builder.append(QueryTokens.token(ctx.ELEMENTS()));
38053806
} else if (ctx.INDICES() != null) {
3806-
builder.append(QueryTokens.expression(ctx.INDICES()));
3807+
builder.append(QueryTokens.token(ctx.INDICES()));
38073808
}
38083809

38093810
builder.append(TOKEN_OPEN_PAREN);
@@ -3836,9 +3837,9 @@ public QueryTokenStream visitExistsExpression(HqlParser.ExistsExpressionContext
38363837
builder.append(QueryTokens.expression(ctx.EXISTS()));
38373838

38383839
if (ctx.ELEMENTS() != null) {
3839-
builder.append(QueryTokens.expression(ctx.ELEMENTS()));
3840+
builder.append(QueryTokens.token(ctx.ELEMENTS()));
38403841
} else if (ctx.INDICES() != null) {
3841-
builder.append(QueryTokens.expression(ctx.INDICES()));
3842+
builder.append(QueryTokens.token(ctx.INDICES()));
38423843
}
38433844

38443845
builder.append(TOKEN_OPEN_PAREN);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class QueryTokens {
3131
/**
3232
* Commonly use tokens.
3333
*/
34+
static final QueryToken EMPTY_TOKEN = token("");
3435
static final QueryToken TOKEN_COMMA = token(", ");
3536
static final QueryToken TOKEN_SPACE = token(" ");
3637
static final QueryToken TOKEN_DOT = token(".");

0 commit comments

Comments
 (0)