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:
Mark Paluch
2020-03-30 10:14:25 +02:00
parent 6d1bb747bb
commit f314d8e091
3 changed files with 17 additions and 2 deletions

View File

@@ -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) == '_');
}
/**

View File

@@ -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);

View File

@@ -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;
}
}