@@ -33,8 +33,11 @@ public class UserType extends DataType implements Iterable<UserType.Field> {
3333
3434 private final String keyspace ;
3535 private final String typeName ;
36+ private final boolean frozen ;
3637 private final ProtocolVersion protocolVersion ;
3738
39+ // can be null, if this object is being constructed from a response message
40+ // see Responses.Result.Rows.Metadata.decode()
3841 private volatile CodecRegistry codecRegistry ;
3942
4043 // Note that we don't expose the order of fields, from an API perspective this is a map
@@ -46,20 +49,31 @@ public class UserType extends DataType implements Iterable<UserType.Field> {
4649 // implementation.
4750 final Map <String , int []> byName ;
4851
49- UserType (String keyspace , String typeName , Collection < Field > fields , ProtocolVersion protocolVersion , CodecRegistry codecRegistry ) {
50- super (DataType . Name . UDT );
52+ private UserType (Name name , String keyspace , String typeName , boolean frozen , ProtocolVersion protocolVersion , CodecRegistry codecRegistry , Field [] byIdx , Map < String , int []> byName ) {
53+ super (name );
5154 this .keyspace = keyspace ;
5255 this .typeName = typeName ;
56+ this .frozen = frozen ;
5357 this .protocolVersion = protocolVersion ;
54- // codecRegistry can be null, if this object is being constructed from a response message
55- // see Responses.Result.Rows.Metadata.decode()
5658 this .codecRegistry = codecRegistry ;
57- this .byIdx = fields .toArray (new Field [fields .size ()]);
59+ this .byIdx = byIdx ;
60+ this .byName = byName ;
61+ }
62+
63+ UserType (String keyspace , String typeName , boolean frozen , Collection <Field > fields , ProtocolVersion protocolVersion , CodecRegistry codecRegistry ) {
64+ this (DataType .Name .UDT , keyspace , typeName , frozen , protocolVersion , codecRegistry ,
65+ fields .toArray (new Field [fields .size ()]),
66+ mapByName (fields ));
67+ }
5868
69+ private static ImmutableMap <String , int []> mapByName (Collection <Field > fields ) {
5970 ImmutableMap .Builder <String , int []> builder = new ImmutableMap .Builder <String , int []>();
60- for (int i = 0 ; i < byIdx .length ; i ++)
61- builder .put (byIdx [i ].getName (), new int []{i });
62- this .byName = builder .build ();
71+ int i = 0 ;
72+ for (Field field : fields ) {
73+ builder .put (field .getName (), new int []{i });
74+ i += 1 ;
75+ }
76+ return builder .build ();
6377 }
6478
6579 static UserType build (KeyspaceMetadata ksm , Row row , VersionNumber version , Cluster cluster , Map <String , UserType > userTypes ) {
@@ -82,7 +96,7 @@ static UserType build(KeyspaceMetadata ksm, Row row, VersionNumber version, Clus
8296 }
8397 fields .add (new Field (fieldNames .get (i ), fieldType ));
8498 }
85- return new UserType (keyspace , name , fields , protocolVersion , codecRegistry );
99+ return new UserType (keyspace , name , false , fields , protocolVersion , codecRegistry );
86100 }
87101
88102 /**
@@ -174,7 +188,15 @@ public DataType getFieldType(String name) {
174188
175189 @ Override
176190 public boolean isFrozen () {
177- return true ;
191+ return frozen ;
192+ }
193+
194+ public UserType copy (boolean newFrozen ) {
195+ if (newFrozen == frozen ) {
196+ return this ;
197+ } else {
198+ return new UserType (name , keyspace , typeName , newFrozen , protocolVersion , codecRegistry , byIdx , byName );
199+ }
178200 }
179201
180202 @ Override
@@ -340,16 +362,18 @@ static class Shallow extends DataType {
340362
341363 final String keyspaceName ;
342364 final String typeName ;
365+ final boolean frozen ;
343366
344- Shallow (String keyspaceName , String typeName ) {
367+ Shallow (String keyspaceName , String typeName , boolean frozen ) {
345368 super (Name .UDT );
346369 this .keyspaceName = keyspaceName ;
347370 this .typeName = typeName ;
371+ this .frozen = frozen ;
348372 }
349373
350374 @ Override
351375 public boolean isFrozen () {
352- return false ;
376+ return frozen ;
353377 }
354378 }
355379}
0 commit comments