Skip to content

Commit 9d1c762

Browse files
committed
Polishing.
Remove constructors defaulting to BatchType.LOGGED and turn batchOps() into default methods to avoid defaulting sprawl. Update since tags. See #1174 Original pull request: #1175.
1 parent acc867a commit 9d1c762

File tree

8 files changed

+54
-80
lines changed

8 files changed

+54
-80
lines changed

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,12 @@ class CassandraBatchTemplate implements CassandraBatchOperations {
5656

5757
private final StatementFactory statementFactory;
5858

59-
/**
60-
* Create a new {@link CassandraBatchTemplate} given {@link CassandraOperations}.
61-
*
62-
* @param operations must not be {@literal null}.
63-
*/
64-
CassandraBatchTemplate(CassandraOperations operations) {
65-
this(operations, BatchType.LOGGED);
66-
}
67-
6859
/**
6960
* Create a new {@link CassandraBatchTemplate} given {@link CassandraOperations} and {@link BatchType}.
7061
*
7162
* @param operations must not be {@literal null}.
7263
* @param batchType must not be {@literal null}.
73-
* @since 3.3.0
64+
* @since 3.2.6
7465
*/
7566
CassandraBatchTemplate(CassandraOperations operations, BatchType batchType) {
7667

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,24 @@
5353
public interface CassandraOperations extends FluentCassandraOperations {
5454

5555
/**
56-
* Returns a new {@link CassandraBatchOperations}. Each {@link CassandraBatchOperations} instance can be executed only
57-
* once, so you might want to obtain new {@link CassandraBatchOperations} instances for each batch.
56+
* Returns a new {@link CassandraBatchOperations} using {@link BatchType#LOGGED}. Each
57+
* {@link CassandraBatchOperations} instance can be executed only once, so you need to obtain new
58+
* {@link CassandraBatchOperations} instances for each batch.
5859
*
5960
* @return a new {@link CassandraBatchOperations} associated with the given entity class.
61+
* @see #batchOps(BatchType)
6062
*/
61-
CassandraBatchOperations batchOps();
63+
default CassandraBatchOperations batchOps() {
64+
return batchOps(BatchType.LOGGED);
65+
}
6266

6367
/**
6468
* Returns a new {@link CassandraBatchOperations}. Each {@link CassandraBatchOperations} instance can be executed only
65-
* once, so you might want to obtain new {@link CassandraBatchOperations} instances for each batch.
69+
* once, so you need to obtain new {@link CassandraBatchOperations} instances for each batch.
6670
*
6771
* @param batchType must not be {@literal null}.
6872
* @return a new {@link ReactiveCassandraBatchOperations} associated with the given entity class.
69-
* @since 3.3.0
73+
* @since 3.2.6
7074
*/
7175
CassandraBatchOperations batchOps(BatchType batchType);
7276

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

-8
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,6 @@ public CassandraTemplate(CqlOperations cqlOperations, CassandraConverter convert
196196
this.statementFactory = new StatementFactory(new QueryMapper(converter), new UpdateMapper(converter));
197197
}
198198

199-
/* (non-Javadoc)
200-
* @see org.springframework.data.cassandra.core.CassandraOperations#batchOps()
201-
*/
202-
@Override
203-
public CassandraBatchOperations batchOps() {
204-
return new CassandraBatchTemplate(this);
205-
}
206-
207199
/* (non-Javadoc)
208200
* @see org.springframework.data.cassandra.core.CassandraOperations#batchOps(com.datastax.oss.driver.api.core.cql.BatchType)
209201
*/

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,12 @@ class ReactiveCassandraBatchTemplate implements ReactiveCassandraBatchOperations
6565

6666
private final StatementFactory statementFactory;
6767

68-
/**
69-
* Create a new {@link CassandraBatchTemplate} given {@link CassandraOperations}.
70-
*
71-
* @param operations must not be {@literal null}.
72-
*/
73-
ReactiveCassandraBatchTemplate(ReactiveCassandraOperations operations) {
74-
this(operations, BatchType.LOGGED);
75-
}
76-
7768
/**
7869
* Create a new {@link CassandraBatchTemplate} given {@link CassandraOperations} and {@link BatchType}.
7970
*
8071
* @param operations must not be {@literal null}.
8172
* @param batchType must not be {@literal null}.
82-
* @since 3.3.0
73+
* @since 3.2.6
8374
*/
8475
ReactiveCassandraBatchTemplate(ReactiveCassandraOperations operations, BatchType batchType) {
8576

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,25 @@
5252
public interface ReactiveCassandraOperations extends ReactiveFluentCassandraOperations {
5353

5454
/**
55-
* Returns a new {@link ReactiveCassandraBatchOperations}. Each {@link ReactiveCassandraBatchOperations} instance can
56-
* be executed only once, so you might want to obtain new {@link ReactiveCassandraBatchOperations} instances for each
57-
* batch.
55+
* Returns a new {@link ReactiveCassandraBatchOperations} using {@link BatchType#LOGGED}. Each
56+
* {@link ReactiveCassandraBatchOperations} instance can be executed only once, so you need to obtain new
57+
* {@link ReactiveCassandraBatchOperations} instances for each batch.
5858
*
5959
* @return a new {@link ReactiveCassandraBatchOperations} associated with the given entity class.
6060
* @since 2.1
61+
* @see #batchOps(BatchType)
6162
*/
62-
ReactiveCassandraBatchOperations batchOps();
63+
default ReactiveCassandraBatchOperations batchOps() {
64+
return batchOps(BatchType.LOGGED);
65+
}
6366

6467
/**
6568
* Returns a new {@link ReactiveCassandraBatchOperations}. Each {@link ReactiveCassandraBatchOperations} instance can
66-
* be executed only once, so you might want to obtain new {@link ReactiveCassandraBatchOperations} instances for each
67-
* batch.
69+
* be executed only once, so you need to obtain new {@link ReactiveCassandraBatchOperations} instances for each batch.
6870
*
6971
* @param batchType must not be {@literal null}.
7072
* @return a new {@link ReactiveCassandraBatchOperations} associated with the given entity class.
71-
* @since 3.3.0
73+
* @since 3.2.6
7274
*/
7375
ReactiveCassandraBatchOperations batchOps(BatchType batchType);
7476

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

-8
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,6 @@ public ReactiveCassandraTemplate(ReactiveCqlOperations reactiveCqlOperations, Ca
193193
this.statementFactory = new StatementFactory(converter);
194194
}
195195

196-
/* (non-Javadoc)
197-
* @see org.springframework.data.cassandra.core.ReactiveCassandraOperations#batchOps()
198-
*/
199-
@Override
200-
public ReactiveCassandraBatchOperations batchOps() {
201-
return new ReactiveCassandraBatchTemplate(this);
202-
}
203-
204196
/* (non-Javadoc)
205197
* @see org.springframework.data.cassandra.core.ReactiveCassandraOperations#batchOps(com.datastax.oss.driver.api.core.cql.BatchType)
206198
*/

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/CassandraBatchTemplateIntegrationTests.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.data.cassandra.repository.support.SchemaTestUtils;
3131
import org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests;
3232

33+
import com.datastax.oss.driver.api.core.cql.BatchType;
3334
import com.datastax.oss.driver.api.core.cql.ResultSet;
3435
import com.datastax.oss.driver.api.core.cql.Row;
3536

@@ -64,7 +65,7 @@ void setUp() throws Exception {
6465
@Test // DATACASS-288
6566
void shouldInsertEntities() {
6667

67-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
68+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
6869
batchOperations.insert(walter).insert(mike).execute();
6970

7071
Group loaded = template.selectOneById(walter.getId(), Group.class);
@@ -89,7 +90,7 @@ void shouldInsertEntitiesWithLwt() {
8990

9091
walter.setAge(100);
9192

92-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
93+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
9394

9495
WriteResult writeResult = batchOperations.insert(walter, lwtOptions).insert(mike).execute();
9596

@@ -108,7 +109,7 @@ void shouldInsertEntitiesWithLwt() {
108109
@Test // DATACASS-288
109110
void shouldInsertCollectionOfEntities() {
110111

111-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
112+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
112113
batchOperations.insert(Arrays.asList(walter, mike)).execute();
113114

114115
Group loaded = template.selectOneById(walter.getId(), Group.class);
@@ -125,7 +126,7 @@ void shouldInsertCollectionOfEntitiesWithTtl() {
125126
int ttl = 30;
126127
WriteOptions options = WriteOptions.builder().ttl(30).build();
127128

128-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
129+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
129130
batchOperations.insert(Arrays.asList(walter, mike), options).execute();
130131

131132
ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;");
@@ -149,7 +150,7 @@ void shouldUpdateEntities() {
149150
walter.setEmail("[email protected]");
150151
mike.setEmail("[email protected]");
151152

152-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
153+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
153154
batchOperations.update(walter).update(mike).execute();
154155

155156
Group loaded = template.selectOneById(walter.getId(), Group.class);
@@ -163,7 +164,7 @@ void shouldUpdateCollectionOfEntities() {
163164
walter.setEmail("[email protected]");
164165
mike.setEmail("[email protected]");
165166

166-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
167+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
167168
batchOperations.update(Arrays.asList(walter, mike)).execute();
168169

169170
Group loaded = template.selectOneById(walter.getId(), Group.class);
@@ -180,7 +181,7 @@ void shouldUpdateCollectionOfEntitiesWithTtl() {
180181
int ttl = 30;
181182
WriteOptions options = WriteOptions.builder().ttl(ttl).build();
182183

183-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
184+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
184185
batchOperations.update(walter, options).execute();
185186

186187
ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT TTL(email), email FROM group");
@@ -209,7 +210,7 @@ void shouldUpdatesCollectionOfEntities() {
209210
walter.setEmail("[email protected]");
210211
mike.setEmail("[email protected]");
211212

212-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
213+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
213214
batchOperations.update(Arrays.asList(walter, mike)).execute();
214215

215216
FlatGroup loaded = template.selectOneById(walter, FlatGroup.class);
@@ -226,7 +227,7 @@ void deleteAsVarargsShouldRejectQueryOptions() {
226227
@Test // DATACASS-288
227228
void shouldDeleteEntities() {
228229

229-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
230+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
230231

231232
batchOperations.delete(walter).delete(mike).execute();
232233

@@ -238,7 +239,7 @@ void shouldDeleteEntities() {
238239
@Test // DATACASS-288
239240
void shouldDeleteCollectionOfEntities() {
240241

241-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
242+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
242243

243244
batchOperations.delete(Arrays.asList(walter, mike)).execute();
244245

@@ -255,7 +256,7 @@ void shouldApplyTimestampToAllEntities() {
255256

256257
long timestamp = (System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)) * 1000;
257258

258-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
259+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
259260
batchOperations.insert(walter).insert(mike).withTimestamp(timestamp).execute();
260261

261262
ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT writetime(email) FROM group;");
@@ -270,7 +271,7 @@ void shouldApplyTimestampToAllEntities() {
270271
@Test // DATACASS-288
271272
void shouldNotExecuteTwice() {
272273

273-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
274+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
274275
batchOperations.insert(walter).execute();
275276

276277
assertThatIllegalStateException().isThrownBy(() -> batchOperations.execute());
@@ -279,7 +280,7 @@ void shouldNotExecuteTwice() {
279280
@Test // DATACASS-288
280281
void shouldNotAllowModificationAfterExecution() {
281282

282-
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template);
283+
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
283284
batchOperations.insert(walter).execute();
284285

285286
assertThatIllegalStateException().isThrownBy(() -> batchOperations.update(new Group()));

0 commit comments

Comments
 (0)