Skip to content

Commit a66556d

Browse files
committed
Deprecate ListenableFuture-based Template API and introduce CompletableFuture Template API replacement.
We now provide a CompletableFuture-based asynchronous Template API for CQL and entity operations. The ListenableFuture-future API is now deprecated and moved to legacy subpackages for easier migration. Closes #1294
1 parent a5047c9 commit a66556d

File tree

51 files changed

+7414
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+7414
-606
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractCassandraConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public CassandraConverter cassandraConverter() {
8686
}
8787

8888
/**
89-
* Returns the a {@link CassandraManagedTypes} object holding the initial entity set.
89+
* Returns the given {@link CassandraManagedTypes} object holding the initial entity set.
9090
*
9191
* @return new instance of {@link CassandraManagedTypes}.
9292
* @throws ClassNotFoundException

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

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

1818
import java.util.List;
19+
import java.util.concurrent.CompletableFuture;
1920
import java.util.function.Consumer;
2021

2122
import org.springframework.dao.DataAccessException;
@@ -27,7 +28,6 @@
2728
import org.springframework.data.cassandra.core.query.Query;
2829
import org.springframework.data.cassandra.core.query.Update;
2930
import org.springframework.data.domain.Slice;
30-
import org.springframework.util.concurrent.ListenableFuture;
3131

3232
import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
3333
import com.datastax.oss.driver.api.core.cql.Statement;
@@ -74,7 +74,7 @@ public interface AsyncCassandraOperations {
7474
* @return the converted results
7575
* @throws DataAccessException if there is any problem executing the query.
7676
*/
77-
<T> ListenableFuture<List<T>> select(String cql, Class<T> entityClass) throws DataAccessException;
77+
<T> CompletableFuture<List<T>> select(String cql, Class<T> entityClass) throws DataAccessException;
7878

7979
/**
8080
* Execute a {@code SELECT} query and convert the resulting items notifying {@link Consumer} for each entity.
@@ -86,7 +86,7 @@ public interface AsyncCassandraOperations {
8686
* @return the completion handle
8787
* @throws DataAccessException if there is any problem executing the query.
8888
*/
89-
<T> ListenableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<T> entityClass)
89+
<T> CompletableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<T> entityClass)
9090
throws DataAccessException;
9191

9292
/**
@@ -97,22 +97,22 @@ <T> ListenableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<
9797
* @return the converted object or {@literal null}.
9898
* @throws DataAccessException if there is any problem executing the query.
9999
*/
100-
<T> ListenableFuture<T> selectOne(String cql, Class<T> entityClass) throws DataAccessException;
100+
<T> CompletableFuture<T> selectOne(String cql, Class<T> entityClass) throws DataAccessException;
101101

102102
// -------------------------------------------------------------------------
103103
// Methods dealing with com.datastax.oss.driver.api.core.cql.Statement
104104
// -------------------------------------------------------------------------
105105

106106
/**
107-
* Execute the a Cassandra {@link Statement}. Any errors that result from executing this command will be converted
107+
* Execute the given Cassandra {@link Statement}. Any errors that result from executing this command will be converted
108108
* into Spring's DAO exception hierarchy.
109109
*
110110
* @param statement a Cassandra {@link Statement}, must not be {@literal null}.
111111
* @return the {@link AsyncResultSet}.
112112
* @throws DataAccessException if there is any problem executing the query.
113113
* @since 3.2
114114
*/
115-
ListenableFuture<AsyncResultSet> execute(Statement<?> statement) throws DataAccessException;
115+
CompletableFuture<AsyncResultSet> execute(Statement<?> statement) throws DataAccessException;
116116

117117
/**
118118
* Execute a {@code SELECT} query and convert the resulting items to a {@link List} of entities.
@@ -122,7 +122,7 @@ <T> ListenableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<
122122
* @return the converted results
123123
* @throws DataAccessException if there is any problem executing the query.
124124
*/
125-
<T> ListenableFuture<List<T>> select(Statement<?> statement, Class<T> entityClass) throws DataAccessException;
125+
<T> CompletableFuture<List<T>> select(Statement<?> statement, Class<T> entityClass) throws DataAccessException;
126126

