Skip to content

Commit edec1ce

Browse files
committed
DATAJDBC-309 - Polishing.
1 parent e85199c commit edec1ce

File tree

19 files changed

+147
-74
lines changed

19 files changed

+147
-74
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ abstract class AbstractSegment implements Segment {
2626

2727
private final Segment[] children;
2828

29-
protected AbstractSegment(Segment ... children) {
29+
protected AbstractSegment(Segment... children) {
3030
this.children = children;
3131
}
3232

33+
/*
34+
* (non-Javadoc)
35+
* @see org.springframework.data.relational.core.sql.Visitable#visit(org.springframework.data.relational.core.sql.Visitor)
36+
*/
3337
@Override
3438
public void visit(Visitor visitor) {
3539

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

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

2525
private final Expression expression;
2626
private final String alias;
@@ -33,11 +33,19 @@ public AliasedExpression(Expression expression, String alias) {
3333
this.alias = alias;
3434
}
3535

36+
/*
37+
* (non-Javadoc)
38+
* @see org.springframework.data.relational.core.sql.Aliased#getAlias()
39+
*/
3640
@Override
3741
public String getAlias() {
3842
return alias;
3943
}
4044

45+
/*
46+
* (non-Javadoc)
47+
* @see java.lang.Object#toString()
48+
*/
4149
@Override
4250
public String toString() {
4351
return expression.toString() + " AS " + alias;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ public class AndCondition extends MultipleCondition {
2626
AndCondition(Condition... conditions) {
2727
super(" AND ", conditions);
2828
}
29-
3029
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package org.springframework.data.relational.core.sql;
1717

18-
import org.springframework.util.Assert;
19-
2018
/**
2119
* {@link Segment} to select all columns from a {@link Table}.
2220
* <p/>
23-
* * Renders to: {@code <table>.*} as in {@code SELECT <table>.* FROM …}.
21+
* * Renders to: {@code
22+
* <table>
23+
* .*} as in {@code SELECT
24+
* <table>
25+
* .* FROM …}.
2426
*
2527
* @author Mark Paluch
2628
* @see Table#asterisk()
@@ -45,6 +47,10 @@ public Table getTable() {
4547
return table;
4648
}
4749

50+
/*
51+
* (non-Javadoc)
52+
* @see java.lang.Object#toString()
53+
*/
4854
@Override
4955
public String toString() {
5056

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
/**
1919
* {@code IN} {@link Condition} clause.
2020
*
21-
* @author Jens Schauder
22-
* TODO: Accept multiple Expressions.
21+
* @author Jens Schauder TODO: Accept multiple Expressions.
2322
*/
2423
public class In extends AbstractSegment implements Condition {
2524

@@ -38,6 +37,10 @@ public static Condition create(Expression columnOrExpression, Expression arg) {
3837
return new In(columnOrExpression, arg);
3938
}
4039

40+
/*
41+
* (non-Javadoc)
42+
* @see java.lang.Object#toString()
43+
*/
4144
@Override
4245
public String toString() {
4346
return left + " IN " + right;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ private IsNull(Expression expression, boolean negated) {
4040
this.negated = negated;
4141
}
4242

43+
/**
44+
* Creates a new {@link IsNull} expression.
45+
*
46+
* @param expression must not be {@literal null}.
47+
* @return
48+
*/
4349
public static IsNull create(Expression expression) {
4450

4551
Assert.notNull(expression, "Expression must not be null");
4652

4753
return new IsNull(expression);
4854
}
4955

56+
/*
57+
* (non-Javadoc)
58+
* @see org.springframework.data.relational.core.sql.Condition#not()
59+
*/
5060
@Override
5161
public Condition not() {
5262
return new IsNull(expression, !negated);
@@ -56,6 +66,10 @@ public boolean isNegated() {
5666
return negated;
5767
}
5868

69+
/*
70+
* (non-Javadoc)
71+
* @see java.lang.Object#toString()
72+
*/
5973
@Override
6074
public String toString() {
6175
return expression + (negated ? " IS NOT NULL" : " IS NULL");

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,26 @@ public class Not extends AbstractSegment implements Condition {
2222

2323
private final Condition condition;
2424

25-
public Not(Condition condition) {
25+
Not(Condition condition) {
2626

2727
super(condition);
2828

2929
this.condition = condition;
3030
}
3131

32+
/*
33+
* (non-Javadoc)
34+
* @see org.springframework.data.relational.core.sql.Condition#not()
35+
*/
3236
@Override
3337
public Condition not() {
3438
return condition;
3539
}
3640

41+
/*
42+
* (non-Javadoc)
43+
* @see java.lang.Object#toString()
44+
*/
3745
@Override
3846
public String toString() {
3947
return "NOT " + condition.toString();

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

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,22 @@
1616
package org.springframework.data.relational.core.sql;
1717

1818
import org.springframework.data.relational.core.sql.BindMarker.NamedBindMarker;
19-
import org.springframework.data.relational.core.sql.SelectBuilder.SelectAndFrom;
2019
import org.springframework.util.Assert;
2120

2221
/**
23-
* Utility to create SQL {@link Segment}s. Typically used as entry point to the Query Builder AST.
22+
* Utility to create SQL {@link Segment}s. Typically used as entry point to the Statement Builder.
2423
* Objects and dependent objects created by the Query AST are immutable except for builders.
25-
* <p/>The Query Builder API is intended for framework usage to produce SQL required for framework operations.
24+
* <p/>The Statement Builder API is intended for framework usage to produce SQL required for framework operations.
2625
*
2726
* @author Mark Paluch
2827
* @author Jens Schauder
2928
* @see Expressions
3029
* @see Conditions
3130
* @see Functions
31+
* @see StatementBuilder
3232
*/
3333
public abstract class SQL {
3434

35-
/**
36-
* Creates a new {@link SelectBuilder} by specifying a {@code SELECT} column.
37-
*
38-
* @param expression the select list expression.
39-
* @return the {@link SelectBuilder} containing {@link Expression}.
40-
* @see SelectBuilder#select(Expression)
41-
*/
42-
public static SelectAndFrom newSelect(Expression expression) {
43-
return Select.builder().select(expression);
44-
}
45-
46-
/**
47-
* Creates a new {@link SelectBuilder} by specifying one or more {@code SELECT} columns.
48-
*
49-
* @param expressions the select list expressions.
50-
* @return the {@link SelectBuilder} containing {@link Expression}s.
51-
* @see SelectBuilder#select(Expression...)
52-
*/
53-
public static SelectAndFrom newSelect(Expression... expressions) {
54-
return Select.builder().select(expressions);
55-
}
56-
57-
/**
58-
* Creates a new {@link SelectBuilder}.
59-
*
60-
* @return the new {@link SelectBuilder}.
61-
* @see SelectBuilder
62-
*/
63-
public static SelectBuilder select() {
64-
return Select.builder();
65-
}
66-
6735
/**
6836
* Creates a new {@link Column} associated with a source {@link Table}.
6937
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* </ol>
3131
*
3232
* @author Mark Paluch
33+
* @see StatementBuilder
3334
* @see SelectBuilder
3435
* @see SQL
3536
*/

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
import java.util.List;
1919

20-
import org.springframework.util.Assert;
2120
import org.springframework.util.StringUtils;
2221

2322
/**
23+
* Value object representing the select list (selected columns, functions).
24+
*
2425
* @author Mark Paluch
2526
*/
2627
public class SelectList extends AbstractSegment {
@@ -32,18 +33,6 @@ public class SelectList extends AbstractSegment {
3233
this.selectList = selectList;
3334
}
3435

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-
4736
/*
4837
* (non-Javadoc)
4938
* @see java.lang.Object#toString()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.relational.core.sql;
1717

18-
import org.springframework.util.Assert;
19-
2018
/**
2119
* Simple condition consisting of {@link Expression}, {@code comparator} and {@code predicate}.
2220
*

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ static class AliasedFunction extends SimpleFunction implements Aliased {
9494
this.alias = alias;
9595
}
9696

97+
/*
98+
* (non-Javadoc)
99+
* @see org.springframework.data.relational.core.sql.Aliased#getAlias()
100+
*/
97101
@Override
98102
public String getAlias() {
99103
return alias;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 org.springframework.data.relational.core.sql.SelectBuilder.SelectAndFrom;
19+
20+
/**
21+
* Entrypoint to build SQL statements.
22+
*
23+
* @author Mark Paluch
24+
* @see SQL
25+
* @see Expressions
26+
* @see Conditions
27+
* @see Functions
28+
*/
29+
public abstract class StatementBuilder {
30+
31+
/**
32+
* Creates a new {@link SelectBuilder} by specifying a {@code SELECT} column.
33+
*
34+
* @param expression the select list expression.
35+
* @return the {@link SelectBuilder} containing {@link Expression}.
36+
* @see SelectBuilder#select(Expression)
37+
*/
38+
public static SelectAndFrom select(Expression expression) {
39+
return Select.builder().select(expression);
40+
}
41+
42+
/**
43+
* Creates a new {@link SelectBuilder} by specifying one or more {@code SELECT} columns.
44+
*
45+
* @param expressions the select list expressions.
46+
* @return the {@link SelectBuilder} containing {@link Expression}s.
47+
* @see SelectBuilder#select(Expression...)
48+
*/
49+
public static SelectAndFrom select(Expression... expressions) {
50+
return Select.builder().select(expressions);
51+
}
52+
53+
/**
54+
* Creates a new {@link SelectBuilder}.
55+
*
56+
* @return the new {@link SelectBuilder}.
57+
* @see SelectBuilder
58+
*/
59+
public static SelectBuilder select() {
60+
return Select.builder();
61+
}
62+
63+
private StatementBuilder() {
64+
65+
}
66+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class SubselectExpression extends AbstractSegment implements Expression {
3131
this.subselect = subselect;
3232
}
3333

34+
/*
35+
* (non-Javadoc)
36+
* @see java.lang.Object#toString()
37+
*/
3438
@Override
3539
public String toString() {
3640
return "(" + subselect.toString() + ")";

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.relational.core.sql;
1717

18-
import org.springframework.util.Assert;
19-
2018
/**
2119
* {@code Where} clause.
2220
*
@@ -33,6 +31,10 @@ public class Where extends AbstractSegment {
3331
this.condition = condition;
3432
}
3533

34+
/*
35+
* (non-Javadoc)
36+
* @see java.lang.Object#toString()
37+
*/
3638
@Override
3739
public String toString() {
3840
return "WHERE " + condition.toString();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/**
3-
* Statement Builder implementation. Use {@link org.springframework.data.relational.core.sql.SQL} as entry point to create SQL objects. Objects and dependent objects created by the Query AST are immutable except for builders.
3+
* Statement Builder implementation. Use {@link org.springframework.data.relational.core.sql.StatementBuilder} to create statements and {@link org.springframework.data.relational.core.sql.SQL} to create SQL objects. Objects and dependent objects created by the Statement Builder are immutable except for builders.
44
* <p/> The Statement Builder API is intended for framework usage to produce SQL required for framework operations.
55
*/
66
@NonNullApi

0 commit comments

Comments
 (0)