Polishing.
Add author tags. Reformat code. Add overrides for methods that were introduced in the meantime. See #978. Original pull request: #1108.
This commit is contained in:
@@ -105,6 +105,11 @@ class AnnotatedCassandraConstructorProperty implements CassandraPersistentProper
|
||||
return delegate.isPrimaryKeyColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStaticColumn() {
|
||||
return delegate.isStaticColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotatedType findAnnotatedType(Class<? extends Annotation> annotationType) {
|
||||
|
||||
@@ -98,6 +98,11 @@ class CassandraConstructorProperty implements CassandraPersistentProperty {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStaticColumn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnnotatedType findAnnotatedType(Class<? extends Annotation> annotationType) {
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Aleksei Zotov
|
||||
* @since 3.0
|
||||
* @see CreateUserTypeSpecification
|
||||
* @see CreateTableSpecification
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -25,14 +27,13 @@ import org.springframework.data.cassandra.core.cql.keyspace.Option;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.TableSpecification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a {@code CREATE TABLE} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
* @author Mark Paluch
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public class CreateTableCqlGenerator extends TableOptionsCqlGenerator<TableSpecification<CreateTableSpecification>> {
|
||||
|
||||
@@ -78,7 +79,7 @@ public class CreateTableCqlGenerator extends TableOptionsCqlGenerator<TableSpeci
|
||||
List<ColumnSpecification> clusterKeys = new ArrayList<>();
|
||||
for (ColumnSpecification col : spec().getColumns()) {
|
||||
if (col.isStatic()) {
|
||||
col.toCql(cql).append(" static, ");
|
||||
col.toCql(cql).append(" STATIC, ");
|
||||
} else {
|
||||
col.toCql(cql).append(", ");
|
||||
}
|
||||
|
||||
@@ -29,14 +29,15 @@ import com.datastax.oss.driver.api.core.type.DataType;
|
||||
/**
|
||||
* Object to configure a CQL column specification.
|
||||
* <p/>
|
||||
* Use {@link #name(String)} and {@link #type(DataType)} 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
|
||||
* {@code PRIMARY KEY} column is or is part of the partition key, use {@link #partitioned()} instead of
|
||||
* Use {@link #name(String)} and {@link #type(DataType)} 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 {@code PRIMARY KEY} column is or is part of the partition key, use {@link #partitioned()} instead of
|
||||
* {@link #clustered()} or {@link #clustered(Ordering)}. To specify {@code STATIC} column, use {@link #staticColumn()}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
* @author Mark Paluch
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public class ColumnSpecification {
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public interface TableDescriptor {
|
||||
|
||||
@@ -60,6 +61,8 @@ public interface TableDescriptor {
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list of static columns.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
List<ColumnSpecification> getStaticColumns();
|
||||
|
||||
|
||||
@@ -15,19 +15,19 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
import com.datastax.oss.driver.api.core.type.DataType;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.Ordering;
|
||||
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
|
||||
import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
import com.datastax.oss.driver.api.core.type.DataType;
|
||||
|
||||
/**
|
||||
* Object to support the configuration of table specifications that have columns. This class can also be used as a
|
||||
@@ -36,6 +36,7 @@ import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
* @author Mark Paluch
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public class TableSpecification<T> extends TableOptionsSpecification<TableSpecification<T>> implements TableDescriptor {
|
||||
|
||||
@@ -355,8 +356,6 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list of static columns.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
@Override
|
||||
public List<ColumnSpecification> getStaticColumns() {
|
||||
|
||||
@@ -54,6 +54,7 @@ import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
* @author Antoine Toulme
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentProperty<CassandraPersistentProperty>
|
||||
implements CassandraPersistentProperty, ApplicationContextAware {
|
||||
@@ -181,6 +182,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
*/
|
||||
@Override
|
||||
public boolean isStaticColumn() {
|
||||
|
||||
Column annotation = findAnnotation(Column.class);
|
||||
|
||||
return annotation != null && annotation.isStatic();
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Frank Spitulski
|
||||
* @author Aleksei Zotov
|
||||
* @since 2.1
|
||||
* @see Element
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.lang.Nullable;
|
||||
* {@link BasicCassandraPersistentProperty} that pre-computes primary key and embedded flags.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Aleksei Zotov
|
||||
* @since 3.1.4
|
||||
*/
|
||||
public class CachingCassandraPersistentProperty extends BasicCassandraPersistentProperty {
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
* @author John Blum
|
||||
* @author Christoph Strobl
|
||||
* @author Frank Spitulski
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public interface CassandraPersistentProperty
|
||||
extends PersistentProperty<CassandraPersistentProperty>, ApplicationContextAware {
|
||||
@@ -160,7 +161,8 @@ public interface CassandraPersistentProperty
|
||||
boolean isPrimaryKeyColumn();
|
||||
|
||||
/**
|
||||
* Whether the property is a static column.
|
||||
* Whether the property maps to a static column.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
boolean isStaticColumn();
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.lang.annotation.Target;
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@@ -54,8 +55,9 @@ public @interface Column {
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* Whether the column is static.
|
||||
* Default is {@literal false}.
|
||||
* Whether the column is {@code static}. Default is {@literal false}. Used primarily for schema creation.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
boolean isStatic() default false;
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
public class SchemaFactoryUnitTests {
|
||||
|
||||
@@ -898,7 +899,7 @@ public class SchemaFactoryUnitTests {
|
||||
@Element(1) int number;
|
||||
}
|
||||
|
||||
@Test // DATACASS-812
|
||||
@Test // GH-978
|
||||
void createdTableSpecificationShouldConsiderStaticColumns() {
|
||||
|
||||
CassandraPersistentEntity<?> persistentEntity = ctx
|
||||
@@ -911,7 +912,7 @@ public class SchemaFactoryUnitTests {
|
||||
assertThat(name.isStatic()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACASS-812
|
||||
@Test // GH-978
|
||||
void createdTableSpecificationShouldConsiderStaticForTypedTupleColumns() {
|
||||
|
||||
CassandraPersistentEntity<?> persistentEntity = ctx
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.datastax.oss.driver.api.core.type.DataTypes;
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
* @author Aleksei Zotov
|
||||
*/
|
||||
class CreateTableCqlGeneratorUnitTests {
|
||||
|
||||
@@ -188,7 +189,7 @@ class CreateTableCqlGeneratorUnitTests {
|
||||
+ "WITH CLUSTERING ORDER BY (date_of_birth ASC) AND COMPACT STORAGE;");
|
||||
}
|
||||
|
||||
@Test // DATACASS-812
|
||||
@Test // GH-978
|
||||
void createTableWithStaticColumns() {
|
||||
|
||||
CreateTableSpecification table = CreateTableSpecification.createTable("person")
|
||||
@@ -198,7 +199,7 @@ class CreateTableCqlGeneratorUnitTests {
|
||||
.staticColumn("country", DataTypes.ASCII);
|
||||
|
||||
assertThat(toCql(table)).isEqualTo("CREATE TABLE person ("
|
||||
+ "id ascii, date_of_birth date, name ascii, country ascii static, "
|
||||
+ "id ascii, date_of_birth date, name ascii, country ascii STATIC, "
|
||||
+ "PRIMARY KEY (id, date_of_birth)) "
|
||||
+ "WITH CLUSTERING ORDER BY (date_of_birth ASC);");
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ This chapter summarizes changes and new features for each release.
|
||||
|
||||
* <<cassandra.template.prepared-statements,Support for prepared statements>> using `CassandraTemplate` and repositories (enabled by default).
|
||||
* `@Column` and `@Element` can be used on constructor arguments.
|
||||
* Schema support for static columns through `@Column(isStatic = …)`.
|
||||
|
||||
[[new-features.3-1-0]]
|
||||
== What's new in Spring Data for Apache Cassandra 3.1
|
||||
|
||||
Reference in New Issue
Block a user