Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATACASS-751: Allow keyspace customization for CassandraPersistentEntity #179

Closed
wants to merge 8 commits into from

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import com.datastax.oss.driver.api.core.cql.BatchStatementBuilder;
import com.datastax.oss.driver.api.core.cql.BatchType;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.cql.Statement;

/**
* Default implementation for {@link CassandraBatchOperations}.
*
* @author Mark Paluch
* @author John Blum
* @author Anup Sabbi
* @author Tomasz Lelek
* @since 1.5
*/
class CassandraBatchTemplate implements CassandraBatchOperations {
Expand Down Expand Up @@ -168,7 +170,7 @@ public CassandraBatchOperations insert(Iterable<?> entities, WriteOptions option
.getRequiredPersistentEntity(entity.getClass());

SimpleStatement insertQuery = getStatementFactory()
.insert(entity, options, persistentEntity, persistentEntity.getTableName()).build();
.insert(entity, options, persistentEntity, TableCoordinates.of(persistentEntity)).build();

this.batch.addStatement(insertQuery);
}
Expand Down Expand Up @@ -213,7 +215,7 @@ public CassandraBatchOperations update(Iterable<?> entities, WriteOptions option
CassandraPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(entity.getClass());

SimpleStatement update = getStatementFactory()
.update(entity, options, persistentEntity, persistentEntity.getTableName()).build();
.update(entity, options, persistentEntity, TableCoordinates.of(persistentEntity)).build();

this.batch.addStatement(update);
}
Expand Down Expand Up @@ -258,7 +260,7 @@ public CassandraBatchOperations delete(Iterable<?> entities, WriteOptions option
CassandraPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(entity.getClass());

SimpleStatement delete = getStatementFactory()
.delete(entity, options, this.getConverter(), persistentEntity.getTableName()).build();
.delete(entity, options, this.getConverter(), TableCoordinates.of(persistentEntity)).build();

this.batch.addStatement(delete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.springframework.dao.DataAccessException;
Expand All @@ -41,6 +42,7 @@
* @author David Webb
* @author Matthew Adams
* @author Mark Paluch
* @author Tomasz Lelek
* @see CassandraTemplate
* @see CqlOperations
* @see Statement
Expand Down Expand Up @@ -80,6 +82,16 @@ public interface CassandraOperations extends FluentCassandraOperations {
*/
CqlIdentifier getTableName(Class<?> entityClass);


/**
* The keyspace used for the specified class by this template.
*
* @param entityClass entity class, may be {@literal null}.
* @return the {@link Optional<CqlIdentifier> } the keyspace to which the entity shall be persisted. If null, then
* default session-level keyspace will be used.
*/
Optional<CqlIdentifier> getKeyspaceName(Class<?> entityClass);

// -------------------------------------------------------------------------
// Methods dealing with static CQL
// -------------------------------------------------------------------------
Expand Down
Loading