1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.transaction;
19
20 import static com.google.common.base.Charsets.UTF_8;
21
22 import org.apache.omid.tso.client.CellId;
23
24 import org.apache.phoenix.thirdparty.com.google.common.hash.Hasher;
25 import org.apache.phoenix.thirdparty.com.google.common.hash.Hashing;
26
27 public class HBaseCellId implements CellId {
28
29 private final TTable table;
30 private final byte[] row;
31 private final byte[] family;
32 private final byte[] qualifier;
33 private long timestamp;
34
35 public HBaseCellId(TTable table, byte[] row, byte[] family, byte[] qualifier, long timestamp) {
36 this.timestamp = timestamp;
37 this.table = table;
38 this.row = row;
39 this.family = family;
40 this.qualifier = qualifier;
41 }
42
43 public TTable getTable() {
44 return table;
45 }
46
47 public byte[] getRow() {
48 return row;
49 }
50
51 public byte[] getFamily() {
52 return family;
53 }
54
55 public byte[] getQualifier() {
56 return qualifier;
57 }
58
59 public long getTimestamp() {
60 return timestamp;
61 }
62
63 @Override
64 public String toString() {
65 return new String(table.getTableName(), UTF_8)
66 + ":" + new String(row, UTF_8)
67 + ":" + new String(family, UTF_8)
68 + ":" + new String(qualifier, UTF_8)
69 + ":" + timestamp;
70 }
71
72 @Override
73 public long getCellId() {
74 return getHasher()
75 .putBytes(table.getTableName())
76 .putBytes(row)
77 .putBytes(family)
78 .putBytes(qualifier)
79 .hash().asLong();
80 }
81
82 @Override
83 public long getTableId() {
84 return getHasher()
85 .putBytes(table.getTableName())
86 .hash().asLong();
87 }
88
89 @Override
90 public long getRowId() {
91 return getHasher()
92 .putBytes(table.getTableName())
93 .putBytes(row)
94 .hash().asLong();
95 }
96
97 public static Hasher getHasher() {
98 return Hashing.murmur3_128().newHasher();
99 }
100 }