@@ -53,11 +53,11 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
Assert.state(converter != null, "Converter was not properly initialized");
|
||||
Assert.state(this.converter != null, "Converter was not properly initialized");
|
||||
|
||||
super.afterPropertiesSet();
|
||||
|
||||
admin = new CassandraAdminTemplate(getObject(), converter);
|
||||
this.admin = new CassandraAdminTemplate(getObject(), this.converter);
|
||||
|
||||
performSchemaAction();
|
||||
}
|
||||
@@ -72,13 +72,13 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
boolean dropUnused = DEFAULT_DROP_UNUSED_TABLES;
|
||||
boolean ifNotExists = DEFAULT_CREATE_IF_NOT_EXISTS;
|
||||
|
||||
switch (schemaAction) {
|
||||
switch (this.schemaAction) {
|
||||
case RECREATE_DROP_UNUSED:
|
||||
dropUnused = true;
|
||||
case RECREATE:
|
||||
drop = true;
|
||||
case CREATE_IF_NOT_EXISTS:
|
||||
ifNotExists = SchemaAction.CREATE_IF_NOT_EXISTS.equals(schemaAction);
|
||||
ifNotExists = SchemaAction.CREATE_IF_NOT_EXISTS.equals(this.schemaAction);
|
||||
case CREATE:
|
||||
create = true;
|
||||
case NONE:
|
||||
@@ -133,7 +133,7 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
* @return the {@link SchemaAction}.
|
||||
*/
|
||||
public SchemaAction getSchemaAction() {
|
||||
return schemaAction;
|
||||
return this.schemaAction;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,8 +151,8 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
|
||||
private void performSchemaActions(boolean drop, boolean dropUnused, boolean ifNotExists) {
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(
|
||||
getMappingContext(), getCassandraAdminOperations());
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(getMappingContext(), getCassandraAdminOperations());
|
||||
|
||||
if (drop) {
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
*/
|
||||
public void createTables(boolean ifNotExists) {
|
||||
|
||||
createTableSpecifications(ifNotExists).forEach(specification -> cassandraAdminOperations.getCqlOperations()
|
||||
createTableSpecifications(ifNotExists).forEach(specification -> this.cassandraAdminOperations.getCqlOperations()
|
||||
.execute(CreateTableCqlGenerator.toCql(specification)));
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
*/
|
||||
protected List<CreateTableSpecification> createTableSpecifications(boolean ifNotExists) {
|
||||
|
||||
return mappingContext.getTableEntities().stream()
|
||||
.map(entity -> mappingContext.getCreateTableSpecificationFor(entity).ifNotExists(ifNotExists))
|
||||
return this.mappingContext.getTableEntities().stream()
|
||||
.map(entity -> this.mappingContext.getCreateTableSpecificationFor(entity).ifNotExists(ifNotExists))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
*/
|
||||
public void createIndexes(boolean ifNotExists) {
|
||||
|
||||
createIndexSpecifications(ifNotExists).forEach(specification -> cassandraAdminOperations.getCqlOperations()
|
||||
createIndexSpecifications(ifNotExists).forEach(specification -> this.cassandraAdminOperations.getCqlOperations()
|
||||
.execute(CreateIndexCqlGenerator.toCql(specification)));
|
||||
}
|
||||
|
||||
@@ -115,10 +115,9 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
*/
|
||||
protected List<CreateIndexSpecification> createIndexSpecifications(boolean ifNotExists) {
|
||||
|
||||
return mappingContext.getTableEntities() //
|
||||
.stream() //
|
||||
.flatMap(entity -> mappingContext.getCreateIndexSpecificationsFor(entity).stream()) //
|
||||
.peek(it -> it.ifNotExists(ifNotExists)) //
|
||||
return this.mappingContext.getTableEntities().stream()
|
||||
.flatMap(entity -> this.mappingContext.getCreateIndexSpecificationsFor(entity).stream())
|
||||
.peek(it -> it.ifNotExists(ifNotExists))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -129,9 +128,8 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
*/
|
||||
public void createUserTypes(boolean ifNotExists) {
|
||||
|
||||
createUserTypeSpecifications(ifNotExists) //
|
||||
.forEach(specification -> cassandraAdminOperations.getCqlOperations() //
|
||||
.execute(CreateUserTypeCqlGenerator.toCql(specification)));
|
||||
createUserTypeSpecifications(ifNotExists).forEach(specification ->
|
||||
this.cassandraAdminOperations.getCqlOperations().execute(CreateUserTypeCqlGenerator.toCql(specification)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,8 +140,8 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
*/
|
||||
protected List<CreateUserTypeSpecification> createUserTypeSpecifications(boolean ifNotExists) {
|
||||
|
||||
Collection<? extends CassandraPersistentEntity<?>> entities = new ArrayList<>(
|
||||
mappingContext.getUserDefinedTypeEntities());
|
||||
Collection<? extends CassandraPersistentEntity<?>> entities =
|
||||
new ArrayList<>(this.mappingContext.getUserDefinedTypeEntities());
|
||||
|
||||
Map<CqlIdentifier, CassandraPersistentEntity<?>> byTableName = entities.stream()
|
||||
.collect(Collectors.toMap(CassandraPersistentEntity::getTableName, entity -> entity));
|
||||
@@ -151,6 +149,7 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
List<CreateUserTypeSpecification> specifications = new ArrayList<>();
|
||||
|
||||
Set<CqlIdentifier> created = new HashSet<>();
|
||||
|
||||
entities.forEach(entity -> {
|
||||
|
||||
Set<CqlIdentifier> seen = new LinkedHashSet<>();
|
||||
@@ -159,12 +158,12 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
visitUserTypes(entity, seen);
|
||||
|
||||
List<CqlIdentifier> ordered = new ArrayList<>(seen);
|
||||
|
||||
Collections.reverse(ordered);
|
||||
|
||||
specifications.addAll(ordered
|
||||
.stream().filter(created::add).map(identifier -> mappingContext
|
||||
.getCreateUserTypeSpecificationFor(byTableName.get(identifier)).ifNotExists(ifNotExists))
|
||||
.collect(Collectors.toList()));
|
||||
specifications.addAll(ordered.stream().filter(created::add).map(identifier ->
|
||||
this.mappingContext.getCreateUserTypeSpecificationFor(byTableName.get(identifier)).ifNotExists(ifNotExists))
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return specifications;
|
||||
@@ -174,7 +173,7 @@ public class CassandraPersistentEntitySchemaCreator {
|
||||
|
||||
for (CassandraPersistentProperty property : entity) {
|
||||
|
||||
BasicCassandraPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(property);
|
||||
BasicCassandraPersistentEntity<?> persistentEntity = this.mappingContext.getPersistentEntity(property);
|
||||
|
||||
if (persistentEntity == null) {
|
||||
continue;
|
||||
|
||||
@@ -65,11 +65,12 @@ public class CassandraPersistentEntitySchemaDropper {
|
||||
*/
|
||||
public void dropTables(boolean dropUnused) {
|
||||
|
||||
cassandraAdminOperations.getKeyspaceMetadata().getTables() //
|
||||
.stream() //
|
||||
.map(AbstractTableMetadata::getName) //
|
||||
.map(CqlIdentifier::cqlId) //
|
||||
.filter(table -> dropUnused || mappingContext.usesTable(table)).forEach(cassandraAdminOperations::dropTable);
|
||||
this.cassandraAdminOperations.getKeyspaceMetadata().getTables()
|
||||
.stream()
|
||||
.map(AbstractTableMetadata::getName)
|
||||
.map(CqlIdentifier::cqlId)
|
||||
.filter(table -> dropUnused || this.mappingContext.usesTable(table))
|
||||
.forEach(this.cassandraAdminOperations::dropTable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,17 +82,17 @@ public class CassandraPersistentEntitySchemaDropper {
|
||||
*/
|
||||
public void dropUserTypes(boolean dropUnused) {
|
||||
|
||||
Set<CqlIdentifier> canRecreate = mappingContext.getUserDefinedTypeEntities().stream()
|
||||
Set<CqlIdentifier> canRecreate = this.mappingContext.getUserDefinedTypeEntities().stream()
|
||||
.map(CassandraPersistentEntity::getTableName).collect(Collectors.toSet());
|
||||
|
||||
cassandraAdminOperations.getKeyspaceMetadata().getUserTypes().forEach(userType -> {
|
||||
this.cassandraAdminOperations.getKeyspaceMetadata().getUserTypes().forEach(userType -> {
|
||||
|
||||
CqlIdentifier typeName = CqlIdentifier.cqlId(userType.getTypeName());
|
||||
|
||||
if (canRecreate.contains(typeName)) {
|
||||
cassandraAdminOperations.dropUserType(typeName);
|
||||
this.cassandraAdminOperations.dropUserType(typeName);
|
||||
} else if (dropUnused && !mappingContext.usesUserType(typeName)) {
|
||||
cassandraAdminOperations.dropUserType(typeName);
|
||||
this.cassandraAdminOperations.dropUserType(typeName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ import com.datastax.driver.core.DataType;
|
||||
|
||||
public class CqlStringUtils {
|
||||
|
||||
protected static final String SINGLE_QUOTE = "\'";
|
||||
protected static final String DOUBLE_SINGLE_QUOTE = "\'\'";
|
||||
public static final String DOUBLE_QUOTE = "\"";
|
||||
protected static final String DOUBLE_QUOTE = "\"";
|
||||
protected static final String DOUBLE_DOUBLE_QUOTE = "\"\"";
|
||||
protected static final String DOUBLE_SINGLE_QUOTE = "\'\'";
|
||||
protected static final String SINGLE_QUOTE = "\'";
|
||||
protected static final String EMPTY_STRING = "";
|
||||
protected static final String TYPE_PARAMETER_PREFIX = "<";
|
||||
protected static final String TYPE_PARAMETER_SUFFIX = ">";
|
||||
|
||||
public static StringBuilder noNull(StringBuilder sb) {
|
||||
return sb == null ? new StringBuilder() : sb;
|
||||
public static StringBuilder noNull(StringBuilder builder) {
|
||||
return (builder == null ? new StringBuilder() : builder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,48 +36,42 @@ public class CqlStringUtils {
|
||||
* encasing the result in single quotes. Given {@code null}, returns <code>null</code>.
|
||||
*/
|
||||
public static String valuize(String candidate) {
|
||||
|
||||
if (candidate == null) {
|
||||
return null;
|
||||
}
|
||||
return singleQuote(escapeSingle(candidate));
|
||||
return (candidate != null ? singleQuote(escapeSingle(candidate)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles single quote characters (' -> ''). Given {@code null}, returns <code>null</code>.
|
||||
*/
|
||||
public static String escapeSingle(Object thing) {
|
||||
return thing == null ? null : thing.toString().replace(SINGLE_QUOTE, DOUBLE_SINGLE_QUOTE);
|
||||
return (thing == null ? null : thing.toString().replace(SINGLE_QUOTE, DOUBLE_SINGLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles double quote characters (" -> ""). Given {@code null}, returns <code>null</code>.
|
||||
*/
|
||||
public static String escapeDouble(Object thing) {
|
||||
return thing == null ? null : thing.toString().replace(DOUBLE_QUOTE, DOUBLE_DOUBLE_QUOTE);
|
||||
return (thing == null ? null : thing.toString().replace(DOUBLE_QUOTE, DOUBLE_DOUBLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with single quotes. Given {@code null}, returns {@code null}.
|
||||
*/
|
||||
public static String singleQuote(Object thing) {
|
||||
return thing == null ? null
|
||||
: new StringBuilder().append(SINGLE_QUOTE).append(thing).append(SINGLE_QUOTE).toString();
|
||||
return (thing == null ? null : SINGLE_QUOTE.concat(thing.toString()).concat(SINGLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with double quotes. Given {@code null}, returns {@code null}.
|
||||
*/
|
||||
public static String doubleQuote(Object thing) {
|
||||
return thing == null ? null
|
||||
: new StringBuilder().append(DOUBLE_QUOTE).append(thing).append(DOUBLE_QUOTE).toString();
|
||||
return (thing == null ? null : DOUBLE_QUOTE.concat(thing.toString()).concat(DOUBLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed single quotes from quoted String option values
|
||||
*/
|
||||
public static String removeSingleQuotes(Object thing) {
|
||||
return thing == null ? null : ((String) thing).replaceAll(SINGLE_QUOTE, EMPTY_STRING);
|
||||
return (thing == null ? null : thing.toString().replaceAll(SINGLE_QUOTE, EMPTY_STRING));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,8 +85,9 @@ public class CqlStringUtils {
|
||||
return dataType.getName().name();
|
||||
}
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(dataType.getName().name()).append(TYPE_PARAMETER_PREFIX);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(dataType.getName().name()).append(TYPE_PARAMETER_PREFIX);
|
||||
|
||||
boolean first = true;
|
||||
|
||||
@@ -101,29 +96,33 @@ public class CqlStringUtils {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
s.append(',');
|
||||
builder.append(',');
|
||||
}
|
||||
|
||||
s.append(argDataType.getName().name());
|
||||
builder.append(argDataType.getName().name());
|
||||
}
|
||||
|
||||
return s.append(TYPE_PARAMETER_SUFFIX).toString();
|
||||
return builder.append(TYPE_PARAMETER_SUFFIX).toString();
|
||||
}
|
||||
|
||||
public static String unquote(String s) {
|
||||
return unquote(s, "\"");
|
||||
public static String unquote(String value) {
|
||||
return unquote(value, "\"");
|
||||
}
|
||||
|
||||
public static String unquote(String s, String quoteChar) {
|
||||
if (s == null) {
|
||||
return s;
|
||||
public static String unquote(String value, String quoteChar) {
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!s.startsWith(quoteChar) || !s.endsWith(quoteChar)) {
|
||||
return s;
|
||||
|
||||
if (!value.startsWith(quoteChar) || !value.endsWith(quoteChar)) {
|
||||
return value;
|
||||
}
|
||||
if (s.length() <= 2) {
|
||||
return s;
|
||||
|
||||
if (value.length() <= 2) {
|
||||
return value;
|
||||
}
|
||||
return s.substring(1, s.length() - 1);
|
||||
|
||||
return value.substring(1, value.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -75,13 +75,14 @@ public class CreateIndexCqlGenerator extends IndexNameCqlGenerator<CreateIndexSp
|
||||
|
||||
List<String> entries = new ArrayList<>(options.size());
|
||||
|
||||
options.forEach((key, value) -> entries
|
||||
.add(String.format("'%s': '%s'", CqlStringUtils.escapeSingle(key), CqlStringUtils.escapeSingle(value))));
|
||||
options.forEach((key, value) -> entries.add(String.format("'%s': '%s'",
|
||||
CqlStringUtils.escapeSingle(key), CqlStringUtils.escapeSingle(value))));
|
||||
|
||||
StringBuilder optionsCql = new StringBuilder(" WITH OPTIONS = ").append("{");
|
||||
optionsCql.append(StringUtils.collectionToDelimitedString(entries, ", "));
|
||||
|
||||
optionsCql.append(StringUtils.collectionToDelimitedString(entries, ", "));
|
||||
optionsCql.append("}");
|
||||
|
||||
cql.append(optionsCql);
|
||||
}
|
||||
|
||||
@@ -89,5 +90,4 @@ public class CreateIndexCqlGenerator extends IndexNameCqlGenerator<CreateIndexSp
|
||||
|
||||
return cql;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateUserTypeSpecification;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.FieldSpecification;
|
||||
@@ -60,6 +60,7 @@ public class CreateUserTypeCqlGenerator extends UserTypeNameCqlGenerator<CreateU
|
||||
}
|
||||
|
||||
private StringBuilder preambleCql(StringBuilder cql) {
|
||||
|
||||
return noNull(cql).append("CREATE TYPE ").append(spec().getIfNotExists() ? "IF NOT EXISTS " : "")
|
||||
.append(spec().getName());
|
||||
}
|
||||
@@ -74,6 +75,7 @@ public class CreateUserTypeCqlGenerator extends UserTypeNameCqlGenerator<CreateU
|
||||
boolean first = true;
|
||||
|
||||
for (FieldSpecification column : spec().getFields()) {
|
||||
|
||||
if (!first) {
|
||||
cql.append(", ");
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -94,7 +94,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
}
|
||||
|
||||
public boolean getIfNotExists() {
|
||||
return ifNotExists;
|
||||
return this.ifNotExists;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -102,7 +102,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
*/
|
||||
@Override
|
||||
public boolean isCustom() {
|
||||
return custom;
|
||||
return this.custom;
|
||||
}
|
||||
|
||||
public CreateIndexSpecification using(String className) {
|
||||
@@ -123,7 +123,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
*/
|
||||
@Override
|
||||
public String getUsing() {
|
||||
return using;
|
||||
return this.using;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -131,7 +131,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
*/
|
||||
@Override
|
||||
public CqlIdentifier getColumnName() {
|
||||
return columnName;
|
||||
return this.columnName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,11 +186,12 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
Assert.notNull(columnFunction, "ColumnFunction must not be null");
|
||||
|
||||
this.columnFunction = columnFunction;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColumnFunction getColumnFunction() {
|
||||
return columnFunction;
|
||||
return this.columnFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,6 +205,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
public CreateIndexSpecification withOption(String name, String value) {
|
||||
|
||||
this.options.put(name, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -211,7 +213,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
* @return index options map.
|
||||
*/
|
||||
public Map<String, String> getOptions() {
|
||||
return Collections.unmodifiableMap(options);
|
||||
return Collections.unmodifiableMap(this.options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,6 +237,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
Assert.notNull(tableName, "CqlIdentifier must not be null");
|
||||
|
||||
this.tableName = tableName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -243,7 +246,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
*/
|
||||
@Override
|
||||
public CqlIdentifier getTableName() {
|
||||
return tableName;
|
||||
return this.tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,6 +270,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
Assert.notNull(columnName, "CqlIdentifier must not be null");
|
||||
|
||||
this.columnName = columnName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
|
||||
}
|
||||
|
||||
public boolean getIfNotExists() {
|
||||
return ifNotExists;
|
||||
return this.ifNotExists;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -48,11 +48,13 @@ public abstract class IndexNameSpecification<T extends IndexNameSpecification<T>
|
||||
public T name(CqlIdentifier name) {
|
||||
|
||||
Assert.notNull(name, "CqlIdentifier must not be null");
|
||||
|
||||
this.name = name;
|
||||
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public CqlIdentifier getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -46,11 +46,13 @@ public abstract class TableNameSpecification<T extends TableNameSpecification<T>
|
||||
public T name(CqlIdentifier name) {
|
||||
|
||||
Assert.notNull(name, "CqlIdentifier must not be null");
|
||||
|
||||
this.name = name;
|
||||
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public CqlIdentifier getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.Map;
|
||||
* @see CachingOption
|
||||
*/
|
||||
public enum TableOption implements Option {
|
||||
|
||||
/**
|
||||
* {@code comment}
|
||||
*/
|
||||
@@ -79,52 +80,52 @@ public enum TableOption implements Option {
|
||||
|
||||
@Override
|
||||
public Class<?> getType() {
|
||||
return delegate.getType();
|
||||
return this.delegate.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesValue() {
|
||||
return delegate.takesValue();
|
||||
return this.delegate.takesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
return this.delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean escapesValue() {
|
||||
return delegate.escapesValue();
|
||||
return this.delegate.escapesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quotesValue() {
|
||||
return delegate.quotesValue();
|
||||
return this.delegate.quotesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresValue() {
|
||||
return delegate.requiresValue();
|
||||
return this.delegate.requiresValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(Object value) {
|
||||
delegate.checkValue(value);
|
||||
this.delegate.checkValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoerceable(Object value) {
|
||||
return delegate.isCoerceable(value);
|
||||
return this.delegate.isCoerceable(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
return this.delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
return delegate.toString(value);
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +145,7 @@ public enum TableOption implements Option {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,52 +175,52 @@ public enum TableOption implements Option {
|
||||
|
||||
@Override
|
||||
public Class<?> getType() {
|
||||
return delegate.getType();
|
||||
return this.delegate.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesValue() {
|
||||
return delegate.takesValue();
|
||||
return this.delegate.takesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
return this.delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean escapesValue() {
|
||||
return delegate.escapesValue();
|
||||
return this.delegate.escapesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quotesValue() {
|
||||
return delegate.quotesValue();
|
||||
return this.delegate.quotesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresValue() {
|
||||
return delegate.requiresValue();
|
||||
return this.delegate.requiresValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(Object value) {
|
||||
delegate.checkValue(value);
|
||||
this.delegate.checkValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoerceable(Object value) {
|
||||
return delegate.isCoerceable(value);
|
||||
return this.delegate.isCoerceable(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
return this.delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
return delegate.toString(value);
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -230,6 +231,7 @@ public enum TableOption implements Option {
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public enum CompactionOption implements Option {
|
||||
|
||||
/**
|
||||
* {@code class}
|
||||
*/
|
||||
@@ -275,52 +277,52 @@ public enum TableOption implements Option {
|
||||
|
||||
@Override
|
||||
public Class<?> getType() {
|
||||
return delegate.getType();
|
||||
return this.delegate.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesValue() {
|
||||
return delegate.takesValue();
|
||||
return this.delegate.takesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
return this.delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean escapesValue() {
|
||||
return delegate.escapesValue();
|
||||
return this.delegate.escapesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quotesValue() {
|
||||
return delegate.quotesValue();
|
||||
return this.delegate.quotesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresValue() {
|
||||
return delegate.requiresValue();
|
||||
return this.delegate.requiresValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(Object value) {
|
||||
delegate.checkValue(value);
|
||||
this.delegate.checkValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoerceable(Object value) {
|
||||
return delegate.isCoerceable(value);
|
||||
return this.delegate.isCoerceable(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
return this.delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
return delegate.toString(value);
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,6 +332,7 @@ public enum TableOption implements Option {
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public enum CompressionOption implements Option {
|
||||
|
||||
/**
|
||||
* {@code sstable_compression}
|
||||
*/
|
||||
@@ -351,52 +354,52 @@ public enum TableOption implements Option {
|
||||
|
||||
@Override
|
||||
public Class<?> getType() {
|
||||
return delegate.getType();
|
||||
return this.delegate.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesValue() {
|
||||
return delegate.takesValue();
|
||||
return this.delegate.takesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
return this.delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean escapesValue() {
|
||||
return delegate.escapesValue();
|
||||
return this.delegate.escapesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean quotesValue() {
|
||||
return delegate.quotesValue();
|
||||
return this.delegate.quotesValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresValue() {
|
||||
return delegate.requiresValue();
|
||||
return this.delegate.requiresValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkValue(Object value) {
|
||||
delegate.checkValue(value);
|
||||
this.delegate.checkValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCoerceable(Object value) {
|
||||
return delegate.isCoerceable(value);
|
||||
return this.delegate.isCoerceable(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
return this.delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
return delegate.toString(value);
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public abstract class TableOptionsSpecification<T extends TableOptionsSpecificat
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T with(String name, Object value, boolean escape, boolean quote) {
|
||||
|
||||
if (!(value instanceof Map)) {
|
||||
if (escape) {
|
||||
value = escapeSingle(value);
|
||||
@@ -105,11 +106,13 @@ public abstract class TableOptionsSpecification<T extends TableOptionsSpecificat
|
||||
value = singleQuote(value);
|
||||
}
|
||||
}
|
||||
options.put(name, value);
|
||||
|
||||
this.options.put(name, value);
|
||||
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Map<String, Object> getOptions() {
|
||||
return Collections.unmodifiableMap(options);
|
||||
return Collections.unmodifiableMap(this.options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
public T clusteredKeyColumn(CqlIdentifier name, DataType type, Ordering ordering) {
|
||||
|
||||
Assert.notNull(ordering, "Ordering must not be null");
|
||||
|
||||
return column(name, type, Optional.of(CLUSTERED), Optional.of(ordering));
|
||||
}
|
||||
|
||||
@@ -228,23 +229,23 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
ColumnSpecification column = new ColumnSpecification().name(name).type(type);
|
||||
|
||||
optionalKeyType.ifPresent(keyType -> {
|
||||
|
||||
column.keyType(keyType);
|
||||
optionalOrdering.filter(o -> keyType == CLUSTERED).ifPresent(column::ordering);
|
||||
|
||||
if (keyType == PrimaryKeyType.PARTITIONED) {
|
||||
partitionKeyColumns.add(column);
|
||||
this.partitionKeyColumns.add(column);
|
||||
}
|
||||
|
||||
if (keyType == PrimaryKeyType.CLUSTERED) {
|
||||
clusteredKeyColumns.add(column);
|
||||
this.clusteredKeyColumns.add(column);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
);
|
||||
columns.add(column);
|
||||
this.columns.add(column);
|
||||
|
||||
if (!optionalKeyType.isPresent()) {
|
||||
nonKeyColumns.add(column);
|
||||
this.nonKeyColumns.add(column);
|
||||
}
|
||||
|
||||
return (T) this;
|
||||
@@ -255,7 +256,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
*/
|
||||
@Override
|
||||
public List<ColumnSpecification> getColumns() {
|
||||
return Collections.unmodifiableList(columns);
|
||||
return Collections.unmodifiableList(this.columns);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +264,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
*/
|
||||
@Override
|
||||
public List<ColumnSpecification> getPartitionKeyColumns() {
|
||||
return Collections.unmodifiableList(partitionKeyColumns);
|
||||
return Collections.unmodifiableList(this.partitionKeyColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,7 +272,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
*/
|
||||
@Override
|
||||
public List<ColumnSpecification> getClusteredKeyColumns() {
|
||||
return Collections.unmodifiableList(clusteredKeyColumns);
|
||||
return Collections.unmodifiableList(this.clusteredKeyColumns);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,9 +281,10 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
@Override
|
||||
public List<ColumnSpecification> getPrimaryKeyColumns() {
|
||||
|
||||
ArrayList<ColumnSpecification> primaryKeyColumns = new ArrayList<>();
|
||||
primaryKeyColumns.addAll(partitionKeyColumns);
|
||||
primaryKeyColumns.addAll(clusteredKeyColumns);
|
||||
List<ColumnSpecification> primaryKeyColumns = new ArrayList<>();
|
||||
|
||||
primaryKeyColumns.addAll(this.partitionKeyColumns);
|
||||
primaryKeyColumns.addAll(this.clusteredKeyColumns);
|
||||
|
||||
return Collections.unmodifiableList(primaryKeyColumns);
|
||||
}
|
||||
@@ -292,6 +294,6 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
*/
|
||||
@Override
|
||||
public List<ColumnSpecification> getNonKeyColumns() {
|
||||
return Collections.unmodifiableList(nonKeyColumns);
|
||||
return Collections.unmodifiableList(this.nonKeyColumns);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ public class BasicCassandraPersistentEntityMetadataVerifier implements Cassandra
|
||||
|
||||
// Can only have one PK
|
||||
if (idProperties.size() != 1) {
|
||||
exceptions
|
||||
.add(new MappingException(String.format("@%s types must have only one primary attribute, if any; Found %s",
|
||||
exceptions.add(new MappingException(
|
||||
String.format("@%s types must have only one primary attribute, if any; Found %s",
|
||||
Table.class.getSimpleName(), idProperties.size())));
|
||||
|
||||
fail(entity, exceptions);
|
||||
@@ -102,8 +102,8 @@ public class BasicCassandraPersistentEntityMetadataVerifier implements Cassandra
|
||||
|
||||
// We have no PKs & only PK Column(s); ensure at least one is of type PARTITIONED
|
||||
if (!primaryKeyColumns.isEmpty() && partitionKeyColumns.isEmpty()) {
|
||||
exceptions
|
||||
.add(new MappingException(String.format("At least one of the @%s annotations must have a type of PARTITIONED",
|
||||
exceptions.add(new MappingException(
|
||||
String.format("At least one of the @%s annotations must have a type of PARTITIONED",
|
||||
PrimaryKeyColumn.class.getSimpleName())));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedParameterizedType;
|
||||
@@ -88,6 +88,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
*/
|
||||
public BasicCassandraPersistentProperty(Property property, CassandraPersistentEntity<?> owner,
|
||||
SimpleTypeHolder simpleTypeHolder) {
|
||||
|
||||
this(property, owner, simpleTypeHolder, null);
|
||||
}
|
||||
|
||||
@@ -115,10 +116,10 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
Assert.notNull(context, "ApplicationContext must not be null");
|
||||
|
||||
spelContext = new StandardEvaluationContext();
|
||||
spelContext.addPropertyAccessor(new BeanFactoryAccessor());
|
||||
spelContext.setBeanResolver(new BeanFactoryResolver(context));
|
||||
spelContext.setRootObject(context);
|
||||
this.spelContext = new StandardEvaluationContext();
|
||||
this.spelContext.addPropertyAccessor(new BeanFactoryAccessor());
|
||||
this.spelContext.setBeanResolver(new BeanFactoryResolver(context));
|
||||
this.spelContext.setRootObject(context);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -150,11 +151,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
PrimaryKeyColumn annotation = findAnnotation(PrimaryKeyColumn.class);
|
||||
|
||||
if (annotation != null) {
|
||||
return annotation.ordering();
|
||||
}
|
||||
|
||||
return null;
|
||||
return (annotation != null ? annotation.ordering() : null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -246,7 +243,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
}
|
||||
|
||||
CqlIdentifier identifier = CqlIdentifier.cqlId(annotation.userTypeName());
|
||||
UserType userType = userTypeResolver.resolveType(identifier);
|
||||
|
||||
UserType userType = this.userTypeResolver.resolveType(identifier);
|
||||
|
||||
if (userType == null) {
|
||||
throw new MappingException(String.format("User type [%s] not found", identifier));
|
||||
@@ -261,7 +259,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
if (dataType == null) {
|
||||
throw new InvalidDataAccessApiUsageException(String.format(
|
||||
"Only primitive types are allowed inside Collections for property [%1$s] of type [%2$s] in entity [%3$s]",
|
||||
"Only primitive types are allowed inside Collections for property [%1$s] of type [%2$s] in entity [%3$s]",
|
||||
getName(), getType(), getOwner().getName()));
|
||||
}
|
||||
|
||||
@@ -274,7 +272,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
if (dataType == null) {
|
||||
throw new InvalidDataAccessApiUsageException(String.format(
|
||||
"Only primitive types are allowed inside Collections for property [%1$s] of type ['%2$s'] in entity [%3$s]",
|
||||
"Only primitive types are allowed inside Collections for property [%1$s] of type ['%2$s'] in entity [%3$s]",
|
||||
getName(), getType(), getOwner().getName()));
|
||||
}
|
||||
|
||||
@@ -283,9 +281,9 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
private void ensureTypeArguments(int args, int expected) {
|
||||
if (args != expected) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
String.format("Expected [%1$s] typed arguments for property ['%2$s'] of type ['%3$s'] in entity [%4$s]",
|
||||
expected, getName(), getType(), getOwner().getName()));
|
||||
throw new InvalidDataAccessApiUsageException(String.format(
|
||||
"Expected [%1$s] typed arguments for property ['%2$s'] of type ['%3$s'] in entity [%4$s]",
|
||||
expected, getName(), getType(), getOwner().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +310,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
public boolean isPartitionKeyColumn() {
|
||||
|
||||
PrimaryKeyColumn annotation = findAnnotation(PrimaryKeyColumn.class);
|
||||
return annotation != null && PrimaryKeyType.PARTITIONED.equals(annotation.type());
|
||||
|
||||
return (annotation != null && PrimaryKeyType.PARTITIONED.equals(annotation.type()));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -322,7 +321,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
public boolean isClusterKeyColumn() {
|
||||
|
||||
PrimaryKeyColumn annotation = findAnnotation(PrimaryKeyColumn.class);
|
||||
return annotation != null && PrimaryKeyType.CLUSTERED.equals(annotation.type());
|
||||
|
||||
return (annotation != null && PrimaryKeyType.CLUSTERED.equals(annotation.type()));
|
||||
}
|
||||
|
||||
private CqlIdentifier determineColumnName() {
|
||||
@@ -333,9 +333,11 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
String defaultName = getName(); // TODO: replace with naming strategy class
|
||||
String overriddenName = null;
|
||||
|
||||
boolean forceQuote = false;
|
||||
|
||||
if (isIdProperty()) { // then the id is of a simple type (since it's not a composite primary key)
|
||||
|
||||
PrimaryKey primaryKey = findAnnotation(PrimaryKey.class);
|
||||
|
||||
if (primaryKey != null) {
|
||||
@@ -344,6 +346,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
}
|
||||
|
||||
} else if (isPrimaryKeyColumn()) { // then it's a simple type
|
||||
|
||||
PrimaryKeyColumn primaryKeyColumn = findAnnotation(PrimaryKeyColumn.class);
|
||||
|
||||
if (primaryKeyColumn != null) {
|
||||
@@ -369,7 +372,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
String name = defaultName;
|
||||
|
||||
if (StringUtils.hasText(overriddenName)) {
|
||||
name = (spelContext != null ? SpelUtils.evaluate(overriddenName, spelContext) : overriddenName);
|
||||
name = (this.spelContext != null ? SpelUtils.evaluate(overriddenName, this.spelContext) : overriddenName);
|
||||
}
|
||||
|
||||
return cqlId(name, forceQuote);
|
||||
@@ -399,6 +402,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
if (changed) {
|
||||
|
||||
CqlIdentifier columnName = getColumnName();
|
||||
|
||||
if (columnName != null) {
|
||||
setColumnName(cqlId(columnName.getUnquoted(), forceQuote));
|
||||
}
|
||||
@@ -435,11 +439,11 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
@Override
|
||||
public AnnotatedType findAnnotatedType(Class<? extends Annotation> annotationType) {
|
||||
|
||||
return Optionals.toStream(Optional.ofNullable(getField()).map(Field::getAnnotatedType), //
|
||||
Optional.ofNullable(getGetter()).map(Method::getAnnotatedReturnType), //
|
||||
Optional.ofNullable(getSetter()).map(it -> it.getParameters()[0].getAnnotatedType())) //
|
||||
.filter(it -> hasAnnotation(it, annotationType, getTypeInformation())) //
|
||||
.findFirst() //
|
||||
return Optionals.toStream(Optional.ofNullable(getField()).map(Field::getAnnotatedType),
|
||||
Optional.ofNullable(getGetter()).map(Method::getAnnotatedReturnType),
|
||||
Optional.ofNullable(getSetter()).map(it -> it.getParameters()[0].getAnnotatedType()))
|
||||
.filter(it -> hasAnnotation(it, annotationType, getTypeInformation()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
|
||||
import static org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification.*;
|
||||
import static org.springframework.data.cassandra.core.mapping.CassandraSimpleTypeHolder.*;
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
import static org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification.createTable;
|
||||
import static org.springframework.data.cassandra.core.mapping.CassandraSimpleTypeHolder.getDataTypeFor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -110,8 +110,8 @@ public class CassandraMappingContext
|
||||
|
||||
private void processMappingOverrides() {
|
||||
|
||||
mapping.getEntityMappings().stream() //
|
||||
.filter(Objects::nonNull) //
|
||||
this.mapping.getEntityMappings().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(entityMapping -> {
|
||||
|
||||
Class<?> entityClass = getEntityClass(entityMapping.getEntityClassName());
|
||||
@@ -138,8 +138,8 @@ public class CassandraMappingContext
|
||||
|
||||
private static void processMappingOverrides(CassandraPersistentEntity<?> entity, EntityMapping entityMapping) {
|
||||
|
||||
entityMapping.getPropertyMappings()
|
||||
.forEach((key, propertyMapping) -> processMappingOverride(entity, propertyMapping));
|
||||
entityMapping.getPropertyMappings().forEach((key, propertyMapping) ->
|
||||
processMappingOverride(entity, propertyMapping));
|
||||
}
|
||||
|
||||
private static void processMappingOverride(CassandraPersistentEntity<?> entity, PropertyMapping mapping) {
|
||||
@@ -228,7 +228,7 @@ public class CassandraMappingContext
|
||||
* @since 1.5
|
||||
*/
|
||||
public Collection<BasicCassandraPersistentEntity<?>> getTableEntities() {
|
||||
return Collections.unmodifiableCollection(tableEntities);
|
||||
return Collections.unmodifiableCollection(this.tableEntities);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +237,7 @@ public class CassandraMappingContext
|
||||
* @since 1.5
|
||||
*/
|
||||
public Collection<CassandraPersistentEntity<?>> getUserDefinedTypeEntities() {
|
||||
return Collections.unmodifiableSet(userDefinedTypes);
|
||||
return Collections.unmodifiableSet(this.userDefinedTypes);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -254,17 +254,17 @@ public class CassandraMappingContext
|
||||
optional.ifPresent(entity -> {
|
||||
|
||||
if (entity.isUserDefinedType()) {
|
||||
userDefinedTypes.add(entity);
|
||||
this.userDefinedTypes.add(entity);
|
||||
}
|
||||
// now do some caching of the entity
|
||||
|
||||
Set<CassandraPersistentEntity<?>> entities = entitySetsByTableName.computeIfAbsent(entity.getTableName(),
|
||||
Set<CassandraPersistentEntity<?>> entities = this.entitySetsByTableName.computeIfAbsent(entity.getTableName(),
|
||||
cqlIdentifier -> new HashSet<>());
|
||||
|
||||
entities.add(entity);
|
||||
|
||||
if (!entity.isUserDefinedType() && entity.isAnnotationPresent(Table.class)) {
|
||||
tableEntities.add(entity);
|
||||
this.tableEntities.add(entity);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -276,7 +276,7 @@ public class CassandraMappingContext
|
||||
*/
|
||||
@Override
|
||||
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> typeInfo) {
|
||||
return (!customConversions.hasCustomWriteTarget(typeInfo.getType())
|
||||
return (!this.customConversions.hasCustomWriteTarget(typeInfo.getType())
|
||||
&& super.shouldCreatePersistentEntityFor(typeInfo));
|
||||
}
|
||||
|
||||
@@ -292,14 +292,14 @@ public class CassandraMappingContext
|
||||
BasicCassandraPersistentEntity<T> entity;
|
||||
|
||||
if (userDefinedType != null) {
|
||||
entity = new CassandraUserTypePersistentEntity<>(typeInformation, verifier, userTypeResolver);
|
||||
entity = new CassandraUserTypePersistentEntity<>(typeInformation, this.verifier, this.userTypeResolver);
|
||||
|
||||
} else {
|
||||
entity = new BasicCassandraPersistentEntity<>(typeInformation, verifier);
|
||||
entity = new BasicCassandraPersistentEntity<>(typeInformation, this.verifier);
|
||||
}
|
||||
|
||||
if (context != null) {
|
||||
entity.setApplicationContext(context);
|
||||
if (this.context != null) {
|
||||
entity.setApplicationContext(this.context);
|
||||
}
|
||||
|
||||
return entity;
|
||||
@@ -313,10 +313,10 @@ public class CassandraMappingContext
|
||||
BasicCassandraPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
|
||||
|
||||
BasicCassandraPersistentProperty cassandraProperty = new BasicCassandraPersistentProperty(property, owner,
|
||||
simpleTypeHolder, userTypeResolver);
|
||||
simpleTypeHolder, this.userTypeResolver);
|
||||
|
||||
if (context != null) {
|
||||
cassandraProperty.setApplicationContext(context);
|
||||
if (this.context != null) {
|
||||
cassandraProperty.setApplicationContext(this.context);
|
||||
}
|
||||
|
||||
return cassandraProperty;
|
||||
@@ -332,7 +332,7 @@ public class CassandraMappingContext
|
||||
|
||||
Assert.notNull(name, "Table name must not be null!");
|
||||
|
||||
return entitySetsByTableName.containsKey(name);
|
||||
return this.entitySetsByTableName.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,17 +351,17 @@ public class CassandraMappingContext
|
||||
|
||||
private boolean hasReferencedUserType(CqlIdentifier identifier) {
|
||||
|
||||
return getPersistentEntities().stream() //
|
||||
.flatMap(entity -> StreamSupport.stream(entity.spliterator(), false)) //
|
||||
.flatMap(it -> Optionals.toStream(Optional.ofNullable(it.findAnnotation(CassandraType.class)))) //
|
||||
.map(CassandraType::userTypeName) //
|
||||
.filter(StringUtils::hasText) //
|
||||
.map(CqlIdentifier::cqlId) //
|
||||
.anyMatch(identifier::equals); //
|
||||
return getPersistentEntities().stream()
|
||||
.flatMap(entity -> StreamSupport.stream(entity.spliterator(), false))
|
||||
.flatMap(it -> Optionals.toStream(Optional.ofNullable(it.findAnnotation(CassandraType.class))))
|
||||
.map(CassandraType::userTypeName)
|
||||
.filter(StringUtils::hasText)
|
||||
.map(CqlIdentifier::cqlId)
|
||||
.anyMatch(identifier::equals);
|
||||
}
|
||||
|
||||
private boolean hasMappedUserType(CqlIdentifier identifier) {
|
||||
return userDefinedTypes.stream().map(CassandraPersistentEntity::getTableName).anyMatch(identifier::equals);
|
||||
return this.userDefinedTypes.stream().map(CassandraPersistentEntity::getTableName).anyMatch(identifier::equals);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,7 +384,6 @@ public class CassandraMappingContext
|
||||
CassandraPersistentEntity<?> primaryKeyEntity = getRequiredPersistentEntity(property.getRawType());
|
||||
|
||||
for (CassandraPersistentProperty primaryKeyProperty : primaryKeyEntity) {
|
||||
|
||||
if (primaryKeyProperty.isPartitionKeyColumn()) {
|
||||
specification.partitionKeyColumn(primaryKeyProperty.getColumnName(), getDataType(primaryKeyProperty));
|
||||
} else { // it's a cluster column
|
||||
@@ -436,7 +435,6 @@ public class CassandraMappingContext
|
||||
List<CreateIndexSpecification> indexes = new ArrayList<>();
|
||||
|
||||
for (CassandraPersistentProperty property : entity) {
|
||||
|
||||
if (property.isCompositePrimaryKey()) {
|
||||
indexes.addAll(getCreateIndexSpecifications(tableName, getRequiredPersistentEntity(property)));
|
||||
} else {
|
||||
@@ -445,6 +443,7 @@ public class CassandraMappingContext
|
||||
}
|
||||
|
||||
indexes.forEach(it -> it.tableName(entity.getTableName()));
|
||||
|
||||
return indexes;
|
||||
}
|
||||
|
||||
@@ -457,7 +456,7 @@ public class CassandraMappingContext
|
||||
|
||||
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
|
||||
|
||||
final CreateUserTypeSpecification specification = CreateUserTypeSpecification.createType(entity.getTableName());
|
||||
CreateUserTypeSpecification specification = CreateUserTypeSpecification.createType(entity.getTableName());
|
||||
|
||||
entity.doWithProperties((PropertyHandler<CassandraPersistentProperty>) property -> {
|
||||
|
||||
@@ -506,10 +505,10 @@ public class CassandraMappingContext
|
||||
}
|
||||
}
|
||||
|
||||
return customConversions.getCustomWriteTarget(property.getType()) //
|
||||
.map(CassandraSimpleTypeHolder::getDataTypeFor) //
|
||||
.orElseGet(() -> customConversions.getCustomWriteTarget(property.getActualType()) //
|
||||
.filter(it -> !property.isMapLike()) //
|
||||
return this.customConversions.getCustomWriteTarget(property.getType())
|
||||
.map(CassandraSimpleTypeHolder::getDataTypeFor)
|
||||
.orElseGet(() -> this.customConversions.getCustomWriteTarget(property.getActualType())
|
||||
.filter(it -> !property.isMapLike())
|
||||
.map(it -> {
|
||||
|
||||
if (property.isCollectionLike()) {
|
||||
@@ -530,6 +529,7 @@ public class CassandraMappingContext
|
||||
|
||||
Class<?> keyType = property.getComponentType();
|
||||
Class<?> valueType = property.getMapValueType();
|
||||
|
||||
return DataType.map(getDataType(keyType, dataTypeProvider), getDataType(valueType, dataTypeProvider));
|
||||
}
|
||||
|
||||
@@ -580,8 +580,8 @@ public class CassandraMappingContext
|
||||
*/
|
||||
public DataType getDataType(Class<?> type) {
|
||||
|
||||
return customConversions.getCustomWriteTarget(type) //
|
||||
.map(CassandraSimpleTypeHolder::getDataTypeFor) //
|
||||
return this.customConversions.getCustomWriteTarget(type)
|
||||
.map(CassandraSimpleTypeHolder::getDataTypeFor)
|
||||
.orElseGet(() -> getDataTypeFor(type));
|
||||
}
|
||||
|
||||
|
||||
@@ -94,14 +94,15 @@ class IndexSpecificationFactory {
|
||||
AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) type;
|
||||
AnnotatedType[] typeArgs = parameterizedType.getAnnotatedActualTypeArguments();
|
||||
|
||||
Indexed keyIndex = typeArgs.length == 2 ? AnnotatedElementUtils.getMergedAnnotation(typeArgs[0], Indexed.class)
|
||||
: null;
|
||||
Indexed keyIndex = typeArgs.length == 2
|
||||
? AnnotatedElementUtils.getMergedAnnotation(typeArgs[0], Indexed.class) : null;
|
||||
|
||||
Indexed valueIndex = typeArgs.length == 2
|
||||
? AnnotatedElementUtils.getMergedAnnotation(typeArgs[1], Indexed.class)
|
||||
: null;
|
||||
? AnnotatedElementUtils.getMergedAnnotation(typeArgs[1], Indexed.class) : null;
|
||||
|
||||
if ((!indexes.isEmpty() && (keyIndex != null || valueIndex != null))
|
||||
|| (keyIndex != null && valueIndex != null)) {
|
||||
|
||||
throw new MappingException("Multiple index declarations for " + property
|
||||
+ " found. A map index must be either declared for entries, keys or values.");
|
||||
}
|
||||
@@ -135,6 +136,7 @@ class IndexSpecificationFactory {
|
||||
|
||||
private static CreateIndexSpecification createIndexSpecification(SASI annotation,
|
||||
CassandraPersistentProperty property) {
|
||||
|
||||
CreateIndexSpecification index;
|
||||
|
||||
if (StringUtils.hasText(annotation.value())) {
|
||||
@@ -150,8 +152,8 @@ class IndexSpecificationFactory {
|
||||
long analyzerCount = INDEX_CONFIGURERS.keySet().stream().filter(property::isAnnotationPresent).count();
|
||||
|
||||
if (analyzerCount > 1) {
|
||||
throw new IllegalStateException(
|
||||
String.format("SASI indexed property %s must be annotated only with a single analyzer annotation", property));
|
||||
throw new IllegalStateException(String.format(
|
||||
"SASI indexed property %s must be annotated only with a single analyzer annotation", property));
|
||||
}
|
||||
|
||||
for (Class<? extends Annotation> annotationType : INDEX_CONFIGURERS.keySet()) {
|
||||
@@ -161,6 +163,7 @@ class IndexSpecificationFactory {
|
||||
}
|
||||
|
||||
Annotation analyzed = property.findAnnotation(annotationType);
|
||||
|
||||
INDEX_CONFIGURERS.get(annotationType).accept(analyzed, index);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ public class PrimaryKeyClassEntityMetadataVerifier implements CassandraPersisten
|
||||
|
||||
// Ensure PrimaryKeyClass only extends Object
|
||||
if (!entityType.getSuperclass().equals(Object.class)) {
|
||||
exceptions.add(
|
||||
new MappingException(String.format("@%s must only extend Object", PrimaryKeyClass.class.getSimpleName())));
|
||||
exceptions.add(new MappingException(String.format("@%s must only extend Object",
|
||||
PrimaryKeyClass.class.getSimpleName())));
|
||||
}
|
||||
|
||||
entity.forEach(property -> {
|
||||
@@ -81,32 +81,30 @@ public class PrimaryKeyClassEntityMetadataVerifier implements CassandraPersisten
|
||||
}
|
||||
});
|
||||
|
||||
if (!compositePrimaryKeys.isEmpty())
|
||||
|
||||
{
|
||||
exceptions
|
||||
.add(new MappingException("Composite primary keys are not allowed inside of composite primary key classes"));
|
||||
if (!compositePrimaryKeys.isEmpty()) {
|
||||
exceptions.add(new MappingException(
|
||||
"Composite primary keys are not allowed inside of composite primary key classes"));
|
||||
}
|
||||
|
||||
// Must have at least 1 attribute annotated with @PrimaryKeyColumn
|
||||
if (primaryKeyColumns.isEmpty()) {
|
||||
exceptions.add(
|
||||
new MappingException(String.format("Composite primary key type [%1$s] has no fields annotated with @%2$s",
|
||||
entity.getType().getName(), PrimaryKeyColumn.class.getSimpleName())));
|
||||
exceptions.add(new MappingException(String.format(
|
||||
"Composite primary key type [%1$s] has no fields annotated with @%2$s",
|
||||
entity.getType().getName(), PrimaryKeyColumn.class.getSimpleName())));
|
||||
}
|
||||
|
||||
// At least one of the PrimaryKeyColumns must have a type PARTIONED
|
||||
if (partitionKeyColumns.isEmpty()) {
|
||||
exceptions
|
||||
.add(new MappingException(String.format("At least one of the @%s annotations must have a type of PARTITIONED",
|
||||
PrimaryKeyColumn.class.getSimpleName())));
|
||||
exceptions.add(new MappingException(String.format(
|
||||
"At least one of the @%s annotations must have a type of PARTITIONED",
|
||||
PrimaryKeyColumn.class.getSimpleName())));
|
||||
}
|
||||
|
||||
// Cannot have any Id or PrimaryKey Annotations
|
||||
if (!idProperties.isEmpty()) {
|
||||
exceptions.add(
|
||||
new MappingException(String.format("Annotations @%1$s and @%2$s are invalid for type annotated with @%3$s",
|
||||
Id.class.getSimpleName(), PrimaryKey.class.getSimpleName(), PrimaryKeyClass.class.getSimpleName())));
|
||||
exceptions.add(new MappingException(String.format(
|
||||
"Annotations @%1$s and @%2$s are invalid for type annotated with @%3$s",
|
||||
Id.class.getSimpleName(), PrimaryKey.class.getSimpleName(), PrimaryKeyClass.class.getSimpleName())));
|
||||
}
|
||||
|
||||
// Determine whether or not to throw Exception based on errors found
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.matches;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -28,6 +29,7 @@ import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.core.cql.CqlOperations;
|
||||
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
|
||||
@@ -67,8 +69,8 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
|
||||
context.getPersistentEntity(MoonType.class);
|
||||
context.getPersistentEntity(PlanetType.class);
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(context,
|
||||
adminOperations);
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(context, adminOperations);
|
||||
|
||||
schemaCreator.createUserTypes(false);
|
||||
|
||||
@@ -80,8 +82,8 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
|
||||
|
||||
context.getPersistentEntity(PlanetType.class);
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(context,
|
||||
adminOperations);
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(context, adminOperations);
|
||||
|
||||
schemaCreator.createUserTypes(false);
|
||||
|
||||
@@ -95,8 +97,8 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
|
||||
|
||||
context.getPersistentEntity(SpaceAgencyType.class);
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(context,
|
||||
adminOperations);
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(context, adminOperations);
|
||||
|
||||
schemaCreator.createUserTypes(false);
|
||||
|
||||
@@ -110,8 +112,8 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
|
||||
|
||||
context.getPersistentEntity(PlanetType.class);
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(context,
|
||||
adminOperations);
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(context, adminOperations);
|
||||
|
||||
schemaCreator.createUserTypes(false);
|
||||
|
||||
@@ -123,8 +125,8 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
|
||||
|
||||
context.getPersistentEntity(IndexedEntity.class);
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(context,
|
||||
adminOperations);
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(context, adminOperations);
|
||||
|
||||
schemaCreator.createIndexes(false);
|
||||
|
||||
@@ -134,6 +136,7 @@ public class CassandraPersistentEntitySchemaCreatorUnitTests {
|
||||
private void verifyTypesGetCreatedInOrderFor(String... typenames) {
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(operations);
|
||||
|
||||
for (String typename : typenames) {
|
||||
inOrder.verify(operations).execute(Mockito.contains("CREATE TYPE " + typename));
|
||||
}
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.generator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
@@ -27,6 +29,7 @@ import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -304,8 +307,8 @@ public class CassandraMappingContextUnitTests {
|
||||
@Test // DATACASS-213
|
||||
public void createIndexShouldConsiderAnnotatedProperties() {
|
||||
|
||||
List<CreateIndexSpecification> specifications = mappingContext
|
||||
.getCreateIndexSpecificationsFor(mappingContext.getRequiredPersistentEntity(IndexedType.class));
|
||||
List<CreateIndexSpecification> specifications = mappingContext.getCreateIndexSpecificationsFor(
|
||||
mappingContext.getRequiredPersistentEntity(IndexedType.class));
|
||||
|
||||
CreateIndexSpecification firstname = getSpecificationFor("first_name", specifications);
|
||||
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.core.cql.generator.CreateIndexCqlGenerator;
|
||||
import org.springframework.data.cassandra.core.cql.generator.CreateTableCqlGenerator;
|
||||
@@ -85,6 +86,7 @@ public class IndexCreationIntegrationTests extends AbstractKeyspaceCreatingInteg
|
||||
Thread.sleep(500); // index creation is async so we do poor man's sync to await completion
|
||||
|
||||
TableMetadata metadata = getMetadata(createTable.getName().toCql());
|
||||
|
||||
assertThat(metadata.getIndex("withsasiindex_firstname_idx")).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
@@ -63,6 +64,7 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
CreateIndexSpecification entries = createIndexFor(IndexedMapKeyProperty.class, "entries");
|
||||
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.cqlId("entries"));
|
||||
assertThat(entries.getTableName()).isNull();
|
||||
assertThat(entries.getName()).isNull();
|
||||
assertThat(entries.getColumnFunction()).isEqualTo(ColumnFunction.KEYS);
|
||||
}
|
||||
@@ -73,6 +75,7 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
CreateIndexSpecification entries = createIndexFor(MapValueIndexProperty.class, "entries");
|
||||
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.cqlId("entries"));
|
||||
assertThat(entries.getTableName()).isNull();
|
||||
assertThat(entries.getName()).isNull();
|
||||
assertThat(entries.getColumnFunction()).isEqualTo(ColumnFunction.VALUES);
|
||||
}
|
||||
@@ -83,11 +86,12 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "simpleSasi");
|
||||
|
||||
assertThat(simpleSasi.getColumnName()).isEqualTo(CqlIdentifier.cqlId("simplesasi"));
|
||||
assertThat(simpleSasi.getTableName()).isNull();
|
||||
assertThat(simpleSasi.isCustom()).isTrue();
|
||||
assertThat(simpleSasi.getUsing()).isEqualTo("org.apache.cassandra.index.sasi.SASIIndex");
|
||||
assertThat(simpleSasi.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("mode", "PREFIX").doesNotContainKeys("analyzed",
|
||||
"analyzer_class");
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("mode", "PREFIX")
|
||||
.doesNotContainKeys("analyzed", "analyzer_class");
|
||||
}
|
||||
|
||||
@Test // DATACASS-306
|
||||
@@ -96,10 +100,10 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "sasiStandard");
|
||||
|
||||
assertThat(simpleSasi.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("mode", "PREFIX") //
|
||||
.containsEntry("analyzed", "true") //
|
||||
.containsEntry("tokenization_skip_stop_words", "false") //
|
||||
.containsEntry("analyzer_class", "org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer") //
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("mode", "PREFIX")
|
||||
.containsEntry("analyzed", "true")
|
||||
.containsEntry("tokenization_skip_stop_words", "false")
|
||||
.containsEntry("analyzer_class", "org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer")
|
||||
.containsEntry("tokenization_locale", "de");
|
||||
}
|
||||
|
||||
@@ -109,10 +113,10 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "sasiStandardWithOptions");
|
||||
|
||||
assertThat(simpleSasi.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("tokenization_skip_stop_words", "true") //
|
||||
.containsEntry("tokenization_locale", "de") //
|
||||
.containsEntry("tokenization_enable_stemming", "true") //
|
||||
.containsEntry("tokenization_normalize_uppercase", "true") //
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("tokenization_skip_stop_words", "true")
|
||||
.containsEntry("tokenization_locale", "de")
|
||||
.containsEntry("tokenization_enable_stemming", "true")
|
||||
.containsEntry("tokenization_normalize_uppercase", "true")
|
||||
.doesNotContainKey("tokenization_normalize_lowercase");
|
||||
}
|
||||
|
||||
@@ -122,7 +126,7 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "sasiStandardLowercase");
|
||||
|
||||
assertThat(simpleSasi.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("tokenization_normalize_lowercase", "true") //
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("tokenization_normalize_lowercase", "true")
|
||||
.doesNotContainKey("tokenization_normalize_uppercase");
|
||||
}
|
||||
|
||||
@@ -131,10 +135,10 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "sasiNontokenizing");
|
||||
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("mode", "PREFIX") //
|
||||
.containsEntry("analyzed", "true") //
|
||||
.containsEntry("case_sensitive", "true") //
|
||||
.containsEntry("analyzer_class", "org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer") //
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("mode", "PREFIX")
|
||||
.containsEntry("analyzed", "true")
|
||||
.containsEntry("case_sensitive", "true")
|
||||
.containsEntry("analyzer_class", "org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer")
|
||||
.doesNotContainKeys("normalize_lowercase", "normalize_uppercase");
|
||||
}
|
||||
|
||||
@@ -143,8 +147,8 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "sasiNontokenizingLowercase");
|
||||
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("normalize_lowercase", "true") //
|
||||
.containsEntry("case_sensitive", "false") //
|
||||
assertThat(simpleSasi.getOptions()).containsEntry("normalize_lowercase", "true")
|
||||
.containsEntry("case_sensitive", "false")
|
||||
.doesNotContainKey("normalize_uppercase");
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
@@ -25,10 +25,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -51,6 +51,8 @@ import org.springframework.data.util.Version;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
@@ -77,7 +79,6 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE_DROP_UNUSED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Autowired CassandraOperations template;
|
||||
@@ -95,9 +96,11 @@ public class QueryDerivationIntegrationTests extends AbstractSpringDataEmbeddedC
|
||||
deleteAllEntities();
|
||||
|
||||
Person person = new Person("Walter", "White");
|
||||
|
||||
person.setNumberOfChildren(2);
|
||||
|
||||
person.setMainAddress(new AddressType("Albuquerque", "USA"));
|
||||
|
||||
person.setAlternativeAddresses(Arrays.asList(new AddressType("Albuquerque", "USA"),
|
||||
new AddressType("New Hampshire", "USA"), new AddressType("Grocery Store", "Mexico")));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user