View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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 }