diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGenerator.java b/spring-cassandra/src/main/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGenerator.java
index 9b15cdd5f..ad8404d2f 100644
--- a/spring-cassandra/src/main/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGenerator.java
+++ b/spring-cassandra/src/main/java/org/springframework/cassandra/core/cql/generator/AlterTableCqlGenerator.java
@@ -25,6 +25,7 @@ import org.springframework.cassandra.core.keyspace.AlterTableSpecification;
import org.springframework.cassandra.core.keyspace.ColumnChangeSpecification;
import org.springframework.cassandra.core.keyspace.DropColumnSpecification;
import org.springframework.cassandra.core.keyspace.Option;
+import org.springframework.cassandra.core.keyspace.TableOption;
/**
* CQL generator for generating ALTER TABLE statements.
@@ -94,6 +95,16 @@ public class AlterTableCqlGenerator extends TableOptionsCqlGenerator changes = new ArrayList();
- /**
+ /*
* Adds a DROP to the list of column changes.
+ *
+ * DW Removed as this only works in C* 2.0
*/
- public AlterTableSpecification drop(String column) {
- changes.add(new DropColumnSpecification(column));
- return this;
- }
+ // public AlterTableSpecification drop(String column) {
+ // changes.add(new DropColumnSpecification(column));
+ // return this;
+ // }
/**
* Adds an ADD to the list of column changes.
diff --git a/spring-cassandra/src/main/java/org/springframework/cassandra/core/keyspace/DropTableSpecification.java b/spring-cassandra/src/main/java/org/springframework/cassandra/core/keyspace/DropTableSpecification.java
index f9f7afd52..be0df1982 100644
--- a/spring-cassandra/src/main/java/org/springframework/cassandra/core/keyspace/DropTableSpecification.java
+++ b/spring-cassandra/src/main/java/org/springframework/cassandra/core/keyspace/DropTableSpecification.java
@@ -22,20 +22,22 @@ package org.springframework.cassandra.core.keyspace;
*/
public class DropTableSpecification extends TableNameSpecification {
- private boolean ifExists;
+ // private boolean ifExists;
- public DropTableSpecification ifExists() {
- return ifExists(true);
- }
+ // Added in Cassandra 2.0.
- public DropTableSpecification ifExists(boolean ifExists) {
- this.ifExists = ifExists;
- return this;
- }
-
- public boolean getIfExists() {
- return ifExists;
- }
+ // public DropTableSpecification ifExists() {
+ // return ifExists(true);
+ // }
+ //
+ // public DropTableSpecification ifExists(boolean ifExists) {
+ // this.ifExists = ifExists;
+ // return this;
+ // }
+ //
+ // public boolean getIfExists() {
+ // return ifExists;
+ // }
/**
* Entry point into the {@link DropTableSpecification}'s fluent API to drop a table. Convenient if imported
diff --git a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java
index 89d682537..70b8b8adc 100644
--- a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java
+++ b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java
@@ -16,6 +16,7 @@
package org.springframework.cassandra.test.integration.core.cql.generator;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.util.List;
import java.util.Map;
@@ -24,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cassandra.core.cql.CqlStringUtils;
import org.springframework.cassandra.core.keyspace.ColumnSpecification;
+import org.springframework.cassandra.core.keyspace.DropTableSpecification;
import org.springframework.cassandra.core.keyspace.TableDescriptor;
import org.springframework.cassandra.core.keyspace.TableOption;
@@ -49,6 +51,13 @@ public class CqlTableSpecificationAssertions {
assertOptions(expected.getOptions(), tmd.getOptions());
}
+ public static void assertNoTable(DropTableSpecification expected, String keyspace, Session session) {
+ TableMetadata tmd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase())
+ .getTable(expected.getName());
+
+ assertNull(tmd);
+ }
+
public static void assertPartitionKeyColumns(TableDescriptor expected, TableMetadata actual) {
assertColumns(expected.getPartitionKeyColumns(), actual.getPartitionKey());
}
diff --git a/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTest.java b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTest.java
new file mode 100644
index 000000000..60e55c9a8
--- /dev/null
+++ b/spring-cassandra/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/TableLifecycleIntegrationTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2011-2013 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.cassandra.test.integration.core.cql.generator;
+
+import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertNoTable;
+import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertTable;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator;
+import org.springframework.cassandra.core.keyspace.DropTableSpecification;
+import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
+import org.springframework.cassandra.test.unit.core.cql.generator.AlterTableCqlGeneratorTests;
+import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests;
+import org.springframework.cassandra.test.unit.core.cql.generator.DropTableCqlGeneratorTests;
+
+/**
+ * Test CREATE TABLE / ALTER TABLE / DROP TABLE
+ *
+ * @author David Webb
+ */
+public class TableLifecycleIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest {
+
+ private final static Logger log = LoggerFactory.getLogger(TableLifecycleIntegrationTest.class);
+
+ CreateTableCqlGeneratorTests.MultipleOptionsTest createTableTest = new CreateTableCqlGeneratorTests.MultipleOptionsTest();
+
+ @Test
+ public void testDrop() {
+
+ createTableTest.prepare();
+
+ log.info(createTableTest.cql);
+
+ session.execute(createTableTest.cql);
+
+ assertTable(createTableTest.specification, keyspace, session);
+
+ DropTableTest dropTest = new DropTableTest();
+ dropTest.prepare();
+
+ log.info(dropTest.cql);
+
+ session.execute(dropTest.cql);
+
+ assertNoTable(dropTest.specification, keyspace, session);
+ }
+
+ @Test
+ public void testAlter() {
+
+ createTableTest.prepare();
+
+ log.info(createTableTest.cql);
+
+ session.execute(createTableTest.cql);
+
+ assertTable(createTableTest.specification, keyspace, session);
+
+ AlterTableCqlGeneratorTests.MultipleOptionsTest alterTest = new AlterTableCqlGeneratorTests.MultipleOptionsTest();
+ alterTest.prepare();
+
+ log.info(alterTest.cql);
+
+ session.execute(alterTest.cql);
+
+ // assertTable(alterTest.specification, keyspace, session);
+
+ }
+
+ public class DropTableTest extends DropTableCqlGeneratorTests.DropTableTest {
+
+ /* (non-Javadoc)
+ * @see org.springframework.cassandra.test.unit.core.cql.generator.TableOperationCqlGeneratorTest#specification()
+ */
+ @Override
+ public DropTableSpecification specification() {
+ return DropTableSpecification.dropTable().name(createTableTest.specification.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.cassandra.test.unit.core.cql.generator.TableOperationCqlGeneratorTest#generator()
+ */
+ @Override
+ public DropTableCqlGenerator generator() {
+ return new DropTableCqlGenerator(specification);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/spring-cassandra/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java b/spring-cassandra/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java
index da0167667..89a6d5ec4 100644
--- a/spring-cassandra/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java
+++ b/spring-cassandra/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java
@@ -1,15 +1,27 @@
package org.springframework.cassandra.test.unit.core.cql.generator;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.cassandra.core.cql.generator.AlterTableCqlGenerator;
import org.springframework.cassandra.core.keyspace.AlterTableSpecification;
+import org.springframework.cassandra.core.keyspace.Option;
+import org.springframework.cassandra.core.keyspace.TableOption;
+import org.springframework.cassandra.core.keyspace.TableOption.CachingOption;
+import org.springframework.cassandra.core.keyspace.TableOption.CompactionOption;
+import org.springframework.cassandra.core.keyspace.TableOption.CompressionOption;
import com.datastax.driver.core.DataType;
public class AlterTableCqlGeneratorTests {
+ private final static Logger log = LoggerFactory.getLogger(AlterTableCqlGeneratorTests.class);
+
/**
* Asserts that the preamble is first & correctly formatted in the given CQL string.
*/
@@ -45,7 +57,7 @@ public class AlterTableCqlGeneratorTests {
public String dropped = "dropped";
public AlterTableSpecification specification() {
- return AlterTableSpecification.alterTable().name(name).alter(altered, alteredType).add(added, addedType).drop(dropped);
+ return AlterTableSpecification.alterTable().name(name).alter(altered, alteredType).add(added, addedType);
}
public AlterTableCqlGenerator generator() {
@@ -61,4 +73,80 @@ public class AlterTableCqlGeneratorTests {
String.format("ALTER %s TYPE %s, ADD %s %s, DROP %s", altered, alteredType, added, addedType, dropped), cql);
}
}
+
+ /**
+ * Fully test all available create table options
+ *
+ * @author David Webb
+ *
+ */
+ public static class MultipleOptionsTest extends AlterTableTest {
+
+ public String name = "timeseries_table";
+ public DataType partitionKeyType0 = DataType.timeuuid();
+ public String partitionKey0 = "tid";
+ public DataType partitionKeyType1 = DataType.timestamp();
+ public String partitionKey1 = "create_timestamp";
+ public DataType columnType1 = DataType.text();
+ public String column1 = "data_point";
+ public Double readRepairChance = 0.6;
+ public Double dcLocalReadRepairChance = 0.8;
+ public Double bloomFilterFpChance = 0.002;
+ public Boolean replcateOnWrite = Boolean.FALSE;
+ public Long gcGraceSeconds = 1200l;
+ public String comment = "This is My Table";
+ public Map