Skip to content

Commit d5f7ab5

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 e228757 commit d5f7ab5

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;
@@ -48,12 +50,6 @@ class ComparisonVisitor extends FilteredSubtreeVisitor {
4850
@Override
4951
Delegation enterNested(Visitable segment) {
5052

51-
if (segment instanceof Condition) {
52-
ConditionVisitor visitor = new ConditionVisitor(context);
53-
current = visitor;
54-
return Delegation.delegateTo(visitor);
55-
}
56-
5753
if (segment instanceof Expression) {
5854
ExpressionVisitor visitor = new ExpressionVisitor(context);
5955
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
@@ -123,6 +123,11 @@ Delegation enterNested(Visitable segment) {
123123
return Delegation.delegateTo(visitor);
124124
}
125125

126+
if (segment instanceof InlineQuery) {
127+
128+
NoopVisitor<InlineQuery> partRenderer = new NoopVisitor(InlineQuery.class);
129+
return Delegation.delegateTo(partRenderer);
130+
}
126131
return super.enterNested(segment);
127132
}
128133

Lines changed: 26 additions & 0 deletions
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
@@ -54,6 +54,13 @@ abstract class TypedSubtreeVisitor<T extends Visitable> extends DelegatingVisito
5454
this.type = ResolvableType.forClass(getClass()).as(TypedSubtreeVisitor.class).getGeneric(0);
5555
}
5656

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

0 commit comments

Comments
 (0)