DATACASS-747 - Quote identifiers that start with underscore.
We now quote identifiers that begin with an underscore such as "_a".
This commit is contained in:
@@ -177,7 +177,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* @since 2.1.10
|
||||
*/
|
||||
public static boolean requiresQuoting(CharSequence chars) {
|
||||
return QUOTED.matcher(chars).matches() || ReservedKeyword.isReserved(chars);
|
||||
return QUOTED.matcher(chars).matches() || ReservedKeyword.isReserved(chars)
|
||||
|| (chars.length() > 0 && chars.charAt(0) == '_');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CqlIdentifierUnitTests {
|
||||
|
||||
@Test
|
||||
public void testIllegals() {
|
||||
String[] illegals = new String[] { null, "", "a ", "a a", "a\"", "a'", "a''", "\"\"", "''", "-", "a-", "_", "_a" };
|
||||
String[] illegals = new String[] { null, "", "a ", "a a", "a\"", "a'", "a''", "\"\"", "''", "-", "a-"};
|
||||
for (String illegal : illegals) {
|
||||
try {
|
||||
of(illegal);
|
||||
|
||||
@@ -626,6 +626,15 @@ public class CassandraMappingContextUnitTests {
|
||||
assertThat(mappingContext.usesTable(CqlIdentifier.of(tableMetadata.getName()))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACASS-747
|
||||
public void shouldQuoteFieldName() {
|
||||
|
||||
BasicCassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(UnsupportedFieldNames.class);
|
||||
|
||||
CassandraPersistentProperty property = entity.getRequiredPersistentProperty("_ent1");
|
||||
assertThat(property.getColumnName()).isEqualTo(CqlIdentifier.quoted("_ent1"));
|
||||
}
|
||||
|
||||
@Table
|
||||
private static class InvalidEntityWithIdAndPrimaryKeyColumn {
|
||||
@Id String foo;
|
||||
@@ -753,4 +762,9 @@ public class CassandraMappingContextUnitTests {
|
||||
@Id String id;
|
||||
Map<String, TupleValue> untyped;
|
||||
}
|
||||
|
||||
class UnsupportedFieldNames {
|
||||
String _ent1;
|
||||
String _ent2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user