Skip to content

Commit 74ea7f8

Browse files
committed
Add @CheckReturnValue to Query and Update API.
Closes #1609
1 parent 1116df1 commit 74ea7f8

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/query/Columns.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.data.cassandra.core.convert.CassandraVector;
3030
import org.springframework.data.cassandra.core.mapping.SimilarityFunction;
3131
import org.springframework.data.domain.Vector;
32+
import org.springframework.lang.CheckReturnValue;
3233
import org.springframework.lang.Nullable;
3334
import org.springframework.util.Assert;
3435
import org.springframework.util.ObjectUtils;
@@ -111,6 +112,7 @@ public static Columns from(CqlIdentifier... columnNames) {
111112
* @param columnName must not be {@literal null}.
112113
* @return a new {@link Columns} object containing all column definitions and the included {@code columnName}.
113114
*/
115+
@CheckReturnValue
114116
public Columns include(String columnName) {
115117
return select(columnName, ColumnSelector.from(columnName));
116118
}
@@ -122,6 +124,7 @@ public Columns include(String columnName) {
122124
* @param columnName must not be {@literal null}.
123125
* @return a new {@link Columns} object containing all column definitions and the included {@code columnName}.
124126
*/
127+
@CheckReturnValue
125128
public Columns include(CqlIdentifier columnName) {
126129
return select(columnName, ColumnSelector.from(columnName));
127130
}
@@ -133,6 +136,7 @@ public Columns include(CqlIdentifier columnName) {
133136
* @param columnName must not be {@literal null}.
134137
* @return a new {@link Columns} object containing all column definitions and the TTL for {@code columnName}.
135138
*/
139+
@CheckReturnValue
136140
public Columns ttl(String columnName) {
137141
return select(columnName, FunctionCall.from("TTL", ColumnSelector.from(columnName)));
138142
}
@@ -144,6 +148,7 @@ public Columns ttl(String columnName) {
144148
* @param columnName must not be {@literal null}.
145149
* @return a new {@link Columns} object containing all column definitions and the TTL for {@code columnName}.
146150
*/
151+
@CheckReturnValue
147152
public Columns ttl(CqlIdentifier columnName) {
148153
return select(columnName, FunctionCall.from("TTL", ColumnSelector.from(columnName)));
149154
}
@@ -155,6 +160,7 @@ public Columns ttl(CqlIdentifier columnName) {
155160
* @param columnName must not be {@literal null}.
156161
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
157162
*/
163+
@CheckReturnValue
158164
public Columns select(String columnName, Selector selector) {
159165
return select(ColumnName.from(columnName), selector);
160166
}
@@ -168,6 +174,7 @@ public Columns select(String columnName, Selector selector) {
168174
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
169175
* @since 4.5
170176
*/
177+
@CheckReturnValue
171178
public Columns select(CqlIdentifier columnName, Function<SelectorBuilder, Selector> builder) {
172179

173180
ColumnName from = ColumnName.from(columnName);
@@ -183,6 +190,7 @@ public Columns select(CqlIdentifier columnName, Function<SelectorBuilder, Select
183190
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
184191
* @since 4.5
185192
*/
193+
@CheckReturnValue
186194
public Columns select(String columnName, Function<SelectorBuilder, Selector> builder) {
187195

188196
ColumnName from = ColumnName.from(columnName);
@@ -196,6 +204,7 @@ public Columns select(String columnName, Function<SelectorBuilder, Selector> bui
196204
* @param columnName must not be {@literal null}.
197205
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
198206
*/
207+
@CheckReturnValue
199208
public Columns select(CqlIdentifier columnName, Selector selector) {
200209
return select(ColumnName.from(columnName), selector);
201210
}
@@ -229,6 +238,7 @@ public boolean isEmpty() {
229238
* @param columns must not be {@literal null}.
230239
* @return a new {@link Columns} with the merged result of the configured and given {@link Columns}.
231240
*/
241+
@CheckReturnValue
232242
public Columns and(Columns columns) {
233243

234244
Map<ColumnName, Selector> result = new LinkedHashMap<>(this.columns);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/**
2727
* Basic class for creating queries. It follows a fluent API style so that you can easily create a
28-
* {@link CriteriaDefinition}. Static import of the 'Criteria.where' method will improve readability.
28+
* {@link CriteriaDefinition}. Static import of the {@code Criteria.where} method will improve readability.
2929
*
3030
* @author Mark Paluch
3131
* @since 2.0

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.data.domain.Pageable;
3434
import org.springframework.data.domain.Sort;
3535
import org.springframework.data.domain.Sort.Order;
36+
import org.springframework.lang.CheckReturnValue;
3637
import org.springframework.lang.Nullable;
3738
import org.springframework.util.Assert;
3839

@@ -133,6 +134,7 @@ public static Query query(Iterable<? extends CriteriaDefinition> criteriaDefinit
133134
* @param criteriaDefinition must not be {@literal null}.
134135
* @return a new {@link Query} object containing the former settings with {@link CriteriaDefinition} applied.
135136
*/
137+
@CheckReturnValue
136138
public Query and(CriteriaDefinition criteriaDefinition) {
137139

138140
Assert.notNull(criteriaDefinition, "Criteria must not be null");
@@ -161,6 +163,7 @@ public Iterable<CriteriaDefinition> getCriteriaDefinitions() {
161163
* @param columns must not be {@literal null}.
162164
* @return a new {@link Query} object containing the former settings with {@link Columns} applied.
163165
*/
166+
@CheckReturnValue
164167
public Query columns(Columns columns) {
165168

166169
Assert.notNull(columns, "Columns must not be null");
@@ -182,6 +185,7 @@ public Columns getColumns() {
182185
* @param sort must not be {@literal null}.
183186
* @return a new {@link Query} object containing the former settings with {@link Sort} applied.
184187
*/
188+
@CheckReturnValue
185189
public Query sort(Sort sort) {
186190

187191
Assert.notNull(sort, "Sort must not be null");
@@ -223,6 +227,7 @@ public Sort getSort() {
223227
* @return a new {@link Query} object containing the former settings with {@link PageRequest} applied.
224228
* @see CassandraPageRequest
225229
*/
230+
@CheckReturnValue
226231
public Query pageRequest(Pageable pageable) {
227232

228233
Assert.notNull(pageable, "Pageable must not be null");
@@ -248,6 +253,7 @@ public Query pageRequest(Pageable pageable) {
248253
* @param scrollPosition must not be {@literal null}.
249254
* @return a new {@link Query} object containing the former settings with paging state applied.
250255
*/
256+
@CheckReturnValue
251257
public Query pagingState(CassandraScrollPosition scrollPosition) {
252258

253259
Assert.notNull(scrollPosition, "CassandraScrollPosition must not be null");
@@ -262,6 +268,7 @@ public Query pagingState(CassandraScrollPosition scrollPosition) {
262268
* @param pagingState must not be {@literal null}.
263269
* @return a new {@link Query} object containing the former settings with {@link ByteBuffer paging state} applied.
264270
*/
271+
@CheckReturnValue
265272
public Query pagingState(ByteBuffer pagingState) {
266273

267274
Assert.notNull(pagingState, "PagingState must not be null");
@@ -288,6 +295,7 @@ public Optional<ByteBuffer> getPagingState() {
288295
* @param queryOptions must not be {@literal null}.
289296
* @return a new {@link Query} object containing the former settings with {@link QueryOptions} applied.
290297
*/
298+
@CheckReturnValue
291299
public Query queryOptions(QueryOptions queryOptions) {
292300

293301
Assert.notNull(queryOptions, "QueryOptions must not be null");
@@ -309,6 +317,7 @@ public Optional<QueryOptions> getQueryOptions() {
309317
* @param limit
310318
* @return a new {@link Query} object containing the former settings with {@code limit} applied.
311319
*/
320+
@CheckReturnValue
312321
public Query limit(long limit) {
313322
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.scrollPosition, this.queryOptions,
314323
Limit.of(Math.toIntExact(limit)), this.allowFiltering);
@@ -320,6 +329,7 @@ public Query limit(long limit) {
320329
* @param limit
321330
* @return a new {@link Query} object containing the former settings with {@code limit} applied.
322331
*/
332+
@CheckReturnValue
323333
public Query limit(Limit limit) {
324334
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.scrollPosition, this.queryOptions, limit,
325335
this.allowFiltering);
@@ -344,6 +354,7 @@ public boolean isLimited() {
344354
*
345355
* @return a new {@link Query} object containing the former settings with {@code allowFiltering} applied.
346356
*/
357+
@CheckReturnValue
347358
public Query withAllowFiltering() {
348359
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.scrollPosition, this.queryOptions,
349360
this.limit, true);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626

2727
import org.springframework.data.cassandra.core.query.Update.AddToOp.Mode;
28+
import org.springframework.lang.CheckReturnValue;
2829
import org.springframework.lang.Nullable;
2930
import org.springframework.util.Assert;
3031
import org.springframework.util.ObjectUtils;
@@ -97,6 +98,7 @@ private Update(List<AssignmentOp> updateOperations) {
9798
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
9899
* assignment.
99100
*/
101+
@CheckReturnValue
100102
public Update set(String columnName, @Nullable Object value) {
101103
return add(new SetOp(ColumnName.from(columnName), value));
102104
}
@@ -105,8 +107,9 @@ public Update set(String columnName, @Nullable Object value) {
105107
* Create a new {@link SetBuilder} to set a collection item for {@code columnName} in a fluent style.
106108
*
107109
* @param columnName must not be {@literal null}.
108-
* @return a new {@link AddToBuilder} to build an set assignment.
110+
* @return a new {@link AddToBuilder} to build a set assignment.
109111
*/
112+
@CheckReturnValue
110113
public SetBuilder set(String columnName) {
111114
return new DefaultSetBuilder(ColumnName.from(columnName));
112115
}
@@ -117,6 +120,7 @@ public SetBuilder set(String columnName) {
117120
* @param columnName must not be {@literal null}.
118121
* @return a new {@link AddToBuilder} to build an add-to assignment.
119122
*/
123+
@CheckReturnValue
120124
public AddToBuilder addTo(String columnName) {
121125
return new DefaultAddToBuilder(ColumnName.from(columnName));
122126
}
@@ -128,6 +132,7 @@ public AddToBuilder addTo(String columnName) {
128132
* @return a new {@link RemoveFromBuilder} to build an remove-from assignment.
129133
* @since 3.1.4
130134
*/
135+
@CheckReturnValue
131136
public RemoveFromBuilder removeFrom(String columnName) {
132137
return new DefaultRemoveFromBuilder(ColumnName.from(columnName));
133138
}
@@ -140,6 +145,7 @@ public RemoveFromBuilder removeFrom(String columnName) {
140145
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
141146
* assignment.
142147
*/
148+
@CheckReturnValue
143149
public Update remove(String columnName, Object value) {
144150
return add(new RemoveOp(ColumnName.from(columnName), Collections.singletonList(value)));
145151
}
@@ -151,6 +157,7 @@ public Update remove(String columnName, Object value) {
151157
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
152158
* assignment.
153159
*/
160+
@CheckReturnValue
154161
public Update clear(String columnName) {
155162
return add(new SetOp(ColumnName.from(columnName), Collections.emptyList()));
156163
}
@@ -162,6 +169,7 @@ public Update clear(String columnName) {
162169
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
163170
* assignment.
164171
*/
172+
@CheckReturnValue
165173
public Update increment(String columnName) {
166174
return increment(columnName, 1);
167175
}
@@ -174,6 +182,7 @@ public Update increment(String columnName) {
174182
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
175183
* assignment.
176184
*/
185+
@CheckReturnValue
177186
public Update increment(String columnName, Number delta) {
178187
return add(new IncrOp(ColumnName.from(columnName), delta));
179188
}
@@ -185,6 +194,7 @@ public Update increment(String columnName, Number delta) {
185194
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
186195
* assignment.
187196
*/
197+
@CheckReturnValue
188198
public Update decrement(String columnName) {
189199
return decrement(columnName, 1);
190200
}
@@ -197,6 +207,7 @@ public Update decrement(String columnName) {
197207
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
198208
* assignment.
199209
*/
210+
@CheckReturnValue
200211
public Update decrement(String columnName, Number delta) {
201212

202213
if (delta instanceof Integer || delta instanceof Long) {

0 commit comments

Comments
 (0)