1919@ SuppressFBWarnings ({"EI_EXPOSE_REP" , "EI_EXPOSE_REP2" })
2020@ Immutable
2121public class ObjectStorageTableMetadata {
22+ public static final Integer DEFAULT_VERSION = 1 ;
2223 private final LinkedHashSet <String > partitionKeyNames ;
2324 private final LinkedHashSet <String > clusteringKeyNames ;
2425 private final Map <String , String > clusteringOrders ;
2526 private final Set <String > secondaryIndexNames ;
2627 private final Map <String , String > columns ;
28+ private final Integer version ;
2729
2830 // The default constructor is required by Jackson to deserialize JSON object
2931 public ObjectStorageTableMetadata () {
30- this (null , null , null , null , null );
32+ this (null , null , null , null , null , null );
3133 }
3234
3335 public ObjectStorageTableMetadata (
3436 @ Nullable LinkedHashSet <String > partitionKeyNames ,
3537 @ Nullable LinkedHashSet <String > clusteringKeyNames ,
3638 @ Nullable Map <String , String > clusteringOrders ,
3739 @ Nullable Set <String > secondaryIndexNames ,
38- @ Nullable Map <String , String > columns ) {
40+ @ Nullable Map <String , String > columns ,
41+ @ Nullable Integer version ) {
3942 this .partitionKeyNames =
4043 partitionKeyNames != null ? new LinkedHashSet <>(partitionKeyNames ) : new LinkedHashSet <>();
4144 this .clusteringKeyNames =
@@ -47,9 +50,10 @@ public ObjectStorageTableMetadata(
4750 this .secondaryIndexNames =
4851 secondaryIndexNames != null ? new HashSet <>(secondaryIndexNames ) : Collections .emptySet ();
4952 this .columns = columns != null ? new HashMap <>(columns ) : Collections .emptyMap ();
53+ this .version = version != null ? version : DEFAULT_VERSION ;
5054 }
5155
52- public ObjectStorageTableMetadata (TableMetadata tableMetadata ) {
56+ public ObjectStorageTableMetadata (TableMetadata tableMetadata , Integer version ) {
5357 Map <String , String > clusteringOrders =
5458 tableMetadata .getClusteringKeyNames ().stream ()
5559 .collect (
@@ -67,6 +71,11 @@ public ObjectStorageTableMetadata(TableMetadata tableMetadata) {
6771 this .clusteringOrders = clusteringOrders ;
6872 this .secondaryIndexNames = tableMetadata .getSecondaryIndexNames ();
6973 this .columns = columnTypeByName ;
74+ this .version = version ;
75+ }
76+
77+ public ObjectStorageTableMetadata (TableMetadata tableMetadata ) {
78+ this (tableMetadata , DEFAULT_VERSION );
7079 }
7180
7281 private ObjectStorageTableMetadata (Builder builder ) {
@@ -75,7 +84,8 @@ private ObjectStorageTableMetadata(Builder builder) {
7584 builder .clusteringKeyNames ,
7685 builder .clusteringOrders ,
7786 builder .secondaryIndexNames ,
78- builder .columns );
87+ builder .columns ,
88+ builder .version );
7989 }
8090
8191 public LinkedHashSet <String > getPartitionKeyNames () {
@@ -98,6 +108,10 @@ public Map<String, String> getColumns() {
98108 return columns ;
99109 }
100110
111+ public Integer getVersion () {
112+ return version ;
113+ }
114+
101115 @ Override
102116 public boolean equals (Object o ) {
103117 if (this == o ) {
@@ -111,13 +125,19 @@ public boolean equals(Object o) {
111125 && Objects .equals (clusteringKeyNames , that .clusteringKeyNames )
112126 && Objects .equals (clusteringOrders , that .clusteringOrders )
113127 && Objects .equals (secondaryIndexNames , that .secondaryIndexNames )
114- && Objects .equals (columns , that .columns );
128+ && Objects .equals (columns , that .columns )
129+ && Objects .equals (version , that .version );
115130 }
116131
117132 @ Override
118133 public int hashCode () {
119134 return Objects .hash (
120- partitionKeyNames , clusteringKeyNames , clusteringOrders , secondaryIndexNames , columns );
135+ partitionKeyNames ,
136+ clusteringKeyNames ,
137+ clusteringOrders ,
138+ secondaryIndexNames ,
139+ columns ,
140+ version );
121141 }
122142
123143 public TableMetadata toTableMetadata () {
@@ -169,6 +189,7 @@ public static final class Builder {
169189 private Map <String , String > clusteringOrders ;
170190 private Set <String > secondaryIndexNames ;
171191 private Map <String , String > columns ;
192+ private Integer version ;
172193
173194 private Builder () {}
174195
@@ -197,6 +218,11 @@ public ObjectStorageTableMetadata.Builder columns(Map<String, String> val) {
197218 return this ;
198219 }
199220
221+ public ObjectStorageTableMetadata .Builder version (Integer val ) {
222+ version = val ;
223+ return this ;
224+ }
225+
200226 public ObjectStorageTableMetadata build () {
201227 return new ObjectStorageTableMetadata (this );
202228 }
0 commit comments