From 28212f673f7f96705f9e7c6c4831ee98394cd4a4 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 21 Feb 2014 15:34:25 -0600 Subject: [PATCH] DATACASS-93 - added composite pk tests, fixed other tests, removed CachingCassandraPersistent{Entity|Property} as caching is now in BasicCassandraPersistent{Entity|Property} --- .../CassandraDataSessionFactoryBean.java | 1 + .../BasicCassandraPersistentEntity.java | 13 ++ .../BasicCassandraPersistentProperty.java | 13 +- .../CachingCassandraPersistentEntity.java | 85 --------- .../CachingCassandraPersistentProperty.java | 165 ------------------ .../mapping/CassandraPersistentEntity.java | 2 + .../DefaultCassandraMappingContext.java | 4 +- .../cassandra/config/spring-cassandra-1.0.xsd | 24 ++- .../compositeprimarykey/Explicit.java | 35 ++++ .../compositeprimarykey/ExplicitKey.java | 35 ++++ .../ExplicitRepository.java | 6 + ...ePrimaryKeyRepositoryIntegrationTests.java | 107 ++++++++++++ ...eyRepositoryIntegrationTestsDelegator.java | 45 +++++ ...yRepositoryJavaConfigIntegrationTests.java | 16 ++ .../compositeprimarykey/Implicit.java | 35 ++++ .../compositeprimarykey/ImplicitKey.java | 32 ++++ .../ImplicitRepository.java | 6 + ...ForceQuotedRepositoryIntegrationTests.java | 8 +- ...edRepositoryIntegrationTestsDelegator.java | 8 +- ...dRepositoryJavaConfigIntegrationTests.java | 8 +- ...edRepositoryXmlConfigIntegrationTests.java | 10 +- ...uotedPropertiesSimpleIntegrationTests.java | 3 +- ...raCompositePrimaryKeyIntegrationTests.java | 4 +- .../CompoundPrimaryKeyIntegrationTests.java | 3 +- ...itoryXmlConfigIntegrationTests-context.xml | 52 ++++++ ...itoryXmlConfigIntegrationTests-context.xml | 5 +- 26 files changed, 450 insertions(+), 275 deletions(-) delete mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentEntity.java delete mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentProperty.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java create mode 100644 spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java create mode 100644 spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraDataSessionFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraDataSessionFactoryBean.java index 880234e4b..9b64e1402 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraDataSessionFactoryBean.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraDataSessionFactoryBean.java @@ -75,6 +75,7 @@ public class CassandraDataSessionFactoryBean extends CassandraSessionFactoryBean Metadata md = session.getCluster().getMetadata(); KeyspaceMetadata kmd = md.getKeyspace(keyspaceName); + // TODO: fix this with KeyspaceIdentifier if (kmd == null) { // try lower-cased keyspace name kmd = md.getKeyspace(keyspaceName.toLowerCase()); } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java index 9ffe79aad..2fa16d58a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentEntity.java @@ -54,6 +54,7 @@ public class BasicCassandraPersistentEntity extends BasicPersistentEntity typeInformation) { this(typeInformation, null); @@ -136,6 +137,18 @@ public class BasicCassandraPersistentEntity extends BasicPersistentEntity determineColumnNames() { + List columnNames = new ArrayList(); if (isCompositePrimaryKey()) { // then the id type has @PrimaryKeyClass @@ -310,7 +315,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP } columnNames.add(createColumnName(defaultName, overriddenName, forceQuote)); - return this.columnNames = Collections.unmodifiableList(columnNames); + + return columnNames; } protected CqlIdentifier createColumnName(String defaultName, String overriddenName, boolean forceQuote) { @@ -351,6 +357,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP public void setColumnNames(List columnNames) { Assert.notNull(columnNames); + + // force calculation of columnNames if not yet known if (this.columnNames == null) { getColumnNames(); } @@ -379,7 +387,8 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP for (CqlIdentifier columnName : getColumnNames()) { columnNames.add(cqlId(columnName.getUnquoted(), forceQuote)); } - this.columnNames = Collections.unmodifiableList(columnNames); + + setColumnNames(columnNames); } @Override diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentEntity.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentEntity.java deleted file mode 100644 index 49273e057..000000000 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentEntity.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2013-2014 the original author or authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.cassandra.mapping; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.cassandra.core.cql.CqlIdentifier; -import org.springframework.data.util.TypeInformation; - -public class CachingCassandraPersistentEntity extends BasicCassandraPersistentEntity { - - protected CqlIdentifier tableName; - protected String name; - protected Boolean isCompositePrimaryKey; - protected List compositePrimaryKeyProperties; - protected Map properties = new HashMap(); - - public CachingCassandraPersistentEntity(TypeInformation typeInformation) { - super(typeInformation); - } - - public CachingCassandraPersistentEntity(TypeInformation typeInformation, CassandraMappingContext mappingContext) { - super(typeInformation, mappingContext); - } - - public CachingCassandraPersistentEntity(TypeInformation typeInformation, CassandraMappingContext mappingContext, - CassandraPersistentEntityMetadataVerifier verifier) { - super(typeInformation, mappingContext, verifier); - } - - @Override - public CqlIdentifier getTableName() { - if (tableName == null) { - tableName = super.getTableName(); - } - return tableName; - } - - @Override - public String getName() { - if (name == null) { - name = super.getName(); - } - return name; - } - - @Override - public boolean isCompositePrimaryKey() { - if (isCompositePrimaryKey == null) { - isCompositePrimaryKey = super.isCompositePrimaryKey(); - } - return isCompositePrimaryKey; - } - - @Override - public List getCompositePrimaryKeyProperties() { - if (compositePrimaryKeyProperties == null) { - compositePrimaryKeyProperties = super.getCompositePrimaryKeyProperties(); - } - return compositePrimaryKeyProperties; - } - - @Override - public CassandraPersistentProperty getPersistentProperty(String name) { - if (properties.get(name) == null) { - properties.put(name, super.getPersistentProperty(name)); - } - return properties.get(name); - } -} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentProperty.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentProperty.java deleted file mode 100644 index 8fdbd0a38..000000000 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CachingCassandraPersistentProperty.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2013-2014 the original author or authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.cassandra.mapping; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; -import java.util.List; - -import org.springframework.cassandra.core.Ordering; -import org.springframework.cassandra.core.cql.CqlIdentifier; -import org.springframework.data.util.TypeInformation; - -import com.datastax.driver.core.DataType; - -/** - * {@link BasicCassandraPersistentProperty} subclass that caches call results from the superclass. - * - * @author Alex Shvid - * @author Matthew T. Adams - */ -public class CachingCassandraPersistentProperty extends BasicCassandraPersistentProperty { - - private Boolean isIdProperty; - private Boolean isIndexed; - private Boolean isCompositePrimaryKey; - private Boolean isPartitionKeyColumn; - private Boolean isClusterKeyColumn; - private Boolean isPrimaryKeyColumn; - private CqlIdentifier columnName; - private List columnNames; - private Ordering ordering; - private boolean orderingCached = false; - private DataType dataType; - private Class compositePrimaryKeyType; - private TypeInformation compositePrimaryKeyTypeInformation; - - /** - * Creates a new {@link CachingCassandraPersistentProperty}. - */ - public CachingCassandraPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, - CassandraPersistentEntity owner, CassandraSimpleTypeHolder simpleTypeHolder) { - super(field, propertyDescriptor, owner, simpleTypeHolder); - } - - @Override - public TypeInformation getCompositePrimaryKeyTypeInformation() { - - if (compositePrimaryKeyTypeInformation == null) { - compositePrimaryKeyTypeInformation = super.getCompositePrimaryKeyTypeInformation(); - } - return compositePrimaryKeyTypeInformation; - } - - @Override - public Class getCompositePrimaryKeyType() { - - if (compositePrimaryKeyType == null) { - compositePrimaryKeyType = super.getCompositePrimaryKeyType(); - } - return compositePrimaryKeyType; - } - - @Override - public boolean isClusterKeyColumn() { - - if (isClusterKeyColumn == null) { - isClusterKeyColumn = super.isClusterKeyColumn(); - } - return isClusterKeyColumn; - } - - @Override - public boolean isPrimaryKeyColumn() { - - if (isPrimaryKeyColumn == null) { - isPrimaryKeyColumn = super.isPrimaryKeyColumn(); - } - return isPrimaryKeyColumn; - } - - @Override - public DataType getDataType() { - - if (dataType == null) { - dataType = super.getDataType(); - } - return dataType; - } - - @Override - public Ordering getPrimaryKeyOrdering() { - - if (!orderingCached) { - ordering = super.getPrimaryKeyOrdering(); - orderingCached = true; - } - return ordering; - } - - @Override - public boolean isCompositePrimaryKey() { - - if (isCompositePrimaryKey == null) { - isCompositePrimaryKey = super.isCompositePrimaryKey(); - } - return isCompositePrimaryKey; - } - - @Override - public boolean isIdProperty() { - - if (isIdProperty == null) { - isIdProperty = super.isIdProperty(); - } - return isIdProperty; - } - - @Override - public CqlIdentifier getColumnName() { - - if (columnName == null) { - columnName = super.getColumnName(); - } - return columnName; - } - - @Override - public boolean isIndexed() { - - if (isIndexed == null) { - isIndexed = super.isIndexed(); - } - return isIndexed; - } - - @Override - public boolean isPartitionKeyColumn() { - - if (isPartitionKeyColumn == null) { - isPartitionKeyColumn = super.isPartitionKeyColumn(); - } - return isPartitionKeyColumn; - } - - @Override - public List getColumnNames() { - if (columnNames == null) { - columnNames = super.getColumnNames(); - } - return columnNames; - } -} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentEntity.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentEntity.java index e402f4035..4c18350b9 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentEntity.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentEntity.java @@ -49,4 +49,6 @@ public interface CassandraPersistentEntity extends MutablePersistentEntity owner, CassandraSimpleTypeHolder simpleTypeHolder) { - return new CachingCassandraPersistentProperty(field, descriptor, owner, simpleTypeHolder); + return new BasicCassandraPersistentProperty(field, descriptor, owner, simpleTypeHolder); } @Override protected CassandraPersistentEntity createPersistentEntity(TypeInformation typeInformation) { - CassandraPersistentEntity entity = new CachingCassandraPersistentEntity(typeInformation, this, verifier); + CassandraPersistentEntity entity = new BasicCassandraPersistentEntity(typeInformation, this, verifier); if (context != null) { entity.setApplicationContext(context); diff --git a/spring-data-cassandra/src/main/resources/org/springframework/data/cassandra/config/spring-cassandra-1.0.xsd b/spring-data-cassandra/src/main/resources/org/springframework/data/cassandra/config/spring-cassandra-1.0.xsd index 37c645fd2..9f7282769 100644 --- a/spring-data-cassandra/src/main/resources/org/springframework/data/cassandra/config/spring-cassandra-1.0.xsd +++ b/spring-data-cassandra/src/main/resources/org/springframework/data/cassandra/config/spring-cassandra-1.0.xsd @@ -665,9 +665,27 @@ Whether to force-quote the table name. - - - + + + + + + + + + + + + + + + diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java new file mode 100644 index 000000000..e6c2fc699 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java @@ -0,0 +1,35 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import java.util.UUID; + +import org.springframework.data.cassandra.mapping.PrimaryKey; +import org.springframework.data.cassandra.mapping.Table; + +@Table(forceQuote = true) +public class Explicit { + + @PrimaryKey + ExplicitKey primaryKey; + + String stringValue = UUID.randomUUID().toString(); + + @SuppressWarnings("unused") + private Explicit() { + } + + public Explicit(ExplicitKey primaryKey) { + setPrimaryKey(primaryKey); + } + + public ExplicitKey getPrimaryKey() { + return primaryKey; + } + + public void setPrimaryKey(ExplicitKey primaryKey) { + this.primaryKey = primaryKey; + } + + public String getStringValue() { + return stringValue; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java new file mode 100644 index 000000000..e7392cbfd --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitKey.java @@ -0,0 +1,35 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import java.io.Serializable; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.PrimaryKeyClass; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; + +@PrimaryKeyClass +public class ExplicitKey implements Serializable { + + public static final String EXPLICIT_KEY_ZERO = "FirstKey"; + public static final String EXPLICIT_KEY_ONE = "SecondKey"; + + private static final long serialVersionUID = 4459456944472099332L; + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED, forceQuote = true, name = EXPLICIT_KEY_ZERO) + String keyZero; + + @PrimaryKeyColumn(ordinal = 1, forceQuote = true, name = EXPLICIT_KEY_ONE) + String keyOne; + + public ExplicitKey(String keyZero, String keyOne) { + this.keyZero = keyZero; + this.keyOne = keyOne; + } + + public String getKeyZero() { + return keyZero; + } + + public String getKeyOne() { + return keyOne; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java new file mode 100644 index 000000000..d825070b2 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java @@ -0,0 +1,6 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +public interface ExplicitRepository extends CassandraRepository { +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java new file mode 100644 index 000000000..99c8c3482 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests.java @@ -0,0 +1,107 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.CassandraTemplate; + +public class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests { + + ImplicitRepository i; + // ImplicitPropertiesRepository ip; + ExplicitRepository e; + // ExplicitPropertiesRepository ep; + CassandraTemplate t; + + public void before() { + t.deleteAll(Implicit.class); + } + + public String query(String columnName, String tableName, String keyZeroColumnName, String keyZero, + String keyOneColumnName, String keyOne) { + + return t.queryForObject(String.format("select %s from %s where %s = '%s' and %s = '%s'", columnName, tableName, + keyZeroColumnName, keyZero, keyOneColumnName, keyOne), String.class); + } + + public void testImplicit() { + + ImplicitKey key = new ImplicitKey(UUID.randomUUID().toString(), UUID.randomUUID().toString()); + Implicit entity = new Implicit(key); + + Implicit s = i.save(entity); + assertSame(s, entity); + + Implicit f = i.findOne(key); + assertNotSame(f, entity); + + String stringValue = query("stringvalue", "\"Implicit\"", "\"keyZero\"", f.getPrimaryKey().getKeyZero(), + "\"keyOne\"", f.getPrimaryKey().getKeyOne()); + assertEquals(f.getStringValue(), stringValue); + + i.delete(key); + + assertNull(i.findOne(key)); + } + + public void testExplicit() { + ExplicitKey key = new ExplicitKey(UUID.randomUUID().toString(), UUID.randomUUID().toString()); + Explicit entity = new Explicit(key); + + Explicit s = e.save(entity); + assertSame(s, entity); + + Explicit f = e.findOne(key); + assertNotSame(f, entity); + + String stringValue = query("stringvalue", "\"Explicit\"", String.format("\"%s\"", ExplicitKey.EXPLICIT_KEY_ZERO), f + .getPrimaryKey().getKeyZero(), String.format("\"%s\"", ExplicitKey.EXPLICIT_KEY_ONE), f.getPrimaryKey() + .getKeyOne()); + assertEquals(f.getStringValue(), stringValue); + + e.delete(key); + + assertNull(e.findOne(key)); + } + + // public void testImplicitProperties() { + // ImplicitProperties entity = new ImplicitProperties(); + // String key = entity.getPrimaryKey(); + // + // ImplicitProperties s = ip.save(entity); + // assertSame(s, entity); + // + // ImplicitProperties f = ip.findOne(key); + // assertNotSame(f, entity); + // + // String stringValue = query("\"stringValue\"", "implicitproperties", "\"primaryKey\"", f.getPrimaryKey()); + // assertEquals(f.getStringValue(), stringValue); + // + // ip.delete(key); + // + // assertNull(ip.findOne(key)); + // } + + // public void testExplicitProperties(String stringValueColumnName, String primaryKeyColumnName) { + // ExplicitProperties entity = new ExplicitProperties(); + // String key = entity.getPrimaryKey(); + // + // ExplicitProperties s = ep.save(entity); + // assertSame(s, entity); + // + // ExplicitProperties f = ep.findOne(key); + // assertNotSame(f, entity); + // + // String stringValue = query(String.format("\"%s\"", ExplicitProperties.EXPLICIT_STRING_VALUE), "explicitproperties", + // String.format("\"%s\"", ExplicitProperties.EXPLICIT_PRIMARY_KEY), f.getPrimaryKey()); + // assertEquals(f.getStringValue(), stringValue); + // + // ip.delete(key); + // + // assertNull(ip.findOne(key)); + // } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java new file mode 100644 index 000000000..0f17fb8d6 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator.java @@ -0,0 +1,45 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +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.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +public abstract class ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator extends + AbstractSpringDataEmbeddedCassandraIntegrationTest { + + ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests tests = new ForceQuotedCompositePrimaryKeyRepositoryIntegrationTests(); + + @Autowired + ImplicitRepository i; + + @Autowired + ExplicitRepository e; + + @Autowired + CassandraTemplate t; + + @Before + public void before() { + + tests.i = i; + tests.e = e; + tests.t = t; + + tests.before(); + } + + @Test + public void testImplicit() { + tests.testImplicit(); + } + + @Test + public void testExplicit() { + tests.testExplicit(); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java new file mode 100644 index 000000000..b21c19cd0 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java @@ -0,0 +1,16 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; +import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration +public class ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests extends + ForceQuotedCompositePrimaryKeyRepositoryIntegrationTestsDelegator { + + @Configuration + @EnableCassandraRepositories(basePackageClasses = ImplicitRepository.class) + public static class Config extends IntegrationTestConfig { + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java new file mode 100644 index 000000000..8d035117f --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java @@ -0,0 +1,35 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +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 + ImplicitKey primaryKey; + + String stringValue = UUID.randomUUID().toString(); + + @SuppressWarnings("unused") + private Implicit() { + } + + public Implicit(ImplicitKey primaryKey) { + setPrimaryKey(primaryKey); + } + + public ImplicitKey getPrimaryKey() { + return primaryKey; + } + + public void setPrimaryKey(ImplicitKey primaryKey) { + this.primaryKey = primaryKey; + } + + public String getStringValue() { + return stringValue; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java new file mode 100644 index 000000000..5494a3560 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitKey.java @@ -0,0 +1,32 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import java.io.Serializable; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.PrimaryKeyClass; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; + +@PrimaryKeyClass +public class ImplicitKey implements Serializable { + + private static final long serialVersionUID = 4459456944472099332L; + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED, forceQuote = true) + String keyZero; + + @PrimaryKeyColumn(ordinal = 1, forceQuote = true) + String keyOne; + + public ImplicitKey(String keyZero, String keyOne) { + this.keyZero = keyZero; + this.keyOne = keyOne; + } + + public String getKeyZero() { + return keyZero; + } + + public String getKeyOne() { + return keyOne; + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java new file mode 100644 index 000000000..7bc2d1277 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java @@ -0,0 +1,6 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import org.springframework.data.cassandra.repository.CassandraRepository; + +public interface ImplicitRepository extends CassandraRepository { +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java index 234623135..f40e2818c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTests.java @@ -42,7 +42,7 @@ public class ForceQuotedRepositoryIntegrationTests { assertNull(i.findOne(key)); } - public void testExplicit() { + public void testExplicit(String tableName) { Explicit entity = new Explicit(); String key = entity.getPrimaryKey(); @@ -52,7 +52,7 @@ public class ForceQuotedRepositoryIntegrationTests { Explicit f = e.findOne(key); assertNotSame(f, entity); - String stringValue = query("stringvalue", "\"Xx\"", "primarykey", f.getPrimaryKey()); + String stringValue = query("stringvalue", String.format("\"%s\"", tableName), "primarykey", f.getPrimaryKey()); assertEquals(f.getStringValue(), stringValue); e.delete(key); @@ -88,8 +88,8 @@ public class ForceQuotedRepositoryIntegrationTests { ExplicitProperties f = ep.findOne(key); assertNotSame(f, entity); - String stringValue = query(String.format("\"%s\"", ExplicitProperties.EXPLICIT_STRING_VALUE), "explicitproperties", - String.format("\"%s\"", ExplicitProperties.EXPLICIT_PRIMARY_KEY), f.getPrimaryKey()); + String stringValue = query(String.format("\"%s\"", stringValueColumnName), "explicitproperties", + String.format("\"%s\"", primaryKeyColumnName), f.getPrimaryKey()); assertEquals(f.getStringValue(), stringValue); ip.delete(key); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java index 1c6ed7d6a..4391c6a24 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryIntegrationTestsDelegator.java @@ -46,9 +46,11 @@ public abstract class ForceQuotedRepositoryIntegrationTestsDelegator extends tests.testImplicit(); } - @Test - public void testExplicit() { - tests.testExplicit(); + /** + * Not a @Test -- used by subclasses! + */ + public void testExplicit(String tableName) { + tests.testExplicit(tableName); } @Test diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java index 5222a6c83..4a133c9a1 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java @@ -7,14 +7,18 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe import org.springframework.test.context.ContextConfiguration; @ContextConfiguration -public class ForceQuotedRepositoryJavaConfigIntegrationTests extends - ForceQuotedRepositoryIntegrationTestsDelegator { +public class ForceQuotedRepositoryJavaConfigIntegrationTests extends ForceQuotedRepositoryIntegrationTestsDelegator { @Configuration @EnableCassandraRepositories(basePackageClasses = ForceQuotedRepositoryIntegrationTests.class) public static class Config extends IntegrationTestConfig { } + @Test + public void testExplicit() { + tests.testExplicit(Explicit.TABLE_NAME); + } + @Test public void testExplicitPropertiesWithJavaValues() { tests.testExplicitProperties(ExplicitProperties.EXPLICIT_STRING_VALUE, ExplicitProperties.EXPLICIT_PRIMARY_KEY); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java index 351a59ace..28e988a93 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests.java @@ -6,10 +6,16 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration public class ForceQuotedRepositoryXmlConfigIntegrationTests extends ForceQuotedRepositoryIntegrationTestsDelegator { + // these values must match the values in + // src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml + + @Test + public void testExplicit() { + tests.testExplicit("Zz"); + } + @Test public void testExplicitPropertiesWithXmlValues() { - // these values must match the values in - // src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml tests.testExplicitProperties("XmlStringValue", "XmlPrimaryKey"); } } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java index 58e4426c5..1e00b9513 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java @@ -1,6 +1,7 @@ package org.springframework.data.cassandra.test.integration.forcequote.simple; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId; import static org.springframework.cassandra.core.cql.CqlIdentifier.quotedCqlId; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java index ec13a0bf7..8bd6cfbf9 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CassandraCompositePrimaryKeyIntegrationTests.java @@ -33,7 +33,6 @@ import org.springframework.cassandra.core.cql.CqlIdentifier; import org.springframework.cassandra.core.keyspace.ColumnSpecification; import org.springframework.cassandra.core.keyspace.CreateTableSpecification; import org.springframework.data.cassandra.mapping.BasicCassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CachingCassandraPersistentProperty; import org.springframework.data.cassandra.mapping.CassandraMappingContext; import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; @@ -129,8 +128,7 @@ public class CassandraCompositePrimaryKeyIntegrationTests { public void validateMappingInfo() { Field field = ReflectionUtils.findField(Thing.class, "id"); - CassandraPersistentProperty property = new CachingCassandraPersistentProperty(field, null, thing, - SIMPLE_TYPE_HOLDER); + CassandraPersistentProperty property = new BasicCassandraPersistentProperty(field, null, thing, SIMPLE_TYPE_HOLDER); assertTrue(property.isIdProperty()); assertTrue(property.isCompositePrimaryKey()); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java index 0f98cd63a..83474fadd 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/CompoundPrimaryKeyIntegrationTests.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity; import org.springframework.data.cassandra.mapping.BasicCassandraPersistentProperty; -import org.springframework.data.cassandra.mapping.CachingCassandraPersistentProperty; import org.springframework.data.cassandra.mapping.CassandraPersistentEntity; import org.springframework.data.cassandra.mapping.CassandraPersistentProperty; import org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder; @@ -82,6 +81,6 @@ public class CompoundPrimaryKeyIntegrationTests { } private CassandraPersistentProperty getPropertyFor(Field field) { - return new CachingCassandraPersistentProperty(field, null, entity, new CassandraSimpleTypeHolder()); + return new BasicCassandraPersistentProperty(field, null, entity, new CassandraSimpleTypeHolder()); } } diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml new file mode 100644 index 000000000..78d9a4893 --- /dev/null +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryXmlConfigIntegrationTests-context.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml index 78d9a4893..381c46030 100644 --- a/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml +++ b/spring-data-cassandra/src/test/resources/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryXmlConfigIntegrationTests-context.xml @@ -20,6 +20,9 @@ + + schema-action="RECREATE_DROP_UNUSED">