Skip to content

Commit d7a48f2

Browse files
OlegDokukamp911de
authored andcommitted
DATACASS-574 - Add reactive batch operations.
Original pull request: #134.
1 parent c61683c commit d7a48f2

File tree

5 files changed

+949
-0
lines changed

5 files changed

+949
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Copyright 2016-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.cassandra.core;
17+
18+
import reactor.core.publisher.Mono;
19+
20+
import org.springframework.data.cassandra.core.cql.WriteOptions;
21+
22+
/**
23+
* Reactive Batch operations for insert/update/delete actions on a table. {@link ReactiveCassandraBatchOperations} use logged Cassandra
24+
* {@code BATCH}es for single entities and collections of entities. A {@link ReactiveCassandraBatchOperations} instance cannot
25+
* be modified/used once it was executed.
26+
* <p>
27+
* Batches are atomic by default. In the context of a Cassandra batch operation, atomic means that if any of the batch
28+
* succeeds, all of it will. Statement order does not matter within a batch. {@link ReactiveCassandraBatchOperations} applies
29+
* all rows using the same {@link #withTimestamp(long) timestamp} if supplied, otherwise Cassandra will generate a
30+
* timestamp.
31+
* <p>
32+
* Multi partition batches should only be used to achieve atomicity for a few writes on different tables. Apart from
33+
* this they should be avoided because they’re too expensive. Single partition batches can be used to get atomicity and
34+
* isolation, they're not much more expensive than normal writes.
35+
*
36+
* @author Oleh Dokuka
37+
* @since 2.0
38+
*/
39+
public interface ReactiveCassandraBatchOperations {
40+
41+
/**
42+
* Execute the batch. The batch can be executed only once.
43+
*
44+
* @return the {@link Mono<WriteResult>} for the bulk operation.
45+
* @throws IllegalStateException if the batch is executed after it was executed already.
46+
*/
47+
Mono<WriteResult> execute();
48+
49+
/**
50+
* Apply a given {@code timestamp} to the whole batch.
51+
*
52+
* @param timestamp the timestamp to apply.
53+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
54+
* @throws IllegalStateException if the batch was already executed.
55+
*/
56+
ReactiveCassandraBatchOperations withTimestamp(long timestamp);
57+
58+
/**
59+
* Add an array of inserts to the batch.
60+
*
61+
* @param entities the entities to insert; must not be {@literal null}.
62+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
63+
* @throws IllegalStateException if the batch was already executed.
64+
*/
65+
ReactiveCassandraBatchOperations insert(Object... entities);
66+
67+
/**
68+
* Add a collection of inserts to the batch.
69+
*
70+
* @param entities the entities to insert; must not be {@literal null}.
71+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
72+
* @throws IllegalStateException if the batch was already executed.
73+
*/
74+
ReactiveCassandraBatchOperations insert(Iterable<?> entities);
75+
76+
/**
77+
* Add a collection of inserts to the batch.
78+
*
79+
* @param entities the entities to insert; must not be {@literal null}.
80+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
81+
* @throws IllegalStateException if the batch was already executed.
82+
*/
83+
ReactiveCassandraBatchOperations insert(Mono<? extends Iterable<?>> entities);
84+
85+
/**
86+
* Add a collection of inserts with given {@link WriteOptions} to the batch.
87+
*
88+
* @param entities the entities to insert; must not be {@literal null}.
89+
* @param options the WriteOptions to apply; must not be {@literal null}.
90+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
91+
* @throws IllegalStateException if the batch was already executed.
92+
* @since 2.0
93+
*/
94+
ReactiveCassandraBatchOperations insert(Iterable<?> entities, WriteOptions options);
95+
96+
97+
/**
98+
* Add a collection of inserts with given {@link WriteOptions} to the batch.
99+
*
100+
* @param entities the entities to insert; must not be {@literal null}.
101+
* @param options the WriteOptions to apply; must not be {@literal null}.
102+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
103+
* @throws IllegalStateException if the batch was already executed.
104+
* @since 2.0
105+
*/
106+
ReactiveCassandraBatchOperations insert(Mono<? extends Iterable<?>> entities, WriteOptions options);
107+
108+
/**
109+
* Add an array of updates to the batch.
110+
*
111+
* @param entities the entities to update; must not be {@literal null}.
112+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
113+
* @throws IllegalStateException if the batch was already executed.
114+
*/
115+
ReactiveCassandraBatchOperations update(Object... entities);
116+
117+
/**
118+
* Add a collection of updates to the batch.
119+
*
120+
* @param entities the entities to update; must not be {@literal null}.
121+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
122+
* @throws IllegalStateException if the batch was already executed.
123+
*/
124+
ReactiveCassandraBatchOperations update(Iterable<?> entities);
125+
126+
/**
127+
* Add a collection of updates to the batch.
128+
*
129+
* @param entities the entities to update; must not be {@literal null}.
130+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
131+
* @throws IllegalStateException if the batch was already executed.
132+
*/
133+
ReactiveCassandraBatchOperations update(Mono<? extends Iterable<?>> entities);
134+
135+
/**
136+
* Add a collection of updates with given {@link WriteOptions} to the batch.
137+
*
138+
* @param entities the entities to update; must not be {@literal null}.
139+
* @param options the WriteOptions to apply; must not be {@literal null}.
140+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
141+
* @throws IllegalStateException if the batch was already executed.
142+
* @since 2.0
143+
*/
144+
ReactiveCassandraBatchOperations update(Iterable<?> entities, WriteOptions options);
145+
146+
/**
147+
* Add a collection of updates with given {@link WriteOptions} to the batch.
148+
*
149+
* @param entities the entities to update; must not be {@literal null}.
150+
* @param options the WriteOptions to apply; must not be {@literal null}.
151+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
152+
* @throws IllegalStateException if the batch was already executed.
153+
* @since 2.0
154+
*/
155+
ReactiveCassandraBatchOperations update(Mono<? extends Iterable<?>> entities, WriteOptions options);
156+
157+
/**
158+
* Add an array of deletes to the batch.
159+
*
160+
* @param entities the entities to delete; must not be {@literal null}.
161+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
162+
* @throws IllegalStateException if the batch was already executed.
163+
*/
164+
ReactiveCassandraBatchOperations delete(Object... entities);
165+
166+
/**
167+
* Add a collection of deletes to the batch.
168+
*
169+
* @param entities the entities to delete; must not be {@literal null}.
170+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
171+
* @throws IllegalStateException if the batch was already executed.
172+
*/
173+
ReactiveCassandraBatchOperations delete(Iterable<?> entities);
174+
175+
/**
176+
* Add a collection of deletes to the batch.
177+
*
178+
* @param entities the entities to delete; must not be {@literal null}.
179+
* @return {@code this} {@link ReactiveCassandraBatchOperations}.
180+
* @throws IllegalStateException if the batch was already executed.
181+
*/
182+
ReactiveCassandraBatchOperations delete(Mono<? extends Iterable<?>> entities);
183+
}

0 commit comments

Comments
 (0)