Skip to content

Commit de7dd80

Browse files
committed
Polishing.
Refine JOIN and function keyword rendering. See #3692
1 parent fd878f3 commit de7dd80

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

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public QueryRendererBuilder visitJoin(HqlParser.JoinContext ctx) {
160160

161161
QueryRendererBuilder builder = QueryRenderer.builder();
162162

163+
builder.append(TOKEN_SPACE);
163164
builder.appendExpression(visit(ctx.joinType()));
164165
builder.append(QueryTokens.expression(ctx.JOIN()));
165166

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ public QueryTokenStream visitEntityWithJoins(HqlParser.EntityWithJoinsContext ct
336336

337337
QueryRendererBuilder builder = QueryRenderer.builder();
338338

339-
builder.appendExpression(visit(ctx.fromRoot()));
340-
builder.appendInline(QueryTokenStream.concat(ctx.joinSpecifier(), this::visit, TOKEN_SPACE));
339+
builder.appendInline(visit(ctx.fromRoot()));
340+
builder.appendInline(QueryTokenStream.concat(ctx.joinSpecifier(), this::visit, EMPTY_TOKEN));
341341

342342
return builder;
343343
}
@@ -396,6 +396,7 @@ public QueryTokenStream visitJoin(HqlParser.JoinContext ctx) {
396396

397397
QueryRendererBuilder builder = QueryRenderer.builder();
398398

399+
builder.append(TOKEN_SPACE);
399400
builder.append(visit(ctx.joinType()));
400401
builder.append(QueryTokens.expression(ctx.JOIN()));
401402

@@ -753,7 +754,7 @@ public QueryTokenStream visitOffsetClause(HqlParser.OffsetClauseContext ctx) {
753754
QueryRendererBuilder builder = QueryRenderer.builder();
754755

755756
builder.append(QueryTokens.expression(ctx.OFFSET()));
756-
builder.append(visit(ctx.parameterOrIntegerLiteral()));
757+
builder.appendExpression(visit(ctx.parameterOrIntegerLiteral()));
757758

758759
if (ctx.ROW() != null) {
759760
builder.append(QueryTokens.expression(ctx.ROW()));
@@ -3384,7 +3385,7 @@ public QueryTokenStream visitEveryFunction(HqlParser.EveryFunctionContext ctx) {
33843385
builder.append(TOKEN_CLOSE_PAREN);
33853386
} else {
33863387

3387-
builder.appendExpression(visit(ctx.collectionQuantifier()));
3388+
builder.append(visit(ctx.collectionQuantifier()));
33883389

33893390
builder.append(TOKEN_OPEN_PAREN);
33903391
builder.appendInline(visit(ctx.simplePath()));
@@ -3419,7 +3420,7 @@ public QueryTokenStream visitAnyFunction(HqlParser.AnyFunctionContext ctx) {
34193420
builder.append(TOKEN_CLOSE_PAREN);
34203421
} else {
34213422

3422-
builder.appendExpression(visit(ctx.collectionQuantifier()));
3423+
builder.append(visit(ctx.collectionQuantifier()));
34233424

34243425
builder.append(TOKEN_OPEN_PAREN);
34253426
builder.appendInline(visit(ctx.simplePath()));
@@ -3808,9 +3809,9 @@ public QueryTokenStream visitInList(HqlParser.InListContext ctx) {
38083809
if (ctx.simplePath() != null) {
38093810

38103811
if (ctx.ELEMENTS() != null) {
3811-
builder.append(QueryTokens.expression(ctx.ELEMENTS()));
3812+
builder.append(QueryTokens.token(ctx.ELEMENTS()));
38123813
} else if (ctx.INDICES() != null) {
3813-
builder.append(QueryTokens.expression(ctx.INDICES()));
3814+
builder.append(QueryTokens.token(ctx.INDICES()));
38143815
}
38153816

38163817
builder.append(TOKEN_OPEN_PAREN);
@@ -3843,9 +3844,9 @@ public QueryTokenStream visitExistsExpression(HqlParser.ExistsExpressionContext
38433844
builder.append(QueryTokens.expression(ctx.EXISTS()));
38443845

38453846
if (ctx.ELEMENTS() != null) {
3846-
builder.append(QueryTokens.expression(ctx.ELEMENTS()));
3847+
builder.append(QueryTokens.token(ctx.ELEMENTS()));
38473848
} else if (ctx.INDICES() != null) {
3848-
builder.append(QueryTokens.expression(ctx.INDICES()));
3849+
builder.append(QueryTokens.token(ctx.INDICES()));
38493850
}
38503851

38513852
builder.append(TOKEN_OPEN_PAREN);

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

+1
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)