Skip to content

Commit 7bd5674

Browse files
committed
Add @CheckReturnValue to Query and Update API.
Closes #1609
1 parent 207e6d4 commit 7bd5674

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map.Entry;
2525
import java.util.Optional;
2626

27+
import org.springframework.lang.CheckReturnValue;
2728
import org.springframework.lang.Nullable;
2829
import org.springframework.util.Assert;
2930
import org.springframework.util.ObjectUtils;
@@ -105,6 +106,7 @@ public static Columns from(CqlIdentifier... columnNames) {
105106
* @param columnName must not be {@literal null}.
106107
* @return a new {@link Columns} object containing all column definitions and the included {@code columnName}.
107108
*/
109+
@CheckReturnValue
108110
public Columns include(String columnName) {
109111
return select(columnName, ColumnSelector.from(columnName));
110112
}
@@ -116,6 +118,7 @@ public Columns include(String columnName) {
116118
* @param columnName must not be {@literal null}.
117119
* @return a new {@link Columns} object containing all column definitions and the included {@code columnName}.
118120
*/
121+
@CheckReturnValue
119122
public Columns include(CqlIdentifier columnName) {
120123
return select(columnName, ColumnSelector.from(columnName));
121124
}
@@ -127,6 +130,7 @@ public Columns include(CqlIdentifier columnName) {
127130
* @param columnName must not be {@literal null}.
128131
* @return a new {@link Columns} object containing all column definitions and the TTL for {@code columnName}.
129132
*/
133+
@CheckReturnValue
130134
public Columns ttl(String columnName) {
131135
return select(columnName, FunctionCall.from("TTL", ColumnSelector.from(columnName)));
132136
}
@@ -138,6 +142,7 @@ public Columns ttl(String columnName) {
138142
* @param columnName must not be {@literal null}.
139143
* @return a new {@link Columns} object containing all column definitions and the TTL for {@code columnName}.
140144
*/
145+
@CheckReturnValue
141146
public Columns ttl(CqlIdentifier columnName) {
142147
return select(columnName, FunctionCall.from("TTL", ColumnSelector.from(columnName)));
143148
}
@@ -149,6 +154,7 @@ public Columns ttl(CqlIdentifier columnName) {
149154
* @param columnName must not be {@literal null}.
150155
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
151156
*/
157+
@CheckReturnValue
152158
public Columns select(String columnName, Selector selector) {
153159

154160
Assert.notNull(columnName, "Column name must not be null");
@@ -166,6 +172,7 @@ public Columns select(String columnName, Selector selector) {
166172
* @param columnName must not be {@literal null}.
167173
* @return a new {@link Columns} object containing all column definitions and the selected {@code columnName}.
168174
*/
175+
@CheckReturnValue
169176
public Columns select(CqlIdentifier columnName, Selector selector) {
170177

171178
Assert.notNull(columnName, "Column name must not be null");
@@ -190,6 +197,7 @@ public boolean isEmpty() {
190197
* @param columns must not be {@literal null}.
191198
* @return a new {@link Columns} with the merged result of the configured and given {@link Columns}.
192199
*/
200+
@CheckReturnValue
193201
public Columns and(Columns columns) {
194202

195203
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
@@ -32,6 +32,7 @@
3232
import org.springframework.data.domain.Pageable;
3333
import org.springframework.data.domain.Sort;
3434
import org.springframework.data.domain.Sort.Order;
35+
import org.springframework.lang.CheckReturnValue;
3536
import org.springframework.lang.Nullable;
3637
import org.springframework.util.Assert;
3738

@@ -122,6 +123,7 @@ public static Query query(Iterable<? extends CriteriaDefinition> criteriaDefinit
122123
* @param criteriaDefinition must not be {@literal null}.
123124
* @return a new {@link Query} object containing the former settings with {@link CriteriaDefinition} applied.
124125
*/
126+
@CheckReturnValue
125127
public Query and(CriteriaDefinition criteriaDefinition) {
126128

127129
Assert.notNull(criteriaDefinition, "Criteria must not be null");
@@ -150,6 +152,7 @@ public Iterable<CriteriaDefinition> getCriteriaDefinitions() {
150152
* @param columns must not be {@literal null}.
151153
* @return a new {@link Query} object containing the former settings with {@link Columns} applied.
152154
*/
155+
@CheckReturnValue
153156
public Query columns(Columns columns) {
154157

155158
Assert.notNull(columns, "Columns must not be null");
@@ -171,6 +174,7 @@ public Columns getColumns() {
171174
* @param sort must not be {@literal null}.
172175
* @return a new {@link Query} object containing the former settings with {@link Sort} applied.
173176
*/
177+
@CheckReturnValue
174178
public Query sort(Sort sort) {
175179

176180
Assert.notNull(sort, "Sort must not be null");
@@ -202,6 +206,7 @@ public Sort getSort() {
202206
* @return a new {@link Query} object containing the former settings with {@link PageRequest} applied.
203207
* @see CassandraPageRequest
204208
*/
209+
@CheckReturnValue
205210
public Query pageRequest(Pageable pageable) {
206211

207212
Assert.notNull(pageable, "Pageable must not be null");
@@ -227,6 +232,7 @@ public Query pageRequest(Pageable pageable) {
227232
* @param scrollPosition must not be {@literal null}.
228233
* @return a new {@link Query} object containing the former settings with paging state applied.
229234
*/
235+
@CheckReturnValue
230236
public Query pagingState(CassandraScrollPosition scrollPosition) {
231237

232238
Assert.notNull(scrollPosition, "CassandraScrollPosition must not be null");
@@ -241,6 +247,7 @@ public Query pagingState(CassandraScrollPosition scrollPosition) {
241247
* @param pagingState must not be {@literal null}.
242248
* @return a new {@link Query} object containing the former settings with {@link ByteBuffer paging state} applied.
243249
*/
250+
@CheckReturnValue
244251
public Query pagingState(ByteBuffer pagingState) {
245252

246253
Assert.notNull(pagingState, "PagingState must not be null");
@@ -267,6 +274,7 @@ public Optional<ByteBuffer> getPagingState() {
267274
* @param queryOptions must not be {@literal null}.
268275
* @return a new {@link Query} object containing the former settings with {@link QueryOptions} applied.
269276
*/
277+
@CheckReturnValue
270278
public Query queryOptions(QueryOptions queryOptions) {
271279

272280
Assert.notNull(queryOptions, "QueryOptions must not be null");
@@ -288,6 +296,7 @@ public Optional<QueryOptions> getQueryOptions() {
288296
* @param limit
289297
* @return a new {@link Query} object containing the former settings with {@code limit} applied.
290298
*/
299+
@CheckReturnValue
291300
public Query limit(long limit) {
292301
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.scrollPosition, this.queryOptions,
293302
Limit.of(Math.toIntExact(limit)), this.allowFiltering);
@@ -299,6 +308,7 @@ public Query limit(long limit) {
299308
* @param limit
300309
* @return a new {@link Query} object containing the former settings with {@code limit} applied.
301310
*/
311+
@CheckReturnValue
302312
public Query limit(Limit limit) {
303313
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.scrollPosition, this.queryOptions, limit,
304314
this.allowFiltering);
@@ -323,6 +333,7 @@ public boolean isLimited() {
323333
*
324334
* @return a new {@link Query} object containing the former settings with {@code allowFiltering} applied.
325335
*/
336+
@CheckReturnValue
326337
public Query withAllowFiltering() {
327338
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.scrollPosition, this.queryOptions,
328339
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
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525

2626
import org.springframework.data.cassandra.core.query.Update.AddToOp.Mode;
27+
import org.springframework.lang.CheckReturnValue;
2728
import org.springframework.lang.Nullable;
2829
import org.springframework.util.Assert;
2930
import org.springframework.util.StringUtils;
@@ -96,6 +97,7 @@ private Update(Map<ColumnName, AssignmentOp> updateOperations) {
9697
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
9798
* assignment.
9899
*/
100+
@CheckReturnValue
99101
public Update set(String columnName, @Nullable Object value) {
100102
return add(new SetOp(ColumnName.from(columnName), value));
101103
}
@@ -104,8 +106,9 @@ public Update set(String columnName, @Nullable Object value) {
104106
* Create a new {@link SetBuilder} to set a collection item for {@code columnName} in a fluent style.
105107
*
106108
* @param columnName must not be {@literal null}.
107-
* @return a new {@link AddToBuilder} to build an set assignment.
109+
* @return a new {@link AddToBuilder} to build a set assignment.
108110
*/
111+
@CheckReturnValue
109112
public SetBuilder set(String columnName) {
110113
return new DefaultSetBuilder(ColumnName.from(columnName));
111114
}
@@ -116,6 +119,7 @@ public SetBuilder set(String columnName) {
116119
* @param columnName must not be {@literal null}.
117120
* @return a new {@link AddToBuilder} to build an add-to assignment.
118121
*/
122+
@CheckReturnValue
119123
public AddToBuilder addTo(String columnName) {
120124
return new DefaultAddToBuilder(ColumnName.from(columnName));
121125
}
@@ -127,6 +131,7 @@ public AddToBuilder addTo(String columnName) {
127131
* @return a new {@link RemoveFromBuilder} to build an remove-from assignment.
128132
* @since 3.1.4
129133
*/
134+
@CheckReturnValue
130135
public RemoveFromBuilder removeFrom(String columnName) {
131136
return new DefaultRemoveFromBuilder(ColumnName.from(columnName));
132137
}
@@ -139,6 +144,7 @@ public RemoveFromBuilder removeFrom(String columnName) {
139144
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
140145
* assignment.
141146
*/
147+
@CheckReturnValue
142148
public Update remove(String columnName, Object value) {
143149
return add(new RemoveOp(ColumnName.from(columnName), Collections.singletonList(value)));
144150
}
@@ -150,6 +156,7 @@ public Update remove(String columnName, Object value) {
150156
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
151157
* assignment.
152158
*/
159+
@CheckReturnValue
153160
public Update clear(String columnName) {
154161
return add(new SetOp(ColumnName.from(columnName), Collections.emptyList()));
155162
}
@@ -161,6 +168,7 @@ public Update clear(String columnName) {
161168
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
162169
* assignment.
163170
*/
171+
@CheckReturnValue
164172
public Update increment(String columnName) {
165173
return increment(columnName, 1);
166174
}
@@ -173,6 +181,7 @@ public Update increment(String columnName) {
173181
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
174182
* assignment.
175183
*/
184+
@CheckReturnValue
176185
public Update increment(String columnName, Number delta) {
177186
return add(new IncrOp(ColumnName.from(columnName), delta));
178187
}
@@ -184,6 +193,7 @@ public Update increment(String columnName, Number delta) {
184193
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
185194
* assignment.
186195
*/
196+
@CheckReturnValue
187197
public Update decrement(String columnName) {
188198
return decrement(columnName, 1);
189199
}
@@ -196,6 +206,7 @@ public Update decrement(String columnName) {
196206
* @return a new {@link Update} object containing the merge result of the existing assignments and the current
197207
* assignment.
198208
*/
209+
@CheckReturnValue
199210
public Update decrement(String columnName, Number delta) {
200211

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

0 commit comments

Comments
 (0)