127127
/**
128128
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities. A sliced
@@ -134,7 +134,7 @@ <T> ListenableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<
134134
* @throws DataAccessException if there is any problem executing the query.
135135
* @see CassandraPageRequest
136136
*/
137-
<T> ListenableFuture<Slice<T>> slice(Statement<?> statement, Class<T> entityClass) throws DataAccessException;
137+
<T> CompletableFuture<Slice<T>> slice(Statement<?> statement, Class<T> entityClass) throws DataAccessException;
138138

139139
/**
140140
* Execute a {@code SELECT} query and convert the resulting items notifying {@link Consumer} for each entity.
@@ -146,7 +146,7 @@ <T> ListenableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<
146146
* @return the completion handle
147147
* @throws DataAccessException if there is any problem executing the query.
148148
*/
149-
<T> ListenableFuture<Void> select(Statement<?> statement, Consumer<T> entityConsumer, Class<T> entityClass)
149+
<T> CompletableFuture<Void> select(Statement<?> statement, Consumer<T> entityConsumer, Class<T> entityClass)
150150
throws DataAccessException;
151151

152152
/**
@@ -157,7 +157,7 @@ <T> ListenableFuture<Void> select(Statement<?> statement, Consumer<T> entityCons
157157
* @return the converted object or {@literal null}.
158158
* @throws DataAccessException if there is any problem executing the query.
159159
*/
160-
<T> ListenableFuture<T> selectOne(Statement<?> statement, Class<T> entityClass) throws DataAccessException;
160+
<T> CompletableFuture<T> selectOne(Statement<?> statement, Class<T> entityClass) throws DataAccessException;
161161

162162
// -------------------------------------------------------------------------
163163
// Methods dealing with org.springframework.data.cassandra.core.query.Query
@@ -171,7 +171,7 @@ <T> ListenableFuture<Void> select(Statement<?> statement, Consumer<T> entityCons
171171
* @return the converted results
172172
* @throws DataAccessException if there is any problem executing the query.
173173
*/
174-
<T> ListenableFuture<List<T>> select(Query query, Class<T> entityClass) throws DataAccessException;
174+
<T> CompletableFuture<List<T>> select(Query query, Class<T> entityClass) throws DataAccessException;
175175

176176
/**
177177
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities.
@@ -182,7 +182,7 @@ <T> ListenableFuture<Void> select(Statement<?> statement, Consumer<T> entityCons
182182
* @throws DataAccessException if there is any problem executing the query.
183183
* @see CassandraPageRequest
184184
*/
185-
<T> ListenableFuture<Slice<T>> slice(Query query, Class<T> entityClass) throws DataAccessException;
185+
<T> CompletableFuture<Slice<T>> slice(Query query, Class<T> entityClass) throws DataAccessException;
186186

187187
/**
188188
* Execute a {@code SELECT} query and convert the resulting items notifying {@link Consumer} for each entity.
@@ -194,7 +194,7 @@ <T> ListenableFuture<Void> select(Statement<?> statement, Consumer<T> entityCons
194194
* @return the completion handle
195195
* @throws DataAccessException if there is any problem executing the query.
196196
*/
197-
<T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class<T> entityClass)
197+
<T> CompletableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class<T> entityClass)
198198
throws DataAccessException;
199199

200200
/**
@@ -205,7 +205,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
205205
* @return the converted object or {@literal null}.
206206
* @throws DataAccessException if there is any problem executing the query.
207207
*/
208-
<T> ListenableFuture<T> selectOne(Query query, Class<T> entityClass) throws DataAccessException;
208+
<T> CompletableFuture<T> selectOne(Query query, Class<T> entityClass) throws DataAccessException;
209209

