亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2019 | 回復(fù): 0
打印 上一主題 下一主題

[HBase] [HBase] hbase ORM simplehbase v0.6簡介 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-03-27 00:08 |只看該作者 |倒序瀏覽
https://github.com/zhang-xzhi/simplehbase/
https://github.com/zhang-xzhi/simplehbase/wiki


simplehbase是java和hbase之間的輕量級中間件。
主要包含以下功能。
*  數(shù)據(jù)類型映射:java類型和hbase的bytes之間的數(shù)據(jù)轉(zhuǎn)換。
*  簡單操作封裝:封裝了hbase的put,get,scan等操作為簡單的java操作方式。
*  hbase query封裝:封裝了hbase的filter,可以使用sql-like的方式操作hbase。
*  動態(tài)query封裝:類似于myibatis,可以使用xml配置動態(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個動態(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本地驗證
代碼下載后,mvn eclipse:eclipse后導(dǎo)入eclipse。
運行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 建測試表。運行CreateTestTable, 新建MyRecordV05表。
* 3 建表成功后,重新運行test,后續(xù)運行,不需要重新建立測試表。
* 4 新增htable的配置,請參考既有表的配置。

### Simplehbaseviewer本地驗證
安裝simplehbase到本地倉庫。
在simplehbase項目中,mvn install。

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

運行Main。

訪問http://localhost:4040/hbaseviewer/
看simplehbaseview是否啟動正常。

目前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 建測試表。運行CreateTestTable, 新建MyRecordV05表。
* 3 建表成功后,重新運行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

如何配置可以參考或直接查看代碼:
https://github.com/zhang-xzhi/si ... -%E9%85%8D%E7%BD%AE

### doc
* https://github.com/zhang-xzhi/simplehbase/wiki
* https://github.com/zhang-xzhi/simplehbaseviewer/wiki
* simplehbase下載后simplehbase\doc
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP