DATACASS-259 - Polish.

This commit is contained in:
John Blum
2016-11-28 15:37:22 -08:00
parent 847db1a52b
commit 47ebed51f9
8 changed files with 78 additions and 75 deletions

View File

@@ -3,13 +3,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-data-cassandra-distribution</artifactId>
<packaging>pom</packaging>
<name>Spring Data for Apache Cassandra - Distribution</name>
<description>Distribution build for Spring Data for Apache Cassandra</description>
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra-parent</artifactId>
@@ -17,6 +10,13 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-data-cassandra-distribution</artifactId>
<packaging>pom</packaging>
<name>Spring Data for Apache Cassandra - Distribution</name>
<description>Distribution build for Spring Data for Apache Cassandra</description>
<url>https://github.com/spring-projects/spring-data-cassandra/tree/master/spring-data-cassandra-distribution</url>
<properties>
<project.root>${basedir}/..</project.root>
<dist.key>SDCASS</dist.key>

View File

@@ -20,6 +20,8 @@ import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
import java.util.ArrayList;
import java.util.List;
import com.datastax.driver.core.UserType;
import org.springframework.beans.BeansException;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.cassandra.support.exception.UnsupportedCassandraOperationException;
@@ -38,8 +40,6 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.datastax.driver.core.UserType;
/**
* Cassandra specific {@link BasicPersistentEntity} implementation that adds Cassandra specific metadata.
*
@@ -67,7 +67,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
protected StandardEvaluationContext spelContext;
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation) {
this(typeInformation, null);
this(typeInformation, null, DEFAULT_VERIFIER);
}
/**
@@ -100,8 +100,8 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
Table tableAnnotation = findAnnotation(Table.class);
return tableAnnotation == null ? determineDefaultName()
: determineName(tableAnnotation.value(), tableAnnotation.forceQuote());
return (tableAnnotation != null ? determineName(tableAnnotation.value(), tableAnnotation.forceQuote())
: determineDefaultName());
}
@Override
@@ -116,7 +116,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
@Override
public boolean isCompositePrimaryKey() {
return findAnnotation(PrimaryKeyClass.class) != null;
return (findAnnotation(PrimaryKeyClass.class) != null);
}
@Override
@@ -139,7 +139,6 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
@Override
public void doWithPersistentProperty(CassandraPersistentProperty property) {
if (property.isCompositePrimaryKey()) {
addCompositePrimaryKeyProperties(property.getCompositePrimaryKeyEntity(), properties);
} else {

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 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.
@@ -38,13 +38,13 @@ import java.lang.annotation.Target;
/**
* Annotation to define custom metadata for document fields.
*
*
* @author Alex Shvid
* @author Matthew T. Adams
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Target(value = { ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD })
public @interface Column {
/**

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 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.
@@ -29,12 +29,12 @@ import org.springframework.data.annotation.Id;
* <p/>
* Remember, if the Cassandra table has multiple primary key columns, then you must define a class annotated with
* {@link PrimaryKeyClass} to represent the primary key!
*
*
* @author Alex Shvid
* @author Matthew T. Adams
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Target(value = { ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD })
@Id
public @interface PrimaryKey {

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 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.
@@ -27,12 +27,12 @@ import org.springframework.core.annotation.AliasFor;
/**
* Identifies the annotated field of a composite primary key class as a primary key field that is either a partition or
* cluster key field.
*
*
* @author Matthew T. Adams
* @author Mark Paluch
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Target(value = { ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD })
public @interface PrimaryKeyColumn {
/**

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 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.
@@ -25,13 +25,13 @@ import org.springframework.data.annotation.QueryAnnotation;
/**
* Annotation to declare finder queries directly on repository methods.
*
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author Mark Paluch
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Documented
@QueryAnnotation
public @interface Query {
@@ -39,7 +39,7 @@ public @interface Query {
/**
* A Cassandra CQL3 string to define the actual query to be executed. Placeholders {@code ?0}, {@code ?1}, etc are
* supported.
*
*
* @return
*/
String value() default "";

View File

@@ -85,11 +85,11 @@ public class CassandraParameters extends Parameters<CassandraParameters, Cassand
AnnotatedParameter annotatedParameter = new AnnotatedParameter(parameter);
if (AnnotatedElementUtils.hasAnnotation(annotatedParameter, CassandraType.class)) {
CassandraType cassandraType = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter,
CassandraType.class);
CassandraType cassandraType = AnnotatedElementUtils.findMergedAnnotation(
annotatedParameter, CassandraType.class);
Assert.notNull(cassandraType.type(),
String.format("You must specify the type() when annotating method parameters with @%s",
Assert.notNull(cassandraType.type(), String.format(
"You must specify the type() when annotating method parameters with @%s",
CassandraType.class.getSimpleName()));
this.cassandraType = cassandraType;
@@ -170,24 +170,24 @@ public class CassandraParameters extends Parameters<CassandraParameters, Cassand
this.methodParameter = methodParameter;
}
/* (non-Javadoc)
* @see java.lang.reflect.AnnotatedElement#getAnnotation(java.lang.Class)
/**
* @inheritDoc
*/
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return methodParameter.getParameterAnnotation(annotationClass);
}
/* (non-Javadoc)
* @see java.lang.reflect.AnnotatedElement#getAnnotations()
/**
* @inheritDoc
*/
@Override
public Annotation[] getAnnotations() {
return methodParameter.getParameterAnnotations();
}
/* (non-Javadoc)
* @see java.lang.reflect.AnnotatedElement#getDeclaredAnnotations()
/**
* @inheritDoc
*/
@Override
public Annotation[] getDeclaredAnnotations() {

View File

@@ -22,14 +22,14 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.util.Date;
import com.datastax.driver.core.DataType.Name;
import org.junit.Test;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.util.ReflectionUtils;
import com.datastax.driver.core.DataType.Name;
/**
* Unit tests for {@link BasicCassandraPersistentProperty}.
*
@@ -62,20 +62,10 @@ public class BasicCassandraPersistentPropertyUnitTests {
@Test
public void shouldConsiderComposedColumnAnnotation() {
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedColumnAnnotation.class, "column");
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("mycolumn", true));
}
CassandraPersistentProperty persistentProperty =
getPropertyFor(TypeWithComposedColumnAnnotation.class, "column");
/**
* @see DATACASS-259
*/
@Test
public void shouldConsiderComposedPrimaryKeyColumnAnnotation() {
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedPrimaryKeyColumnAnnotation.class,
"column");
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("mycolumn", true));
assertThat(persistentProperty.isPrimaryKeyColumn()).isTrue();
}
/**
@@ -84,20 +74,34 @@ public class BasicCassandraPersistentPropertyUnitTests {
@Test
public void shouldConsiderComposedPrimaryKeyAnnotation() {
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedPrimaryKeyAnnotation.class,
"column");
CassandraPersistentProperty persistentProperty =
getPropertyFor(TypeWithComposedPrimaryKeyAnnotation.class, "column");
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("primary-key", true));
assertThat(persistentProperty.isIdProperty()).isTrue();
}
/**
* @see DATACASS-259
*/
@Test
public void shouldConsiderComposedPrimaryKeyColumnAnnotation() {
CassandraPersistentProperty persistentProperty =
getPropertyFor(TypeWithComposedPrimaryKeyColumnAnnotation.class, "column");
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("mycolumn", true));
assertThat(persistentProperty.isPrimaryKeyColumn()).isTrue();
}
/**
* @see DATACASS-259
*/
@Test
public void shouldConsiderComposedCassandraTypeAnnotation() {
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedCassandraTypeAnnotation.class,
"column");
CassandraPersistentProperty persistentProperty =
getPropertyFor(TypeWithComposedCassandraTypeAnnotation.class, "column");
assertThat(persistentProperty.getDataType().getName()).isEqualTo(Name.COUNTER);
assertThat(persistentProperty.findAnnotation(CassandraType.class)).isNotNull();
@@ -131,6 +135,14 @@ public class BasicCassandraPersistentPropertyUnitTests {
String value();
}
@Retention(RetentionPolicy.RUNTIME)
@PrimaryKey(forceQuote = true)
@interface ComposedPrimaryKeyAnnotation {
@AliasFor(annotation = PrimaryKey.class)
String value() default "primary-key";
}
@Retention(RetentionPolicy.RUNTIME)
@PrimaryKeyColumn(forceQuote = true)
@interface ComposedPrimaryKeyColumnAnnotation {
@@ -142,14 +154,6 @@ public class BasicCassandraPersistentPropertyUnitTests {
int ordinal() default 42;
}
@Retention(RetentionPolicy.RUNTIME)
@PrimaryKey(forceQuote = true)
@interface ComposedPrimaryKeyAnnotation {
@AliasFor(annotation = PrimaryKey.class)
String value() default "primary-key";
}
@Retention(RetentionPolicy.RUNTIME)
@CassandraType(type = Name.COUNTER)
@interface ComposedCassandraTypeAnnotation {
@@ -159,14 +163,14 @@ public class BasicCassandraPersistentPropertyUnitTests {
@ComposedColumnAnnotation("mycolumn") String column;
}
static class TypeWithComposedPrimaryKeyColumnAnnotation {
@ComposedPrimaryKeyColumnAnnotation("mycolumn") String column;
}
static class TypeWithComposedPrimaryKeyAnnotation {
@ComposedPrimaryKeyAnnotation String column;
}
static class TypeWithComposedPrimaryKeyColumnAnnotation {
@ComposedPrimaryKeyColumnAnnotation("mycolumn") String column;
}
static class TypeWithComposedCassandraTypeAnnotation {
@ComposedCassandraTypeAnnotation String column;
}