210210
/**
211211
* Update the queried entities and return {@literal true} if the update was applied.
@@ -215,7 +215,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
215215
* @param entityClass The entity type must not be {@literal null}.
216216
* @throws DataAccessException if there is any problem executing the query.
217217
*/
218-
ListenableFuture<Boolean> update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
218+
CompletableFuture<Boolean> update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
219219

220220
/**
221221
* Remove entities (rows)/columns from the table by {@link Query}.
@@ -225,7 +225,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
225225
* @return {@literal true} if the deletion was applied.
226226
* @throws DataAccessException if there is any problem executing the query.
227227
*/
228-
ListenableFuture<Boolean> delete(Query query, Class<?> entityClass) throws DataAccessException;
228+
CompletableFuture<Boolean> delete(Query query, Class<?> entityClass) throws DataAccessException;
229229

230230
// -------------------------------------------------------------------------
231231
// Methods dealing with entities
@@ -238,7 +238,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
238238
* @return the number of existing entities.
239239
* @throws DataAccessException if any problem occurs while executing the query.
240240
*/
241-
ListenableFuture<Long> count(Class<?> entityClass) throws DataAccessException;
241+
CompletableFuture<Long> count(Class<?> entityClass) throws DataAccessException;
242242

243243
/**
244244
* Returns the number of rows for the given entity class applying {@link Query}. This overridden method allows users
@@ -251,7 +251,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
251251
* @throws DataAccessException if any problem occurs while executing the query.
252252
* @since 2.1
253253
*/
254-
ListenableFuture<Long> count(Query query, Class<?> entityClass) throws DataAccessException;
254+
CompletableFuture<Long> count(Query query, Class<?> entityClass) throws DataAccessException;
255255

256256
/**
257257
* Determine whether a row of {@code entityClass} with the given {@code id} exists.
@@ -263,7 +263,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
263263
* @return {@literal true} if the object exists.
264264
* @throws DataAccessException if any problem occurs while executing the query.
265265
*/
266-
ListenableFuture<Boolean> exists(Object id, Class<?> entityClass) throws DataAccessException;
266+
CompletableFuture<Boolean> exists(Object id, Class<?> entityClass) throws DataAccessException;
267267

268268
/**
269269
* Determine whether the result for {@code entityClass} {@link Query} yields at least one row.
@@ -274,7 +274,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
274274
* @throws DataAccessException if any problem occurs while executing the query.
275275
* @since 2.1
276276
*/
277-
ListenableFuture<Boolean> exists(Query query, Class<?> entityClass) throws DataAccessException;
277+
CompletableFuture<Boolean> exists(Query query, Class<?> entityClass) throws DataAccessException;
278278

279279
/**
280280
* Execute the Select by {@code id} for the given {@code entityClass}.
@@ -286,7 +286,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
286286
* @return the converted object or {@literal null}.
287287
* @throws DataAccessException if there is any problem executing the query.
288288
*/
289-
<T> ListenableFuture<T> selectOneById(Object id, Class<T> entityClass) throws DataAccessException;
289+
<T> CompletableFuture<T> selectOneById(Object id, Class<T> entityClass) throws DataAccessException;
290290

291291
/**
292292
* Insert the given entity and return the entity if the insert was applied.
@@ -295,7 +295,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
295295
* @return the inserted entity.
296296
* @throws DataAccessException if there is any problem executing the query.
297297
*/
298-
<T> ListenableFuture<T> insert(T entity) throws DataAccessException;
298+
<T> CompletableFuture<T> insert(T entity) throws DataAccessException;
299299

300300
/**
301301
* Insert the given entity applying {@link WriteOptions} and return the entity if the insert was applied.
@@ -306,7 +306,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
306306
* @throws DataAccessException if there is any problem executing the query.
307307
* @see InsertOptions#empty()
308308
*/
309-
<T> ListenableFuture<EntityWriteResult<T>> insert(T entity, InsertOptions options) throws DataAccessException;
309+
<T> CompletableFuture<EntityWriteResult<T>> insert(T entity, InsertOptions options) throws DataAccessException;
310310

