DATACASS-522 - Polish.
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
|
||||
import com.datastax.driver.core.KeyspaceMetadata;
|
||||
import com.datastax.driver.core.TableMetadata;
|
||||
@@ -48,29 +49,40 @@ public interface CassandraAdminOperations extends CassandraOperations {
|
||||
Map<String, Object> optionsByName);
|
||||
|
||||
/**
|
||||
* Drops the named table.
|
||||
* Drops a table based on the given {@link Class entity type}.
|
||||
*
|
||||
* @param tableName The name of the table.
|
||||
* The name of the table is derived from either the simple name of the {@link Class entity class}
|
||||
* or name of the table specified with the {@link Table} mapping annotation.
|
||||
*
|
||||
* @param entityType {@link Class type} of the entity for which the table will be dropped.
|
||||
*/
|
||||
void dropTable(Class<?> entityType);
|
||||
|
||||
/**
|
||||
* Drops the {@link String named} table.
|
||||
*
|
||||
* @param tableName {@link String Name} of the table to drop.
|
||||
* @see #dropTable(boolean, CqlIdentifier)
|
||||
*/
|
||||
void dropTable(CqlIdentifier tableName);
|
||||
|
||||
/**
|
||||
* Drops the named table.
|
||||
* Drops the {@link String named} table.
|
||||
*
|
||||
* @param ifExists If true, will only drop the table if it exists, else the create operation will be ignored.
|
||||
* @param tableName The name of the table.
|
||||
* @param ifExists If {@literal true}, will only drop the table if it exists,
|
||||
* else the drop operation will be ignored.
|
||||
* @param tableName {@link String Name} of the table to drop.
|
||||
* @since 2.1
|
||||
*/
|
||||
void dropTable(boolean ifExists, CqlIdentifier tableName);
|
||||
|
||||
/**
|
||||
* Lookup {@link TableMetadata}.
|
||||
* Drops a user type.
|
||||
*
|
||||
* @param keyspace must not be empty or {@literal null}.
|
||||
* @param tableName must not be {@literal null}.
|
||||
* @return the {@link TableMetadata} or {@literal null}.
|
||||
* @param typeName must not be {@literal null}.
|
||||
* @since 1.5
|
||||
*/
|
||||
Optional<TableMetadata> getTableMetadata(String keyspace, CqlIdentifier tableName);
|
||||
void dropUserType(CqlIdentifier typeName);
|
||||
|
||||
/**
|
||||
* Returns {@link KeyspaceMetadata} for the current keyspace.
|
||||
@@ -81,10 +93,12 @@ public interface CassandraAdminOperations extends CassandraOperations {
|
||||
KeyspaceMetadata getKeyspaceMetadata();
|
||||
|
||||
/**
|
||||
* Drops a user type.
|
||||
* Lookup {@link TableMetadata}.
|
||||
*
|
||||
* @param typeName must not be {@literal null}.
|
||||
* @since 1.5
|
||||
* @param keyspace must not be empty or {@literal null}.
|
||||
* @param tableName must not be {@literal null}.
|
||||
* @return the {@link TableMetadata} or {@literal null}.
|
||||
*/
|
||||
void dropUserType(CqlIdentifier typeName);
|
||||
Optional<TableMetadata> getTableMetadata(String keyspace, CqlIdentifier tableName);
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ import com.datastax.driver.core.TableMetadata;
|
||||
*/
|
||||
public class CassandraAdminTemplate extends CassandraTemplate implements CassandraAdminOperations {
|
||||
|
||||
protected static final boolean DEFAULT_DROP_TABLE_IF_EXISTS = false;
|
||||
|
||||
/**
|
||||
* Constructor used for a basic template configuration.
|
||||
*
|
||||
@@ -79,6 +81,10 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
|
||||
getCqlOperations().execute(CreateTableCqlGenerator.toCql(createTableSpecification));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.CassandraAdminOperations#dropTable(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public void dropTable(Class<?> entityClass) {
|
||||
dropTable(getTableName(entityClass));
|
||||
}
|
||||
@@ -88,7 +94,7 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
|
||||
*/
|
||||
@Override
|
||||
public void dropTable(CqlIdentifier tableName) {
|
||||
dropTable(false, tableName);
|
||||
dropTable(DEFAULT_DROP_TABLE_IF_EXISTS, tableName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -96,8 +102,11 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
|
||||
*/
|
||||
@Override
|
||||
public void dropTable(boolean ifExists, CqlIdentifier tableName) {
|
||||
getCqlOperations()
|
||||
.execute(DropTableCqlGenerator.toCql(DropTableSpecification.dropTable(tableName).ifExists(ifExists)));
|
||||
|
||||
String dropTableCql =
|
||||
DropTableCqlGenerator.toCql(DropTableSpecification.dropTable(tableName).ifExists(ifExists));
|
||||
|
||||
getCqlOperations().execute(dropTableCql);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -108,7 +117,10 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
|
||||
|
||||
Assert.notNull(typeName, "Type name must not be null");
|
||||
|
||||
getCqlOperations().execute(DropUserTypeCqlGenerator.toCql(DropUserTypeSpecification.dropType(typeName)));
|
||||
String dropUserTypeCql =
|
||||
DropUserTypeCqlGenerator.toCql(DropUserTypeSpecification.dropType(typeName));
|
||||
|
||||
getCqlOperations().execute(dropUserTypeCql);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.springframework.data.cassandra.core.cql.keyspace.DropTableSpecificati
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @see org.springframework.data.cassandra.core.cql.generator.TableNameCqlGenerator
|
||||
* @see org.springframework.data.cassandra.core.cql.keyspace.DropTableSpecification
|
||||
*/
|
||||
public class DropTableCqlGenerator extends TableNameCqlGenerator<DropTableSpecification> {
|
||||
|
||||
@@ -35,8 +37,11 @@ public class DropTableCqlGenerator extends TableNameCqlGenerator<DropTableSpecif
|
||||
|
||||
@Override
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
|
||||
DropTableSpecification specification = spec();
|
||||
|
||||
return cql.append("DROP TABLE ")
|
||||
.append(spec().getIfExists() ? "IF EXISTS " : "")
|
||||
.append(spec().getName()).append(";");
|
||||
.append(specification.getIfExists() ? "IF EXISTS " : "")
|
||||
.append(specification.getName()).append(";");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,6 @@ public class DropTableSpecification extends TableNameSpecification {
|
||||
}
|
||||
|
||||
public boolean getIfExists() {
|
||||
return ifExists;
|
||||
return this.ifExists;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user