DATACASS-656 - Migrate CQL generators to new CqlIdentifier.

Original pull request: #167.
This commit is contained in:
Mark Paluch
2019-12-02 12:37:40 +01:00
parent 3eb2bb10f0
commit 24f73b89c7
28 changed files with 78 additions and 75 deletions

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.driver.core.DataType;
@@ -40,7 +40,7 @@ public class AddColumnSpecification extends ColumnTypeChangeSpecification {
* @return a new {@link AddColumnSpecification}.
*/
public static AddColumnSpecification addColumn(String name, DataType type) {
return addColumn(CqlIdentifier.of(name), type);
return addColumn(CqlIdentifier.fromCql(name), type);
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.driver.core.DataType;
@@ -41,7 +41,7 @@ public class AlterColumnSpecification extends ColumnTypeChangeSpecification {
* @return a new {@link AlterColumnSpecification}.
*/
public static AlterColumnSpecification alterColumn(String name, DataType type) {
return alterColumn(CqlIdentifier.of(name), type);
return alterColumn(CqlIdentifier.fromCql(name), type);
}
/**

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import lombok.EqualsAndHashCode;
import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
@@ -27,7 +28,7 @@ import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
@EqualsAndHashCode(callSuper = true)
public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<AlterKeyspaceSpecification> {
private AlterKeyspaceSpecification(KeyspaceIdentifier name) {
private AlterKeyspaceSpecification(CqlIdentifier name) {
super(name);
}
@@ -39,7 +40,7 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<Alt
* @return a new {@link AlterKeyspaceSpecification}.
*/
public static AlterKeyspaceSpecification alterKeyspace(String name) {
return alterKeyspace(KeyspaceIdentifier.of(name));
return alterKeyspace(CqlIdentifier.fromCql(name));
}
/**
@@ -49,7 +50,7 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<Alt
* @param name must not be {@literal null} or empty.
* @return a new {@link AlterKeyspaceSpecification}.
*/
public static AlterKeyspaceSpecification alterKeyspace(KeyspaceIdentifier name) {
public static AlterKeyspaceSpecification alterKeyspace(CqlIdentifier name) {
return new AlterKeyspaceSpecification(name);
}
}

View File

@@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.driver.core.DataType;
@@ -56,7 +56,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
* @return a new {@link AlterTableSpecification}.
*/
public static AlterTableSpecification alterTable(String tableName) {
return alterTable(CqlIdentifier.of(tableName));
return alterTable(CqlIdentifier.fromCql(tableName));
}
/**
@@ -78,7 +78,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification add(String column, DataType type) {
return add(CqlIdentifier.of(column), type);
return add(CqlIdentifier.fromCql(column), type);
}
/**
@@ -100,7 +100,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification drop(String column) {
return drop(CqlIdentifier.of(column));
return drop(CqlIdentifier.fromCql(column));
}
/*
@@ -122,7 +122,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification rename(String from, String to) {
return rename(CqlIdentifier.of(from), CqlIdentifier.of(to));
return rename(CqlIdentifier.fromCql(from), CqlIdentifier.fromCql(to));
}
/**
@@ -145,7 +145,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
* @return {@literal this} {@link AlterTableSpecification}.
*/
public AlterTableSpecification alter(String column, DataType type) {
return alter(CqlIdentifier.of(column), type);
return alter(CqlIdentifier.fromCql(column), type);
}
/**

View File

@@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.driver.core.DataType;
@@ -47,7 +47,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
* @return a new {@link AlterUserTypeSpecification}.
*/
public static AlterUserTypeSpecification alterType(String typeName) {
return alterType(CqlIdentifier.of(typeName));
return alterType(CqlIdentifier.fromCql(typeName));
}
/**
@@ -69,7 +69,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification add(String field, DataType type) {
return add(CqlIdentifier.of(field), type);
return add(CqlIdentifier.fromCql(field), type);
}
/**
@@ -91,7 +91,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification alter(String field, DataType type) {
return alter(CqlIdentifier.of(field), type);
return alter(CqlIdentifier.fromCql(field), type);
}
/**
@@ -113,7 +113,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
* @return {@code this} {@link AlterUserTypeSpecification}.
*/
public AlterUserTypeSpecification rename(String from, String to) {
return rename(CqlIdentifier.of(from), CqlIdentifier.of(to));
return rename(CqlIdentifier.fromCql(from), CqlIdentifier.fromCql(to));
}
/**

View File

@@ -15,7 +15,8 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.util.Assert;
/**

View File

@@ -15,17 +15,16 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
import static org.springframework.data.cassandra.core.cql.Ordering.*;
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.datastax.driver.core.DataType;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Object to configure a CQL column specification.
@@ -65,7 +64,7 @@ public class ColumnSpecification {
* @return a new {@link ColumnSpecification} for {@code name}.
*/
public static ColumnSpecification name(String name) {
return name(of(name));
return name(CqlIdentifier.fromCql(name));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.util.Assert;
import com.datastax.driver.core.DataType;

View File

@@ -15,14 +15,14 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
import static com.datastax.oss.driver.api.core.CqlIdentifier.*;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -73,7 +73,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
* @return a new {@link CreateIndexSpecification}.
*/
public static CreateIndexSpecification createIndex(String indexName) {
return createIndex(CqlIdentifier.of(indexName));
return createIndex(CqlIdentifier.fromCql(indexName));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.lang.Nullable;
/**
@@ -40,7 +40,7 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
* @return a new {@link CreateTableSpecification}.
*/
public static CreateTableSpecification createTable(String tableName) {
return new CreateTableSpecification(CqlIdentifier.of(tableName));
return new CreateTableSpecification(CqlIdentifier.fromCql(tableName));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Object to configure a {@code CREATE TYPE} specification.
@@ -41,7 +41,7 @@ public class CreateUserTypeSpecification extends UserTypeSpecification<CreateUse
* @return a new {@link CreateUserTypeSpecification}.
*/
public static CreateUserTypeSpecification createType(String name) {
return new CreateUserTypeSpecification(CqlIdentifier.of(name));
return new CreateUserTypeSpecification(CqlIdentifier.fromCql(name));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Value object representing a specification to drop a column.
@@ -35,7 +35,7 @@ public class DropColumnSpecification extends ColumnChangeSpecification {
* @param name must not be {@literal null} or empty.
*/
public static DropColumnSpecification dropColumn(String name) {
return dropColumn(CqlIdentifier.of(name));
return dropColumn(CqlIdentifier.fromCql(name));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Value object representing a {@code DROP INDEX} specification.
@@ -37,7 +37,7 @@ public class DropIndexSpecification extends IndexNameSpecification<DropIndexSpec
* @return a new {@link DropIndexSpecification}.
*/
public static DropIndexSpecification dropIndex(String indexName) {
return dropIndex(CqlIdentifier.of(indexName));
return dropIndex(CqlIdentifier.fromCql(indexName));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Object to configure a {@code DROP TABLE} specification.
@@ -39,7 +39,7 @@ public class DropTableSpecification extends TableNameSpecification {
* @return a new {@link DropTableSpecification}.
*/
public static DropTableSpecification dropTable(String tableName) {
return dropTable(CqlIdentifier.of(tableName));
return dropTable(CqlIdentifier.fromCql(tableName));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Object to configure a {@code DROP TYPE} specification.
@@ -41,7 +41,7 @@ public class DropUserTypeSpecification extends UserTypeNameSpecification {
* @return a new {@link DropUserTypeSpecification}.
*/
public static DropUserTypeSpecification dropType(String name) {
return new DropUserTypeSpecification(CqlIdentifier.of(name));
return new DropUserTypeSpecification(CqlIdentifier.fromCql(name));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.util.Assert;
import com.datastax.driver.core.DataType;
@@ -50,7 +50,7 @@ public class FieldSpecification {
* @param type must not be {@literal null}.
*/
public static FieldSpecification of(String name, DataType type) {
return new FieldSpecification(CqlIdentifier.of(name), type);
return new FieldSpecification(CqlIdentifier.fromCql(name), type);
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.lang.Nullable;
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

View File

@@ -17,9 +17,10 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import lombok.EqualsAndHashCode;
import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
import org.springframework.util.Assert;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Base value object to support the construction of keyspace specifications.
*
@@ -33,16 +34,16 @@ public abstract class KeyspaceActionSpecification {
/**
* The name of the keyspace.
*/
private final KeyspaceIdentifier name;
private final CqlIdentifier name;
protected KeyspaceActionSpecification(KeyspaceIdentifier name) {
protected KeyspaceActionSpecification(CqlIdentifier name) {
Assert.notNull(name, "KeyspaceIdentifier must not be null");
Assert.notNull(name, "CqlIdentifier must not be null");
this.name = name;
}
public KeyspaceIdentifier getName() {
public CqlIdentifier getName() {
return name;
}
}

View File

@@ -17,6 +17,7 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import static org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils.*;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import lombok.EqualsAndHashCode;
import java.util.Collections;
@@ -45,7 +46,7 @@ public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpec
protected Map<String, Object> options = new LinkedHashMap<>();
protected KeyspaceOptionsSpecification(KeyspaceIdentifier name) {
protected KeyspaceOptionsSpecification(CqlIdentifier name) {
super(name);
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.util.Assert;
/**

View File

@@ -18,7 +18,7 @@ package org.springframework.data.cassandra.core.cql.keyspace;
import java.util.List;
import java.util.Map;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Describes a table.

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.util.Assert;
/**

View File

@@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.lang.Nullable;
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
import static com.datastax.oss.driver.api.core.CqlIdentifier.*;
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.*;
import java.util.ArrayList;
@@ -23,7 +23,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.util.Assert;
@@ -138,7 +138,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
Assert.notNull(ordering, "Ordering must not be null");
return column(CqlIdentifier.of(name), type, Optional.of(CLUSTERED), Optional.of(ordering));
return column(CqlIdentifier.fromCql(name), type, Optional.of(CLUSTERED), Optional.of(ordering));
}
/**

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import org.springframework.util.Assert;
/**

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.data.cassandra.core.cql.keyspace;
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
import static com.datastax.oss.driver.api.core.CqlIdentifier.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.driver.core.DataType;

View File

@@ -16,14 +16,13 @@
package org.springframework.data.cassandra.core.cql.generator;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
import static org.springframework.data.cassandra.core.cql.generator.CreateTableCqlGenerator.*;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification;
import org.springframework.data.cassandra.core.cql.keyspace.Option;
@@ -34,6 +33,7 @@ import org.springframework.data.cassandra.core.cql.keyspace.TableOption.Compress
import org.springframework.data.cassandra.core.cql.keyspace.TableOption.KeyCachingOption;
import com.datastax.driver.core.DataType;
import com.datastax.oss.driver.api.core.CqlIdentifier;
/**
* Unit tests for {@link CreateTableCqlGenerator}.
@@ -47,9 +47,9 @@ public class CreateTableCqlGeneratorUnitTests {
@Test
public void shouldGenerateCorrectCQL() {
CqlIdentifier name = of("mytable");
CqlIdentifier name = CqlIdentifier.fromCql("mytable");
DataType partitionKeyType0 = DataType.text();
CqlIdentifier partitionKey0 = of("partitionKey0");
CqlIdentifier partitionKey0 = CqlIdentifier.fromCql("partitionKey0");
DataType columnType1 = DataType.text();
String column1 = "column1";
@@ -59,18 +59,18 @@ public class CreateTableCqlGeneratorUnitTests {
String cql = toCql(table);
assertPreamble(name, cql);
assertColumns(String.format("%s %s, %s %s", partitionKey0, partitionKeyType0, column1, columnType1), cql);
assertPrimaryKey(partitionKey0.toCql(), cql);
assertPrimaryKey(partitionKey0.toString(), cql);
}
@Test
public void shouldGenerateCompositePrimaryKey() {
CqlIdentifier name = of("composite_partition_key_table");
CqlIdentifier name = CqlIdentifier.fromCql("composite_partition_key_table");
DataType partKeyType0 = DataType.text();
CqlIdentifier partKey0 = of("partKey0");
CqlIdentifier partKey0 = CqlIdentifier.fromCql("partKey0");
DataType partKeyType1 = DataType.text();
CqlIdentifier partKey1 = of("partKey1");
CqlIdentifier column0 = of("column0");
CqlIdentifier partKey1 = CqlIdentifier.fromCql("partKey1");
CqlIdentifier column0 = CqlIdentifier.fromCql("column0");
DataType columnType0 = DataType.text();
CreateTableSpecification table = CreateTableSpecification.createTable(name)
@@ -89,13 +89,13 @@ public class CreateTableCqlGeneratorUnitTests {
@Test
public void shouldGenerateTableOptions() {
CqlIdentifier name = of("mytable");
CqlIdentifier name = CqlIdentifier.fromCql("mytable");
DataType partitionKeyType0 = DataType.text();
CqlIdentifier partitionKey0 = of("partitionKey0");
CqlIdentifier partitionKey0 = CqlIdentifier.fromCql("partitionKey0");
DataType partitionKeyType1 = DataType.timestamp();
CqlIdentifier partitionKey1 = of("create_timestamp");
CqlIdentifier partitionKey1 = CqlIdentifier.fromCql("create_timestamp");
DataType columnType1 = DataType.text();
CqlIdentifier column1 = of("column1");
CqlIdentifier column1 = CqlIdentifier.fromCql("column1");
Double readRepairChance = 0.5;
CreateTableSpecification table = CreateTableSpecification.createTable(name)
@@ -114,13 +114,13 @@ public class CreateTableCqlGeneratorUnitTests {
@Test
public void shouldGenerateMultipleOptions() {
CqlIdentifier name = of("timeseries_table");
CqlIdentifier name = CqlIdentifier.fromCql("timeseries_table");
DataType partitionKeyType0 = DataType.timeuuid();
CqlIdentifier partitionKey0 = of("tid");
CqlIdentifier partitionKey0 = CqlIdentifier.fromCql("tid");
DataType partitionKeyType1 = DataType.timestamp();
CqlIdentifier partitionKey1 = of("create_timestamp");
CqlIdentifier partitionKey1 = CqlIdentifier.fromCql("create_timestamp");
DataType columnType1 = DataType.text();
CqlIdentifier column1 = of("data_point");
CqlIdentifier column1 = CqlIdentifier.fromCql("data_point");
Double readRepairChance = 0.5;
Double dcLocalReadRepairChance = 0.7;
Double bloomFilterFpChance = 0.001;