Skip to content

Commit f3256b2

Browse files
committed
Add @CheckReturnValue to Query and Update API.
Closes #2145
1 parent 3c0ff9e commit f3256b2

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
@@ -29,12 +29,13 @@
2929
import org.springframework.data.relational.core.sql.IdentifierProcessing;
3030
import org.springframework.data.relational.core.sql.SqlIdentifier;
3131
import org.springframework.data.util.Pair;
32+
import org.springframework.lang.CheckReturnValue;
3233
import org.springframework.util.Assert;
3334

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

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

187190
Assert.notNull(criteria, "Criteria must not be null");
@@ -196,6 +199,7 @@ public Criteria and(CriteriaDefinition criteria) {
196199
* @return a new {@link Criteria} object.
197200
*/
198201
@SuppressWarnings("unchecked")
202+
@CheckReturnValue
199203
public Criteria and(List<? extends CriteriaDefinition> criteria) {
200204

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

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

234240
Assert.notNull(criteria, "Criteria must not be null");
@@ -244,6 +250,7 @@ public Criteria or(CriteriaDefinition criteria) {
244250
* @since 1.1
245251
*/
246252
@SuppressWarnings("unchecked")
253+
@CheckReturnValue
247254
public Criteria or(List<? extends CriteriaDefinition> criteria) {
248255

249256
Assert.notNull(criteria, "Criteria must not be null");
@@ -257,6 +264,7 @@ public Criteria or(List<? extends CriteriaDefinition> criteria) {
257264
* @param ignoreCase {@literal true} if comparison should be done in case-insensitive way
258265
* @return a new {@link Criteria} object
259266
*/
267+
@CheckReturnValue
260268
public Criteria ignoreCase(boolean ignoreCase) {
261269
if (this.ignoreCase != ignoreCase) {
262270
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
@@ -27,11 +27,12 @@
2727
import org.springframework.data.domain.Pageable;
2828
import org.springframework.data.domain.Sort;
2929
import org.springframework.data.relational.core.sql.SqlIdentifier;
30+
import org.springframework.lang.CheckReturnValue;
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
@@ -94,6 +95,7 @@ public static Query empty() {
9495
* @param columns
9596
* @return a new {@link Query} object containing the former settings with {@code columns} applied.
9697
*/
98+
@CheckReturnValue
9799
public Query columns(String... columns) {
98100

99101
Assert.notNull(columns, "Columns must not be null");
@@ -107,6 +109,7 @@ public Query columns(String... columns) {
107109
* @param columns
108110
* @return a new {@link Query} object containing the former settings with {@code columns} applied.
109111
*/
112+
@CheckReturnValue
110113
public Query columns(Collection<String> columns) {
111114

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

126130
Assert.notNull(columns, "Columns must not be null");
@@ -149,6 +153,7 @@ private Query withColumns(Collection<SqlIdentifier> columns) {
149153
* @param offset
150154
* @return a new {@link Query} object containing the former settings with {@code offset} applied.
151155
*/
156+
@CheckReturnValue
152157
public Query offset(long offset) {
153158
return new Query(this.criteria, this.columns, this.sort, this.limit, offset);
154159
}
@@ -159,6 +164,7 @@ public Query offset(long offset) {
159164
* @param limit
160165
* @return a new {@link Query} object containing the former settings with {@code limit} applied.
161166
*/
167+
@CheckReturnValue
162168
public Query limit(int limit) {
163169
return new Query(this.criteria, this.columns, this.sort, limit, this.offset);
164170
}
@@ -170,6 +176,7 @@ public Query limit(int limit) {
170176
* @param pageable
171177
* @return a new {@link Query} object containing the former settings with {@link Pageable} applied.
172178
*/
179+
@CheckReturnValue
173180
public Query with(Pageable pageable) {
174181

175182
assertNoCaseSort(pageable.getSort());
@@ -188,6 +195,7 @@ public Query with(Pageable pageable) {
188195
* @param sort
189196
* @return a new {@link Query} object containing the former settings with {@link Sort} applied.
190197
*/
198+
@CheckReturnValue
191199
public Query sort(Sort sort) {
192200

193201
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
@@ -23,10 +23,12 @@
2323
import org.jspecify.annotations.Nullable;
2424
import org.springframework.data.relational.core.sql.IdentifierProcessing;
2525
import org.springframework.data.relational.core.sql.SqlIdentifier;
26+
import org.springframework.lang.CheckReturnValue;
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)