作用
- 可以创建一个连接实例(利用HbaseConfig
- 返回一个Connection对象
-典型用法
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("mytable"));
try {
table.get(...);
...
} finally {
table.close();
connection.close();
}
ConnectionFactory有四个静态方法,返回值为Connection对象.
创建Connection对象.Connection对象可以获取客户端对象Admin以及Table对象,如下图
Admin对象
The administrative API for HBase. Obtain an instance from an Connection.getAdmin() and call close() afterwards. Admin can be used to create, drop, list, enable and disable tables, add and drop table column families and other administrative operations.
admin可以做什么呢?
- 创建表格
public abstract void createTable(org.apache.hadoop.hbase.HTableDescriptor desc)
throws java.io.IOException
- 添加列簇
public abstract void addColumn(org.apache.hadoop.hbase.TableName tableName,
org.apache.hadoop.hbase.HColumnDescriptor column)
throws java.io.IOException
修改列簇
public abstract void modifyColumn(org.apache.hadoop.hbase.TableName tableName,
org.apache.hadoop.hbase.HColumnDescriptor descriptor)
throws java.io.IOException
删除CF
public abstract void deleteColumn(org.apache.hadoop.hbase.TableName tableName,
byte[] columnName)
throws java.io.IOException
列出所有表
public abstract org.apache.hadoop.hbase.TableName[] listTableNames()
throws java.io.IOException
删除表
public abstract void deleteTable(org.apache.hadoop.hbase.TableName tableName)
throws java.io.IOException