package com.felix.hbaseapi_test;

 /*   
这是旧版的 API操作
*/
public class hbaseapifelix { public static final String TABLE_NAME = "testapi";
public static final String COLUMNFAMILY_NAME = "cf";
public static final String ROW_KEY = "rowkey1"; public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin=new HBaseAdmin(conf);
createtable(admin);
HTable htable=new HTable(conf, TABLE_NAME); put(htable,"age","25");
put(htable,"age","26");
put(htable,"age","27");
put(htable,"age","28"); //Get
Get get=new Get(ROW_KEY.getBytes());
htable.get(get); //scan
Scan scan=new Scan();
ResultScanner scanner = htable.getScanner(scan);
} private static void put(HTable htable,String column,String value) throws IOException {
Put put=new Put(ROW_KEY.getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), column.getBytes(), value.getBytes());
htable.put(put);
} private static void createtable(HBaseAdmin admin) throws IOException {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor family = new HColumnDescriptor(COLUMNFAMILY_NAME);
desc.addFamily(family);
family.setMaxVersions(3);
if (!admin.tableExists(TABLE_NAME)) {
//该表不存在,直接创建
admin.createTable(desc);
}else{
//该表存在,删除后再创建
if(!admin.isTableAvailable(TABLE_NAME)){
//该表disable,直接删除
admin.deleteTable(TABLE_NAME);
}else{
//该表enable,先disable,再删除
admin.disableTable(TABLE_NAME);
admin.deleteTable(TABLE_NAME);
}
admin.createTable(desc);
}
} }
 
 package com.felix.hbaseapi_test;

 import java.io.IOException;

 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.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table; public class hbaseapifelix { public static final String TABLE_NAME = "testapi";
public static final String COLUMNFAMILY_NAME = "cf";
public static final String ROW_KEY = "rowkey1"; public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
//下面的配置,在configuration文件中都配置过了这里没必要配置,也不方便
//conf.set("hbase.rootdir", "hdfs://centos:9000/hbase");
//conf.set("hbase.zookeeper.quorum","centos");
//conf.set("hbase.zookeeper.property.clientPort", "2181"); Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin();
Table table = connection.getTable(TableName.valueOf("user"));
TableName name = table.getName(); initBeforeCreate(admin, name);
createTable(admin, table); try {
Put put=new Put("rowkey".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "25".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "26".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "27".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "28".getBytes());
table.put(put);
} finally {
table.close();
connection.close();
} Get get = new Get(ROW_KEY.getBytes());
Result result = table.get(get); Scan scan=new Scan();
ResultScanner scanner = table.getScanner(scan); /* HBaseAdmin admin=new HBaseAdmin(conf);
createtable(admin); HTable htable=new HTable(conf, TABLE_NAME); put(htable,"age","25");
put(htable,"age","26");
put(htable,"age","27");
put(htable,"age","28"); //Get
Get get=new Get(ROW_KEY.getBytes());
htable.get(get); //scan
Scan scan=new Scan();
ResultScanner scanner = htable.getScanner(scan);*/
} private static void initBeforeCreate(Admin admin, TableName name)
throws IOException {
/*创建前存在就删除
* */
if(admin.tableExists(name)){
if(admin.isTableEnabled(name)){
admin.disableTable(name);
}
admin.deleteTable(name);
}
} private static void createTable(Admin admin, Table table)
throws IOException {
HTableDescriptor desc=new HTableDescriptor(table.getName());
HColumnDescriptor family=new HColumnDescriptor(COLUMNFAMILY_NAME);
family.setMaxVersions(3);
family.setMinVersions(0);
desc.addFamily(family);
admin.createTable(desc);
} /*private static void put(HTable htable,String column,String value) throws IOException {
Put put=new Put(ROW_KEY.getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), column.getBytes(), value.getBytes());
htable.put(put);
} private static void createtable(HBaseAdmin admin) throws IOException {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor family = new HColumnDescriptor(COLUMNFAMILY_NAME);
desc.addFamily(family);
family.setMaxVersions(3);
if (!admin.tableExists(TABLE_NAME)) {
//该表不存在,直接创建
admin.createTable(desc);
}else{
//该表存在,删除后再创建
if(!admin.isTableAvailable(TABLE_NAME)){
//该表disable,直接删除
admin.deleteTable(TABLE_NAME);
}else{
//该表enable,先disable,再删除
admin.disableTable(TABLE_NAME);
admin.deleteTable(TABLE_NAME);
}
admin.createTable(desc);
}
}*/ }

具体改成什么了,以及为什么修改,源码里面说的很清楚,比如:

