How to use Hbase 1.0 Java API

58 views
Skip to first unread message

manish mandora

unread,
Sep 29, 2015, 7:20:10 AM9/29/15
to Async HBase
hello frnds,
i'm new in Hbase.and I have to update the version of Hbase 1.0
this is my code

//==============================================

package org.reducedata.reporter.hbase.Table;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;


public abstract class HBaseTable
{
protected static final Logger LOG = LoggerFactory.getLogger(HBaseTable.class);

protected static final HTablePool TABLE_POOL = new HTablePool();

protected synchronized void create() {
final Configuration conf = HBaseConfiguration.create();
try (final HBaseAdmin admin = new HBaseAdmin(conf)) {
if (!admin.tableExists(this.getTableName())) {
final HTableDescriptor desc = new HTableDescriptor(this.getTableName());
for (final String family : this.getColumnFamilies()) {
desc.addFamily(new HColumnDescriptor(family));
}
admin.createTable(desc);
LOG.info("HBaseTable={} created.", this.getTableName());
}
} catch (final Exception e) {
LOG.error("Error creating HBase tables with HBaseAdmin. error={}", e.getLocalizedMessage());
LOG.debug(Arrays.toString(e.getStackTrace()));
e.printStackTrace();
}
}

protected abstract HTableInterface getTable();

protected abstract String getTableName();

protected abstract String[] getColumnFamilies();


}

//==============================================

package org.reducedata.reporter.hbase.Table;

import org.apache.hadoop.hbase.client.HTableInterface;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* Created by manish on 7/8/15.
*/
public class UserProfileTable extends HBaseTable
{

private static final UserProfileTable INSTANCE = new UserProfileTable();
private static final AtomicBoolean STARTED = new AtomicBoolean(false);

public static synchronized UserProfileTable getInstance() {
return INSTANCE;
}
@Override
public HTableInterface getTable()
{
if (!STARTED.getAndSet(true)) {
this.create();
LOG.info("HBaseTable={} created.", getClass().getSimpleName());
}
return TABLE_POOL.getTable(this.getTableName());

}

@Override
public String getTableName() {
return "user_profile";
}

@Override
public String[] getColumnFamilies() {
return new String[]{"users","demographic"};
}
}




can u help me to update the code of hbase 1.0

Reply all
Reply to author
Forward
0 new messages