Index: spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java (revision ) +++ spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/entity/CorrelationEntity.java (revision ) @@ -0,0 +1,184 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey.entity; + +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.data.cassandra.mapping.*; + +import java.io.Serializable; +import java.util.Date; +import java.util.Map; + +/** + * User: Barak Cohen + * Date: 7/9/2014 + */ +@Table(value = "identity_correlations") +public class CorrelationEntity { + + @PrimaryKeyClass + public static class IdentityEntity implements Serializable{ + @PrimaryKeyColumn(name="type", ordinal = 0, type= PrimaryKeyType.PARTITIONED) + private String type; + + @PrimaryKeyColumn(name="value", ordinal = 1, type= PrimaryKeyType.PARTITIONED) + private String value; + + @PrimaryKeyColumn(name="correlated_type", forceQuote = true, ordinal = 2, type= PrimaryKeyType.CLUSTERED) + private String correlatedType; + + @PrimaryKeyColumn(name="ts", ordinal = 3, type= PrimaryKeyType.CLUSTERED) + private Date ts; + + @PrimaryKeyColumn(name="correlated_value", forceQuote = true, ordinal = 4, type= PrimaryKeyType.CLUSTERED) + private String correlatedValue; + + public IdentityEntity(){} + + public IdentityEntity(String type, String value) { + this.type = type; + this.value = value; + } + + public IdentityEntity(String type, String value, String correlatedType) { + this.type = type; + this.value = value; + this.correlatedType = correlatedType; + } + + public IdentityEntity(String type, String value, String correlatedType, Date ts) { + this.type = type; + this.value = value; + this.correlatedType = correlatedType; + this.ts = ts; + } + + public IdentityEntity(String type, String value, String correlatedType, Date ts, String correlatedValue) { + this.type = type; + this.value = value; + this.correlatedType = correlatedType; + this.ts = ts; + this.correlatedValue = correlatedValue; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getCorrelatedType() { + return correlatedType; + } + + public void setCorrelatedType(String correlatedType) { + this.correlatedType = correlatedType; + } + + public Date getTs() { + return ts; + } + + public void setTs(Date ts) { + this.ts = ts; + } + + public String getCorrelatedValue() { + return correlatedValue; + } + + public void setCorrelatedValue(String correlatedValue) { + this.correlatedValue = correlatedValue; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof IdentityEntity)) return false; + + IdentityEntity that = (IdentityEntity) o; + + if (correlatedType != null ? !correlatedType.equals(that.correlatedType) : that.correlatedType != null) + return false; + if (correlatedValue != null ? !correlatedValue.equals(that.correlatedValue) : that.correlatedValue != null) + return false; + if (ts != null ? !ts.equals(that.ts) : that.ts != null) return false; + if (!type.equals(that.type)) return false; + if (!value.equals(that.value)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = type.hashCode(); + result = 31 * result + value.hashCode(); + result = 31 * result + (correlatedType != null ? correlatedType.hashCode() : 0); + result = 31 * result + (ts != null ? ts.hashCode() : 0); + result = 31 * result + (correlatedValue != null ? correlatedValue.hashCode() : 0); + return result; + } + } + + @PrimaryKey(forceQuote = true) + private IdentityEntity identityEntity; + + @Column(value = "extra") + private Map extra; + + public CorrelationEntity(){} + + public CorrelationEntity(IdentityEntity identityEntity, Map extra) { + this.identityEntity = identityEntity; + this.extra = extra; + } + + public CorrelationEntity(String type, String value, String correlatedType, Date ts, String correlatedValue, Map extra) { + this.identityEntity = new IdentityEntity(type, value, correlatedType, ts, correlatedValue); + this.extra = extra; + } + + public IdentityEntity getIdentityEntity() { + return identityEntity; + } + + public void setIdentityEntity(IdentityEntity identityEntity) { + this.identityEntity = identityEntity; + } + + public Map getExtra() { + return extra; + } + + public void setExtra(Map extra) { + this.extra = extra; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof CorrelationEntity)) return false; + + CorrelationEntity that = (CorrelationEntity) o; + + if (extra != null ? !extra.equals(that.extra) : that.extra != null) return false; + if (!identityEntity.equals(that.identityEntity)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = identityEntity.hashCode(); + result = 31 * result + (extra != null ? extra.hashCode() : 0); + return result; + } +} Index: spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudTest.java (revision ) +++ spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/CompositeKeyCrudTest.java (revision ) @@ -0,0 +1,82 @@ +package org.springframework.data.cassandra.test.integration.forcequote.compositeprimarykey; + +import com.datastax.driver.core.ConsistencyLevel; +import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.querybuilder.Select; +import junit.framework.Assert; +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.QueryOptions; +import org.springframework.cassandra.core.RetryPolicy; +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.forcequote.compositeprimarykey.entity.CorrelationEntity; +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; + +import java.util.*; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class CompositeKeyCrudTest extends + AbstractSpringDataEmbeddedCassandraIntegrationTest { + + @Configuration + @EnableCassandraRepositories(basePackageClasses = ImplicitRepository.class) + public static class Config extends IntegrationTestConfig { + } + + @Autowired + CassandraTemplate t; + + CorrelationEntity c1, c2; + + @Before + public void setUp() throws Throwable { + + Map map1 = new HashMap(2); + map1.put("v", "1"); + map1.put("labels", "1,2,3"); + Map map2 = new HashMap(2); + map2.put("v", "1"); + map2.put("labels", "4,5,6"); + + c1 = new CorrelationEntity("a", "b", "c", new Date(1), "d", map1); + c2 = new CorrelationEntity("a", "b", "c", new Date(2), "e", map2); + } + + @Test + public void test() { + log.error("\n\n\n\n\n!!!!!!!!!!!!!!!!!!!! Running Barak Test !!!!!!!!!!!!!"); + t.insert(c1); + t.insert(c2); + + Select select = QueryBuilder.select().from("identity_correlations"); + select.where(QueryBuilder.eq("type", "a")).and(QueryBuilder.eq("value", "b")); + select.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); + select.setConsistencyLevel(ConsistencyLevel.ONE); + List correlationEntities = t.select(select, CorrelationEntity.class); + + assertEquals("inserted 2 correlations but found only " + correlationEntities.size(), 2, correlationEntities.size()); + + QueryOptions qo = new QueryOptions(); + qo.setConsistencyLevel(org.springframework.cassandra.core.ConsistencyLevel.ONE); + ArrayList entities = new ArrayList(); + entities.add(c1); + entities.add(c2); + t.delete(entities, qo); + + correlationEntities = t.select(select, CorrelationEntity.class); + + assertEquals("deleted the 2 correlations and so no correlations should be left but found" + correlationEntities.size(), 0, correlationEntities.size()); + } + +}