HBaseAdmin is no longer a client API. It is marked InterfaceAudience.Private indicating that
* this is an HBase-internal class as defined in
* https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/InterfaceClassification.html
* There are no guarantees for backwards source / binary compatibility and methods or class can
* change or go away without deprecation.
* Use {@link Connection#getAdmin()} to obtain an instance of {@link Admin} instead of constructing
* an HBaseAdmin directly.

其他的自己关联源码自己看吧!

HBase1.0.1.1 API与原来有所不同的更多相关文章

  1. Hbase1.0 客户端api

    最近在试用Hbase1.0的客户端API,发觉变化还是挺大(以前版本也不熟).到处都是deprecated. 现在应该是这样子: Configuration  conf = HBaseConfigur ...

  2. HBase1.0以上版本的API改变

    HBase1.0以上版本已经废弃了 HTableInterface,HTable,HBaseAdmin等API的使用,新增了一些API来实现之前的功能: Connectioninterface: Co ...

  3. HBase1.0以上版本号的API改变

    HBase1.0以上版本号已经废弃了 HTableInterface,HTable,HBaseAdmin等API的使用.新增了一些API来实现之前的功能: Connectioninterface: C ...

  4. ElasticSearch 5.0.1 java API操作

    今天来说下使用ES 5.0.1的API来进行编码. 开始之前,简单说下5.0.1跟之前的几个变化.之前的ES自身是不支持delete-by-query的,也就是通过查询来删除,可以达到批量的效果,是因 ...

  5. hadoop: hbase1.0.1.1 伪分布安装

    环境:hadoop 2.6.0 + hbase 1.0.1.1 + mac OS X yosemite 10.10.3 安装步骤: 一.下载解压 到官网 http://hbase.apache.org ...

  6. 使用OAuth2.0访问豆瓣API

    如何计算某个用户的access_token过期时间?开发者可以通过两种方式计算:用户授权时,oauth2/access_token接口返回的expires_in值就是access_token的生命周期 ...

  7. Android 8.0 功能和 API

    Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...

  8. laravel Passport - 创建 REST API 用户认证以及Dingo/Api v2.0+Passport实现api认证

    第一部分: 安装passport 使⽤ Composer 依赖包管理器安装 Passport : composer require laravel/passport 接下来,将 Passport 的服 ...

  9. Web3.js 0.20.x API 中文版翻译

    文档原始链接为:https://web3.learnblockchain.cn/0.2x.x/,欢迎大家前往查阅,本文只是节选开头部分的介绍及API列表索引,以下为翻译正文: 为了开发一个基于以太坊的 ...

随机推荐

  1. Android RecyclerView预览item

    参考: Android Tools Attributes listItem 和 Sample Data 的用法 笔记 tools:text TextView可以实现预览,不影响实际的效果 例如: to ...

  2. JSJ—类与对象

    当你在设计类时,要记得对象时靠类的模型塑造出来的,你可以这样看: ——对象是已知事物 ——对象会执行的动作 对象本身已知的事物称为实例变量,它们代表对象的状态(数据),且该类型的每一个对象都会独立的拥 ...

  3. Java学习笔记之——单例模式

      (1)懒汉式:对象在方法中,第一次调用时创建对象,线程不安全的 public class Singleton { //外部不可以创建对象,就要在内部创建一个对象,还能够在外部获取 private ...

  4. python基础学习(十)字符串

    字符串的定义 字符串 就是 一串字符,是编程语言中表示文本的数据类型 在 Python 中可以使用 一对双引号 " 或者 一对单引号 ' 定义一个字符串 虽然可以使用 \" 或者 ...

  5. nginx比apache处理静态文件速度快,但是nginx处理大量并发的php请求时,容易出现502错误,频率大概是多少

    首先要明确一点的是502是怎么出现的,为什么会出现502呢? 一般而言,出现502的错误是因为php-cgi连接数不够导致的.举个例子:php-cgi开10个进程,前端发20个请求,每个请求的脚本都s ...

  6. #WEB安全基础 : HTML/CSS | 0x3文件夹管理网站

    没有头脑的管理方式会酿成大灾难,应该使用文件夹管理网站 这是一个典型的管理方法,现在传授给你,听好了 下面是0x3初识a标签里使用的网站的目录,我把它重新配置了一下

  7. select2 插件加载后端数据

    //html <select class="form-group form-control" name="roomId" id="roomLis ...

  8. c#无边框窗体移动

    [DllImport("user32.dll")]//拖动无窗体的控件 public static extern bool ReleaseCapture(); [DllImport ...

  9. C#基础(204)--对象初始化器,基本数据类型与引用数据类型特点总结,ref,out关键字的使用

    对象初始化器: 对象在创建过程中也可以使用对象初始化器完成“属性的初始化” Student stu =new Student(){ StudentId=, StudentName="张三&q ...

  10. 【机器学习基本理论】详解最大后验概率估计(MAP)的理解

    [机器学习基本理论]详解最大后验概率估计(MAP)的理解 https://blog.csdn.net/weixin_42137700/article/details/81628065 最大似然估计(M ...