311311
/**
312312
* Update the given entity and return the entity if the update was applied.
@@ -315,7 +315,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
315315
* @return the updated entity.
316316
* @throws DataAccessException if there is any problem executing the query.
317317
*/
318-
<T> ListenableFuture<T> update(T entity) throws DataAccessException;
318+
<T> CompletableFuture<T> update(T entity) throws DataAccessException;
319319

320320
/**
321321
* Update the given entity applying {@link WriteOptions} and return the entity if the update was applied.
@@ -326,30 +326,30 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
326326
* @throws DataAccessException if there is any problem executing the query.
327327
* @see UpdateOptions#empty()
328328
*/
329-
<T> ListenableFuture<EntityWriteResult<T>> update(T entity, UpdateOptions options) throws DataAccessException;
329+
<T> CompletableFuture<EntityWriteResult<T>> update(T entity, UpdateOptions options) throws DataAccessException;
330330

331331
/**
332-
* Delete the given entity and return the entity if the delete was applied.
332+
* Delete the given entity and return the entity if the delete statement was applied.
333333
*
334334
* @param entity must not be {@literal null}.
335335
* @return the deleted entity.
336336
* @throws DataAccessException if there is any problem executing the query.
337337
*/
338-
<T> ListenableFuture<T> delete(T entity) throws DataAccessException;
338+
<T> CompletableFuture<T> delete(T entity) throws DataAccessException;
339339

340340
/**
341-
* Delete the given entity applying {@link QueryOptions} and return the entity if the delete was applied.
341+
* Delete the given entity applying {@link QueryOptions} and return the entity if the delete statement was applied.
342342
*
343343
* @param entity must not be {@literal null}.
344344
* @param options must not be {@literal null}.
345345
* @return the {@link WriteResult} for this operation.
346346
* @throws DataAccessException if there is any problem executing the query.
347347
* @see QueryOptions#empty()
348348
*/
349-
ListenableFuture<WriteResult> delete(Object entity, QueryOptions options) throws DataAccessException;
349+
CompletableFuture<WriteResult> delete(Object entity, QueryOptions options) throws DataAccessException;
350350

351351
/**
352-
* Delete the given entity applying {@link DeleteOptions} and return the entity if the delete was applied.
352+
* Delete the given entity applying {@link DeleteOptions} and return the entity if the delete statement was applied.
353353
*
354354
* @param entity must not be {@literal null}.
355355
* @param options must not be {@literal null}.
@@ -358,7 +358,7 @@ <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class
358358
* @see DeleteOptions#empty()
359359
* @since 2.2
360360
*/
361-
default ListenableFuture<WriteResult> delete(Object entity, DeleteOptions options) throws DataAccessException {
361+
default CompletableFuture<WriteResult> delete(Object entity, DeleteOptions options) throws DataAccessException {
362362
return delete(entity, (QueryOptions) options);
363363
}
364364

@@ -372,14 +372,14 @@ default ListenableFuture<WriteResult> delete(Object entity, DeleteOptions option
372372
* @return {@literal true} if the deletion was applied.
373373
* @throws DataAccessException if there is any problem executing the query.
374374
*/
375-
ListenableFuture<Boolean> deleteById(Object id, Class<?> entityClass) throws DataAccessException;
375+
CompletableFuture<Boolean> deleteById(Object id, Class<?> entityClass) throws DataAccessException;
376376

377377
/**
378378
* Execute a {@code TRUNCATE} query to remove all entities of a given class.
379379
*
380380
* @param entityClass The entity type must not be {@literal null}.
381381
* @throws DataAccessException if there is any problem executing the query.
382382
*/
383-
ListenableFuture<Void> truncate(Class<?> entityClass) throws DataAccessException;
383+
CompletableFuture<Void> truncate(Class<?> entityClass) throws DataAccessException;
384384

385385
}

0 commit comments

Comments
 (0)