DATACASS-482 - Introduce KeyspaceSpecifications factory methods.

Encapsulate required KeyspaceSpecification properties in immutable base classes. Introduce static factory methods to create value objects where possible. Rewrite Javadoc to reflect the nature of configuration objects and not builders since these objects to not build a target object. Refactor duplicate code into utility classes.
This commit is contained in:
Mark Paluch
2017-07-31 11:41:31 +02:00
parent 94d6a3ddc7
commit 88d7bb231a
33 changed files with 534 additions and 348 deletions

View File

@@ -24,13 +24,13 @@ import org.springframework.util.Assert;
* @param <T> subtype of {@link KeyspaceActionSpecification}.
* @author Mark Paluch
*/
public abstract class KeyspaceNameCqlGenerator<T extends KeyspaceActionSpecification<T>> {
public abstract class KeyspaceNameCqlGenerator<T extends KeyspaceActionSpecification> {
public abstract StringBuilder toCql(StringBuilder cql);
private final KeyspaceActionSpecification<T> specification;
private final KeyspaceActionSpecification specification;
public KeyspaceNameCqlGenerator(KeyspaceActionSpecification<T> specification) {
public KeyspaceNameCqlGenerator(KeyspaceActionSpecification specification) {
Assert.notNull(specification, "KeyspaceActionSpecification must not be null");
this.specification = specification;

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.cassandra.core.cql.generator;
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
import java.util.Map;
import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOptionsSpecification;
@@ -41,37 +39,6 @@ public abstract class KeyspaceOptionsCqlGenerator<T extends KeyspaceOptionsSpeci
}
void optionValueMap(Map<Option, Object> valueMap, StringBuilder cql) {
if (valueMap.isEmpty()) {
return;
}
// else option value is a non-empty map
// append { 'name' : 'value', ... }
cql.append("{ ");
boolean mapFirst = true;
for (Map.Entry<Option, Object> entry : valueMap.entrySet()) {
if (mapFirst) {
mapFirst = false;
} else {
cql.append(", ");
}
Option option = entry.getKey();
cql.append(singleQuote(option.getName())); // entries in map keys are always quoted
cql.append(" : ");
Object entryValue = entry.getValue();
entryValue = entryValue == null ? "" : entryValue.toString();
if (option.escapesValue()) {
entryValue = escapeSingle(entryValue);
}
if (option.quotesValue()) {
entryValue = singleQuote(entryValue);
}
cql.append(entryValue);
}
cql.append(" }");
return;
cql.append(OptionRenderUtil.render(valueMap));
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2017 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
*
* http://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.cql.generator;
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
import java.util.Map;
import org.springframework.data.cassandra.core.cql.keyspace.Option;
/**
* @author Mark Paluch
*/
public class OptionRenderUtil {
static String render(Map<Option, Object> valueMap) {
if (valueMap.isEmpty()) {
return "";
}
StringBuilder cql = new StringBuilder(valueMap.size() * 2 * 16);
// else option value is a non-empty map
// append { 'name' : 'value', ... }
cql.append("{ ");
boolean mapFirst = true;
for (Map.Entry<Option, Object> entry : valueMap.entrySet()) {
if (mapFirst) {
mapFirst = false;
} else {
cql.append(", ");
}
Option option = entry.getKey();
cql.append(singleQuote(option.getName())); // entries in map keys are always quoted
cql.append(" : ");
Object entryValue = entry.getValue();
entryValue = entryValue == null ? "" : entryValue.toString();
if (option.escapesValue()) {
entryValue = escapeSingle(entryValue);
}
if (option.quotesValue()) {
entryValue = singleQuote(entryValue);
}
cql.append(entryValue);
}
cql.append(" }");
return cql.toString();
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.cassandra.core.cql.generator;
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
import java.util.Map;
import org.springframework.data.cassandra.core.cql.keyspace.Option;
@@ -41,37 +39,6 @@ public abstract class TableOptionsCqlGenerator<T extends TableOptionsSpecificati
}
void optionValueMap(Map<Option, Object> valueMap, StringBuilder cql) {
if (valueMap.isEmpty()) {
return;
}
// else option value is a non-empty map
// append { 'name' : 'value', ... }
cql.append("{ ");
boolean mapFirst = true;
for (Map.Entry<Option, Object> entry : valueMap.entrySet()) {
if (mapFirst) {
mapFirst = false;
} else {
cql.append(", ");
}
Option option = entry.getKey();
cql.append(singleQuote(option.getName())); // entries in map keys are always quoted
cql.append(" : ");
Object entryValue = entry.getValue();
entryValue = entryValue == null ? "" : entryValue.toString();
if (option.escapesValue()) {
entryValue = escapeSingle(entryValue);
}
if (option.quotesValue()) {
entryValue = singleQuote(entryValue);
}
cql.append(entryValue);
}
cql.append(" }");
return;
cql.append(OptionRenderUtil.render(valueMap));
}
}

View File

@@ -27,16 +27,16 @@ import org.springframework.util.Assert;
* @since 1.5
* @see UserTypeNameSpecification
*/
public abstract class UserTypeNameCqlGenerator<T extends UserTypeNameSpecification<T>> {
public abstract class UserTypeNameCqlGenerator<T extends UserTypeNameSpecification> {
private final UserTypeNameSpecification<T> specification;
private final UserTypeNameSpecification specification;
/**
* Create a new {@link UserTypeNameCqlGenerator}.
*
* @param specification must not be {@literal null}.
*/
public UserTypeNameCqlGenerator(UserTypeNameSpecification<T> specification) {
public UserTypeNameCqlGenerator(UserTypeNameSpecification specification) {
Assert.notNull(specification, "UserTypeNameSpecification must not be null");

View File

@@ -20,7 +20,7 @@ import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.driver.core.DataType;
/**
* Specification to add a column.
* Value object representing a specification to add a column.
*
* @author Matthew Adams
* @author Mark Paluch
@@ -28,33 +28,29 @@ import com.datastax.driver.core.DataType;
*/
public class AddColumnSpecification extends ColumnTypeChangeSpecification {
/**
* Create a new {@link AddColumnSpecification} for the given {@code name} and {@link type}
*
* @param name must not be empty or {@literal null}.
* @param type must not be {@literal null}.
*/
public static AddColumnSpecification addColumn(String name, DataType type) {
return new AddColumnSpecification(CqlIdentifier.cqlId(name), type);
private AddColumnSpecification(CqlIdentifier name, DataType type) {
super(name, type);
}
/**
* Create a new {@link AddColumnSpecification} for the given {@code name} and {@link type}
* Create a new {@link AddColumnSpecification} for the given {@code name} and {@link DataType}.
*
* @param name must not be {@literal null} or empty.
* @param type must not be {@literal null}.
* @return a new {@link AddColumnSpecification}.
*/
public static AddColumnSpecification addColumn(String name, DataType type) {
return addColumn(CqlIdentifier.cqlId(name), type);
}
/**
* Create a new {@link AddColumnSpecification} for the given {@code name} and {@link DataType}.
*
* @param name must not be {@literal null}.
* @param type must not be {@literal null}.
* @return a new {@link AddColumnSpecification}.
*/
public static AddColumnSpecification addColumn(CqlIdentifier name, DataType type) {
return new AddColumnSpecification(name, type);
}
/**
* Create a new {@link AddColumnSpecification} for the given {@code name} and {@link type}
*
* @param name must not be {@literal null}.
* @param type must not be {@literal null}.
*/
private AddColumnSpecification(CqlIdentifier name, DataType type) {
super(name, type);
}
}

View File

@@ -20,7 +20,7 @@ import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.driver.core.DataType;
/**
* Value object for altering a column.
* Value object representing a specification to alter a column.
*
* @author Matthew T. Adams
* @author Mark Paluch
@@ -28,33 +28,31 @@ import com.datastax.driver.core.DataType;
*/
public class AlterColumnSpecification extends ColumnTypeChangeSpecification {
/**
* Create a new {@link AlterColumnSpecification} for the given {@code name} and {@link DataType}
*
* @param name must not be empty or {@literal null}.
* @param type must not be {@literal null}.
*/
public static AlterColumnSpecification alterColumn(String name, DataType type) {
return new AlterColumnSpecification(CqlIdentifier.cqlId(name), type);
private AlterColumnSpecification(CqlIdentifier name, DataType type) {
super(name, type);
}
/**
* Create a new {@link AlterColumnSpecification} for the given {@code name} and {@link DataType}
* Entry point into the {@link AlterColumnSpecification}'s fluent API given {@code name} and {@link DataType} to alter
* a column. Convenient if imported statically.
*
* @param name must not be {@literal null} or empty.
* @param type must not be {@literal null}.
* @return a new {@link AlterColumnSpecification}.
*/
public static AlterColumnSpecification alterColumn(String name, DataType type) {
return alterColumn(CqlIdentifier.cqlId(name), type);
}
/**
* Entry point into the {@link AlterColumnSpecification}'s fluent API given {@code name} and {@link DataType} to alter
* a column. Convenient if imported statically.
*
* @param name must not be {@literal null}.
* @param type must not be {@literal null}.
* @return a new {@link AlterColumnSpecification}.
*/
public static AlterColumnSpecification alterColumn(CqlIdentifier name, DataType type) {
return new AlterColumnSpecification(name, type);
}
/**
* Create a new {@link AlterColumnSpecification} for the given {@code name} and {@link DataType}
*
* @param name must not be {@literal null}.
* @param type must not be {@literal null}.
*/
private AlterColumnSpecification(CqlIdentifier name, DataType type) {
super(name, type);
}
}

View File

@@ -19,6 +19,11 @@ import lombok.EqualsAndHashCode;
import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
/**
* Object to configure a {@code ALTER KEYSPACE} specification.
*
* @author Mark Paluch
*/
@EqualsAndHashCode(callSuper = true)
public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<AlterKeyspaceSpecification> {
@@ -27,18 +32,24 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<Alt
}
/**
* Entry point into the {@link AlterKeyspaceSpecification}'s fluent API to alter a keyspace. Convenient if imported
* statically.
* Entry point into the {@link AlterKeyspaceSpecification}'s fluent API given {@code name} to alter a keyspace.
* Convenient if imported statically.
*
* @param name must not be {@literal null} or empty.
* @return a new {@link AlterKeyspaceSpecification}.
*/
public static AlterKeyspaceSpecification alterKeyspace(String name) {
return alterKeyspace(KeyspaceIdentifier.ksId(name));
}
/**
* Entry point into the {@link AlterKeyspaceSpecification}'s fluent API given {@code name} to alter a keyspace.
* Convenient if imported statically.
*
* @param name must not be {@literal null} or empty.
* @return a new {@link AlterKeyspaceSpecification}.
*/
public static AlterKeyspaceSpecification alterKeyspace(KeyspaceIdentifier name) {
return new AlterKeyspaceSpecification(name);
}
/**
* Entry point into the {@link AlterKeyspaceSpecification}'s fluent API to alter a keyspace. Convenient if imported
* statically.
*/
public static AlterKeyspaceSpecification alterKeyspace(String name) {
return new AlterKeyspaceSpecification(KeyspaceIdentifier.ksId(name));
}
}

View File

@@ -24,7 +24,7 @@ import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.driver.core.DataType;
/**
* Builder class to construct an {@code ALTER TABLE} specification.
* Object to configure a {@code ALTER TABLE} specification.
*
* @author Matthew T. Adams
* @author Mark Paluch
@@ -49,65 +49,121 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
}
/**
* Entry point into the {@link AlterTableSpecification}'s fluent API to alter a table. Convenient if imported
* statically.
* Entry point into the {@link AlterTableSpecification}'s fluent API given {@code tableName} to alter a table.
* Convenient if imported statically.
*
* @param tableName must not be {@literal null} or empty.
* @return a new {@link AlterTableSpecification}.
*/
public static AlterTableSpecification alterTable(String tableName) {
return alterTable(CqlIdentifier.cqlId(tableName));
}
/**
* Entry point into the {@link AlterTableSpecification}'s fluent API given {@code tableName} to alter a table.
* Convenient if imported statically.
*
* @param tableName must not be {@literal null}.
* @return a new {@link AlterTableSpecification}.
*/
public static AlterTableSpecification alterTable(CqlIdentifier tableName) {
return new AlterTableSpecification(tableName);
}
/**
* Entry point into the {@link AlterTableSpecification}'s fluent API to alter a table. Convenient if imported
* statically.
*/
public static AlterTableSpecification alterTable(String tableName) {
return new AlterTableSpecification(CqlIdentifier.cqlId(tableName));
}
/*
* Adds a {@code DROP} to the list of column changes.
* Adds an {@code ADD} to the list of column changes.
*
* @param column must not be empty or {@literal null}
* @return {@literal this} {@link AlterTableSpecification}
* @param column must not be {@literal null} or empty.
* @param type must not be {@literal null}.
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification drop(String column) {
changes.add(DropColumnSpecification.dropColumn(column));
return this;
public AlterTableSpecification add(String column, DataType type) {
return add(CqlIdentifier.cqlId(column), type);
}
/**
* Adds an {@code ADD} to the list of column changes.
*
* @param column must not be empty or {@literal null}
* @param type must not be {@literal null}
* @return {@literal this} {@link AlterTableSpecification}
* @param column must not be {@literal null}.
* @param type must not be {@literal null}.
* @return {@literal this} {@link AlterTableSpecification}.
* @since 2.0
*/
public AlterTableSpecification add(String column, DataType type) {
changes.add(AddColumnSpecification.addColumn(column, type));
return this;
public AlterTableSpecification add(CqlIdentifier column, DataType type) {
return add(AddColumnSpecification.addColumn(column, type));
}
/*
* Adds a {@code DROP} to the list of column changes.
*
* @param column must not be {@literal null} or empty.
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification drop(String column) {
return drop(CqlIdentifier.cqlId(column));
}
/*
* Adds a {@code DROP} to the list of column changes.
*
* @param column must not be {@literal null} or empty.
* @return {@literal this} {@link AlterTableSpecification}.
* @since 2.0
*/
public AlterTableSpecification drop(CqlIdentifier column) {
return add(DropColumnSpecification.dropColumn(column));
}
/**
* Adds a {@code RENAME} to the list of column changes.
*
* @param from must not be empty or {@literal null}
* @param to must not be empty or {@literal null}
* @return {@literal this} {@link AlterTableSpecification}
* @param from must not be {@literal null} or empty.
* @param to must not be {@literal null} or empty.
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification rename(String from, String to) {
changes.add(new RenameColumnSpecification(from, to));
return this;
return rename(CqlIdentifier.cqlId(from), CqlIdentifier.cqlId(to));
}
/**
* Adds a {@code RENAME} to the list of column changes.
*
* @param from must not be {@literal null}.
* @param to must not be {@literal null}.
* @return {@literal this} {@link AlterTableSpecification}.
* @since 2.0
*/
public AlterTableSpecification rename(CqlIdentifier from, CqlIdentifier to) {
return add(new RenameColumnSpecification(from, to));
}
/**
* Adds an {@literal ALTER} to the list of column changes.
*
* @param column must not be empty or {@literal null}
* @param column must not be {@literal null} or empty
* @param type must not be {@literal null}
* @return {@literal this} {@link AlterTableSpecification}
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification alter(String column, DataType type) {
changes.add(AlterColumnSpecification.alterColumn(column, type));
return alter(CqlIdentifier.cqlId(column), type);
}
/**
* Adds an {@literal ALTER} to the list of column changes.
*
* @param column must not be {@literal null}.
* @param type must not be {@literal null}.
* @return {@literal this} {@link AlterTableSpecification}.
* @since 2.0
*/
public AlterTableSpecification alter(CqlIdentifier column, DataType type) {
return add(AlterColumnSpecification.alterColumn(column, type));
}
private AlterTableSpecification add(ColumnChangeSpecification specification) {
changes.add(specification);
return this;
}
@@ -117,5 +173,4 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
public List<ColumnChangeSpecification> getChanges() {
return Collections.unmodifiableList(changes);
}
}

View File

@@ -24,41 +24,47 @@ import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.driver.core.DataType;
/**
* Builder class to construct an {@code ALTER TYPE} specification.
* Object to configure a {@code ALTER TYPE} specification.
*
* @author Fabio J. Mendes
* @author Mark Paluch
* @since 1.5
* @see CqlIdentifier
*/
public class AlterUserTypeSpecification extends UserTypeNameSpecification<AlterUserTypeSpecification> {
public class AlterUserTypeSpecification extends UserTypeNameSpecification {
private final List<ColumnChangeSpecification> changes = new ArrayList<>();
/**
* Entry point into the {@link AlterUserTypeSpecification}'s fluent API to alter a type. Convenient if imported
* statically.
*/
public static AlterUserTypeSpecification alterType(String typeName) {
return alterType(CqlIdentifier.cqlId(typeName));
}
/**
* Entry point into the {@link AlterUserTypeSpecification}'s fluent API to alter a type. Convenient if imported
* statically.
*/
private static AlterUserTypeSpecification alterType(CqlIdentifier typeName) {
return new AlterUserTypeSpecification(typeName);
}
private AlterUserTypeSpecification(CqlIdentifier name) {
super(name);
}
/**
* Entry point into the {@link AlterColumnSpecification}'s fluent API given {@code typeName} to alter a user type.
* Convenient if imported statically.
*
* @param typeName must not be {@literal null} or empty.
* @return a new {@link AlterUserTypeSpecification}.
*/
public static AlterUserTypeSpecification alterType(String typeName) {
return alterType(CqlIdentifier.cqlId(typeName));
}
/**
* Entry point into the {@link AlterUserTypeSpecification}'s fluent API given {@code typeName} to alter a type.
* Convenient if imported statically.
*
* @param typeName must not be {@literal null} or empty.
* @return a new {@link AlterUserTypeSpecification}.
*/
private static AlterUserTypeSpecification alterType(CqlIdentifier typeName) {
return new AlterUserTypeSpecification(typeName);
}
/**
* Adds an {@literal ADD} to the list of field changes.
*
* @param field must not be empty or {@literal null}.
* @param field must not be {@literal null} or empty.
* @param type must not be {@literal null}.
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
@@ -74,16 +80,13 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification<AlterU
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification add(CqlIdentifier field, DataType type) {
changes.add(AddColumnSpecification.addColumn(field, type));
return this;
return add(AddColumnSpecification.addColumn(field, type));
}
/**
* Adds an {@literal ALTER} to the list of field changes.
*
* @param field must not be empty or {@literal null}.
* @param field must not be {@literal null} or empty.
* @param type must not be {@literal null}.
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
@@ -99,17 +102,14 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification<AlterU
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification alter(CqlIdentifier field, DataType type) {
changes.add(AlterColumnSpecification.alterColumn(field, type));
return this;
return add(AlterColumnSpecification.alterColumn(field, type));
}
/**
* Adds an {@literal RENAME} to the list of field changes.
*
* @param from must not be empty or {@literal null}.
* @param to must not be empty or {@literal null}.
* @param from must not be {@literal null} or empty.
* @param to must not be {@literal null} or empty.
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification rename(String from, String to) {
@@ -120,12 +120,16 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification<AlterU
* Adds an {@literal RENAME} to the list of field changes.
*
* @param from must not be {@literal null}.
* @param to must not be empty or {@literal null}.
* @param to must not be {@literal null} or empty.
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification rename(CqlIdentifier from, CqlIdentifier to) {
return add(new RenameColumnSpecification(from, to));
}
changes.add(new RenameColumnSpecification(from, to));
private AlterUserTypeSpecification add(ColumnChangeSpecification specification) {
changes.add(specification);
return this;
}

View File

@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
import com.datastax.driver.core.DataType;
/**
* Builder class to specify columns.
* Object to configure a CQL column specification.
* <p/>
* Use {@link #name(String)} and {@link #type(String)} to set the name and type of the column, respectively. To specify
* a clustered {@code PRIMARY KEY} column, use {@link #clustered()} or {@link #clustered(Ordering)}. To specify that the
@@ -37,6 +37,7 @@ import com.datastax.driver.core.DataType;
*
* @author Matthew T. Adams
* @author Alex Shvid
* @author Mark Paluch
*/
public class ColumnSpecification {
@@ -58,17 +59,25 @@ public class ColumnSpecification {
}
/**
* Sets the column's name.
* Create a new {@link ColumnSpecification} for the given {@code name}.
*
* @return this
* @param name must not be {@literal null} or empty.
* @return a new {@link ColumnSpecification} for {@code name}.
*/
public static ColumnSpecification name(String name) {
return name(cqlId(name));
}
/**
* Create a new {@link ColumnSpecification} for the given {@code name}.
*
* @param name must not be {@literal null}.
* @return a new {@link ColumnSpecification} for {@code name}.
*/
public static ColumnSpecification name(CqlIdentifier name) {
Assert.notNull(name, "CqlIdentifier must not be null");
return new ColumnSpecification(name);
}
@@ -78,7 +87,11 @@ public class ColumnSpecification {
* @return this
*/
public ColumnSpecification type(DataType type) {
Assert.notNull(type, "DataType must not be null!");
this.type = type;
return this;
}
@@ -100,8 +113,10 @@ public class ColumnSpecification {
* @return this
*/
public ColumnSpecification partitioned(boolean partitioned) {
this.keyType = partitioned ? PARTITIONED : null;
this.ordering = null;
return this;
}
@@ -133,8 +148,10 @@ public class ColumnSpecification {
* @return this
*/
public ColumnSpecification clustered(Ordering order, boolean primary) {
this.keyType = primary ? CLUSTERED : null;
this.ordering = primary ? order : null;
return this;
}
@@ -143,8 +160,10 @@ public class ColumnSpecification {
*
* @return this
*/
ColumnSpecification keyType(PrimaryKeyType keyType) {
public ColumnSpecification keyType(PrimaryKeyType keyType) {
this.keyType = keyType;
return this;
}
@@ -153,8 +172,10 @@ public class ColumnSpecification {
*
* @return this
*/
ColumnSpecification ordering(Ordering ordering) {
public ColumnSpecification ordering(Ordering ordering) {
this.ordering = ordering;
return this;
}

View File

@@ -36,11 +36,12 @@ public abstract class ColumnTypeChangeSpecification extends ColumnChangeSpecific
* @param name must not be {@literal null}.
* @param type must not be {@literal null}.
*/
public ColumnTypeChangeSpecification(CqlIdentifier name, DataType type) {
protected ColumnTypeChangeSpecification(CqlIdentifier name, DataType type) {
super(name);
Assert.notNull(type, "DataType must not be null");
this.type = type;
}

View File

@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Builder class to construct a {@code CREATE INDEX} specification.
* Object to configure a {@code CREATE INDEX} specification.
*
* @author Matthew T. Adams
* @author David Webb
@@ -49,7 +49,13 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
private @Nullable String using;
private Map<String, String> options = new LinkedHashMap<>();
private final Map<String, String> options = new LinkedHashMap<>();
private CreateIndexSpecification() {}
private CreateIndexSpecification(CqlIdentifier name) {
super(name);
}
/**
* Entry point into the {@link CreateIndexSpecification}'s fluent API to create a index. Convenient if imported
@@ -60,19 +66,25 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
}
/**
* Entry point into the {@link CreateIndexSpecification}'s fluent API to create a index. Convenient if imported
* statically.
* Entry point into the {@link CreateIndexSpecification}'s fluent API given {@code indexName} to create a index.
* Convenient if imported statically.
*
* @param indexName must not be {@literal null} or empty.
* @return a new {@link CreateIndexSpecification}.
*/
public static CreateIndexSpecification createIndex(CqlIdentifier name) {
return new CreateIndexSpecification().name(name);
public static CreateIndexSpecification createIndex(String indexName) {
return createIndex(CqlIdentifier.cqlId(indexName));
}
/**
* Entry point into the {@link CreateIndexSpecification}'s fluent API to create a index. Convenient if imported
* statically.
* Entry point into the {@link CreateIndexSpecification}'s fluent API given {@code indexName} to create a index.
* Convenient if imported statically.
*
* @param indexName must not be {@literal null}.
* @return a new {@link CreateIndexSpecification}.
*/
public static CreateIndexSpecification createIndex(String name) {
return new CreateIndexSpecification().name(name);
public static CreateIndexSpecification createIndex(CqlIdentifier indexName) {
return new CreateIndexSpecification(indexName);
}
/**
@@ -90,7 +102,9 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
* @return this
*/
public CreateIndexSpecification ifNotExists(boolean ifNotExists) {
this.ifNotExists = ifNotExists;
return this;
}
@@ -123,6 +137,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
* @see org.springframework.data.cassandra.core.cql.keyspace.IndexDescriptor#getUsing()
*/
@Override
@Nullable
public String getUsing() {
return this.using;
}

View File

@@ -20,7 +20,13 @@ import lombok.EqualsAndHashCode;
import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption.ReplicationStrategy;
import org.springframework.data.cassandra.util.MapBuilder;
import org.springframework.lang.Nullable;
/**
* Object to configure a {@code CREATE KEYSPACE} specification.
*
* @author Mark Paluch
*/
@EqualsAndHashCode(callSuper = true)
public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification<CreateKeyspaceSpecification>
implements KeyspaceDescriptor {
@@ -32,16 +38,22 @@ public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification<Cr
}
/**
* Entry point into the {@link CreateKeyspaceSpecification}'s fluent API to create a keyspace. Convenient if imported
* statically.
* Entry point into the {@link CreateKeyspaceSpecification}'s fluent API given {@code name} to create a keyspace.
* Convenient if imported statically.
*
* @param name must not be {@literal null} or empty.
* @return a new {@link CreateKeyspaceSpecification}.
*/
public static CreateKeyspaceSpecification createKeyspace(String name) {
return new CreateKeyspaceSpecification(KeyspaceIdentifier.ksId(name));
}
/**
* Entry point into the {@link CreateKeyspaceSpecification}'s fluent API to create a keyspace. Convenient if imported
* statically.
* Entry point into the {@link CreateKeyspaceSpecification}'s fluent API given {@code name} to create a keyspace.
* Convenient if imported statically.
*
* @param name must not be {@literal null}.
* @return a new {@link CreateKeyspaceSpecification}.
*/
public static CreateKeyspaceSpecification createKeyspace(KeyspaceIdentifier name) {
return new CreateKeyspaceSpecification(name);
@@ -70,11 +82,22 @@ public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification<Cr
return ifNotExists;
}
/**
* Configure simple replication with a replication factor of {@code 1}.
*
* @return this.
*/
public CreateKeyspaceSpecification withSimpleReplication() {
return withSimpleReplication(1);
}
/**
* Configure simple replication with a {@code replicationFactor}.
*
* @return this.
*/
public CreateKeyspaceSpecification withSimpleReplication(long replicationFactor) {
return with(KeyspaceOption.REPLICATION,
MapBuilder.map(Option.class, Object.class)
.entry(new DefaultOption("class", String.class, true, false, true),
@@ -82,6 +105,11 @@ public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification<Cr
.entry(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor).build());
}
/**
* Configure datacenter replication given {@link DataCenterReplication}.
*
* @return this.
*/
public CreateKeyspaceSpecification withNetworkReplication(DataCenterReplication... dcrs) {
MapBuilder<Option, Object> builder = MapBuilder.map(Option.class, Object.class).entry(
@@ -95,18 +123,27 @@ public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification<Cr
return with(KeyspaceOption.REPLICATION, builder.build());
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOptionsSpecification#with(org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption)
*/
@Override
public CreateKeyspaceSpecification with(KeyspaceOption option) {
return super.with(option);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOptionsSpecification#with(org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption, java.lang.Object)
*/
@Override
public CreateKeyspaceSpecification with(KeyspaceOption option, Object value) {
return super.with(option, value);
}
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOptionsSpecification#with(java.lang.String, java.lang.Object, boolean, boolean)
*/
@Override
public CreateKeyspaceSpecification with(String name, Object value, boolean escape, boolean quote) {
public CreateKeyspaceSpecification with(String name, @Nullable Object value, boolean escape, boolean quote) {
return super.with(name, value, escape, quote);
}
}

View File

@@ -16,9 +16,10 @@
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.lang.Nullable;
/**
* Builder class to construct a {@code CREATE TABLE} specification.
* Object to configure a {@code CREATE TABLE} specification.
*
* @author Matthew T. Adams
* @author Mark Paluch
@@ -32,19 +33,25 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
}
/**
* Entry point into the {@link CreateTableSpecification}'s fluent API to create a table. Convenient if imported
* statically.
* Entry point into the {@link CreateTableSpecification}'s fluent API given {@code tableName} to create a table.
* Convenient if imported statically.
*
* @param tableName must not be {@literal null} or empty.
* @return a new {@link CreateTableSpecification}.
*/
public static CreateTableSpecification createTable(CqlIdentifier name) {
return new CreateTableSpecification(name);
public static CreateTableSpecification createTable(String tableName) {
return new CreateTableSpecification(CqlIdentifier.cqlId(tableName));
}
/**
* Entry point into the {@link CreateTableSpecification}'s fluent API to create a table. Convenient if imported
* statically.
* Entry point into the {@link CreateTableSpecification}'s fluent API given {@code tableName} to create a table.
* Convenient if imported statically.
*
* @param tableName must not be {@literal null}.
* @return a new {@link CreateTableSpecification}.
*/
public static CreateTableSpecification createTable(String name) {
return new CreateTableSpecification(CqlIdentifier.cqlId(name));
public static CreateTableSpecification createTable(CqlIdentifier tableName) {
return new CreateTableSpecification(tableName);
}
/**
@@ -62,7 +69,9 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
* @return this
*/
public CreateTableSpecification ifNotExists(boolean ifNotExists) {
this.ifNotExists = ifNotExists;
return this;
}
@@ -70,18 +79,30 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
return this.ifNotExists;
}
/*
* (non-Javadoc)
* @see org.springframework.data.cassandra.core.cql.keyspace.TableOptionsSpecification#with(org.springframework.data.cassandra.core.cql.keyspace.TableOption)
*/
@Override
public CreateTableSpecification with(TableOption option) {
return (CreateTableSpecification) super.with(option);
}
/*
* (non-Javadoc)
* @see org.springframework.data.cassandra.core.cql.keyspace.TableOptionsSpecification#with(org.springframework.data.cassandra.core.cql.keyspace.TableOption, java.lang.Object)
*/
@Override
public CreateTableSpecification with(TableOption option, Object value) {
return (CreateTableSpecification) super.with(option, value);
}
/*
* (non-Javadoc)
* @see org.springframework.data.cassandra.core.cql.keyspace.TableOptionsSpecification#with(java.lang.String, java.lang.Object, boolean, boolean)
*/
@Override
public CreateTableSpecification with(String name, Object value, boolean escape, boolean quote) {
public CreateTableSpecification with(String name, @Nullable Object value, boolean escape, boolean quote) {
return (CreateTableSpecification) super.with(name, value, escape, quote);
}
}

View File

@@ -18,7 +18,7 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
/**
* Builder class to construct a {@code CREATE TYPE} specification.
* Object to configure a {@code CREATE TYPE} specification.
*
* @author Fabio J. Mendes
* @author Mark Paluch
@@ -29,26 +29,32 @@ public class CreateUserTypeSpecification extends UserTypeSpecification<CreateUse
private boolean ifNotExists;
public CreateUserTypeSpecification(CqlIdentifier name) {
private CreateUserTypeSpecification(CqlIdentifier name) {
super(name);
}
/**
* Entry point into the {@link CreateUserTypeSpecification}'s fluent API to create a type. Convenient if imported
* statically.
*/
public static CreateUserTypeSpecification createType(CqlIdentifier name) {
return new CreateUserTypeSpecification(name);
}
/**
* Entry point into the {@link CreateUserTypeSpecification}'s fluent API to create a type. Convenient if imported
* statically.
* Entry point into the {@link CreateUserTypeSpecification}'s fluent API given {@code name} to create a type.
* Convenient if imported statically.
*
* @param name must not {@literal null} or empty.
* @return a new {@link CreateUserTypeSpecification}.
*/
public static CreateUserTypeSpecification createType(String name) {
return new CreateUserTypeSpecification(CqlIdentifier.cqlId(name));
}
/**
* Entry point into the {@link CreateUserTypeSpecification}'s fluent API given {@code name} to create a type.
* Convenient if imported statically.
*
* @param name must not {@literal null}.
* @return a new {@link CreateUserTypeSpecification}.
*/
public static CreateUserTypeSpecification createType(CqlIdentifier name) {
return new CreateUserTypeSpecification(name);
}
/**
* Enables the inclusion of an{@code IF NOT EXISTS} clause.
*

View File

@@ -15,23 +15,18 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import lombok.ToString;
/**
* Simple data structure to be used when setting the replication factor for a given data center.
* Value object representing replication factor for a given data center.
*
* @author Mark Paluch
*/
@ToString
public class DataCenterReplication {
/**
* Creates a new {@link DataCenterReplication} given {@code dataCenter} and {@code replicationFactor}.
*
* @param dataCenter must not be {@literal null}.
* @param replicationFactor
* @return
*/
public static DataCenterReplication of(String dataCenter, long replicationFactor) {
return new DataCenterReplication(dataCenter, replicationFactor);
}
private final String dataCenter;
private final long replicationFactor;
private DataCenterReplication(String dataCenter, long replicationFactor) {
@@ -40,6 +35,17 @@ public class DataCenterReplication {
this.replicationFactor = replicationFactor;
}
/**
* Creates a new {@link DataCenterReplication} given {@code dataCenter} and {@code replicationFactor}.
*
* @param dataCenter must not be {@literal null}.
* @param replicationFactor the replication factor.
* @return {@link DataCenterReplication} for {@code dataCenter} and {@code replicationFactor}.
*/
public static DataCenterReplication of(String dataCenter, long replicationFactor) {
return new DataCenterReplication(dataCenter, replicationFactor);
}
/**
* @return the data center.
*/
@@ -53,15 +59,4 @@ public class DataCenterReplication {
public long getReplicationFactor() {
return replicationFactor;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getSimpleName());
sb.append(" [dataCenter='").append(dataCenter).append('\'');
sb.append(", replicationFactor=").append(replicationFactor);
sb.append(']');
return sb.toString();
}
}

View File

@@ -18,21 +18,32 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
/**
* A specification to drop a column.
* Value object representing a specification to drop a column.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class DropColumnSpecification extends ColumnChangeSpecification {
public static DropColumnSpecification dropColumn(String name) {
return new DropColumnSpecification(CqlIdentifier.cqlId(name));
private DropColumnSpecification(CqlIdentifier name) {
super(name);
}
/**
* Create a new {@link DropColumnSpecification} for the given {@code name}.
*
* @param name must not be {@literal null} or empty.
*/
public static DropColumnSpecification dropColumn(String name) {
return dropColumn(CqlIdentifier.cqlId(name));
}
/**
* Create a new {@link DropColumnSpecification} for the given {@code name}.
*
* @param name must not be {@literal null} or empty.
*/
public static DropColumnSpecification dropColumn(CqlIdentifier name) {
return new DropColumnSpecification(name);
}
public DropColumnSpecification(CqlIdentifier name) {
super(name);
}
}

View File

@@ -18,10 +18,11 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
/**
* Builder class that supports the construction of {@code DROP INDEX} specifications.
* Value object representing a {@code DROP INDEX} specification.
*
* @author Matthew T. Adams
* @author David Webb
* @author Mark Paluch
*/
public class DropIndexSpecification extends IndexNameSpecification<DropIndexSpecification> {
@@ -30,18 +31,22 @@ public class DropIndexSpecification extends IndexNameSpecification<DropIndexSpec
}
/**
* Entry point into the {@link DropIndexSpecification}'s fluent API to drop a table. Convenient if imported
* statically.
* Create a new {@link DropIndexSpecification} for the given {@code indexName}.
*
* @param indexName must not be {@literal null} or empty.
* @return a new {@link DropIndexSpecification}.
*/
public static DropIndexSpecification dropIndex(String name) {
return new DropIndexSpecification(CqlIdentifier.cqlId(name));
public static DropIndexSpecification dropIndex(String indexName) {
return dropIndex(CqlIdentifier.cqlId(indexName));
}
/**
* Entry point into the {@link DropIndexSpecification}'s fluent API to drop a table. Convenient if imported
* statically.
* Create a new {@link DropIndexSpecification} for the given {@code indexName}.
*
* @param indexName must not be {@literal null}.
* @return a new {@link DropIndexSpecification}.
*/
public static DropIndexSpecification dropIndex(CqlIdentifier name) {
return new DropIndexSpecification(name);
public static DropIndexSpecification dropIndex(CqlIdentifier indexName) {
return new DropIndexSpecification(indexName);
}
}

View File

@@ -19,8 +19,13 @@ import lombok.EqualsAndHashCode;
import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
/**
* Object to configure a {@code DROP KEYSPACE} specification.
*
* @author Mark Paluch
*/
@EqualsAndHashCode(callSuper = true)
public class DropKeyspaceSpecification extends KeyspaceActionSpecification<DropKeyspaceSpecification> {
public class DropKeyspaceSpecification extends KeyspaceActionSpecification {
private boolean ifExists;
@@ -29,27 +34,43 @@ public class DropKeyspaceSpecification extends KeyspaceActionSpecification<DropK
}
/**
* Entry point into the {@link DropKeyspaceSpecification}'s fluent API to drop a keyspace. Convenient if imported
* statically.
* Create a new {@link DropKeyspaceSpecification} for the given {@code name}.
*
* @param name must not be {@literal null} or empty.
* @return a new {@link DropKeyspaceSpecification}.
*/
public static DropKeyspaceSpecification dropKeyspace(String name) {
return new DropKeyspaceSpecification(KeyspaceIdentifier.ksId(name));
}
/**
* Create a new {@link DropKeyspaceSpecification} for the given {@code name}.
*
* @param name must not be {@literal null}.
* @return a new {@link DropKeyspaceSpecification}.
*/
public static DropKeyspaceSpecification dropKeyspace(KeyspaceIdentifier name) {
return new DropKeyspaceSpecification(name);
}
/**
* Entry point into the {@link DropKeyspaceSpecification}'s fluent API to drop a keyspace. Convenient if imported
* statically.
* Causes the inclusion of an {@code IF EXISTS} clause.
*
* @return this
*/
public static DropKeyspaceSpecification dropKeyspace(String name) {
return new DropKeyspaceSpecification(KeyspaceIdentifier.ksId(name));
}
public DropKeyspaceSpecification ifExists() {
return ifExists(true);
}
/**
* Toggles the inclusion of an {@code IF EXISTS} clause.
*
* @return this
*/
public DropKeyspaceSpecification ifExists(boolean ifExists) {
this.ifExists = ifExists;
return this;
}

View File

@@ -18,9 +18,10 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
/**
* Builder class that supports the construction of {@code DROP TABLE} specifications.
* Object to configure a {@code DROP TABLE} specification.
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class DropTableSpecification extends TableNameSpecification {
@@ -29,22 +30,24 @@ public class DropTableSpecification extends TableNameSpecification {
}
/**
* Entry point into the {@link DropTableSpecification}'s fluent API to drop a table. Convenient if imported
* statically. This static method is shorter than the no-arg form, which would be {@code dropTable().name(tableName)}.
* Entry point into the {@link DropTableSpecification}'s fluent API {@code tableName} to drop a table. Convenient if
* imported statically.
*
* @param tableName The name of the table to drop.
* @param tableName must not be {@literal null} or empty.
* @return a new {@link DropTableSpecification}.
*/
public static DropTableSpecification dropTable(String tableName) {
return dropTable(CqlIdentifier.cqlId(tableName));
}
/**
* Entry point into the {@link DropTableSpecification}'s fluent API given {@code tableName} to drop a table.
* Convenient if imported statically.
*
* @param tableName must not be {@literal null}.
* @return a new {@link DropTableSpecification}.
*/
public static DropTableSpecification dropTable(CqlIdentifier tableName) {
return new DropTableSpecification(tableName);
}
/**
* Entry point into the {@link DropTableSpecification}'s fluent API to drop a table. Convenient if imported
* statically. This static method is shorter than the no-arg form, which would be {@code dropTable().name(tableName)}.
*
* @param tableName The name of the table to drop.
*/
public static DropTableSpecification dropTable(String tableName) {
return new DropTableSpecification(CqlIdentifier.cqlId(tableName));
}
}

View File

@@ -18,14 +18,14 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
/**
* Builder class that supports the construction of {@code DROP TYPE} specifications.
* Object to configure a {@code DROP TYPE} specification.
*
* @author Fabio J. Mendes
* @author Mark Paluch
* @since 1.5
* @see CqlIdentifier
*/
public class DropUserTypeSpecification extends UserTypeNameSpecification<DropUserTypeSpecification> {
public class DropUserTypeSpecification extends UserTypeNameSpecification {
private boolean ifExists;
@@ -34,23 +34,25 @@ public class DropUserTypeSpecification extends UserTypeNameSpecification<DropUse
}
/**
* Entry point into the {@link DropUserTypeSpecification}'s fluent API to drop a type. Convenient if imported
* statically.
* Entry point into the {@link DropUserTypeSpecification}'s fluent API given {@code name} to drop a type. Convenient
* if imported statically.
*
* @param typeName The name of the type to drop.
* @param name must not be {@link null} or empty.
* @return a new {@link DropUserTypeSpecification}.
*/
public static DropUserTypeSpecification dropType(String typeName) {
return new DropUserTypeSpecification(CqlIdentifier.cqlId(typeName));
public static DropUserTypeSpecification dropType(String name) {
return new DropUserTypeSpecification(CqlIdentifier.cqlId(name));
}
/**
* Entry point into the {@link DropUserTypeSpecification}'s fluent API to drop a type. Convenient if imported
* statically.
* Entry point into the {@link DropUserTypeSpecification}'s fluent API given {@code name} to drop a type. Convenient
* if imported statically.
*
* @param typeName The name of the type to drop.
* @param name must not be {@link null} or empty.
* @return a new {@link DropUserTypeSpecification}.
*/
public static DropUserTypeSpecification dropType(CqlIdentifier typeName) {
return new DropUserTypeSpecification(typeName);
public static DropUserTypeSpecification dropType(CqlIdentifier name) {
return new DropUserTypeSpecification(name);
}
/**

View File

@@ -21,7 +21,7 @@ import org.springframework.util.Assert;
import com.datastax.driver.core.DataType;
/**
* Builder class to specify fields.
* Base value object class to specify user type fields.
* <p/>
* A {@link FieldSpecification} consists of a name and a {@link DataType}.
*
@@ -46,7 +46,7 @@ public class FieldSpecification {
/**
* Create a new {@link FieldSpecification} for the given {@code name} and {@link DataType}
*
* @param name must not be empty or {@literal null}.
* @param name must not be {@literal null} or empty.
* @param type must not be {@literal null}.
*/
public static FieldSpecification of(String name, DataType type) {

View File

@@ -16,6 +16,7 @@
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.lang.Nullable;
/**
* Describes an index.
@@ -28,6 +29,7 @@ public interface IndexDescriptor {
/**
* Returns the name of the index.
*/
@Nullable
CqlIdentifier getName();
/**
@@ -37,6 +39,7 @@ public interface IndexDescriptor {
CqlIdentifier getColumnName();
@Nullable
String getUsing();
boolean isCustom();

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -34,9 +32,11 @@ public abstract class IndexNameSpecification<T extends IndexNameSpecification<T>
/**
* The name of the index.
*/
private @Nullable CqlIdentifier name;
private final @Nullable CqlIdentifier name;
protected IndexNameSpecification() {}
protected IndexNameSpecification() {
this.name = null;
}
protected IndexNameSpecification(CqlIdentifier name) {
@@ -44,25 +44,6 @@ public abstract class IndexNameSpecification<T extends IndexNameSpecification<T>
this.name = name;
}
/**
* Sets the index name.
*
* @return this
*/
public T name(String name) {
return name(cqlId(name));
}
@SuppressWarnings("unchecked")
public T name(CqlIdentifier name) {
Assert.notNull(name, "CqlIdentifier must not be null");
this.name = name;
return (T) this;
}
@Nullable
public CqlIdentifier getName() {
return this.name;

View File

@@ -21,14 +21,14 @@ import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
import org.springframework.util.Assert;
/**
* Abstract builder class to support the construction of keyspace specifications.
* Base value object to support the construction of keyspace specifications.
*
* @author John McPeek
* @author David Webb
* @param <T> The subtype of the {@link KeyspaceActionSpecification}
*/
@EqualsAndHashCode
public abstract class KeyspaceActionSpecification<T extends KeyspaceActionSpecification<T>> {
public abstract class KeyspaceActionSpecification {
/**
* The name of the keyspace.

View File

@@ -42,7 +42,7 @@ import org.springframework.lang.Nullable;
*/
@EqualsAndHashCode(callSuper = true)
public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpecification<T>>
extends KeyspaceActionSpecification<KeyspaceOptionsSpecification<T>> {
extends KeyspaceActionSpecification {
protected Map<String, Object> options = new LinkedHashMap<>();

View File

@@ -34,8 +34,8 @@ public class RenameColumnSpecification extends ColumnChangeSpecification {
/**
* Create a new {@link ColumnChangeSpecification}.
*
* @param from must not be empty or {@literal null}.
* @param to must not be empty or {@literal null}.
* @param from must not be {@literal null} or empty.
* @param to must not be {@literal null} or empty.
*/
RenameColumnSpecification(String from, String to) {
this(cqlId(from), cqlId(to));

View File

@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
import com.datastax.driver.core.DataType;
/**
* Builder class to support the construction of table specifications that have columns. This class can also be used as a
* Object to support the configuration of table specifications that have columns. This class can also be used as a
* standalone {@link TableDescriptor}, independent of {@link CreateTableSpecification}.
*
* @author Matthew T. Adams

View File

@@ -19,16 +19,18 @@ import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.util.Assert;
/**
* Abstract builder class to support the construction of user type specifications.
* Base value object builder class to construction of user type specifications.
*
* @author Fabio J. Mendes
* @author Mark Paluch
* @param <T> Subtype of {@link UserTypeNameSpecification}.
* @since 1.5
* @see CqlIdentifier
*/
public abstract class UserTypeNameSpecification<T extends UserTypeNameSpecification<T>> {
public abstract class UserTypeNameSpecification {
/**
* User type name.
*/
private final CqlIdentifier name;
protected UserTypeNameSpecification(CqlIdentifier name) {

View File

@@ -26,15 +26,15 @@ import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.driver.core.DataType;
/**
* Builder class to support the construction of user type specifications that have columns. This class can also be used
* as a standalone {@link UserTypeSpecification}.
* Object to support the configuration of user type specifications that have columns. This class can also be used as a
* standalone {@link UserTypeSpecification}.
*
* @author Fabio J. Mendes
* @author Mark Paluch
* @since 1.5
* @see CqlIdentifier
*/
public class UserTypeSpecification<T extends UserTypeSpecification<T>> extends UserTypeNameSpecification<T> {
public class UserTypeSpecification<T extends UserTypeSpecification<T>> extends UserTypeNameSpecification {
private final List<FieldSpecification> fields = new ArrayList<>();
@@ -45,7 +45,7 @@ public class UserTypeSpecification<T extends UserTypeSpecification<T>> extends U
/**
* Adds the given field to the type.
*
* @param name must not be empty or {@literal null}.
* @param name must not be {@literal null} or empty.
* @param type The data type of the field.
* @return {@code this} specification.
*/

View File

@@ -30,7 +30,7 @@ import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceActionSpecif
* @param <S> The type of the {@link TableNameSpecification}
* @param <G> The type of the {@link TableNameCqlGenerator}
*/
public abstract class AbstractKeyspaceOperationCqlGeneratorTest<S extends KeyspaceActionSpecification<?>, G extends KeyspaceNameCqlGenerator<?>> {
public abstract class AbstractKeyspaceOperationCqlGeneratorTest<S extends KeyspaceActionSpecification, G extends KeyspaceNameCqlGenerator<?>> {
public abstract S specification();

View File

@@ -15,10 +15,9 @@
*/
package org.springframework.data.cassandra.core.cql.generator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
/**
@@ -33,7 +32,7 @@ public class CreateIndexCqlGeneratorUnitTests {
@Test // DATACASS-213
public void createIndex() {
CreateIndexSpecification spec = CreateIndexSpecification.createIndex().name("myindex").tableName("mytable")
CreateIndexSpecification spec = CreateIndexSpecification.createIndex("myindex").tableName("mytable")
.columnName("column");
assertThat(CreateIndexCqlGenerator.toCql(spec)).isEqualTo("CREATE INDEX myindex ON mytable (column);");
@@ -42,7 +41,7 @@ public class CreateIndexCqlGeneratorUnitTests {
@Test // DATACASS-213
public void createCustomIndex() {
CreateIndexSpecification spec = CreateIndexSpecification.createIndex().name("myindex").tableName("mytable")
CreateIndexSpecification spec = CreateIndexSpecification.createIndex("myindex").tableName("mytable")
.columnName("column").using("indexclass");
assertThat(CreateIndexCqlGenerator.toCql(spec))