diff --git a/src/main/java/org/springframework/data/cassandra/cql/builder/ColumnBuilder.java b/src/main/java/org/springframework/data/cassandra/cql/builder/ColumnBuilder.java index 65c25d8d5..b613bb799 100644 --- a/src/main/java/org/springframework/data/cassandra/cql/builder/ColumnBuilder.java +++ b/src/main/java/org/springframework/data/cassandra/cql/builder/ColumnBuilder.java @@ -10,6 +10,8 @@ import org.springframework.data.cassandra.cql.CqlStringUtils; import org.springframework.data.cassandra.mapping.KeyType; import org.springframework.data.cassandra.mapping.Ordering; +import com.datastax.driver.core.DataType; + /** * Builder class to help construct CQL statements that involve column manipulation. Not threadsafe. *

@@ -28,7 +30,7 @@ public class ColumnBuilder { public static final Ordering DFAULT_ORDERING = ASCENDING; private String name; - private String type; + private DataType type; private KeyType keyType; private Ordering ordering; @@ -51,7 +53,7 @@ public class ColumnBuilder { * * @return this */ - public ColumnBuilder type(String type) { + public ColumnBuilder type(DataType type) { this.type = type; return this; } @@ -136,7 +138,7 @@ public class ColumnBuilder { return name; } - public String getType() { + public DataType getType() { return type; } @@ -158,6 +160,7 @@ public class ColumnBuilder { @Override public String toString() { - return toCql(null).append(" /* key=").append(keyType).append(", order=").append(ordering).append(" */").toString(); + return toCql(null).append(" /* keyType=").append(keyType).append(", ordering=").append(ordering).append(" */ ") + .toString(); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/cassandra/cql/builder/CreateTableBuilder.java b/src/main/java/org/springframework/data/cassandra/cql/builder/CreateTableBuilder.java index a89949191..72728aadf 100644 --- a/src/main/java/org/springframework/data/cassandra/cql/builder/CreateTableBuilder.java +++ b/src/main/java/org/springframework/data/cassandra/cql/builder/CreateTableBuilder.java @@ -17,6 +17,8 @@ import org.springframework.data.cassandra.cql.CqlStringUtils; import org.springframework.data.cassandra.mapping.KeyType; import org.springframework.data.cassandra.mapping.Ordering; +import com.datastax.driver.core.DataType; + /** * Builder class to construct CQL for a CREATE TABLE statement. Not threadsafe. * @@ -129,24 +131,24 @@ public class CreateTableBuilder { return this; } - public CreateTableBuilder column(String name, String type) { + public CreateTableBuilder column(String name, DataType type) { return column(name, type, null, null); } - public CreateTableBuilder partitionColumn(String name, String type) { + public CreateTableBuilder partitionKeyColumn(String name, DataType type) { return column(name, type, PARTITION, null); } - public CreateTableBuilder primaryKeyColumn(String name, String type) { + public CreateTableBuilder primaryKeyColumn(String name, DataType type) { return primaryKeyColumn(name, type, ASCENDING); } - public CreateTableBuilder primaryKeyColumn(String name, String type, Ordering order) { + public CreateTableBuilder primaryKeyColumn(String name, DataType type, Ordering order) { return column(name, type, PRIMARY, order); } - protected CreateTableBuilder column(String name, String type, KeyType key, Ordering order) { - columns().add(new ColumnBuilder().name(name).type(type).keyType(key).ordering(order)); + protected CreateTableBuilder column(String name, DataType type, KeyType keyType, Ordering ordering) { + columns().add(new ColumnBuilder().name(name).type(type).keyType(keyType).ordering(ordering)); return this; } @@ -309,10 +311,10 @@ public class CreateTableBuilder { cql.append(", "); } - cql.append("'").append(entry.getKey()).append("'"); // 'name' + cql.append(singleQuote(entry.getKey())); // 'name' cql.append(" : "); Object entryValue = entry.getValue(); - cql.append("'").append(entryValue == null ? "" : entryValue.toString()).append("'"); // 'value' + cql.append(singleQuote(entryValue == null ? "" : entryValue.toString())); // 'value' } cql.append(" }"); diff --git a/src/test/java/org/springframework/data/cassandra/cql/CreateTableBuilderTest.java b/src/test/java/org/springframework/data/cassandra/cql/CreateTableBuilderTest.java index 799e28b51..69a3585e1 100644 --- a/src/test/java/org/springframework/data/cassandra/cql/CreateTableBuilderTest.java +++ b/src/test/java/org/springframework/data/cassandra/cql/CreateTableBuilderTest.java @@ -8,18 +8,20 @@ import java.util.Map; import org.junit.Test; import org.springframework.data.cassandra.cql.builder.CreateTableBuilder; +import com.datastax.driver.core.DataType; + public class CreateTableBuilderTest { @Test public void createTableTest() { String name = "mytable"; - String type0 = "text"; + DataType type0 = DataType.text(); String partition0 = "partitionKey0"; String partition1 = "partitionKey1"; String primary0 = "primary0"; - String type1 = "text"; + DataType type1 = DataType.text(); String column1 = "column1"; - String type2 = "text"; + DataType type2 = DataType.bigint(); String column2 = "column2"; Object value2 = "this is a comment"; String option2 = "comment"; @@ -29,8 +31,8 @@ public class CreateTableBuilderTest { value4.put("class", "LeveledCompactionStrategy"); String option4 = "compaction"; - CreateTableBuilder builder = createTable().ifNotExists().name(name).partitionColumn(partition0, type0) - .partitionColumn(partition1, type0).primaryKeyColumn(primary0, type0).column(column1, type1) + CreateTableBuilder builder = createTable().ifNotExists().name(name).partitionKeyColumn(partition0, type0) + .partitionKeyColumn(partition1, type0).primaryKeyColumn(primary0, type0).column(column1, type1) .column(column2, type2).withQuoted(option2, value2).withUnquoted(option3, value3).with(option4, value4) .withCompactStorage();