Skip to content

Commit 2f482a6

Browse files
committed
Add @CheckReturnValue to Query and Update API.
Closes #2145
1 parent 2d732d5 commit 2f482a6

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

spring-data-relational/src/main/java/org/springframework/data/relational/core/query/Criteria.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
import org.springframework.data.relational.core.sql.IdentifierProcessing;
2828
import org.springframework.data.relational.core.sql.SqlIdentifier;
2929
import org.springframework.data.util.Pair;
30+
import org.springframework.lang.CheckReturnValue;
3031
import org.springframework.lang.Nullable;
3132
import org.springframework.util.Assert;
3233

3334
/**
34-
* Central class for creating queries. It follows a fluent API style so that you can easily chain together multiple
35-
* criteria. Static import of the {@code Criteria.property(…)} method will improve readability as in
36-
* {@code where(property(…).is(…)}.
35+
* Central value class for creating criteria predicates. It follows a fluent (and immutable) API style so that you can
36+
* easily chain together multiple criteria. Static import of the {@code Criteria.property(…)} method will improve
37+
* readability as in {@code where(property(…).is(…)}.
3738
* <p>
3839
* The Criteria API supports composition with a {@link #empty() NULL object} and a {@link #from(List) static factory
3940
* method}. Example usage:
@@ -161,6 +162,7 @@ public static CriteriaStep where(String column) {
161162
* @param column Must not be {@literal null} or empty.
162163
* @return a new {@link CriteriaStep} object to complete the next {@link Criteria}.
163164
*/
165+
@CheckReturnValue
164166
public CriteriaStep and(String column) {
165167

166168
Assert.hasText(column, "Column name must not be null or empty");
@@ -181,6 +183,7 @@ protected Criteria createCriteria(Comparator comparator, @Nullable Object value)
181183
* @return a new {@link Criteria} object.
182184
* @since 1.1
183185
*/
186+
@CheckReturnValue
184187
public Criteria and(CriteriaDefinition criteria) {
185188

186189
Assert.notNull(criteria, "Criteria must not be null");
@@ -195,6 +198,7 @@ public Criteria and(CriteriaDefinition criteria) {
195198
* @return a new {@link Criteria} object.
196199
*/
197200
@SuppressWarnings("unchecked")
201+
@CheckReturnValue
198202
public Criteria and(List<? extends CriteriaDefinition> criteria) {
199203

200204
Assert.notNull(criteria, "Criteria must not be null");
@@ -208,6 +212,7 @@ public Criteria and(List<? extends CriteriaDefinition> criteria) {
208212
* @param column Must not be {@literal null} or empty.
209213
* @return a new {@link CriteriaStep} object to complete the next {@link Criteria}.
210214
*/
215+
@CheckReturnValue
211216
public CriteriaStep or(String column) {
212217

213218
Assert.hasText(column, "Column name must not be null or empty");
@@ -228,6 +233,7 @@ protected Criteria createCriteria(Comparator comparator, @Nullable Object value)
228233
* @return a new {@link Criteria} object.
229234
* @since 1.1
230235
*/
236+
@CheckReturnValue
231237
public Criteria or(CriteriaDefinition criteria) {
232238

233239
Assert.notNull(criteria, "Criteria must not be null");
@@ -243,6 +249,7 @@ public Criteria or(CriteriaDefinition criteria) {
243249
* @since 1.1
244250
*/
245251
@SuppressWarnings("unchecked")
252+
@CheckReturnValue
246253
public Criteria or(List<? extends CriteriaDefinition> criteria) {
247254

248255
Assert.notNull(criteria, "Criteria must not be null");
@@ -256,6 +263,7 @@ public Criteria or(List<? extends CriteriaDefinition> criteria) {
256263
* @param ignoreCase {@literal true} if comparison should be done in case-insensitive way
257264
* @return a new {@link Criteria} object
258265
*/
266+
@CheckReturnValue
259267
public Criteria ignoreCase(boolean ignoreCase) {
260268
if (this.ignoreCase != ignoreCase) {
261269
return new Criteria(previous, combinator, group, column, comparator, value, ignoreCase);

spring-data-relational/src/main/java/org/springframework/data/relational/core/query/CriteriaDefinition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @author Mark Paluch
3030
* @author Jens Schauder
3131
* @since 2.0
32+
* @see Criteria
3233
*/
3334
public interface CriteriaDefinition {
3435

spring-data-relational/src/main/java/org/springframework/data/relational/core/query/Query.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
import org.springframework.data.domain.Pageable;
2727
import org.springframework.data.domain.Sort;
2828
import org.springframework.data.relational.core.sql.SqlIdentifier;
29+
import org.springframework.lang.CheckReturnValue;
2930
import org.springframework.lang.Nullable;
3031
import org.springframework.util.Assert;
3132

3233
/**
33-
* Query object representing {@link Criteria}, columns, {@link Sort}, and limit/offset for a SQL query. {@link Query} is
34-
* created with a fluent API creating immutable objects.
34+
* Query object representing {@link Criteria}, columns, {@link Sort}, and limit/offset for a SQL query. Methods on this
35+
* class are designed to be used in a fluent style creating immutable objects.
3536
*
3637
* @author Mark Paluch
3738
* @since 2.0
@@ -93,6 +94,7 @@ public static Query empty() {
9394
* @param columns
9495
* @return a new {@link Query} object containing the former settings with {@code columns} applied.
9596
*/
97+
@CheckReturnValue
9698
public Query columns(String... columns) {
9799

98100
Assert.notNull(columns, "Columns must not be null");
@@ -106,6 +108,7 @@ public Query columns(String... columns) {
106108
* @param columns
107109
* @return a new {@link Query} object containing the former settings with {@code columns} applied.
108110
*/
111+
@CheckReturnValue
109112
public Query columns(Collection<String> columns) {
110113

111114
Assert.notNull(columns, "Columns must not be null");
@@ -120,6 +123,7 @@ public Query columns(Collection<String> columns) {
120123
* @return a new {@link Query} object containing the former settings with {@code columns} applied.
121124
* @since 1.1
122125
*/
126+
@CheckReturnValue
123127
public Query columns(SqlIdentifier... columns) {
124128

125129
Assert.notNull(columns, "Columns must not be null");
@@ -148,6 +152,7 @@ private Query withColumns(Collection<SqlIdentifier> columns) {
148152
* @param offset
149153
* @return a new {@link Query} object containing the former settings with {@code offset} applied.
150154
*/
155+
@CheckReturnValue
151156
public Query offset(long offset) {
152157
return new Query(this.criteria, this.columns, this.sort, this.limit, offset);
153158
}
@@ -158,6 +163,7 @@ public Query offset(long offset) {
158163
* @param limit
159164
* @return a new {@link Query} object containing the former settings with {@code limit} applied.
160165
*/
166+
@CheckReturnValue
161167
public Query limit(int limit) {
162168
return new Query(this.criteria, this.columns, this.sort, limit, this.offset);
163169
}
@@ -169,6 +175,7 @@ public Query limit(int limit) {
169175
* @param pageable
170176
* @return a new {@link Query} object containing the former settings with {@link Pageable} applied.
171177
*/
178+
@CheckReturnValue
172179
public Query with(Pageable pageable) {
173180

174181
assertNoCaseSort(pageable.getSort());
@@ -187,6 +194,7 @@ public Query with(Pageable pageable) {
187194
* @param sort
188195
* @return a new {@link Query} object containing the former settings with {@link Sort} applied.
189196
*/
197+
@CheckReturnValue
190198
public Query sort(Sort sort) {
191199

192200
Assert.notNull(sort, "Sort must not be null");

spring-data-relational/src/main/java/org/springframework/data/relational/core/query/Update.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
import org.springframework.data.relational.core.sql.IdentifierProcessing;
2424
import org.springframework.data.relational.core.sql.SqlIdentifier;
25+
import org.springframework.lang.CheckReturnValue;
2526
import org.springframework.lang.Nullable;
2627
import org.springframework.util.Assert;
2728

2829
/**
29-
* Class to easily construct SQL update assignments.
30+
* Class to easily construct SQL update assignments. Methods on this class are designed to be used in a fluent style
31+
* creating immutable objects.
3032
*
3133
* @author Mark Paluch
3234
* @author Oliver Drotbohm
@@ -70,6 +72,7 @@ public static Update update(String column, @Nullable Object value) {
7072
* @param value can be {@literal null}.
7173
* @return
7274
*/
75+
@CheckReturnValue
7376
public Update set(String column, @Nullable Object value) {
7477

7578
Assert.hasText(column, "Column for update must not be null or blank");
@@ -85,6 +88,7 @@ public Update set(String column, @Nullable Object value) {
8588
* @return
8689
* @since 1.1
8790
*/
91+
@CheckReturnValue
8892
public Update set(SqlIdentifier column, @Nullable Object value) {
8993
return addMultiFieldOperation(column, value);
9094
}

0 commit comments

Comments
 (0)