DATACASS-656 - Deprecate forceQuote.
Forced quoting is now deprecated as we're using CqlIdentifier which is able to determine whether an identifier requires quoting. Original pull request: #167.
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -163,10 +163,6 @@
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
|
||||
@@ -270,10 +270,10 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
/**
|
||||
* Create a Cassandra driver {@link com.datastax.oss.driver.api.core.CqlIdentifier} from this {@link CqlIdentifier}.
|
||||
*
|
||||
* @return the {@link com.datastax.oss.driver.api.core.CqlIdentifier} from this {@link CqlIdentifierIdentifier}.
|
||||
* @return the {@link com.datastax.oss.driver.api.core.CqlIdentifier} from this {@link CqlIdentifier}.
|
||||
* @since 3.0
|
||||
*/
|
||||
public com.datastax.oss.driver.api.core.CqlIdentifier toCqlIdentifier() {
|
||||
return com.datastax.oss.driver.api.core.CqlIdentifier.fromCql(this.identifier);
|
||||
return com.datastax.oss.driver.api.core.CqlIdentifier.fromInternal(this.unquoted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
import com.datastax.oss.driver.api.core.type.TupleType;
|
||||
@@ -39,7 +40,11 @@ public interface CassandraPersistentEntity<T> extends PersistentEntity<T, Cassan
|
||||
* Sets whether to enforce quoting when using the {@link #getTableName()} in CQL.
|
||||
*
|
||||
* @param forceQuote {@literal true} to enforce quoting; {@literal false} to disable enforced quoting usage.
|
||||
* @deprecated since 3.0. The table name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
@Deprecated
|
||||
void setForceQuote(boolean forceQuote);
|
||||
|
||||
/**
|
||||
@@ -47,6 +52,19 @@ public interface CassandraPersistentEntity<T> extends PersistentEntity<T, Cassan
|
||||
*/
|
||||
CqlIdentifier getTableName();
|
||||
|
||||
/**
|
||||
* Sets the CQL table name.
|
||||
*
|
||||
* @param tableName must not be {@literal null}.
|
||||
* @deprecated since 3.0, use {@link #setTableName(CqlIdentifier)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void setTableName(org.springframework.data.cassandra.core.cql.CqlIdentifier tableName) {
|
||||
|
||||
Assert.notNull(tableName, "Table name must not be null");
|
||||
setTableName(tableName.toCqlIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the CQL table name.
|
||||
*
|
||||
|
||||
@@ -40,6 +40,23 @@ import com.datastax.oss.driver.api.core.type.DataType;
|
||||
public interface CassandraPersistentProperty
|
||||
extends PersistentProperty<CassandraPersistentProperty>, ApplicationContextAware {
|
||||
|
||||
/**
|
||||
* If this property is mapped with a single column, set the column name to the given
|
||||
* {@link org.springframework.data.cassandra.core.cql.CqlIdentifier}. If this property is not mapped by a single
|
||||
* column, throws {@link IllegalStateException}. If the given column name is null, {@link IllegalArgumentException} is
|
||||
* thrown.
|
||||
*
|
||||
* @param columnName must not be {@literal null}.
|
||||
* @deprecated since 3.0, use {@link #setColumnName(CqlIdentifier)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default void setColumnName(org.springframework.data.cassandra.core.cql.CqlIdentifier columnName) {
|
||||
|
||||
Assert.notNull(columnName, "Column name must not be null");
|
||||
|
||||
setColumnName(columnName.toCqlIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* If this property is mapped with a single column, set the column name to the given {@link CqlIdentifier}. If this
|
||||
* property is not mapped by a single column, throws {@link IllegalStateException}. If the given column name is null,
|
||||
@@ -85,7 +102,11 @@ public interface CassandraPersistentProperty
|
||||
*
|
||||
* @param forceQuote {@literal true} to enforce quoting.
|
||||
* @see CassandraPersistentProperty#getColumnName()
|
||||
* @deprecated since 3.0. The column name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
@Deprecated
|
||||
void setForceQuote(boolean forceQuote);
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,6 +54,10 @@ public @interface Column {
|
||||
|
||||
/**
|
||||
* Whether to cause the column name to be force-quoted.
|
||||
*
|
||||
* @deprecated since 3.0. The column name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
boolean forceQuote() default false;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,11 @@ public class EntityMapping {
|
||||
|
||||
/**
|
||||
* Whether to force the table name to be quoted.
|
||||
*
|
||||
* @deprecated since 3.0. The table name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
*/
|
||||
private String forceQuote = "false";
|
||||
private @Deprecated String forceQuote = "false";
|
||||
|
||||
/**
|
||||
* The name of the table to which the entity is mapped.
|
||||
@@ -73,10 +76,17 @@ public class EntityMapping {
|
||||
this.entityClassName = entityClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @deprecated since 3.0. The type name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getForceQuote() {
|
||||
return this.forceQuote;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setForceQuote(String forceQuote) {
|
||||
|
||||
Assert.notNull(forceQuote, "Force quote must not be null or empty");
|
||||
|
||||
@@ -35,6 +35,6 @@ class IdentifierFactory {
|
||||
return CqlIdentifier.fromCql("\"" + simpleName.toLowerCase() + "\"");
|
||||
}
|
||||
|
||||
return CqlIdentifier.fromCql(simpleName.toLowerCase());
|
||||
return CqlIdentifier.fromInternal(simpleName.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ public @interface PrimaryKey {
|
||||
|
||||
/**
|
||||
* Whether to cause the column name to be force-quoted if the primary key is of a simple type, else ignored.
|
||||
*
|
||||
* @deprecated since 3.0. The column name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
@Deprecated
|
||||
boolean forceQuote() default false;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,11 @@ public @interface PrimaryKeyColumn {
|
||||
|
||||
/**
|
||||
* Whether to cause the column name to be force-quoted.
|
||||
*
|
||||
* @deprecated since 3.0. The column name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
@Deprecated
|
||||
boolean forceQuote() default false;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ public class PropertyMapping {
|
||||
|
||||
private @Nullable String columnName;
|
||||
|
||||
/**
|
||||
* @deprecated since 3.0. The column name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
private @Nullable String forceQuote;
|
||||
|
||||
private String propertyName;
|
||||
@@ -70,10 +75,12 @@ public class PropertyMapping {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public String getForceQuote() {
|
||||
return this.forceQuote;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setForceQuote(String forceQuote) {
|
||||
this.forceQuote = forceQuote;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ public @interface Table {
|
||||
|
||||
/**
|
||||
* Whether to cause the table name to be force-quoted.
|
||||
*
|
||||
* @deprecated since 3.0. The table name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
@Deprecated
|
||||
boolean forceQuote() default false;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ public @interface UserDefinedType {
|
||||
|
||||
/**
|
||||
* Whether to cause the UDT name to be force-quoted.
|
||||
*
|
||||
* @deprecated since 3.0. The type name gets converted into {@link com.datastax.oss.driver.api.core.CqlIdentifier}
|
||||
* hence it no longer requires an indication whether the name should be quoted.
|
||||
* @see com.datastax.oss.driver.api.core.CqlIdentifier#fromInternal(String)
|
||||
*/
|
||||
@Deprecated
|
||||
boolean forceQuote() default false;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,17 @@ public class BasicCassandraPersistentPropertyUnitTests {
|
||||
assertThat(getPropertyFor(Timeline.class, "text").getRequiredColumnName()).hasToString("message");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesReservedColumnName() {
|
||||
assertThat(getPropertyFor(Timeline.class, "keyspace").getRequiredColumnName().asCql(true))
|
||||
.isEqualTo("\"keyspace\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesReservedAnnotatedColumnName() {
|
||||
assertThat(getPropertyFor(Timeline.class, "table").getRequiredColumnName().asCql(true)).isEqualTo("\"table\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksIdProperty() {
|
||||
|
||||
@@ -155,6 +166,10 @@ public class BasicCassandraPersistentPropertyUnitTests {
|
||||
Date time;
|
||||
|
||||
@Column("message") String text;
|
||||
|
||||
String keyspace;
|
||||
|
||||
@Column("table") String table;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
Reference in New Issue
Block a user