Skip to content

Commit fe181e1

Browse files
schaudermp911de
authored andcommitted
Fix broken join conditions with InlineQuery.
Before this fix, whenever a column of an inline query was rendered the `InlineQuery` and all its children were visited, resulting in spurious output. This is no prevented by injecting a NoopVisitor. Closes: #1362 Original pull request: #1368
1 parent 59a114a commit fe181e1

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/ComparisonVisitor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class ComparisonVisitor extends FilteredSubtreeVisitor {
3939
private @Nullable PartRenderer current;
4040

4141
ComparisonVisitor(RenderContext context, Comparison condition, RenderTarget target) {
42+
4243
super(it -> it == condition);
44+
4345
this.condition = condition;
4446
this.target = target;
4547
this.context = context;
@@ -52,12 +54,6 @@ class ComparisonVisitor extends FilteredSubtreeVisitor {
5254
@Override
5355
Delegation enterNested(Visitable segment) {
5456

55-
if (segment instanceof Condition) {
56-
ConditionVisitor visitor = new ConditionVisitor(context);
57-
current = visitor;
58-
return Delegation.delegateTo(visitor);
59-
}
60-
6157
if (segment instanceof Expression) {
6258
ExpressionVisitor visitor = new ExpressionVisitor(context);
6359
current = visitor;

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/ExpressionVisitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ Delegation enterNested(Visitable segment) {
131131
return Delegation.delegateTo(visitor);
132132
}
133133

134+
if (segment instanceof InlineQuery) {
135+
136+
NoopVisitor<InlineQuery> partRenderer = new NoopVisitor(InlineQuery.class);
137+
return Delegation.delegateTo(partRenderer);
138+
}
134139
return super.enterNested(segment);
135140
}
136141

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.relational.core.sql.render;
18+
19+
20+
import org.springframework.data.relational.core.sql.Visitable;
21+
22+
class NoopVisitor<T extends Visitable> extends TypedSubtreeVisitor<T> {
23+
NoopVisitor(Class<T> type) {
24+
super(type);
25+
}
26+
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/render/TypedSubtreeVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ abstract class TypedSubtreeVisitor<T extends Visitable> extends DelegatingVisito
5353
this.type = ResolvableType.forClass(getClass()).as(TypedSubtreeVisitor.class).getGeneric(0);
5454
}
5555

56+
/**
57+
* Creates a new {@link TypedSubtreeVisitor} with an explicitly provided type.
58+
*/
59+
TypedSubtreeVisitor(Class <T> type) {
60+
this.type = ResolvableType.forType(type);
61+
}
62+
5663
/**
5764
* {@link Visitor#enter(Visitable) Enter} callback for a {@link Visitable} that this {@link Visitor} is responsible
5865
* for. The default implementation retains delegation by default.

0 commit comments

Comments
 (0)