1616package com .datastax .driver .mapping ;
1717
1818import com .datastax .driver .core .ConsistencyLevel ;
19+ import com .datastax .driver .core .Metadata ;
1920import com .datastax .driver .core .TableMetadata ;
2021import com .datastax .driver .core .TypeCodec ;
2122import com .datastax .driver .core .UserType ;
3435import java .util .*;
3536import java .util .concurrent .atomic .AtomicInteger ;
3637
37- import static com .datastax .driver .core .Metadata .quote ;
38-
3938/**
4039 * Static methods that facilitates parsing:
4140 * - {@link #parseEntity(Class, MappingManager)}: entity classes into {@link EntityMapper} instances
@@ -48,13 +47,13 @@ class AnnotationParser {
4847 @ VisibleForTesting
4948 static final Set <Class <? extends Annotation >> VALID_PROPERTY_ANNOTATIONS = ImmutableSet .of (
5049 Column .class ,
50+ Computed .class ,
5151 ClusteringColumn .class ,
5252 Frozen .class ,
5353 FrozenKey .class ,
5454 FrozenValue .class ,
5555 PartitionKey .class ,
56- Transient .class ,
57- Computed .class );
56+ Transient .class );
5857
5958 @ VisibleForTesting
6059 static final Set <Class <? extends Annotation >> VALID_FIELD_ANNOTATIONS = ImmutableSet .of (
@@ -77,20 +76,20 @@ private AnnotationParser() {
7776 static <T > EntityMapper <T > parseEntity (final Class <T > entityClass , MappingManager mappingManager ) {
7877 Table table = AnnotationChecks .getTypeAnnotation (Table .class , entityClass );
7978
80- String ksName = table .caseSensitiveKeyspace () ? table .keyspace () : table .keyspace ().toLowerCase ();
81- String tableName = table .caseSensitiveTable () ? table .name () : table .name ().toLowerCase ();
79+ String ksName = table .caseSensitiveKeyspace () ? Metadata . quote ( table .keyspace () ) : table .keyspace ().toLowerCase ();
80+ String tableName = table .caseSensitiveTable () ? Metadata . quote ( table .name () ) : table .name ().toLowerCase ();
8281
8382 ConsistencyLevel writeConsistency = table .writeConsistency ().isEmpty () ? null : ConsistencyLevel .valueOf (table .writeConsistency ().toUpperCase ());
8483 ConsistencyLevel readConsistency = table .readConsistency ().isEmpty () ? null : ConsistencyLevel .valueOf (table .readConsistency ().toUpperCase ());
8584
8685 if (Strings .isNullOrEmpty (table .keyspace ())) {
87- ksName = mappingManager .getSession ().getLoggedKeyspace ();
88- if (Strings .isNullOrEmpty (ksName ))
86+ String loggedKeyspace = mappingManager .getSession ().getLoggedKeyspace ();
87+ if (Strings .isNullOrEmpty (loggedKeyspace ))
8988 throw new IllegalArgumentException (String .format (
90- "Error creating mapper for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace" ,
91- entityClass .getSimpleName (),
92- Table .class .getSimpleName ()
89+ "Error creating mapper for %s, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace" ,
90+ entityClass
9391 ));
92+ ksName = Metadata .quote (loggedKeyspace );
9493 }
9594
9695 EntityMapper <T > mapper = new EntityMapper <T >(entityClass , ksName , tableName , writeConsistency , readConsistency );
@@ -154,17 +153,17 @@ else if (propertyMapper.isClusteringColumn())
154153 static <T > MappedUDTCodec <T > parseUDT (Class <T > udtClass , MappingManager mappingManager ) {
155154 UDT udt = AnnotationChecks .getTypeAnnotation (UDT .class , udtClass );
156155
157- String ksName = udt .caseSensitiveKeyspace () ? udt .keyspace () : udt .keyspace ().toLowerCase ();
158- String udtName = udt .caseSensitiveType () ? quote (udt .name ()) : udt .name ().toLowerCase ();
156+ String ksName = udt .caseSensitiveKeyspace () ? Metadata . quote ( udt .keyspace () ) : udt .keyspace ().toLowerCase ();
157+ String udtName = udt .caseSensitiveType () ? Metadata . quote (udt .name ()) : udt .name ().toLowerCase ();
159158
160159 if (Strings .isNullOrEmpty (udt .keyspace ())) {
161- ksName = mappingManager .getSession ().getLoggedKeyspace ();
162- if (Strings .isNullOrEmpty (ksName ))
160+ String loggedKeyspace = mappingManager .getSession ().getLoggedKeyspace ();
161+ if (Strings .isNullOrEmpty (loggedKeyspace ))
163162 throw new IllegalArgumentException (String .format (
164- "Error creating UDT codec for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace" ,
165- udtClass .getSimpleName (),
166- UDT .class .getSimpleName ()
163+ "Error creating UDT codec for %s, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace" ,
164+ udtClass
167165 ));
166+ ksName = Metadata .quote (loggedKeyspace );
168167 }
169168
170169 UserType userType = mappingManager .getSession ().getCluster ().getMetadata ().getKeyspace (ksName ).getUserType (udtName );
0 commit comments