1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.io.hfile;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.HConstants;
22 import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
23 import org.apache.hadoop.hbase.io.crypto.Encryption;
24 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25 import org.apache.hadoop.hbase.util.ChecksumType;
26
27
28
29
30 @InterfaceAudience.Private
31 public class HFileContextBuilder {
32
33 public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
34
35
36 private boolean usesHBaseChecksum = true;
37
38 private boolean includesMvcc = true;
39
40 private boolean includesTags = false;
41
42 private Algorithm compression = Algorithm.NONE;
43
44 private boolean compressTags = false;
45
46 private ChecksumType checksumType = ChecksumType.getDefaultChecksumType();
47
48 private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
49
50 private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
51 private DataBlockEncoding encoding = DataBlockEncoding.NONE;
52
53 private Encryption.Context cryptoContext = Encryption.Context.NONE;
54 private long fileCreateTime = 0;
55
56 private String hfileName = null;
57 private byte[] columnFamily = null;
58 private byte[] tableName = null;
59
60 public HFileContextBuilder() {}
61
62
63
64
65 public HFileContextBuilder(final HFileContext hfc) {
66 this.usesHBaseChecksum = hfc.isUseHBaseChecksum();
67 this.includesMvcc = hfc.isIncludesMvcc();
68 this.includesTags = hfc.isIncludesTags();
69 this.compression = hfc.getCompression();
70 this.compressTags = hfc.isCompressTags();
71 this.checksumType = hfc.getChecksumType();
72 this.bytesPerChecksum = hfc.getBytesPerChecksum();
73 this.blocksize = hfc.getBlocksize();
74 this.encoding = hfc.getDataBlockEncoding();
75 this.cryptoContext = hfc.getEncryptionContext();
76 this.fileCreateTime = hfc.getFileCreateTime();
77 this.hfileName = hfc.getHFileName();
78 this.columnFamily = hfc.getColumnFamily();
79 this.tableName = hfc.getTableName();
80 }
81
82 public HFileContextBuilder withHBaseCheckSum(boolean useHBaseCheckSum) {
83 this.usesHBaseChecksum = useHBaseCheckSum;
84 return this;
85 }
86
87 public HFileContextBuilder withIncludesMvcc(boolean includesMvcc) {
88 this.includesMvcc = includesMvcc;
89 return this;
90 }
91
92 public HFileContextBuilder withIncludesTags(boolean includesTags) {
93 this.includesTags = includesTags;
94 return this;
95 }
96
97 public HFileContextBuilder withCompression(Algorithm compression) {
98 this.compression = compression;
99 return this;
100 }
101
102 public HFileContextBuilder withCompressTags(boolean compressTags) {
103 this.compressTags = compressTags;
104 return this;
105 }
106
107 public HFileContextBuilder withChecksumType(ChecksumType checkSumType) {
108 this.checksumType = checkSumType;
109 return this;
110 }
111
112 public HFileContextBuilder withBytesPerCheckSum(int bytesPerChecksum) {
113 this.bytesPerChecksum = bytesPerChecksum;
114 return this;
115 }
116
117 public HFileContextBuilder withBlockSize(int blockSize) {
118 this.blocksize = blockSize;
119 return this;
120 }
121
122 public HFileContextBuilder withDataBlockEncoding(DataBlockEncoding encoding) {
123 this.encoding = encoding;
124 return this;
125 }
126
127 public HFileContextBuilder withEncryptionContext(Encryption.Context cryptoContext) {
128 this.cryptoContext = cryptoContext;
129 return this;
130 }
131
132 public HFileContextBuilder withCreateTime(long fileCreateTime) {
133 this.fileCreateTime = fileCreateTime;
134 return this;
135 }
136
137 public HFileContextBuilder withHFileName(String name) {
138 this.hfileName = name;
139 return this;
140 }
141
142 public HFileContextBuilder withColumnFamily(byte[] columnFamily){
143 this.columnFamily = columnFamily;
144 return this;
145 }
146
147 public HFileContextBuilder withTableName(byte[] tableName){
148 this.tableName = tableName;
149 return this;
150 }
151
152 public HFileContext build() {
153 return new HFileContext(usesHBaseChecksum, includesMvcc, includesTags, compression,
154 compressTags, checksumType, bytesPerChecksum, blocksize, encoding, cryptoContext,
155 fileCreateTime, hfileName, columnFamily, tableName);
156 }
157 }