From 88d7bb231a989faa34372717f42b59daebbe34fe Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 31 Jul 2017 11:41:31 +0200 Subject: [PATCH] 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. --- .../generator/KeyspaceNameCqlGenerator.java | 6 +- .../KeyspaceOptionsCqlGenerator.java | 35 +----- .../core/cql/generator/OptionRenderUtil.java | 65 ++++++++++ .../generator/TableOptionsCqlGenerator.java | 35 +----- .../generator/UserTypeNameCqlGenerator.java | 6 +- .../cql/keyspace/AddColumnSpecification.java | 36 +++--- .../keyspace/AlterColumnSpecification.java | 38 +++--- .../keyspace/AlterKeyspaceSpecification.java | 31 +++-- .../cql/keyspace/AlterTableSpecification.java | 119 +++++++++++++----- .../keyspace/AlterUserTypeSpecification.java | 68 +++++----- .../cql/keyspace/ColumnSpecification.java | 31 ++++- .../ColumnTypeChangeSpecification.java | 3 +- .../keyspace/CreateIndexSpecification.java | 35 ++++-- .../keyspace/CreateKeyspaceSpecification.java | 47 ++++++- .../keyspace/CreateTableSpecification.java | 41 ++++-- .../keyspace/CreateUserTypeSpecification.java | 30 +++-- .../cql/keyspace/DataCenterReplication.java | 41 +++--- .../cql/keyspace/DropColumnSpecification.java | 25 ++-- .../cql/keyspace/DropIndexSpecification.java | 23 ++-- .../keyspace/DropKeyspaceSpecification.java | 39 ++++-- .../cql/keyspace/DropTableSpecification.java | 31 ++--- .../keyspace/DropUserTypeSpecification.java | 26 ++-- .../core/cql/keyspace/FieldSpecification.java | 4 +- .../core/cql/keyspace/IndexDescriptor.java | 3 + .../cql/keyspace/IndexNameSpecification.java | 27 +--- .../keyspace/KeyspaceActionSpecification.java | 4 +- .../KeyspaceOptionsSpecification.java | 2 +- .../keyspace/RenameColumnSpecification.java | 4 +- .../core/cql/keyspace/TableSpecification.java | 2 +- .../keyspace/UserTypeNameSpecification.java | 8 +- .../cql/keyspace/UserTypeSpecification.java | 8 +- ...ractKeyspaceOperationCqlGeneratorTest.java | 2 +- .../CreateIndexCqlGeneratorUnitTests.java | 7 +- 33 files changed, 534 insertions(+), 348 deletions(-) create mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/OptionRenderUtil.java diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceNameCqlGenerator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceNameCqlGenerator.java index 0d77c9f48..c617069d3 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceNameCqlGenerator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceNameCqlGenerator.java @@ -24,13 +24,13 @@ import org.springframework.util.Assert; * @param subtype of {@link KeyspaceActionSpecification}. * @author Mark Paluch */ -public abstract class KeyspaceNameCqlGenerator> { +public abstract class KeyspaceNameCqlGenerator { public abstract StringBuilder toCql(StringBuilder cql); - private final KeyspaceActionSpecification specification; + private final KeyspaceActionSpecification specification; - public KeyspaceNameCqlGenerator(KeyspaceActionSpecification specification) { + public KeyspaceNameCqlGenerator(KeyspaceActionSpecification specification) { Assert.notNull(specification, "KeyspaceActionSpecification must not be null"); this.specification = specification; diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceOptionsCqlGenerator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceOptionsCqlGenerator.java index e9c285a86..d5de7205c 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceOptionsCqlGenerator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/KeyspaceOptionsCqlGenerator.java @@ -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 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 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)); } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/OptionRenderUtil.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/OptionRenderUtil.java new file mode 100644 index 000000000..7cf8846b1 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/OptionRenderUtil.java @@ -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 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 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(); + } +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/TableOptionsCqlGenerator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/TableOptionsCqlGenerator.java index d8a8231cb..a28f925e1 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/TableOptionsCqlGenerator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/TableOptionsCqlGenerator.java @@ -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 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 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)); } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/UserTypeNameCqlGenerator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/UserTypeNameCqlGenerator.java index 242e90658..f2b794c2e 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/UserTypeNameCqlGenerator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/UserTypeNameCqlGenerator.java @@ -27,16 +27,16 @@ import org.springframework.util.Assert; * @since 1.5 * @see UserTypeNameSpecification */ -public abstract class UserTypeNameCqlGenerator> { +public abstract class UserTypeNameCqlGenerator { - private final UserTypeNameSpecification specification; + private final UserTypeNameSpecification specification; /** * Create a new {@link UserTypeNameCqlGenerator}. * * @param specification must not be {@literal null}. */ - public UserTypeNameCqlGenerator(UserTypeNameSpecification specification) { + public UserTypeNameCqlGenerator(UserTypeNameSpecification specification) { Assert.notNull(specification, "UserTypeNameSpecification must not be null"); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AddColumnSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AddColumnSpecification.java index e8d87a022..b25a33592 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AddColumnSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AddColumnSpecification.java @@ -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); - } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterColumnSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterColumnSpecification.java index 152b66e90..0f8defbc0 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterColumnSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterColumnSpecification.java @@ -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); - } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java index 5684699ab..907e99416 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterKeyspaceSpecification.java @@ -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 { @@ -27,18 +32,24 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification getChanges() { return Collections.unmodifiableList(changes); } - } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterUserTypeSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterUserTypeSpecification.java index e1586b8c3..97b457e7b 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterUserTypeSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/AlterUserTypeSpecification.java @@ -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 { +public class AlterUserTypeSpecification extends UserTypeNameSpecification { private final List 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 * 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; } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/ColumnTypeChangeSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/ColumnTypeChangeSpecification.java index e31bd2ce7..ffb041bec 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/ColumnTypeChangeSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/ColumnTypeChangeSpecification.java @@ -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; } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/CreateIndexSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/CreateIndexSpecification.java index 43ff9ccac..8a15a6e9c 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/CreateIndexSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/CreateIndexSpecification.java @@ -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 options = new LinkedHashMap<>(); + private final Map 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 implements KeyspaceDescriptor { @@ -32,16 +38,22 @@ public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification builder = MapBuilder.map(Option.class, Object.class).entry( @@ -95,18 +123,27 @@ public class CreateKeyspaceSpecification extends KeyspaceOptionsSpecification The subtype of the {@link KeyspaceActionSpecification} */ @EqualsAndHashCode -public abstract class KeyspaceActionSpecification> { +public abstract class KeyspaceActionSpecification { /** * The name of the keyspace. diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/KeyspaceOptionsSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/KeyspaceOptionsSpecification.java index 0ccd8a09b..f0ad12bf9 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/KeyspaceOptionsSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/KeyspaceOptionsSpecification.java @@ -42,7 +42,7 @@ import org.springframework.lang.Nullable; */ @EqualsAndHashCode(callSuper = true) public abstract class KeyspaceOptionsSpecification> - extends KeyspaceActionSpecification> { + extends KeyspaceActionSpecification { protected Map options = new LinkedHashMap<>(); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/RenameColumnSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/RenameColumnSpecification.java index e3563f26b..0e99094e9 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/RenameColumnSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/RenameColumnSpecification.java @@ -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)); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/TableSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/TableSpecification.java index c6757adac..ff4f0308e 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/TableSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/TableSpecification.java @@ -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 diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeNameSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeNameSpecification.java index f1691d179..77e26aaa5 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeNameSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeNameSpecification.java @@ -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 Subtype of {@link UserTypeNameSpecification}. * @since 1.5 * @see CqlIdentifier */ -public abstract class UserTypeNameSpecification> { +public abstract class UserTypeNameSpecification { + /** + * User type name. + */ private final CqlIdentifier name; protected UserTypeNameSpecification(CqlIdentifier name) { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeSpecification.java index fefff907b..a9d288585 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/keyspace/UserTypeSpecification.java @@ -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> extends UserTypeNameSpecification { +public class UserTypeSpecification> extends UserTypeNameSpecification { private final List fields = new ArrayList<>(); @@ -45,7 +45,7 @@ public class UserTypeSpecification> 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. */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java index 406f53053..ab84d1376 100755 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java @@ -30,7 +30,7 @@ import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceActionSpecif * @param The type of the {@link TableNameSpecification} * @param The type of the {@link TableNameCqlGenerator} */ -public abstract class AbstractKeyspaceOperationCqlGeneratorTest, G extends KeyspaceNameCqlGenerator> { +public abstract class AbstractKeyspaceOperationCqlGeneratorTest> { public abstract S specification(); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java index 11faec30b..f36d21784 100755 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/CreateIndexCqlGeneratorUnitTests.java @@ -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))