Skip to content

Commit ec6ed0e

Browse files
committed
Add Contract annotations.
See #1549
1 parent 0dd856c commit ec6ed0e

12 files changed

+100
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.springframework.data.cassandra.core.cql.QueryOptions;
2121
import org.springframework.data.cassandra.core.cql.WriteOptions;
22+
import org.springframework.lang.Contract;
2223
import org.springframework.util.Assert;
2324

2425
import com.datastax.oss.driver.api.core.cql.BatchableStatement;
@@ -58,6 +59,7 @@ public interface CassandraBatchOperations {
5859
* @return {@code this} {@link CassandraBatchOperations}.
5960
* @throws IllegalStateException if the batch was already executed.
6061
*/
62+
@Contract("_ -> this")
6163
CassandraBatchOperations withTimestamp(long timestamp);
6264

6365
/**
@@ -68,6 +70,7 @@ public interface CassandraBatchOperations {
6870
* @throws IllegalStateException if the batch was already executed.
6971
* @since 4.4
7072
*/
73+
@Contract("_ -> this")
7174
CassandraBatchOperations withQueryOptions(QueryOptions options);
7275

7376
/**
@@ -78,6 +81,7 @@ public interface CassandraBatchOperations {
7881
* @throws IllegalStateException if the batch was already executed.
7982
* @since 4.4
8083
*/
84+
@Contract("_ -> this")
8185
CassandraBatchOperations addStatement(BatchableStatement<?> statement);
8286

8387
/**
@@ -88,6 +92,7 @@ public interface CassandraBatchOperations {
8892
* @throws IllegalStateException if the batch was already executed.
8993
* @since 4.4
9094
*/
95+
@Contract("_ -> this")
9196
CassandraBatchOperations addStatements(BatchableStatement<?>... statements);
9297

9398
/**
@@ -98,6 +103,7 @@ public interface CassandraBatchOperations {
98103
* @throws IllegalStateException if the batch was already executed.
99104
* @since 4.4
100105
*/
106+
@Contract("_ -> this")
101107
CassandraBatchOperations addStatements(Iterable<? extends BatchableStatement<?>> statements);
102108

103109
/**
@@ -109,6 +115,7 @@ public interface CassandraBatchOperations {
109115
* @throws IllegalStateException if the batch was already executed.
110116
* @since 3.2.2
111117
*/
118+
@Contract("_, _ -> this")
112119
default CassandraBatchOperations insert(Object entity, WriteOptions options) {
113120

114121
Assert.notNull(entity, "Entity must not be null");
@@ -123,6 +130,7 @@ default CassandraBatchOperations insert(Object entity, WriteOptions options) {
123130
* @return {@code this} {@link CassandraBatchOperations}.
124131
* @throws IllegalStateException if the batch was already executed.
125132
*/
133+
@Contract("_ -> this")
126134
CassandraBatchOperations insert(Object... entities);
127135

128136
/**
@@ -132,6 +140,7 @@ default CassandraBatchOperations insert(Object entity, WriteOptions options) {
132140
* @return {@code this} {@link CassandraBatchOperations}.
133141
* @throws IllegalStateException if the batch was already executed.
134142
*/
143+
@Contract("_ -> this")
135144
CassandraBatchOperations insert(Iterable<?> entities);
136145

137146
/**
@@ -144,6 +153,7 @@ default CassandraBatchOperations insert(Object entity, WriteOptions options) {
144153
* @since 2.0
145154
* @see InsertOptions
146155
*/
156+
@Contract("_, _ -> this")
147157
CassandraBatchOperations insert(Iterable<?> entities, WriteOptions options);
148158

149159
/**
@@ -155,6 +165,7 @@ default CassandraBatchOperations insert(Object entity, WriteOptions options) {
155165
* @throws IllegalStateException if the batch was already executed.
156166
* @since 3.2.2
157167
*/
168+
@Contract("_, _ -> this")
158169
default CassandraBatchOperations update(Object entity, WriteOptions options) {
159170

160171
Assert.notNull(entity, "Entity must not be null");
@@ -169,6 +180,7 @@ default CassandraBatchOperations update(Object entity, WriteOptions options) {
169180
* @return {@code this} {@link CassandraBatchOperations}.
170181
* @throws IllegalStateException if the batch was already executed.
171182
*/
183+
@Contract("_ -> this")
172184
CassandraBatchOperations update(Object... entities);
173185

174186
/**
@@ -178,6 +190,7 @@ default CassandraBatchOperations update(Object entity, WriteOptions options) {
178190
* @return {@code this} {@link CassandraBatchOperations}.
179191
* @throws IllegalStateException if the batch was already executed.
180192
*/
193+
@Contract("_ -> this")
181194
CassandraBatchOperations update(Iterable<?> entities);
182195

183196
/**
@@ -190,6 +203,7 @@ default CassandraBatchOperations update(Object entity, WriteOptions options) {
190203
* @since 2.0
191204
* @see UpdateOptions
192205
*/
206+
@Contract("_, _ -> this")
193207
CassandraBatchOperations update(Iterable<?> entities, WriteOptions options);
194208

195209
/**
@@ -201,6 +215,7 @@ default CassandraBatchOperations update(Object entity, WriteOptions options) {
201215
* @throws IllegalStateException if the batch was already executed.
202216
* @since 3.2.2
203217
*/
218+
@Contract("_, _ -> this")
204219
default CassandraBatchOperations delete(Object entity, WriteOptions options) {
205220

206221
Assert.notNull(entity, "Entity must not be null");
@@ -215,6 +230,7 @@ default CassandraBatchOperations delete(Object entity, WriteOptions options) {
215230
* @return {@code this} {@link CassandraBatchOperations}.
216231
* @throws IllegalStateException if the batch was already executed.
217232
*/
233+
@Contract("_ -> this")
218234
CassandraBatchOperations delete(Object... entities);
219235

220236
/**
@@ -224,6 +240,7 @@ default CassandraBatchOperations delete(Object entity, WriteOptions options) {
224240
* @return {@code this} {@link CassandraBatchOperations}.
225241
* @throws IllegalStateException if the batch was already executed.
226242
*/
243+
@Contract("_ -> this")
227244
CassandraBatchOperations delete(Iterable<?> entities);
228245

229246
/**
@@ -236,5 +253,6 @@ default CassandraBatchOperations delete(Object entity, WriteOptions options) {
236253
* @since 2.2
237254
* @see DeleteOptions
238255
*/
256+
@Contract("_, _ -> this")
239257
CassandraBatchOperations delete(Iterable<?> entities, WriteOptions options);
240258
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.cassandra.core;
1717

1818
import org.springframework.data.cassandra.core.query.Query;
19+
import org.springframework.lang.Contract;
1920
import org.springframework.util.Assert;
2021

2122
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -69,6 +70,7 @@ interface DeleteWithTable {
6970
* @see #inTable(CqlIdentifier)
7071
* @see DeleteWithQuery
7172
*/
73+
@Contract("_ -> new")
7274
default DeleteWithQuery inTable(String table) {
7375

7476
Assert.hasText(table, "Table name must not be null or empty");
@@ -87,6 +89,7 @@ default DeleteWithQuery inTable(String table) {
8789
* @see com.datastax.oss.driver.api.core.CqlIdentifier
8890
* @see DeleteWithQuery
8991
*/
92+
@Contract("_ -> new")
9093
DeleteWithQuery inTable(CqlIdentifier table);
9194

9295
}
@@ -104,6 +107,7 @@ interface DeleteWithQuery {
104107
* @throws IllegalArgumentException if {@link Query} is {@literal null}.
105108
* @see TerminatingDelete
106109
*/
110+
@Contract("_ -> new")
107111
TerminatingDelete matching(Query query);
108112

109113
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.cassandra.core;
1717

18+
import org.springframework.lang.Contract;
1819
import org.springframework.util.Assert;
1920

2021
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -66,6 +67,7 @@ interface InsertWithTable<T> extends InsertWithOptions<T> {
6667
* @throws IllegalArgumentException if {@link String table} is {@literal null} or empty.
6768
* @see InsertWithOptions
6869
*/
70+
@Contract("_ -> new")
6971
default InsertWithOptions<T> inTable(String table) {
7072

7173
Assert.hasText(table, "Table name must not be null or empty");
@@ -84,6 +86,7 @@ default InsertWithOptions<T> inTable(String table) {
8486
* @see com.datastax.oss.driver.api.core.CqlIdentifier
8587
* @see InsertWithOptions
8688
*/
89+
@Contract("_ -> new")
8790
InsertWithOptions<T> inTable(CqlIdentifier table);
8891

8992
}
@@ -102,6 +105,7 @@ interface InsertWithOptions<T> extends TerminatingInsert<T> {
102105
* @see org.springframework.data.cassandra.core.InsertOptions
103106
* @see TerminatingInsert
104107
*/
108+
@Contract("_ -> new")
105109
TerminatingInsert<T> withOptions(InsertOptions insertOptions);
106110

107111
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.jspecify.annotations.Nullable;
2323
import org.springframework.data.cassandra.core.query.Query;
24+
import org.springframework.lang.Contract;
2425
import org.springframework.util.Assert;
2526

2627
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -83,6 +84,7 @@ interface SelectWithTable<T> extends SelectWithQuery<T> {
8384
* @see #inTable(CqlIdentifier)
8485
* @see SelectWithProjection
8586
*/
87+
@Contract("_ -> new")
8688
default SelectWithProjection<T> inTable(String table) {
8789

8890
Assert.hasText(table, "Table name must not be null or empty");
@@ -101,6 +103,7 @@ default SelectWithProjection<T> inTable(String table) {
101103
* @see com.datastax.oss.driver.api.core.CqlIdentifier
102104
* @see SelectWithProjection
103105
*/
106+
@Contract("_ -> new")
104107
SelectWithProjection<T> inTable(CqlIdentifier table);
105108

106109
}
@@ -121,6 +124,7 @@ interface SelectWithProjection<T> extends SelectWithQuery<T> {
121124
* @throws IllegalArgumentException if resultType is {@literal null}.
122125
* @see SelectWithQuery
123126
*/
127+
@Contract("_ -> new")
124128
<R> SelectWithQuery<R> as(Class<R> resultType);
125129

126130
}
@@ -221,6 +225,7 @@ default Optional<T> one() {
221225
default Stream<T> stream() {
222226
return all().stream();
223227
}
228+
224229
}
225230

226231
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.springframework.data.cassandra.core.query.Query;
1919
import org.springframework.data.cassandra.core.query.Update;
20+
import org.springframework.lang.Contract;
2021
import org.springframework.util.Assert;
2122

2223
import com.datastax.oss.driver.api.core.CqlIdentifier;
@@ -75,6 +76,7 @@ interface UpdateWithTable {
7576
* @see #inTable(CqlIdentifier)
7677
* @see UpdateWithQuery
7778
*/
79+
@Contract("_ -> new")
7880
default UpdateWithQuery inTable(String table) {
7981

8082
Assert.hasText(table, "Table name must not be null or empty");
@@ -93,6 +95,7 @@ default UpdateWithQuery inTable(String table) {
9395
* @see com.datastax.oss.driver.api.core.CqlIdentifier
9496
* @see UpdateWithQuery
9597
*/
98+
@Contract("_ -> new")
9699
UpdateWithQuery inTable(CqlIdentifier table);
97100

98101
}
@@ -110,6 +113,7 @@ interface UpdateWithQuery {
110113
* @throws IllegalArgumentException if {@link Query} is {@literal null}.
111114
* @see TerminatingUpdate
112115
*/
116+
@Contract("_ -> new")
113117
TerminatingUpdate matching(Query query);
114118

115119
}

0 commit comments

Comments
 (0)