com.flipkart.hbaseobjectmapper.AsyncHBAdmin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbase-object-mapper Show documentation
Show all versions of hbase-object-mapper Show documentation
HBase ORM is a light-weight, thread-safe and performant library that enables:
[1] object-oriented access of HBase rows (Data Access Object) with minimal code and good testability.
[2] reading from and/or writing to HBase tables in Hadoop MapReduce jobs.
This can also be used as an ORM for Bigtable.
The newest version!
package com.flipkart.hbaseobjectmapper;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.client.AsyncConnection;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
class AsyncHBAdmin implements HBAdmin {
private final AsyncConnection connection;
AsyncHBAdmin(final AsyncConnection connection) {
this.connection = connection;
}
@Override
public void createNamespace(String namespace) {
connection.getAdmin().createNamespace(
NamespaceDescriptor.create(namespace).build())
.join();
}
@Override
public , T extends HBRecord> void createTable(Class hbRecordClass) throws IOException {
WrappedHBTable wrappedHBTable = new WrappedHBTable<>(hbRecordClass);
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(wrappedHBTable.getName());
for (Map.Entry e : wrappedHBTable.getFamiliesAndVersions().entrySet()) {
tableDescriptorBuilder.setColumnFamily(
ColumnFamilyDescriptorBuilder.newBuilder(
Bytes.toBytes(e.getKey())
).setMaxVersions(e.getValue()).build());
}
connection.getAdmin().createTable(tableDescriptorBuilder.build())
.join();
}
@Override
public , T extends HBRecord> void deleteTable(Class hbRecordClass) throws IOException {
WrappedHBTable wrappedHBTable = new WrappedHBTable<>(hbRecordClass);
connection.getAdmin().deleteTable(wrappedHBTable.getName())
.join();
}
@Override
public , T extends HBRecord> void enableTable(Class hbRecordClass) throws IOException {
WrappedHBTable wrappedHBTable = new WrappedHBTable<>(hbRecordClass);
connection.getAdmin().enableTable(wrappedHBTable.getName())
.join();
}
@Override
public , T extends HBRecord> void disableTable(Class hbRecordClass) throws IOException {
WrappedHBTable wrappedHBTable = new WrappedHBTable<>(hbRecordClass);
connection.getAdmin().disableTable(wrappedHBTable.getName())
.join();
}
@Override
public , T extends HBRecord> boolean tableExists(Class hbRecordClass) throws IOException {
WrappedHBTable wrappedHBTable = new WrappedHBTable<>(hbRecordClass);
return connection.getAdmin().tableExists(wrappedHBTable.getName())
.join();
}
}