All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.data.cassandra.core.ReactiveCassandraBatchOperations Maven / Gradle / Ivy

There is a newer version: 4.3.0
Show newest version
/*
 * Copyright 2018-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.cassandra.core;

import reactor.core.publisher.Mono;

import org.reactivestreams.Subscriber;
import org.springframework.data.cassandra.core.cql.WriteOptions;

/**
 * Reactive Batch operations for insert/update/delete actions on a table. {@link ReactiveCassandraBatchOperations} use
 * logged Cassandra {@code BATCH}es for single entities and collections of entities. A
 * {@link ReactiveCassandraBatchOperations} instance cannot be modified/used once it was executed.
 * 

* Batches are atomic by default. In the context of a Cassandra batch operation, atomic means that if any of the batch * succeeds, all of it will. Statement order does not matter within a batch. {@link ReactiveCassandraBatchOperations} * applies all rows using the same {@link #withTimestamp(long) timestamp} if supplied, otherwise Cassandra will generate * a timestamp. *

* Multi partition batches should only be used to achieve atomicity for a few writes on different tables. Apart from * this they should be avoided because they’re too expensive. Single partition batches can be used to get atomicity and * isolation, they're not much more expensive than normal writes. * * @author Oleh Dokuka * @since 2.1 */ public interface ReactiveCassandraBatchOperations { /** * Execute the batch. The batch can be executed only once. An execution is registered on * {@link org.reactivestreams.Publisher#subscribe(Subscriber) subscribe}. * * @return the {@link Mono} for the bulk operation. Terminates with {@link IllegalStateException} if an * already executed batch is being attempted to execute. */ Mono execute(); /** * Apply a given {@code timestamp} to the whole batch. * * @param timestamp the timestamp to apply. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations withTimestamp(long timestamp); /** * Add an array of inserts to the batch. * * @param entities the entities to insert; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations insert(Object... entities); /** * Add a collection of inserts to the batch. * * @param entities the entities to insert; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations insert(Iterable entities); /** * Add a collection of inserts to the batch. * * @param entities the entities to insert; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations insert(Mono> entities); /** * Add a collection of inserts with given {@link WriteOptions} to the batch. * * @param entities the entities to insert; must not be {@literal null}. * @param options the WriteOptions to apply; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. * @since 2.0 */ ReactiveCassandraBatchOperations insert(Iterable entities, WriteOptions options); /** * Add a collection of inserts with given {@link WriteOptions} to the batch. * * @param entities the entities to insert; must not be {@literal null}. * @param options the WriteOptions to apply; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. * @since 2.0 */ ReactiveCassandraBatchOperations insert(Mono> entities, WriteOptions options); /** * Add an array of updates to the batch. * * @param entities the entities to update; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations update(Object... entities); /** * Add a collection of updates to the batch. * * @param entities the entities to update; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations update(Iterable entities); /** * Add a collection of updates to the batch. * * @param entities the entities to update; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations update(Mono> entities); /** * Add a collection of updates with given {@link WriteOptions} to the batch. * * @param entities the entities to update; must not be {@literal null}. * @param options the WriteOptions to apply; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. * @since 2.0 */ ReactiveCassandraBatchOperations update(Iterable entities, WriteOptions options); /** * Add a collection of updates with given {@link WriteOptions} to the batch. * * @param entities the entities to update; must not be {@literal null}. * @param options the WriteOptions to apply; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. * @since 2.0 */ ReactiveCassandraBatchOperations update(Mono> entities, WriteOptions options); /** * Add an array of deletes to the batch. * * @param entities the entities to delete; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations delete(Object... entities); /** * Add a collection of deletes to the batch. * * @param entities the entities to delete; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations delete(Iterable entities); /** * Add a collection of deletes to the batch. * * @param entities the entities to delete; must not be {@literal null}. * @return {@code this} {@link ReactiveCassandraBatchOperations}. * @throws IllegalStateException if the batch was already executed. */ ReactiveCassandraBatchOperations delete(Mono> entities); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy