怎樣解析hbaseORMsimplehbasev0.7

本篇文章為大家展示了怎樣解析hbase ORM simplehbase v0.7,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

創(chuàng)新互聯(lián)公司從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元保山做網(wǎng)站,已為上家服務(wù),為保山各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575


### v0.7新增功能:
支持查詢時(shí)主記錄和關(guān)聯(lián)的RowKey同時(shí)返回。

由于github不穩(wěn)定,使用說明附在文檔后面。

## simplehbase簡介
simplehbase是java和hbase之間的輕量級中間件。
主要包含以下功能。
*  數(shù)據(jù)類型映射:java類型和hbase的bytes之間的數(shù)據(jù)轉(zhuǎn)換。
*  簡單操作封裝:封裝了hbase的put,get,scan等操作為簡單的java操作方式。
*  hbase query封裝:封裝了hbase的filter,可以使用sql-like的方式操作hbase。
*  動(dòng)態(tài)query封裝:類似于myibatis,可以使用xml配置動(dòng)態(tài)語句查詢hbase。
*  insert,update支持: 建立在hbase的checkAndPut之上。
*  hbase多版本支持:提供接口可以對hbase多版本數(shù)據(jù)進(jìn)行查詢,映射。
*  hbase原生接口支持。


## simplehbase示例(SampleMain.java)

### 使用simplehbaseclient操作hbase

        SimpleHbaseClient simpleHbaseClient = getSimpleHbaseClient();

        //insert one record.
        Person one = new Person();
        one.setId(1);
        one.setName("allen");
        one.setAge(30);
        one.setGender(Gender.MALE);
        simpleHbaseClient.putObject(new PersonRowKey(1), one);

        //insert another record.
        Person two = new Person();
        two.setId(2);
        two.setName("dan");
        two.setAge(31);
        two.setGender(Gender.FEMALE);
        simpleHbaseClient.putObject(new PersonRowKey(2), two);

        //search by row key.
        Person result = simpleHbaseClient.findObject(new PersonRowKey(1),
                Person.class);
        log.info(result);

        //search by range.
        List<Person> resultList = simpleHbaseClient.findObjectList(
                new PersonRowKey(1), new PersonRowKey(3), Person.class);
        log.info(resultList);

        //HQL query.
        Map<String, Object> para = new HashMap<String, Object>();
        para.put("id", 1);
        resultList = simpleHbaseClient.findObjectList(new PersonRowKey(1),
                new PersonRowKey(3), Person.class, "queryById", para);
        log.info(resultList);

        //dynamic HQL.
        para.put("name", "allen");
        para.put("age", 0);
        resultList = simpleHbaseClient.findObjectList(new PersonRowKey(1),
                new PersonRowKey(3), Person.class, "queryByNameAndAge", para);
        log.info(resultList);

        //batch delete.
        simpleHbaseClient.deleteObjectList(new PersonRowKey(0),
                new PersonRowKey(100), Person.class);




### 初始化simplehbase


        HBaseDataSource hbaseDataSource = new HBaseDataSource();

        List<Resource> hbaseConfigResources = new ArrayList<Resource>();
        //If run on hbase cluster, modify the following config files.
        //If run on hbase stand alone mode, comment out the following config files.
        hbaseConfigResources.add(new CachedFileSystemResource(
                "sample\\hbase_site"));
        hbaseConfigResources
                .add(new CachedFileSystemResource("sample\\zk_conf"));
        hbaseDataSource.setHbaseConfigResources(hbaseConfigResources);

        hbaseDataSource.init();

        HBaseTableConfig hbaseTableConfig = new HBaseTableConfig();
        //simplehbase config file.
        hbaseTableConfig.setConfigResource(new CachedFileSystemResource(
                "sample\\myRecord.xml"));

        hbaseTableConfig.init();

        SimpleHbaseClient tClient = new SimpleHbaseClientImpl();
        tClient.setHbaseDataSource(hbaseDataSource);
        tClient.setHbaseTableConfig(hbaseTableConfig);

        return tClient;
 
   
### simplehbase配置xml
包含htable的配置和2個(gè)動(dòng)態(tài)查詢的配置
<SimpleHbase>

    <HBaseTableSchema tableName="MyRecordV05" defaultFamily="MyRecordFamily">
        <HBaseColumnSchema qualifier="id" typeName="int" />
        <HBaseColumnSchema qualifier="name" typeName="string" />
        <HBaseColumnSchema qualifier="date" typeName="date" />
        <HBaseColumnSchema qualifier="gender" typeName="allen.sample.Gender" />
        <HBaseColumnSchema qualifier="age" typeName="int" />
    </HBaseTableSchema>
   
   
    <statements>   
        
        <statement id="queryByNameAndAge">
            select where id greaterequal #id#
            <isPropertyAvailable prepend="and" property="name">
                name equal #name#
            </isPropertyAvailable>
            <isPropertyAvailable prepend="and" property="age">
                age greater #age#
            </isPropertyAvailable>
        </statement>   
        
        <statement id="queryById">
            select where id equal #id#            
        </statement>            
               
    </statements>   
</SimpleHbase>     

### 定義DO對象
    @HBaseTable(defaultFamily = "MyRecordFamily")
    public class Person {
        @HBaseColumn(qualifier = "id")
        private int    id;
        @HBaseColumn(qualifier = "name")
        private String name;
        @HBaseColumn(qualifier = "date")
        private Date   date;
        @HBaseColumn(qualifier = "gender")
        private Gender gender;
        @HBaseColumn(qualifier = "age")
        private int    age;
    }

### 定義該DO對象對應(yīng)的rowkey
    public class PersonRowKey implements RowKey {
   
        private int row;
   
        public PersonRowKey(int row) {
            this.row = row;
        }
   
        @Override
        public byte[] toBytes() {
            return Bytes.toBytes(row);
        }
    }

##simphbase simplehbaseviewer使用說明

### simplehbase/simplehbaseviewer版本
0.5.1 / 0.6 / 0.7

### jdk
jdk/jre 1.6

### maven
maven2

### 代碼下載
最新simplehbase代碼下載。
https://github.com/zhang-xzhi/simplehbase
右下角的download zip。

帶版本的simplehbase版本下載。
https://github.com/zhang-xzhi/simplehbase/releases

最新simplehbaseviewer代碼下載。
https://github.com/zhang-xzhi/simplehbaseviewer
右下角的download zip。

帶版本的simplehbaseviewer版本下載。
https://github.com/zhang-xzhi/simplehbaseviewer/releases

### Simplehbase本地驗(yàn)證
代碼下載后,mvn eclipse:eclipse后導(dǎo)入eclipse。
運(yùn)行simplehbase的test。(Junit)

目前simplehbase默認(rèn)的測試環(huán)境為

    hbase.zookeeper.quorum=hbdev-1.alipay.net,hbdev-2.alipay.net,hbdev-3.alipay.net,hbdev-4.alipay.net,hbdev-5.alipay.net
    hbase.zookeeper.property.clientPort=2181
    zookeeper.znode.parent=/hbase-94

* 1 若無法連接,修改test/zk_conf文件(集成測試使用,修改sample/zk_conf文件(樣例程序使用)。
* 2 建測試表。運(yùn)行CreateTestTable, 新建MyRecordV05表。
* 3 建表成功后,重新運(yùn)行test,后續(xù)運(yùn)行,不需要重新建立測試表。
* 4 新增htable的配置,請參考既有表的配置。

### Simplehbaseviewer本地驗(yàn)證
安裝simplehbase到本地倉庫。
在simplehbase項(xiàng)目中,mvn install。

simplehbaseviewer代碼下載后,mvn eclipse:eclipse后導(dǎo)入eclipse。

運(yùn)行Main。

訪問http://localhost:4040/hbaseviewer/
看simplehbaseview是否啟動(dòng)正常。

目前simplehbaseviewer默認(rèn)的測試環(huán)境為

    hbase.zookeeper.quorum=hbdev-1.alipay.net,hbdev-2.alipay.net,hbdev-3.alipay.net,hbdev-4.alipay.net,hbdev-5.alipay.net
    hbase.zookeeper.property.clientPort=2181
    zookeeper.znode.parent=/hbase-94

* 1 若無法連接,修改config/zk_conf文件。
* 2 建測試表。運(yùn)行CreateTestTable, 新建MyRecordV05表。
* 3 建表成功后,重新運(yùn)行Main。

### Simplehbase jar包依賴
pom依賴,請參考simplehbase的pom文件。

其中,hadoop和hbase可以修改為目前集團(tuán)hbase使用的版本。

Simplehbase開發(fā)測試過程中使用的hbase版本為0.94.0。

理論上,hbase0.92也可以使用,但是未經(jīng)測試,可以跑test進(jìn)行測試。

### Simplehbaseclient配置
SimpleHbaseClient為simplehbase的核心接口。

Java方式配置可以參考simplehbase的SampleMain。

Spring方式配置可以參考simplehbaseviewer的
\hbaseviewer\WEB-INF\spring\simplehbase.xml

上述內(nèi)容就是怎樣解析hbase ORM simplehbase v0.7,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)頁題目:怎樣解析hbaseORMsimplehbasev0.7
鏈接URL:http://muchs.cn/article16/gjgcgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄網(wǎng)站內(nèi)鏈、用戶體驗(yàn)App設(shè)計(jì)、網(wǎng)站導(dǎo)航小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作