Skip to content

Commit c4db62e

Browse files
committed
DATAJDBC-309 - Polishing.
Javadoc, static factory methods, typos.
1 parent 3235158 commit c4db62e

File tree

19 files changed

+271
-165
lines changed

19 files changed

+271
-165
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Column aliased(String name, Table table, String alias) {
7272
}
7373

7474
/**
75-
* Create a new aliased {@link Column}.
75+
* Creates a new aliased {@link Column}.
7676
*
7777
* @param alias column alias name, must not {@literal null} or empty.
7878
* @return the aliased {@link Column}.
@@ -85,7 +85,7 @@ public Column as(String alias) {
8585
}
8686

8787
/**
88-
* Create a new {@link Column} associated with a {@link Table}.
88+
* Creates a new {@link Column} associated with a {@link Table}.
8989
*
9090
* @param table the table, must not be {@literal null}.
9191
* @return a new {@link Column} associated with {@link Table}.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* AST {@link Segment} for a condition.
2020
*
2121
* @author Mark Paluch
22+
* @author Jens Schauder
2223
* @see Conditions
2324
*/
2425
public interface Condition extends Segment {
@@ -43,6 +44,11 @@ default Condition or(Condition other) {
4344
return new OrCondition(this, other);
4445
}
4546

47+
/**
48+
* Creates a {@link Condition} that negates this {@link Condition}.
49+
*
50+
* @return the negated {@link Condition}.
51+
*/
4652
default Condition not() {
4753
return new Not(this);
4854
}

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

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

18+
import org.springframework.util.Assert;
19+
1820
/**
1921
* Factory for common {@link Condition}s.
2022
*
2123
* @author Mark Paluch
24+
* @author Jens Schauder
2225
* @see SQL
2326
* @see Expressions
2427
* @see Functions
2528
*/
2629
public abstract class Conditions {
2730

28-
/**
29-
* @return a new {@link Equals} condition.
30-
*/
31-
public static Equals equals(Expression left, Expression right) {
32-
return Equals.create(left, right);
33-
}
34-
3531
/**
3632
* Creates a plain {@code sql} {@link Condition}.
3733
*
@@ -42,20 +38,55 @@ public static Condition just(String sql) {
4238
return new ConstantCondition(sql);
4339
}
4440

45-
// Utility constructor.
46-
private Conditions() {
41+
/**
42+
* Creates a {@code IS NULL} condition.
43+
*
44+
* @param expression the expression to check for nullability, must not be {@literal null}.
45+
* @return the {@code IS NULL} condition.
46+
*/
47+
public static Condition isNull(Expression expression) {
48+
return IsNull.create(expression);
4749
}
4850

49-
public static Condition isNull(Expression expression) {
50-
return new IsNull(expression);
51+
/**
52+
* Creates a {@code =} (equals) {@link Condition}.
53+
*
54+
* @param leftColumnOrExpression left side of the comparison.
55+
* @param rightColumnOrExpression right side of the comparison.
56+
* @return the {@link Equals} condition.
57+
*/
58+
public static Equals isEqual(Expression leftColumnOrExpression, Expression rightColumnOrExpression) {
59+
return Equals.create(leftColumnOrExpression, rightColumnOrExpression);
5160
}
5261

53-
public static Condition isEqual(Column bar, Expression param) {
54-
return new Equals(bar, param);
62+
/**
63+
* Creates a {@code IN} {@link Condition clause}.
64+
*
65+
* @param columnOrExpression left side of the comparison.
66+
* @param arg IN argument.
67+
* @return the {@link In} condition.
68+
*/
69+
public static Condition in(Expression columnOrExpression, Expression arg) {
70+
71+
Assert.notNull(columnOrExpression, "Comparison column or expression must not be null");
72+
Assert.notNull(columnOrExpression, "Expression argument must not be null");
73+
74+
return In.create(columnOrExpression, arg);
5575
}
5676

57-
public static Condition in(Column bar, Expression subselectExpression) {
58-
return new In(bar, subselectExpression);
77+
/**
78+
* Creates a {@code IN} {@link Condition clause} for a {@link Select subselect}.
79+
*
80+
* @param Column the column to compare.
81+
* @param subselect the subselect.
82+
* @return the {@link In} condition.
83+
*/
84+
public static Condition in(Column column, Select subselect) {
85+
86+
Assert.notNull(column, "Column must not be null");
87+
Assert.notNull(subselect, "Subselect must not be null");
88+
89+
return in(column, new SubselectExpression(subselect));
5990
}
6091

6192
static class ConstantCondition extends AbstractSegment implements Condition {
@@ -71,6 +102,10 @@ public String toString() {
71102
return condition;
72103
}
73104
}
105+
106+
// Utility constructor.
107+
private Conditions() {
108+
}
74109
}
75110

76111

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Equals extends AbstractSegment implements Condition {
2929
private final Expression left;
3030
private final Expression right;
3131

32-
Equals(Expression left, Expression right) {
32+
private Equals(Expression left, Expression right) {
3333

3434
super(left, right);
3535

@@ -44,12 +44,12 @@ public class Equals extends AbstractSegment implements Condition {
4444
* @param right the right {@link Expression}.
4545
* @return the {@link Equals} condition.
4646
*/
47-
public static Equals create(Expression left, Expression right) {
47+
public static Equals create(Expression leftColumnOrExpression, Expression rightColumnOrExpression) {
4848

49-
Assert.notNull(left, "Left expression must not be null!");
50-
Assert.notNull(right, "Right expression must not be null!");
49+
Assert.notNull(leftColumnOrExpression, "Left expression must not be null!");
50+
Assert.notNull(rightColumnOrExpression, "Right expression must not be null!");
5151

52-
return new Equals(left, right);
52+
return new Equals(leftColumnOrExpression, rightColumnOrExpression);
5353
}
5454

5555
/**

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static SimpleFunction count(Column... columns) {
4242
Assert.notNull(columns, "Columns must not be null!");
4343
Assert.notEmpty(columns, "Columns must contains at least one column");
4444

45-
return new SimpleFunction("COUNT", Arrays.asList(columns));
45+
return SimpleFunction.create("COUNT", Arrays.asList(columns));
4646
}
4747

4848
/**
@@ -55,9 +55,10 @@ public static SimpleFunction count(Collection<? extends Expression> columns) {
5555

5656
Assert.notNull(columns, "Columns must not be null!");
5757

58-
return new SimpleFunction("COUNT", new ArrayList<>(columns));
58+
return SimpleFunction.create("COUNT", new ArrayList<>(columns));
5959
}
6060

6161
// Utility constructor.
62-
private Functions() {}
62+
private Functions() {
63+
}
6364
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,28 @@
1616
package org.springframework.data.relational.core.sql;
1717

1818
/**
19+
* {@code IN} {@link Condition} clause.
20+
*
1921
* @author Jens Schauder
22+
* TODO: Accept multiple Expressions.
2023
*/
2124
public class In extends AbstractSegment implements Condition {
2225

2326
private final Expression left;
2427
private final Expression right;
2528

26-
public In(Expression left, Expression right) {
29+
private In(Expression left, Expression right) {
2730

2831
super(left, right);
2932

3033
this.left = left;
3134
this.right = right;
3235
}
3336

37+
public static Condition create(Expression columnOrExpression, Expression arg) {
38+
return new In(columnOrExpression, arg);
39+
}
40+
3441
@Override
3542
public String toString() {
3643
return left + " IN " + right;

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

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

18+
import org.springframework.util.Assert;
19+
1820
/**
21+
* {@code IS NULL} {@link Condition}.
22+
*
1923
* @author Jens Schauder
2024
*/
2125
public class IsNull extends AbstractSegment implements Condition {
@@ -24,29 +28,36 @@ public class IsNull extends AbstractSegment implements Condition {
2428

2529
private final boolean negated;
2630

27-
public IsNull(Expression expression, boolean negated) {
31+
private IsNull(Expression expression) {
32+
this(expression, false);
33+
}
34+
35+
private IsNull(Expression expression, boolean negated) {
2836

2937
super(expression);
3038

3139
this.expression = expression;
3240
this.negated = negated;
3341
}
3442

35-
public IsNull(Expression expression) {
36-
this(expression, false);
43+
public static IsNull create(Expression expression) {
44+
45+
Assert.notNull(expression, "Expression must not be null");
46+
47+
return new IsNull(expression);
3748
}
3849

3950
@Override
4051
public Condition not() {
4152
return new IsNull(expression, !negated);
4253
}
4354

55+
public boolean isNegated() {
56+
return negated;
57+
}
58+
4459
@Override
4560
public String toString() {
4661
return expression + (negated ? " IS NOT NULL" : " IS NULL");
4762
}
48-
49-
public boolean isNegated() {
50-
return negated;
51-
}
5263
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import java.util.List;
2020
import java.util.StringJoiner;
2121

22-
import org.springframework.util.Assert;
23-
2422
/**
23+
* Wrapper for multiple {@link Condition}s.
24+
*
2525
* @author Jens Schauder
2626
*/
2727
public abstract class MultipleCondition extends AbstractSegment implements Condition {

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.springframework.util.Assert;
2323

2424
/**
25+
* Represents a field in the {@code ORDER BY} clause.
26+
*
2527
* @author Mark Paluch
2628
*/
2729
public class OrderByField extends AbstractSegment {
@@ -30,7 +32,7 @@ public class OrderByField extends AbstractSegment {
3032
private final @Nullable Sort.Direction direction;
3133
private final Sort.NullHandling nullHandling;
3234

33-
OrderByField(Expression expression, Direction direction, NullHandling nullHandling) {
35+
OrderByField(Expression expression, @Nullable Direction direction, NullHandling nullHandling) {
3436

3537
super(expression);
3638
Assert.notNull(expression, "Order by expression must not be null");
@@ -41,18 +43,42 @@ public class OrderByField extends AbstractSegment {
4143
this.nullHandling = nullHandling;
4244
}
4345

46+
/**
47+
* Creates a new {@link OrderByField} from a {@link Column} applying default ordering.
48+
*
49+
* @param column must not be {@literal null}.
50+
* @return the {@link OrderByField}.
51+
*/
4452
public static OrderByField from(Column column) {
4553
return new OrderByField(column, null, NullHandling.NATIVE);
4654
}
4755

56+
/**
57+
* Creates a new {@link OrderByField} from a the current one using ascending sorting.
58+
*
59+
* @return the new {@link OrderByField} with ascending sorting.
60+
* @see #desc()
61+
*/
4862
public OrderByField asc() {
49-
return new OrderByField(expression, Direction.ASC, NullHandling.NATIVE);
63+
return new OrderByField(expression, Direction.ASC, nullHandling);
5064
}
5165

66+
/**
67+
* Creates a new {@link OrderByField} from a the current one using descending sorting.
68+
*
69+
* @return the new {@link OrderByField} with descending sorting.
70+
* @see #asc()
71+
*/
5272
public OrderByField desc() {
53-
return new OrderByField(expression, Direction.DESC, NullHandling.NATIVE);
73+
return new OrderByField(expression, Direction.DESC, nullHandling);
5474
}
5575

76+
/**
77+
* Creates a new {@link OrderByField} with {@link NullHandling} applied.
78+
*
79+
* @param nullHandling must not be {@literal null}.
80+
* @return the new {@link OrderByField} with {@link NullHandling} applied.
81+
*/
5682
public OrderByField withNullHandling(NullHandling nullHandling) {
5783
return new OrderByField(expression, direction, nullHandling);
5884
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* <p/>The Query Builder API is intended for framework usage to produce SQL required for framework operations.
2626
*
2727
* @author Mark Paluch
28+
* @author Jens Schauder
2829
* @see Expressions
2930
* @see Conditions
3031
* @see Functions

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import java.util.Set;
2020

2121
/**
22+
* Validator for {@link Select} statements.
23+
* <p/>
24+
* Validates that all {@link Column}s using a table qualifier have a table import from either the {@code FROM} or {@code JOIN} clause.
25+
*
2226
* @author Mark Paluch
2327
*/
2428
class SelectValidator implements Visitor {
@@ -130,5 +134,6 @@ public void enter(Visitable segment) {
130134
* @see org.springframework.data.relational.core.sql.Visitor#leave(org.springframework.data.relational.core.sql.Visitable)
131135
*/
132136
@Override
133-
public void leave(Visitable segment) {}
137+
public void leave(Visitable segment) {
138+
}
134139
}

0 commit comments

Comments
 (0)