Skip to content

Commit

Permalink
Add consistencyLevel setter for batchOps
Browse files Browse the repository at this point in the history
  • Loading branch information
wtetsu committed Nov 15, 2021
1 parent 25260ad commit d806d32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.cassandra.core;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -42,6 +43,7 @@
* @since 1.5
*/
class CassandraBatchTemplate implements CassandraBatchOperations {
//public class CassandraBatchTemplate implements CassandraBatchOperations {

private final AtomicBoolean executed = new AtomicBoolean();

Expand All @@ -60,8 +62,7 @@ class CassandraBatchTemplate implements CassandraBatchOperations {
*
* @param operations must not be {@literal null}.
*/
CassandraBatchTemplate(CassandraOperations operations) {

public CassandraBatchTemplate(CassandraOperations operations) {
Assert.notNull(operations, "CassandraOperations must not be null");

this.operations = operations;
Expand All @@ -70,6 +71,16 @@ class CassandraBatchTemplate implements CassandraBatchOperations {
this.statementFactory = new StatementFactory(new UpdateMapper(converter));
}

/**
* Create a new {@link CassandraBatchTemplate} given {@link CassandraOperations} with {@link ConsistencyLevel}.
*
* @param operations must not be {@literal null}.
*/
public CassandraBatchTemplate(CassandraOperations operations, ConsistencyLevel consistencyLevel) {
this(operations);
batch.setConsistencyLevel(consistencyLevel);
}

/**
* Return a reference to the configured {@link CassandraConverter} used to map {@link Object Objects} to
* {@link com.datastax.driver.core.Row Rows}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.cassandra.core;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
Expand Down Expand Up @@ -58,6 +59,14 @@ public interface CassandraOperations extends FluentCassandraOperations {
*/
CassandraBatchOperations batchOps();

/**
* Returns a new {@link CassandraBatchOperations}. Each {@link CassandraBatchOperations} instance can be executed only
* once so you might want to obtain new {@link CassandraBatchOperations} instances for each batch.
*
* @return a new {@link CassandraBatchOperations} associated with the given entity class.
*/
CassandraBatchOperations batchOps(ConsistencyLevel consistencyLevel);

/**
* Expose the underlying {@link CqlOperations} to allow CQL operations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.cassandra.core;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -202,6 +203,12 @@ public CassandraBatchOperations batchOps() {
return new CassandraBatchTemplate(this);
}

@Override
public CassandraBatchOperations batchOps(ConsistencyLevel consistencyLevel) {
return new CassandraBatchTemplate(this, consistencyLevel);
}


/* (non-Javadoc)
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
*/
Expand Down

1 comment on commit d806d32

@wtetsu
Copy link
Owner Author

@wtetsu wtetsu commented on d806d32 Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on 3.2.2

Please # to comment.