@@ -26,19 +26,18 @@ import com.datastax.driver.core.TableMetadata;
|
||||
|
||||
/**
|
||||
* This encapsulates the logic for CQL quoted and unquoted identifiers.
|
||||
* <p/>
|
||||
* CQL identifiers, when unquoted, are converted to lower case. When quoted, they are returned as-is with no lower
|
||||
*
|
||||
* <p>CQL identifiers, when unquoted, are converted to lower case. When quoted, they are returned as-is with no lower
|
||||
* casing and encased in double quotes. To render, use any of the methods {@link #toCql()},
|
||||
* {@link #toCql(StringBuilder)}, or {@link #toString()}.
|
||||
*
|
||||
* @see #CqlIdentifier(String)
|
||||
* @see #CqlIdentifier(String, boolean)
|
||||
* @see #toCql()
|
||||
* @see #toCql(StringBuilder)
|
||||
* @see #toString()
|
||||
*
|
||||
* @author John McPeek
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @see #toCql()
|
||||
* @see #toCql(StringBuilder)
|
||||
* @see #toString()
|
||||
*/
|
||||
public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializable {
|
||||
|
||||
@@ -52,8 +51,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
|
||||
/**
|
||||
* Factory method for {@link CqlIdentifier}. Convenient if imported statically.
|
||||
*
|
||||
* @see #CqlIdentifier(String)
|
||||
*
|
||||
* @see #CqlIdentifier(CharSequence)
|
||||
*/
|
||||
public static CqlIdentifier cqlId(CharSequence identifier) {
|
||||
return new CqlIdentifier(identifier);
|
||||
@@ -61,8 +60,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
|
||||
/**
|
||||
* Factory method for {@link CqlIdentifier}. Convenient if imported statically.
|
||||
*
|
||||
* @see #CqlIdentifier(String)
|
||||
*
|
||||
* @see #CqlIdentifier(CharSequence, boolean)
|
||||
*/
|
||||
public static CqlIdentifier cqlId(CharSequence identifier, boolean forceQuote) {
|
||||
return new CqlIdentifier(identifier, forceQuote);
|
||||
@@ -70,8 +69,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
|
||||
/**
|
||||
* Factory method for a force-quoted {@link CqlIdentifier}. Convenient if imported statically.
|
||||
*
|
||||
* @see #CqlIdentifier(String, boolean)
|
||||
*
|
||||
* @see #CqlIdentifier(CharSequence, boolean)
|
||||
*/
|
||||
public static CqlIdentifier quotedCqlId(CharSequence identifier) {
|
||||
return new CqlIdentifier(identifier, true);
|
||||
@@ -97,8 +96,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
|
||||
/**
|
||||
* Creates a new {@link CqlIdentifier} without force-quoting it. It may end up quoted, depending on its value.
|
||||
*
|
||||
* @see #cqlId(String)
|
||||
*
|
||||
* @see #cqlId(CharSequence)
|
||||
*/
|
||||
public CqlIdentifier(CharSequence identifier) {
|
||||
this(identifier, false);
|
||||
@@ -113,9 +112,9 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* plus the name will be converted to lower case and rendered as such.</li>
|
||||
* <li>If the given identifier is illegal, an {@link IllegalArgumentException} is thrown.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see #cqlId(String)
|
||||
* @see #quotedCqlId(String)
|
||||
*
|
||||
* @see #cqlId(CharSequence, boolean)
|
||||
* @see #quotedCqlId(CharSequence)
|
||||
*/
|
||||
public CqlIdentifier(CharSequence identifier, boolean forceQuote) {
|
||||
setIdentifier(identifier, forceQuote);
|
||||
@@ -129,6 +128,7 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
Assert.notNull(identifier, "Identifier must not be null");
|
||||
|
||||
String string = identifier.toString();
|
||||
|
||||
Assert.hasText(string, "Identifier must not be empty");
|
||||
|
||||
if (forceQuoting || isQuotedIdentifier(string)) {
|
||||
@@ -167,17 +167,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* {@link StringBuilder}. If <code>null</code> is given, a new {@link StringBuilder} is created, appended to, and
|
||||
* returned.
|
||||
*/
|
||||
public StringBuilder toCql(StringBuilder sb) {
|
||||
sb = sb == null ? new StringBuilder() : sb;
|
||||
return sb.append(toCql());
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for {@link #toCql()}.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return toCql();
|
||||
public StringBuilder toCql(StringBuilder builder) {
|
||||
return (builder != null ? builder : new StringBuilder()).append(toCql());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,9 +178,16 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
return quoted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unquoted identifiers sort before quoted ones. Otherwise, they compare according to their identifiers.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((Boolean) quoted).hashCode() ^ identifier.hashCode();
|
||||
@SuppressWarnings("all")
|
||||
public int compareTo(CqlIdentifier identifier) {
|
||||
|
||||
int comparison = ((Boolean) this.quoted).compareTo(identifier.quoted);
|
||||
|
||||
return (comparison != 0 ? comparison : this.identifier.compareTo(identifier.identifier));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,32 +196,32 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* a {@link CqlIdentifier}.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(that instanceof CqlIdentifier) && !(that instanceof CharSequence)) {
|
||||
|
||||
if (!(obj instanceof CqlIdentifier || obj instanceof CharSequence)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CqlIdentifier other = (that instanceof CqlIdentifier) ? (CqlIdentifier) that : cqlId((CharSequence) that);
|
||||
CqlIdentifier that = (obj instanceof CqlIdentifier) ? (CqlIdentifier) obj : cqlId((CharSequence) obj);
|
||||
|
||||
return this.quoted == other.quoted && this.identifier.equals(other.identifier);
|
||||
return (this.quoted == that.quoted && this.identifier.equals(that.identifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO hmmm, re-evaluate this since it is not a proper hash code matching equals!
|
||||
public int hashCode() {
|
||||
return ((Boolean) quoted).hashCode() ^ identifier.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unquoted identifiers sort before quoted ones. Otherwise, they compare according to their identifiers.
|
||||
* Alias for {@link #toCql()}.
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(CqlIdentifier that) {
|
||||
|
||||
int comparison = ((Boolean) this.quoted).compareTo(that.quoted);
|
||||
if (comparison != 0) {
|
||||
return comparison;
|
||||
}
|
||||
return this.identifier.compareTo(that.identifier);
|
||||
public String toString() {
|
||||
return toCql();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -21,10 +21,11 @@ import org.springframework.cassandra.core.keyspace.AddColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating an {@code ADD} clause of an {@code ALTER TABLE} statement.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @see AddColumnSpecification
|
||||
* @see ColumnChangeCqlGenerator
|
||||
* @see org.springframework.cassandra.core.keyspace.AlterTableSpecification
|
||||
*/
|
||||
public class AddColumnCqlGenerator extends ColumnChangeCqlGenerator<AddColumnSpecification> {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -21,8 +21,10 @@ 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
|
||||
* @see AlterColumnSpecification
|
||||
* @see ColumnChangeCqlGenerator
|
||||
*/
|
||||
public class AlterColumnCqlGenerator extends ColumnChangeCqlGenerator<AlterColumnSpecification> {
|
||||
|
||||
@@ -31,6 +33,7 @@ public class AlterColumnCqlGenerator extends ColumnChangeCqlGenerator<AlterColum
|
||||
}
|
||||
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
return noNull(cql).append("ALTER ").append(spec().getName()).append(" TYPE ").append(spec().getType().asFunctionParameterString());
|
||||
return noNull(cql).append("ALTER ").append(spec().getName()).append(" TYPE ")
|
||||
.append(spec().getType().asFunctionParameterString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -30,16 +30,17 @@ import org.springframework.cassandra.core.keyspace.TableOption;
|
||||
|
||||
/**
|
||||
* CQL generator for generating {@code ALTER TABLE} statements.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @see AlterTableSpecification
|
||||
* @see TableOptionsCqlGenerator
|
||||
*/
|
||||
public class AlterTableCqlGenerator extends TableOptionsCqlGenerator<AlterTableSpecification> {
|
||||
|
||||
/**
|
||||
* Generates a CQL statement from the given {@code specification}.
|
||||
*
|
||||
*
|
||||
* @param specification must not be {@literal null}.
|
||||
* @return the generated CQL statement.
|
||||
*/
|
||||
@@ -49,7 +50,7 @@ public class AlterTableCqlGenerator extends TableOptionsCqlGenerator<AlterTableS
|
||||
|
||||
/**
|
||||
* Creates a new {@literal {@link AlterTableCqlGenerator}.
|
||||
*
|
||||
*
|
||||
* @param specification must not be {@literal null}.
|
||||
*/
|
||||
public AlterTableCqlGenerator(AlterTableSpecification specification) {
|
||||
@@ -85,6 +86,7 @@ public class AlterTableCqlGenerator extends TableOptionsCqlGenerator<AlterTableS
|
||||
cql = noNull(cql);
|
||||
|
||||
boolean first = true;
|
||||
|
||||
for (ColumnChangeSpecification change : spec().getChanges()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
@@ -124,17 +126,19 @@ public class AlterTableCqlGenerator extends TableOptionsCqlGenerator<AlterTableS
|
||||
cql = noNull(cql);
|
||||
|
||||
Map<String, Object> options = spec().getOptions();
|
||||
|
||||
if (options == null || options.isEmpty()) {
|
||||
return cql;
|
||||
}
|
||||
|
||||
cql.append("WITH ");
|
||||
|
||||
boolean first = true;
|
||||
|
||||
for (String key : options.keySet()) {
|
||||
|
||||
/*
|
||||
* Compact storage is illegal on alter table.
|
||||
*
|
||||
* TODO - Is there a way to handle this in the specification?
|
||||
*/
|
||||
if (key.equals(TableOption.COMPACT_STORAGE.getName())) {
|
||||
@@ -150,9 +154,11 @@ public class AlterTableCqlGenerator extends TableOptionsCqlGenerator<AlterTableS
|
||||
cql.append(key);
|
||||
|
||||
Object value = options.get(key);
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cql.append(" = ");
|
||||
|
||||
if (value instanceof Map) {
|
||||
@@ -163,6 +169,7 @@ public class AlterTableCqlGenerator extends TableOptionsCqlGenerator<AlterTableS
|
||||
// else just use value as string
|
||||
cql.append(value.toString());
|
||||
}
|
||||
|
||||
return cql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -21,9 +21,10 @@ import org.springframework.cassandra.core.keyspace.DropColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a {@code DROP} column clause of an {@code ALTER TABLE} statement.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @see DropColumnSpecification
|
||||
* @see ColumnChangeCqlGenerator
|
||||
* @see org.springframework.cassandra.core.keyspace.AlterTableSpecification
|
||||
*/
|
||||
public class DropColumnCqlGenerator extends ColumnChangeCqlGenerator<DropColumnSpecification> {
|
||||
|
||||
@@ -21,9 +21,10 @@ import org.springframework.cassandra.core.keyspace.RenameColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating an {@code RENAME} column clause of an {@code ALTER TABLE} statement.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 1.5
|
||||
* @see ColumnChangeCqlGenerator
|
||||
* @see RenameColumnSpecification
|
||||
* @see org.springframework.cassandra.core.keyspace.AlterTableSpecification
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -21,15 +21,16 @@ import com.datastax.driver.core.DataType;
|
||||
|
||||
/**
|
||||
* Specification to add a column.
|
||||
*
|
||||
*
|
||||
* @author Matthew Adams
|
||||
* @author Mark Paluch
|
||||
* @see ColumnTypeChangeSpecification
|
||||
*/
|
||||
public class AddColumnSpecification extends ColumnTypeChangeSpecification {
|
||||
|
||||
/**
|
||||
* Creates a new {@link AddColumnSpecification} for the given {@code name} and {@link type}
|
||||
*
|
||||
*
|
||||
* @param name must not be empty or {@literal null}.
|
||||
* @param type must not be {@literal null}.
|
||||
*/
|
||||
@@ -39,7 +40,7 @@ public class AddColumnSpecification extends ColumnTypeChangeSpecification {
|
||||
|
||||
/**
|
||||
* Creates a new {@link AddColumnSpecification} for the given {@code name} and {@link type}
|
||||
*
|
||||
*
|
||||
* @param name must not be {@literal null}.
|
||||
* @param type must not be {@literal null}.
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -25,7 +25,7 @@ import com.datastax.driver.core.DataType;
|
||||
|
||||
/**
|
||||
* Builder class to construct an {@code ALTER TABLE} specification.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @see AddColumnSpecification
|
||||
@@ -34,6 +34,7 @@ import com.datastax.driver.core.DataType;
|
||||
* @see RenameColumnSpecification
|
||||
* @see CreateTableSpecification
|
||||
* @see DropTableSpecification
|
||||
* @see TableOptionsSpecification
|
||||
* @see org.springframework.cassandra.core.cql.generator.AlterTableCqlGenerator
|
||||
*/
|
||||
public class AlterTableSpecification extends TableOptionsSpecification<AlterTableSpecification> {
|
||||
@@ -69,7 +70,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
|
||||
/*
|
||||
* Adds a {@code DROP} to the list of column changes.
|
||||
*
|
||||
*
|
||||
* @param column must not be empty or {@literal null}
|
||||
* @return {@literal this} {@link AlterTableSpecification}
|
||||
*/
|
||||
@@ -80,7 +81,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
|
||||
/**
|
||||
* Adds an {@code ADD} to the list of column changes.
|
||||
*
|
||||
*
|
||||
* @param column must not be empty or {@literal null}
|
||||
* @param type must not be {@literal null}
|
||||
* @return {@literal this} {@link AlterTableSpecification}
|
||||
@@ -104,7 +105,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
|
||||
/**
|
||||
* Adds an {@literal ALTER} to the list of column changes.
|
||||
*
|
||||
*
|
||||
* @param column must not be empty or {@literal null}
|
||||
* @param type must not be {@literal null}
|
||||
* @return {@literal this} {@link AlterTableSpecification}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.
|
||||
@@ -24,8 +24,9 @@ import com.datastax.driver.core.DataType;
|
||||
|
||||
/**
|
||||
* Base value object class for column changes that include {@link DataType} information.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @see ColumnChangeSpecification
|
||||
*/
|
||||
public abstract class ColumnTypeChangeSpecification extends ColumnChangeSpecification {
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link ColumnChangeSpecification} to rename a column.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 1.5
|
||||
* @see ColumnChangeSpecification
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RenameColumnSpecification extends ColumnChangeSpecification {
|
||||
|
||||
@@ -51,6 +51,7 @@ public class RenameColumnSpecification extends ColumnChangeSpecification {
|
||||
super(from);
|
||||
|
||||
Assert.notNull(to, "Target name must not be null");
|
||||
|
||||
this.targetName = to;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,12 +58,13 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
session.execute(
|
||||
"CREATE TABLE addamsFamily (name varchar PRIMARY KEY, gender varchar,\n" + " lastknownlocation bigint);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.varint());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.varint());
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("addamsFamily").getColumn("lastKnownLocation");
|
||||
|
||||
assertThat(column.getType(), is(equalTo(DataType.varint())));
|
||||
}
|
||||
|
||||
@@ -76,12 +77,13 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
session.execute(
|
||||
"CREATE TABLE addamsFamily (name varchar PRIMARY KEY, gender varchar,\n" + " lastknownlocation list<ascii>);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.list(DataType.varchar()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.list(DataType.varchar()));
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("addamsFamily").getColumn("lastKnownLocation");
|
||||
|
||||
assertThat(column.getType(), is(equalTo((DataType) DataType.list(DataType.varchar()))));
|
||||
}
|
||||
|
||||
@@ -94,12 +96,13 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
session.execute(
|
||||
"CREATE TABLE addamsFamily (name varchar PRIMARY KEY, gender varchar,\n" + " lastknownlocation varchar);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").add("gravesite",
|
||||
DataType.varchar());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.add("gravesite", DataType.varchar());
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("addamsFamily").getColumn("gravesite");
|
||||
|
||||
assertThat(column.getType(), is(equalTo(DataType.varchar())));
|
||||
}
|
||||
|
||||
@@ -111,12 +114,13 @@ public class AlterTableCqlGeneratorIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
session.execute("CREATE TABLE users (user_name varchar PRIMARY KEY);");
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users").add("top_places",
|
||||
DataType.list(DataType.ascii()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users")
|
||||
.add("top_places", DataType.list(DataType.ascii()));
|
||||
|
||||
execute(spec);
|
||||
|
||||
ColumnMetadata column = getTableMetadata("users").getColumn("top_places");
|
||||
|
||||
assertThat(column.getType(), is(equalTo((DataType) DataType.list(DataType.ascii()))));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAlterColumnType() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.uuid());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.uuid());
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily ALTER lastknownlocation TYPE uuid;")));
|
||||
}
|
||||
@@ -56,8 +56,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAlterListColumnType() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").alter("lastKnownLocation",
|
||||
DataType.list(DataType.ascii()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.alter("lastKnownLocation", DataType.list(DataType.ascii()));
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily ALTER lastknownlocation TYPE list<ascii>;")));
|
||||
}
|
||||
@@ -68,8 +68,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAddColumn() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").add("gravesite",
|
||||
DataType.varchar());
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.add("gravesite", DataType.varchar());
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily ADD gravesite varchar;")));
|
||||
}
|
||||
@@ -80,8 +80,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableAddListColumn() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users").add("top_places",
|
||||
DataType.list(DataType.ascii()));
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("users")
|
||||
.add("top_places", DataType.list(DataType.ascii()));
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE users ADD top_places list<ascii>;")));
|
||||
}
|
||||
@@ -103,7 +103,8 @@ public class AlterTableCqlGeneratorUnitTests {
|
||||
@Test
|
||||
public void alterTableRenameColumn() {
|
||||
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily").rename("firstname", "lastname");
|
||||
AlterTableSpecification spec = AlterTableSpecification.alterTable("addamsFamily")
|
||||
.rename("firstname", "lastname");
|
||||
|
||||
assertThat(toCql(spec), is(equalTo("ALTER TABLE addamsfamily RENAME firstname TO lastname;")));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.cql.generator.AlterTableCqlGeneratorUnitTests;
|
||||
import org.springframework.cassandra.core.cql.generator.CreateTableCqlGeneratorUnitTests;
|
||||
import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.cql.generator.DropTableCqlGeneratorUnitTests;
|
||||
@@ -39,7 +38,8 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(TableLifecycleIntegrationTests.class);
|
||||
|
||||
CreateTableCqlGeneratorUnitTests.MultipleOptionsTest createTableTest = new CreateTableCqlGeneratorUnitTests.MultipleOptionsTest();
|
||||
CreateTableCqlGeneratorUnitTests.MultipleOptionsTest createTableTest =
|
||||
new CreateTableCqlGeneratorUnitTests.MultipleOptionsTest();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -47,7 +47,7 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDrop() {
|
||||
public void dropIsSuccessful() {
|
||||
|
||||
createTableTest.prepare();
|
||||
|
||||
@@ -79,7 +79,5 @@ public class TableLifecycleIntegrationTests extends AbstractKeyspaceCreatingInte
|
||||
public DropTableCqlGenerator generator() {
|
||||
return new DropTableCqlGenerator(specification);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user