diff --git a/src/main/java/org/springframework/data/cassandra/core/CassandraAdminOperations.java b/src/main/java/org/springframework/data/cassandra/core/CassandraAdminOperations.java
index 438c0b147..d8cb5b64a 100644
--- a/src/main/java/org/springframework/data/cassandra/core/CassandraAdminOperations.java
+++ b/src/main/java/org/springframework/data/cassandra/core/CassandraAdminOperations.java
@@ -20,56 +20,60 @@ import java.util.Map;
import com.datastax.driver.core.TableMetadata;
/**
- * @author David Webb
+ * Operations for managing a Cassandra keyspace.
*
+ * @author David Webb
+ * @author Matthew T. Adams
*/
public interface CassandraAdminOperations {
/**
- * Get the Table Meta Data from Cassandra
+ * Get the given table's metadata.
*
- * @param entityClass
- * @param tableName
- * @return
+ * @param tableName The name of the table.
*/
- TableMetadata getTableMetadata(Class> entityClass, String tableName);
+ TableMetadata getTableMetadata(String tableName);
/**
- * Create a table with the name and fields indicated by the entity class
+ * Create a table with the name given and fields corresponding to the given class. If the table already exists and
+ * parameter ifNotExists is {@literal true}, this is a no-op and {@literal false} is returned. If the
+ * table doesn't exist, parameter ifNotExists is ignored, the table is created and {@literal true} is
+ * returned.
*
- * @param ifNotExists
- * @param tableName
- * @param entityClass
- * @param optionsByName
+ * @param ifNotExists If true, will only create the table if it doesn't exist, else the create operation will be
+ * ignored and the method will return {@literal false}.
+ * @param tableName The name of the table.
+ * @param entityClass The class whose fields determine the columns created.
+ * @param optionsByName Table options, given by the string option name and the appropriate option value.
+ * @return Returns true if a table was created, false if not.
*/
- void createTable(boolean ifNotExists, String tableName, Class> entityClass, Map optionsByName);
+ boolean createTable(boolean ifNotExists, String tableName, Class> entityClass, Map optionsByName);
/**
- * Alter table with the name and fields indicated by the entity class
+ * Add columns to the given table from the given class. If parameter dropRemovedAttributColumns is true, then this
+ * effectively becomes a synchronization operation between the class's fields and the existing table's columns.
*
- * @param entityClass class that determines metadata of the table to create/drop.
- * @param tableName explicit name of the table
+ * @param tableName The name of the existing table.
+ * @param entityClass The class whose fields determine the columns added.
+ * @param dropRemovedAttributeColumns Whether to drop columns that exist on the table but that don't have
+ * corresponding fields in the class. If true, this effectively becomes a synchronziation operation.
*/
void alterTable(String tableName, Class> entityClass, boolean dropRemovedAttributeColumns);
/**
- * @param tableName
- * @param entityClass
+ * Drops the existing table with the given name and creates a new one; basically a {@link #dropTable(String)} followed
+ * by a {@link #createTable(boolean, String, Class, Map)}.
+ *
+ * @param tableName The name of the table.
+ * @param entityClass The class whose fields determine the new table's columns.
+ * @param optionsByName Table options, given by the string option name and the appropriate option value.
*/
- void replaceTable(String tableName, Class> entityClass);
+ void replaceTable(String tableName, Class> entityClass, Map optionsByName);
/**
- * Alter table with the name and fields indicated by the entity class
+ * Drops the named table.
*
- * @param entityClass class that determines metadata of the table to create/drop.
- */
- void dropTable(Class> entityClass);
-
- /**
- * Alter table with the name and fields indicated by the entity class
- *
- * @param tableName explicit name of the table.
+ * @param tableName The name of the table.
*/
void dropTable(String tableName);
-
}
diff --git a/src/main/java/org/springframework/data/cassandra/core/CassandraAdmin.java b/src/main/java/org/springframework/data/cassandra/core/CassandraAdminTemplate.java
similarity index 71%
rename from src/main/java/org/springframework/data/cassandra/core/CassandraAdmin.java
rename to src/main/java/org/springframework/data/cassandra/core/CassandraAdminTemplate.java
index 8f356b988..cf130a156 100644
--- a/src/main/java/org/springframework/data/cassandra/core/CassandraAdmin.java
+++ b/src/main/java/org/springframework/data/cassandra/core/CassandraAdminTemplate.java
@@ -9,6 +9,7 @@ import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.cassandra.convert.CassandraConverter;
+import org.springframework.data.cassandra.core.exceptions.CassandraTableExistsException;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.mapping.CassandraPersistentProperty;
import org.springframework.data.cassandra.util.CqlUtils;
@@ -20,16 +21,16 @@ import com.datastax.driver.core.Session;
import com.datastax.driver.core.TableMetadata;
/**
- *
+ * Default implementation of {@link CassandraAdminOperations}.
*/
-public class CassandraAdmin implements CassandraAdminOperations {
+public class CassandraAdminTemplate implements CassandraAdminOperations {
- private static Logger log = LoggerFactory.getLogger(CassandraAdmin.class);
+ private static Logger log = LoggerFactory.getLogger(CassandraAdminTemplate.class);
- private final Keyspace keyspace;
- private final Session session;
- private final CassandraConverter cassandraConverter;
- private final MappingContext extends CassandraPersistentEntity>, CassandraPersistentProperty> mappingContext;
+ private Keyspace keyspace;
+ private Session session;
+ private CassandraConverter converter;
+ private MappingContext extends CassandraPersistentEntity>, CassandraPersistentProperty> mappingContext;
private final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
@@ -40,18 +41,38 @@ public class CassandraAdmin implements CassandraAdminOperations {
*
* @param keyspace must not be {@literal null}.
*/
- public CassandraAdmin(Keyspace keyspace) {
+ public CassandraAdminTemplate(Keyspace keyspace) {
+ setKeyspace(keyspace);
+ }
+
+ protected CassandraAdminTemplate setKeyspace(Keyspace keyspace) {
+ Assert.notNull(keyspace);
this.keyspace = keyspace;
- this.session = keyspace.getSession();
- this.cassandraConverter = keyspace.getCassandraConverter();
- this.mappingContext = this.cassandraConverter.getMappingContext();
+ return setSession(keyspace.getSession()).setCassandraConverter(keyspace.getCassandraConverter());
+ }
+
+ protected CassandraAdminTemplate setSession(Session session) {
+ Assert.notNull(session);
+ return this;
+ }
+
+ protected CassandraAdminTemplate setCassandraConverter(CassandraConverter converter) {
+ Assert.notNull(converter);
+ this.converter = converter;
+ return setMappingContext(converter.getMappingContext());
+ }
+
+ protected CassandraAdminTemplate setMappingContext(
+ MappingContext extends CassandraPersistentEntity>, CassandraPersistentProperty> mappingContext) {
+ Assert.notNull(mappingContext);
+ return this;
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.CassandraAdminOperations#createTable(boolean, java.lang.String, java.lang.Class, java.util.Map)
*/
@Override
- public void createTable(boolean ifNotExists, final String tableName, Class> entityClass,
+ public boolean createTable(boolean ifNotExists, final String tableName, Class> entityClass,
Map optionsByName) {
try {
@@ -59,25 +80,21 @@ public class CassandraAdmin implements CassandraAdminOperations {
final CassandraPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
execute(new SessionCallback