DATACASS-93 - xml & java config tests with forceQuote working
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package org.springframework.cassandra.core.cql;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.cassandra.core.ReservedKeyword;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* This encapsulates the logic for keyspace identifiers.
|
||||
* <p/>
|
||||
* Keyspace identifiers are converted to lower case. To render, use any of the methods {@link #toCql()},
|
||||
* {@link #toCql(StringBuilder)}, or {@link #toString()}.
|
||||
*
|
||||
* @see #KeyspaceIdentifier(String)
|
||||
* @see #toCql()
|
||||
* @see #toCql(StringBuilder)
|
||||
* @see #toString()
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public final class KeyspaceIdentifier implements Comparable<KeyspaceIdentifier> {
|
||||
|
||||
public static final String REGEX = "(?i)[a-z][\\w]{0,47}";
|
||||
public static final Pattern PATTERN = Pattern.compile(REGEX);
|
||||
|
||||
/**
|
||||
* Factory method for {@link KeyspaceIdentifier}. Convenient if imported statically.
|
||||
*/
|
||||
public static KeyspaceIdentifier ksId(CharSequence identifier) {
|
||||
return new KeyspaceIdentifier(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given {@link CharSequence} is a legal keyspace identifier.
|
||||
*/
|
||||
public static boolean isIdentifier(CharSequence chars) {
|
||||
return PATTERN.matcher(chars).matches() && !ReservedKeyword.isReserved(chars);
|
||||
}
|
||||
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* Creates a new {@link KeyspaceIdentifier}.
|
||||
*/
|
||||
public KeyspaceIdentifier(CharSequence identifier) {
|
||||
setIdentifier(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests & sets the given identifier.
|
||||
*/
|
||||
private void setIdentifier(CharSequence identifier) {
|
||||
|
||||
Assert.notNull(identifier);
|
||||
|
||||
String string = identifier.toString();
|
||||
Assert.hasText(string);
|
||||
|
||||
if (!isIdentifier(string)) {
|
||||
throw new IllegalArgumentException(String.format("given string [%s] is not a valid keyspace identifier",
|
||||
identifier));
|
||||
}
|
||||
this.identifier = string.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders this identifier appropriately.
|
||||
*/
|
||||
public String toCql() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the rendering of this identifier to the given {@link StringBuilder}, then returns that
|
||||
* {@link StringBuilder}. If <code>null</code> is given, a new {@link StringBuilder} is created, appended to, and
|
||||
* returned.
|
||||
*/
|
||||
public StringBuilder toCql(StringBuilder sb) {
|
||||
sb = sb == null ? new StringBuilder() : sb;
|
||||
return sb.append(toCql());
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for {@link #toCql()}.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return toCql();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return identifier.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this {@link KeyspaceIdentifier} to the given object. Note that if a {@link CharSequence} is given, a new
|
||||
* {@link KeyspaceIdentifier} is created from it and compared, such that a {@link CharSequence} can be effectively
|
||||
* equal to a {@link KeyspaceIdentifier}.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(that instanceof KeyspaceIdentifier) && !(that instanceof CharSequence)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
KeyspaceIdentifier other = (that instanceof KeyspaceIdentifier) ? (KeyspaceIdentifier) that
|
||||
: ksId((CharSequence) that);
|
||||
|
||||
return this.identifier.equals(other.identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(KeyspaceIdentifier that) {
|
||||
return this.identifier.compareTo(that.identifier);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import org.springframework.cassandra.core.cql.KeyspaceIdentifier;
|
||||
|
||||
public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<AlterKeyspaceSpecification> {
|
||||
|
||||
/**
|
||||
@@ -24,4 +26,23 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<Alt
|
||||
public static AlterKeyspaceSpecification alterKeyspace() {
|
||||
return new AlterKeyspaceSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link AlterKeyspaceSpecification}'s fluent API to alter a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static AlterKeyspaceSpecification alterKeyspace(KeyspaceIdentifier name) {
|
||||
return new AlterKeyspaceSpecification(name);
|
||||
}
|
||||
|
||||
public AlterKeyspaceSpecification() {
|
||||
}
|
||||
|
||||
public AlterKeyspaceSpecification(String name) {
|
||||
name(name);
|
||||
}
|
||||
|
||||
public AlterKeyspaceSpecification(KeyspaceIdentifier name) {
|
||||
name(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import org.springframework.cassandra.config.DataCenterReplication;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.cassandra.core.cql.KeyspaceIdentifier;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceOption.ReplicationStrategy;
|
||||
import org.springframework.cassandra.core.util.MapBuilder;
|
||||
|
||||
@@ -30,8 +31,35 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
|
||||
return new CreateKeyspaceSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CreateKeyspaceSpecification}'s fluent API to create a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static CreateKeyspaceSpecification createKeyspace(String name) {
|
||||
return new CreateKeyspaceSpecification(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CreateKeyspaceSpecification}'s fluent API to create a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static CreateKeyspaceSpecification createKeyspace(KeyspaceIdentifier name) {
|
||||
return new CreateKeyspaceSpecification(name);
|
||||
}
|
||||
|
||||
private boolean ifNotExists = false;
|
||||
|
||||
public CreateKeyspaceSpecification() {
|
||||
}
|
||||
|
||||
public CreateKeyspaceSpecification(String name) {
|
||||
name(name);
|
||||
}
|
||||
|
||||
public CreateKeyspaceSpecification(KeyspaceIdentifier name) {
|
||||
name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
*
|
||||
@@ -88,7 +116,7 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateKeyspaceSpecification name(CqlIdentifier name) {
|
||||
public CreateKeyspaceSpecification name(KeyspaceIdentifier name) {
|
||||
return (CreateKeyspaceSpecification) super.name(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,47 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import org.springframework.cassandra.core.cql.KeyspaceIdentifier;
|
||||
|
||||
public class DropKeyspaceSpecification extends KeyspaceActionSpecification<DropKeyspaceSpecification> {
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropKeyspaceSpecification}'s fluent API to drop a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static DropKeyspaceSpecification dropKeyspace() {
|
||||
return new DropKeyspaceSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropKeyspaceSpecification}'s fluent API to drop a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static DropKeyspaceSpecification dropKeyspace(KeyspaceIdentifier name) {
|
||||
return new DropKeyspaceSpecification(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropKeyspaceSpecification}'s fluent API to drop a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static DropKeyspaceSpecification dropKeyspace(String name) {
|
||||
return new DropKeyspaceSpecification(name);
|
||||
}
|
||||
|
||||
private boolean ifExists;
|
||||
|
||||
public DropKeyspaceSpecification() {
|
||||
}
|
||||
|
||||
public DropKeyspaceSpecification(String name) {
|
||||
name(name);
|
||||
}
|
||||
|
||||
public DropKeyspaceSpecification(KeyspaceIdentifier name) {
|
||||
name(name);
|
||||
}
|
||||
|
||||
public DropKeyspaceSpecification ifExists() {
|
||||
return ifExists(true);
|
||||
}
|
||||
@@ -31,12 +68,4 @@ public class DropKeyspaceSpecification extends KeyspaceActionSpecification<DropK
|
||||
public boolean getIfExists() {
|
||||
return ifExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropKeyspaceSpecification}'s fluent API to drop a keyspace. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static DropKeyspaceSpecification dropKeyspace() {
|
||||
return new DropKeyspaceSpecification();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
import static org.springframework.cassandra.core.cql.KeyspaceIdentifier.ksId;
|
||||
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.cassandra.core.cql.KeyspaceIdentifier;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ public abstract class KeyspaceActionSpecification<T extends KeyspaceActionSpecif
|
||||
/**
|
||||
* The name of the keyspace.
|
||||
*/
|
||||
private CqlIdentifier name;
|
||||
private KeyspaceIdentifier name;
|
||||
|
||||
/**
|
||||
* Sets the keyspace name.
|
||||
@@ -40,7 +40,7 @@ public abstract class KeyspaceActionSpecification<T extends KeyspaceActionSpecif
|
||||
* @return this
|
||||
*/
|
||||
public T name(String name) {
|
||||
return name(cqlId(name));
|
||||
return name(ksId(name));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,13 +49,13 @@ public abstract class KeyspaceActionSpecification<T extends KeyspaceActionSpecif
|
||||
* @return this
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T name(CqlIdentifier name) {
|
||||
public T name(KeyspaceIdentifier name) {
|
||||
Assert.notNull(name);
|
||||
this.name = name;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public CqlIdentifier getName() {
|
||||
public KeyspaceIdentifier getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.cassandra.core.cql.KeyspaceIdentifier;
|
||||
|
||||
/**
|
||||
* Describes a Keyspace.
|
||||
@@ -29,7 +29,7 @@ public interface KeyspaceDescriptor {
|
||||
/**
|
||||
* Returns the name of the table.
|
||||
*/
|
||||
CqlIdentifier getName();
|
||||
KeyspaceIdentifier getName();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable {@link Map} of keyspace options.
|
||||
|
||||
@@ -92,16 +92,16 @@ public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionP
|
||||
|
||||
String tableName = table.getAttribute("name");
|
||||
if (!StringUtils.hasText(tableName)) {
|
||||
tableName = null;
|
||||
tableName = "";
|
||||
}
|
||||
|
||||
String forceQuote = table.getAttribute("force-quote");
|
||||
if (!StringUtils.hasText(forceQuote)) {
|
||||
forceQuote = "false";
|
||||
forceQuote = Boolean.FALSE.toString();
|
||||
}
|
||||
|
||||
// TODO: parse future entity mappings here, like table options
|
||||
|
||||
return new EntityMapping(className, tableName, Boolean.valueOf(forceQuote));
|
||||
return new EntityMapping(className, tableName, forceQuote);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,6 +757,6 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
|
||||
throw new IllegalArgumentException(String.format("unknown persistent entity class [%s]", clazz.getName()));
|
||||
}
|
||||
|
||||
truncate(mappingContext.getPersistentEntity(clazz).getTableName().toCql());
|
||||
truncate(mappingContext.getPersistentEntity(clazz).getTableName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class DefaultCassandraMappingContext extends
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.setTableName(cqlId(tableName, entityMapping.getForceQuote()));
|
||||
entity.setTableName(cqlId(tableName, Boolean.valueOf(entityMapping.getForceQuote())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.quotedCqlId;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -38,12 +35,12 @@ public class EntityMapping {
|
||||
/**
|
||||
* The name of the table to which the entity is mapped.
|
||||
*/
|
||||
protected String tableName;
|
||||
protected String tableName = "";
|
||||
|
||||
/**
|
||||
* Whether to force the table name to be quoted.
|
||||
*/
|
||||
protected boolean forceQuote = false;
|
||||
protected String forceQuote = "false";
|
||||
|
||||
/**
|
||||
* The {@link PropertyMapping}s for each persistent property, keyed on property name.
|
||||
@@ -51,10 +48,10 @@ public class EntityMapping {
|
||||
protected Map<String, PropertyMapping> propertyMappings = new HashMap<String, PropertyMapping>();
|
||||
|
||||
public EntityMapping(String entityClassName, String tableName) {
|
||||
this(entityClassName, tableName, false);
|
||||
this(entityClassName, tableName, Boolean.FALSE.toString());
|
||||
}
|
||||
|
||||
public EntityMapping(String entityClassName, String tableName, boolean forceQuote) {
|
||||
public EntityMapping(String entityClassName, String tableName, String forceQuote) {
|
||||
|
||||
setEntityClassName(entityClassName);
|
||||
setTableName(tableName);
|
||||
@@ -77,15 +74,17 @@ public class EntityMapping {
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
|
||||
Assert.hasText(tableName);
|
||||
Assert.notNull(tableName);
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public boolean getForceQuote() {
|
||||
public String getForceQuote() {
|
||||
return forceQuote;
|
||||
}
|
||||
|
||||
public void setForceQuote(boolean forceQuote) {
|
||||
public void setForceQuote(String forceQuote) {
|
||||
|
||||
Assert.notNull(forceQuote);
|
||||
this.forceQuote = forceQuote;
|
||||
}
|
||||
|
||||
@@ -103,12 +102,12 @@ public class EntityMapping {
|
||||
|
||||
EntityMapping other = (EntityMapping) that;
|
||||
|
||||
return this.entityClassName.equals(other.entityClassName)
|
||||
&& (forceQuote ? quotedCqlId(this.tableName) : cqlId(this.tableName)).equals(other.tableName);
|
||||
return this.entityClassName.equals(other.entityClassName) && this.forceQuote.equals(other.forceQuote)
|
||||
&& this.tableName.equals(other.tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return entityClassName.hashCode() ^ (forceQuote ? quotedCqlId(this.tableName) : cqlId(this.tableName)).hashCode();
|
||||
return entityClassName.hashCode() ^ forceQuote.hashCode() ^ tableName.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.collections;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -31,9 +28,7 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.Book;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.BookHistory;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.BookReference;
|
||||
@@ -56,16 +51,6 @@ public class CollectionsRowValueProviderTest extends AbstractSpringDataEmbeddedC
|
||||
@Configuration
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
|
||||
return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getEntityBasePackages() {
|
||||
return new String[] { Book.class.getPackage().getName() };
|
||||
|
||||
@@ -15,18 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.composites;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.repository.UserRepository;
|
||||
@@ -48,24 +41,10 @@ public class CommentRepositoryJavaConfigIntegrationTests extends AbstractSpringD
|
||||
@EnableCassandraRepositories(basePackageClasses = CommentRepository.class)
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
|
||||
@Override
|
||||
protected String getKeyspaceName() {
|
||||
return CommentRepositoryJavaConfigIntegrationTests.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
|
||||
List<CreateKeyspaceSpecification> creates = new ArrayList<CreateKeyspaceSpecification>();
|
||||
|
||||
creates.add(createKeyspace().name(getKeyspaceName()).withSimpleReplication());
|
||||
|
||||
return creates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE;
|
||||
}
|
||||
// @Override
|
||||
// protected String getKeyspaceName() {
|
||||
// return CommentRepositoryJavaConfigIntegrationTests.class.getSimpleName();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String[] getEntityBasePackages() {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table(forceQuote = true, value = Explicit.TABLE_NAME)
|
||||
public class Explicit {
|
||||
|
||||
public static final String TABLE_NAME = "Xx";
|
||||
|
||||
@PrimaryKey
|
||||
String key;
|
||||
|
||||
public Explicit() {
|
||||
this(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
public Explicit(String key) {
|
||||
setKey(key);
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
|
||||
public interface ExplicitRepository extends CassandraRepository<Explicit, String> {
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
|
||||
public class ForceQuotedRepositoryIntegrationTests {
|
||||
|
||||
ImplicitRepository implicits;
|
||||
ExplicitRepository explicits;
|
||||
CassandraTemplate template;
|
||||
|
||||
public ForceQuotedRepositoryIntegrationTests() {
|
||||
}
|
||||
|
||||
public ForceQuotedRepositoryIntegrationTests(ImplicitRepository implicits, ExplicitRepository explicits,
|
||||
CassandraTemplate template) {
|
||||
this.implicits = implicits;
|
||||
this.explicits = explicits;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public void before() {
|
||||
template.deleteAll(Implicit.class);
|
||||
}
|
||||
|
||||
public void testImplicit() {
|
||||
Implicit entity = new Implicit();
|
||||
String key = entity.getKey();
|
||||
|
||||
Implicit si = implicits.save(entity);
|
||||
assertSame(si, entity);
|
||||
|
||||
Implicit fi = implicits.findOne(key);
|
||||
assertNotSame(fi, entity);
|
||||
|
||||
implicits.delete(key);
|
||||
|
||||
assertNull(implicits.findOne(key));
|
||||
}
|
||||
|
||||
public void testExplicit() {
|
||||
Explicit entity = new Explicit();
|
||||
String key = entity.getKey();
|
||||
|
||||
Explicit si = explicits.save(entity);
|
||||
assertSame(si, entity);
|
||||
|
||||
Explicit fi = explicits.findOne(key);
|
||||
assertNotSame(fi, entity);
|
||||
|
||||
explicits.delete(key);
|
||||
|
||||
assertNull(explicits.findOne(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
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.Configuration;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ForceQuotedRepositoryJavaConfigIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Configuration
|
||||
@EnableCassandraRepositories(basePackageClasses = ForceQuotedRepositoryIntegrationTests.class)
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
ImplicitRepository implicits;
|
||||
|
||||
@Autowired
|
||||
ExplicitRepository explicits;
|
||||
|
||||
@Autowired
|
||||
CassandraTemplate template;
|
||||
|
||||
ForceQuotedRepositoryIntegrationTests tests;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
tests = new ForceQuotedRepositoryIntegrationTests(implicits, explicits, template);
|
||||
tests.before();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicit() {
|
||||
tests.testImplicit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicit() {
|
||||
tests.testExplicit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ForceQuotedRepositoryXmlConfigIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
ImplicitRepository implicits;
|
||||
|
||||
@Autowired
|
||||
ExplicitRepository explicits;
|
||||
|
||||
@Autowired
|
||||
CassandraTemplate template;
|
||||
|
||||
ForceQuotedRepositoryIntegrationTests tests;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
tests = new ForceQuotedRepositoryIntegrationTests(implicits, explicits, template);
|
||||
tests.before();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicit() {
|
||||
tests.testImplicit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicit() {
|
||||
tests.testExplicit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table(forceQuote = true)
|
||||
public class Implicit {
|
||||
|
||||
@PrimaryKey
|
||||
String key;
|
||||
|
||||
public Implicit() {
|
||||
this(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
public Implicit(String key) {
|
||||
setKey(key);
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.config;
|
||||
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
|
||||
public interface ImplicitRepository extends CassandraRepository<Implicit, String> {
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.springframework.data.cassandra.test.integration.forcequote.simple;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
public class ForceQuotedEntitiesSimpleIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testImplicitTableNameForceQuoted() {
|
||||
BasicCassandraPersistentEntity<ImplicitTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<ImplicitTableNameForceQuoted>(
|
||||
ClassTypeInformation.from(ImplicitTableNameForceQuoted.class));
|
||||
|
||||
assertEquals("\"" + ImplicitTableNameForceQuoted.class.getSimpleName() + "\"", entity.getTableName().toCql());
|
||||
assertEquals(ImplicitTableNameForceQuoted.class.getSimpleName(), entity.getTableName().getUnquoted());
|
||||
}
|
||||
|
||||
@Table(forceQuote = true)
|
||||
public static class ImplicitTableNameForceQuoted {
|
||||
}
|
||||
|
||||
public static final String EXPLICIT_TABLE_NAME = "Xx";
|
||||
|
||||
@Test
|
||||
public void testExplicitTableNameForceQuoted() {
|
||||
BasicCassandraPersistentEntity<ExplicitTableNameForceQuoted> entity = new BasicCassandraPersistentEntity<ExplicitTableNameForceQuoted>(
|
||||
ClassTypeInformation.from(ExplicitTableNameForceQuoted.class));
|
||||
|
||||
assertEquals("\"" + EXPLICIT_TABLE_NAME + "\"", entity.getTableName().toCql());
|
||||
assertEquals(EXPLICIT_TABLE_NAME, entity.getTableName().getUnquoted());
|
||||
}
|
||||
|
||||
@Table(value = EXPLICIT_TABLE_NAME, forceQuote = true)
|
||||
public static class ExplicitTableNameForceQuoted {
|
||||
}
|
||||
}
|
||||
@@ -26,16 +26,16 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link BasicCassandraPersistentEntity}.
|
||||
*
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BasicCassandraPersistentEntityIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
public class BasicCassandraPersistentEntityIntegrationTests {
|
||||
|
||||
@Mock
|
||||
ApplicationContext context;
|
||||
|
||||
@@ -15,19 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.repository;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
@@ -48,24 +40,10 @@ public class UserRepositoryJavaConfigIntegrationTests extends AbstractSpringData
|
||||
@EnableCassandraRepositories(basePackageClasses = UserRepository.class)
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
|
||||
@Override
|
||||
protected String getKeyspaceName() {
|
||||
return UserRepositoryJavaConfigIntegrationTests.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
|
||||
List<CreateKeyspaceSpecification> creates = new ArrayList<CreateKeyspaceSpecification>();
|
||||
|
||||
creates.add(createKeyspace().name(getKeyspaceName()).withSimpleReplication());
|
||||
|
||||
return creates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE;
|
||||
}
|
||||
// @Override
|
||||
// protected String getKeyspaceName() {
|
||||
// return UserRepositoryJavaConfigIntegrationTests.class.getSimpleName();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String[] getEntityBasePackages() {
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.support;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.test.unit.support.Utils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.config.java.AbstractSpringDataCassandraConfiguration;
|
||||
|
||||
/**
|
||||
@@ -34,13 +41,23 @@ public class IntegrationTestConfig extends AbstractSpringDataCassandraConfigurat
|
||||
|
||||
public String keyspaceName = Utils.randomKeyspaceName();
|
||||
|
||||
@Override
|
||||
protected int getPort() {
|
||||
return PORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKeyspaceName() {
|
||||
return keyspaceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPort() {
|
||||
return PORT;
|
||||
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
|
||||
return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.test.integration.template;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -31,9 +27,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.cassandra.core.ConsistencyLevel;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.RetryPolicy;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.Book;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
|
||||
@@ -56,16 +50,6 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa
|
||||
@Configuration
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
|
||||
return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getEntityBasePackages() {
|
||||
return new String[] { Book.class.getPackage().getName() };
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cass="http://www.springframework.org/schema/data/cassandra"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
|
||||
">
|
||||
|
||||
<import resource="classpath:/spring-data-cassandra-basic.xml" />
|
||||
|
||||
<cass:mapping
|
||||
entity-base-packages="org.springframework.data.cassandra.test.integration.forcequote.config">
|
||||
<cass:entity
|
||||
class="org.springframework.data.cassandra.test.integration.forcequote.config.Implicit">
|
||||
<cass:table force-quote="true" />
|
||||
</cass:entity>
|
||||
<cass:entity
|
||||
class="org.springframework.data.cassandra.test.integration.forcequote.config.Explicit">
|
||||
<cass:table force-quote="true" name="Zz" />
|
||||
</cass:entity>
|
||||
</cass:mapping>
|
||||
|
||||
<cass:cluster port="${cassandra.native_transport_port}">
|
||||
<cass:keyspace name="ForceQuoteRepositoryXmlConfigIntegrationTests"
|
||||
action="CREATE" durable-writes="true">
|
||||
</cass:keyspace>
|
||||
</cass:cluster>
|
||||
|
||||
<cass:session keyspace-name="ForceQuoteRepositoryXmlConfigIntegrationTests"
|
||||
schema-action="RECREATE">
|
||||
</cass:session>
|
||||
|
||||
<cass:repositories
|
||||
base-package="org.springframework.data.cassandra.test.integration.forcequote.config" />
|
||||
</beans>
|
||||
Reference in New Issue
Block a user