DATACASS-93 - added composite pk tests, fixed other tests, removed CachingCassandraPersistent{Entity|Property} as caching is now in BasicCassandraPersistent{Entity|Property}
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
|
||||
protected StandardEvaluationContext spelContext;
|
||||
protected CassandraPersistentEntityMetadataVerifier verifier = DEFAULT_VERIFIER;
|
||||
protected ApplicationContext context;
|
||||
protected Boolean forceQuote;
|
||||
|
||||
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
this(typeInformation, null);
|
||||
@@ -136,6 +137,18 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForceQuote(boolean forceQuote) {
|
||||
|
||||
if (this.forceQuote != null && this.forceQuote == forceQuote) {
|
||||
return;
|
||||
} else {
|
||||
this.forceQuote = forceQuote;
|
||||
}
|
||||
|
||||
setTableName(cqlId(tableName.getUnquoted(), forceQuote));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CassandraMappingContext getMappingContext() {
|
||||
return mappingContext;
|
||||
|
||||
@@ -276,6 +276,11 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
return columnNames;
|
||||
}
|
||||
|
||||
return this.columnNames = Collections.unmodifiableList(determineColumnNames());
|
||||
}
|
||||
|
||||
protected List<CqlIdentifier> determineColumnNames() {
|
||||
|
||||
List<CqlIdentifier> columnNames = new ArrayList<CqlIdentifier>();
|
||||
|
||||
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<CqlIdentifier> 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
|
||||
|
||||
@@ -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<T> extends BasicCassandraPersistentEntity<T> {
|
||||
|
||||
protected CqlIdentifier tableName;
|
||||
protected String name;
|
||||
protected Boolean isCompositePrimaryKey;
|
||||
protected List<CassandraPersistentProperty> compositePrimaryKeyProperties;
|
||||
protected Map<String, CassandraPersistentProperty> properties = new HashMap<String, CassandraPersistentProperty>();
|
||||
|
||||
public CachingCassandraPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
super(typeInformation);
|
||||
}
|
||||
|
||||
public CachingCassandraPersistentEntity(TypeInformation<T> typeInformation, CassandraMappingContext mappingContext) {
|
||||
super(typeInformation, mappingContext);
|
||||
}
|
||||
|
||||
public CachingCassandraPersistentEntity(TypeInformation<T> 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<CassandraPersistentProperty> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<CqlIdentifier> 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<CqlIdentifier> getColumnNames() {
|
||||
if (columnNames == null) {
|
||||
columnNames = super.getColumnNames();
|
||||
}
|
||||
return columnNames;
|
||||
}
|
||||
}
|
||||
@@ -49,4 +49,6 @@ public interface CassandraPersistentEntity<T> extends MutablePersistentEntity<T,
|
||||
CassandraMappingContext getMappingContext();
|
||||
|
||||
ApplicationContext getApplicationContext();
|
||||
|
||||
void setForceQuote(boolean forceQuote);
|
||||
}
|
||||
|
||||
@@ -114,13 +114,13 @@ public class DefaultCassandraMappingContext extends
|
||||
public CassandraPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
|
||||
CassandraPersistentEntity<?> owner, CassandraSimpleTypeHolder simpleTypeHolder) {
|
||||
|
||||
return new CachingCassandraPersistentProperty(field, descriptor, owner, simpleTypeHolder);
|
||||
return new BasicCassandraPersistentProperty(field, descriptor, owner, simpleTypeHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> CassandraPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
|
||||
|
||||
CassandraPersistentEntity<T> entity = new CachingCassandraPersistentEntity<T>(typeInformation, this, verifier);
|
||||
CassandraPersistentEntity<T> entity = new BasicCassandraPersistentEntity<T>(typeInformation, this, verifier);
|
||||
|
||||
if (context != null) {
|
||||
entity.setApplicationContext(context);
|
||||
|
||||
@@ -665,9 +665,27 @@ Whether to force-quote the table name.
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="propertyType">
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="column-name" use="optional" type="xsd:string" />
|
||||
<xsd:attribute name="force-quote" use="optional" type="xsd:string" />
|
||||
<xsd:attribute name="name" use="required" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the property. Required.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="column-name" use="optional" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The column-name that the property should be mapped to.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="force-quote" use="optional" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Whether the column name should be force-quoted.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:simpleType name="cassandraTemplateRef" final="union">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Explicit, ExplicitKey> {
|
||||
}
|
||||
@@ -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));
|
||||
// }
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Implicit, ImplicitKey> {
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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:entity
|
||||
class="org.springframework.data.cassandra.test.integration.forcequote.config.ImplicitProperties">
|
||||
<cass:property name="primaryKey" force-quote="true" />
|
||||
<cass:property name="stringValue" force-quote="true" />
|
||||
</cass:entity>
|
||||
<cass:entity
|
||||
class="org.springframework.data.cassandra.test.integration.forcequote.config.ExplicitProperties">
|
||||
<!-- these values must match those in
|
||||
org.springframework.data.cassandra.test.integration.forcequote.config.ForceQuotedRepositoryXmlConfigIntegrationTests
|
||||
testExplicitPropertiesWithXmlValues() -->
|
||||
<cass:property name="primaryKey" force-quote="true" column-name="XmlPrimaryKey"/>
|
||||
<cass:property name="stringValue" force-quote="true" column-name="XmlStringValue"/>
|
||||
</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>
|
||||
@@ -20,6 +20,9 @@
|
||||
</cass:entity>
|
||||
<cass:entity
|
||||
class="org.springframework.data.cassandra.test.integration.forcequote.config.Explicit">
|
||||
<!-- this value must match those in
|
||||
org.springframework.data.cassandra.test.integration.forcequote.config.ForceQuotedRepositoryXmlConfigIntegrationTests
|
||||
testExplicit() -->
|
||||
<cass:table force-quote="true" name="Zz" />
|
||||
</cass:entity>
|
||||
<cass:entity
|
||||
@@ -44,7 +47,7 @@
|
||||
</cass:cluster>
|
||||
|
||||
<cass:session keyspace-name="ForceQuoteRepositoryXmlConfigIntegrationTests"
|
||||
schema-action="RECREATE">
|
||||
schema-action="RECREATE_DROP_UNUSED">
|
||||
</cass:session>
|
||||
|
||||
<cass:repositories
|
||||
|
||||
Reference in New Issue
Block a user