Skip to content

Commit 8c627ac

Browse files
committed
DATAJDBC-309 - Refactoring.
Refactor SQL rendering from a shared stack-based implementation to independent delegating visitors. Introduce DelegatingVisitor and TypedSubtreeVisitor base classes. Introduce SelectList container. Extract nested renderes to top-level types. TODO: Replace null as delegation signal with Delegation object.
1 parent c4db62e commit 8c627ac

28 files changed

+1796
-659
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class DefaultSelect implements Select {
3131

3232
private final boolean distinct;
33-
private final List<Expression> selectList;
33+
private final SelectList selectList;
3434
private final From from;
3535
private final long limit;
3636
private final long offset;
@@ -42,7 +42,7 @@ class DefaultSelect implements Select {
4242
List<Join> joins, @Nullable Condition where, List<OrderByField> orderBy) {
4343

4444
this.distinct = distinct;
45-
this.selectList = new ArrayList<>(selectList);
45+
this.selectList = new SelectList(new ArrayList<>(selectList));
4646
this.from = new From(from);
4747
this.limit = limit;
4848
this.offset = offset;
@@ -85,7 +85,7 @@ public void visit(Visitor visitor) {
8585

8686
visitor.enter(this);
8787

88-
selectList.forEach(it -> it.visit(visitor));
88+
selectList.visit(visitor);
8989
from.visit(visitor);
9090
joins.forEach(it -> it.visit(visitor));
9191

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
*/
3636
public interface Select extends Segment, Visitable {
3737

38-
3938
/**
4039
* Creates a new {@link SelectBuilder}.
4140
*
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2019 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+
* http://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+
package org.springframework.data.relational.core.sql;
17+
18+
import java.util.List;
19+
20+
import org.springframework.util.Assert;
21+
import org.springframework.util.StringUtils;
22+
23+
/**
24+
* @author Mark Paluch
25+
*/
26+
public class SelectList extends AbstractSegment {
27+
28+
private final List<Expression> selectList;
29+
30+
SelectList(List<Expression> selectList) {
31+
super(selectList.toArray(new Expression[0]));
32+
this.selectList = selectList;
33+
}
34+
35+
@Override
36+
public void visit(Visitor visitor) {
37+
38+
Assert.notNull(visitor, "Visitor must not be null!");
39+
40+
visitor.enter(this);
41+
for (Segment child : selectList) {
42+
child.visit(visitor);
43+
}
44+
visitor.leave(this);
45+
}
46+
47+
/*
48+
* (non-Javadoc)
49+
* @see java.lang.Object#toString()
50+
*/
51+
@Override
52+
public String toString() {
53+
return StringUtils.collectionToDelimitedString(selectList, ", ");
54+
}
55+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @author Jens Schauder
2222
*/
23-
class SubselectExpression extends AbstractSegment implements Expression {
23+
public class SubselectExpression extends AbstractSegment implements Expression {
2424

2525
private final Select subselect;
2626

0 commit comments

Comments
 (0)