more CQL generation refactoring
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.escapeSingle;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
@@ -11,14 +11,14 @@ import org.springframework.cassandra.core.keyspace.Option;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class that contains behavior common to table operations.
|
||||
* Base class that contains behavior common to CQL generation for table operations.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param T The subtype of AbstractTableSpecification for which this is a CQL generator.
|
||||
* @param T The subtype of this class for which this is a CQL generator.
|
||||
*/
|
||||
public abstract class AbstractTableOperationCqlGenerator<T extends AbstractTableSpecification<T>> {
|
||||
|
||||
protected abstract StringBuilder toCql(StringBuilder cql);
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
|
||||
private AbstractTableSpecification<T> specification;
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.AddColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating an <code>ADD</code> clause of an <code>ALTER TABLE</code> statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class AddColumnCqlGenerator extends ColumnChangeCqlGenerator<AddColumnSpecification> {
|
||||
|
||||
public AddColumnCqlGenerator(AddColumnSpecification specification) {
|
||||
super(specification);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
return noNull(cql).append("ADD ").append(spec().getNameAsIdentifier()).append(" TYPE ")
|
||||
.append(spec().getType().getName());
|
||||
@@ -1,9 +1,14 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.AlterColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating an <code>ALTER</code> column clause of an <code>ALTER TABLE</code> statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class AlterColumnCqlGenerator extends ColumnChangeCqlGenerator<AlterColumnSpecification> {
|
||||
|
||||
public AlterColumnCqlGenerator(AlterColumnSpecification specification) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
@@ -11,13 +11,17 @@ import org.springframework.cassandra.core.keyspace.ColumnChangeSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropColumnSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
/**
|
||||
* CQL generator for generating <code>ALTER TABLE</code> statements.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class AlterTableCqlGenerator extends AbstractTableOperationCqlGenerator<AlterTableSpecification> {
|
||||
|
||||
public AlterTableCqlGenerator(AlterTableSpecification specification) {
|
||||
super(specification);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
cql = noNull(cql);
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.ColumnChangeSpecification;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class for column change CQL generators.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param <T> The corresponding {@link ColumnChangeSpecification} type for this CQL generator.
|
||||
*/
|
||||
public abstract class ColumnChangeCqlGenerator<T extends ColumnChangeSpecification> {
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.data.cassandra.mapping.KeyType.PARTITION;
|
||||
@@ -13,7 +13,7 @@ import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
/**
|
||||
* Builder class to construct CQL for a <code>CREATE TABLE</code> statement. Not threadsafe.
|
||||
* CQL generator for generating a <code>CREATE TABLE</code> statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
@@ -1,9 +1,14 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.DropColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>DROP</code> column clause of an <code>ALTER TABLE</code> statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class DropColumnCqlGenerator extends ColumnChangeCqlGenerator<DropColumnSpecification> {
|
||||
|
||||
public DropColumnCqlGenerator(DropColumnSpecification specification) {
|
||||
@@ -1,10 +1,15 @@
|
||||
package org.springframework.cassandra.core.cql.builder;
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>DROP TABLE</code> statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class DropTableCqlGenerator {
|
||||
|
||||
protected DropTableSpecification specification;
|
||||
@@ -1,46 +0,0 @@
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
public class CqlBuilder {
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CqlBuilder}'s fluent API to create a table. Convenient if imported statically.
|
||||
*/
|
||||
public static CreateTableSpecification createTable() {
|
||||
return new CreateTableSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CqlBuilder}'s fluent API to create a table. Convenient if imported statically.
|
||||
*/
|
||||
public static CreateTableSpecification createTable(String name) {
|
||||
return new CreateTableSpecification().name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CqlBuilder}'s fluent API to alter a table. Convenient if imported statically.
|
||||
*/
|
||||
public static AlterTableSpecification alterTable() {
|
||||
return new AlterTableSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CqlBuilder}'s fluent API to alter a table. Convenient if imported statically.
|
||||
*/
|
||||
public static AlterTableSpecification alterTable(String name) {
|
||||
return new AlterTableSpecification().name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CqlBuilder}'s fluent API to drop a table. Convenient if imported statically.
|
||||
*/
|
||||
public static DropTableSpecification dropTable() {
|
||||
return new DropTableSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CqlBuilder}'s fluent API to drop a table. Convenient if imported statically.
|
||||
*/
|
||||
public static DropTableSpecification dropTable(String name) {
|
||||
return new DropTableSpecification().name(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
/**
|
||||
* Class that offers static methods as entry points into the fluent API for building create, drop and alter table
|
||||
* specifications. These methods are most convenient when imported statically.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class TableOperations {
|
||||
|
||||
/**
|
||||
* Entry point into the {@link CreateTableSpecification}'s fluent API to create a table. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static CreateTableSpecification createTable() {
|
||||
return new CreateTableSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropTableSpecification}'s fluent API to drop a table. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static DropTableSpecification dropTable() {
|
||||
return new DropTableSpecification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point into the {@link AlterTableSpecification}'s fluent API to alter a table. Convenient if imported
|
||||
* statically.
|
||||
*/
|
||||
public static AlterTableSpecification alterTable() {
|
||||
return new AlterTableSpecification();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.springframework.cassandra.cql.builder;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CqlBuilder.alterTable;
|
||||
import static org.springframework.cassandra.core.keyspace.TableOperations.alterTable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.builder.AlterTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.cql.generator.AlterTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.AlterTableSpecification;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.springframework.cassandra.cql.builder;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.springframework.cassandra.core.keyspace.CqlBuilder.createTable;
|
||||
import static org.springframework.cassandra.core.keyspace.TableOperations.createTable;
|
||||
import static org.springframework.cassandra.core.keyspace.MapBuilder.map;
|
||||
import static org.springframework.cassandra.core.keyspace.TableOption.BLOOM_FILTER_FP_CHANCE;
|
||||
import static org.springframework.cassandra.core.keyspace.TableOption.CACHING;
|
||||
@@ -10,7 +10,7 @@ import static org.springframework.cassandra.core.keyspace.TableOption.COMPACTION
|
||||
import static org.springframework.cassandra.core.keyspace.TableOption.CompactionOption.TOMBSTONE_THRESHOLD;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.builder.CreateTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.cql.generator.CreateTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CachingOption;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.springframework.cassandra.cql.builder;
|
||||
|
||||
import static org.springframework.cassandra.core.keyspace.CqlBuilder.dropTable;
|
||||
import static org.springframework.cassandra.core.keyspace.TableOperations.dropTable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.builder.DropTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
|
||||
public class DropTableBuilderTest {
|
||||
|
||||
Reference in New Issue
Block a user