Return-Path: X-Original-To: apmail-hbase-user-archive@www.apache.org Delivered-To: apmail-hbase-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D17710209 for ; Sun, 5 Jan 2014 16:40:35 +0000 (UTC) Received: (qmail 95382 invoked by uid 500); 5 Jan 2014 16:40:18 -0000 Delivered-To: apmail-hbase-user-archive@hbase.apache.org Received: (qmail 95344 invoked by uid 500); 5 Jan 2014 16:40:17 -0000 Mailing-List: contact user-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hbase.apache.org Delivered-To: mailing list user@hbase.apache.org Received: (qmail 95335 invoked by uid 99); 5 Jan 2014 16:40:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jan 2014 16:40:15 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_FILL_THIS_FORM_SHORT,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of yuzhihong@gmail.com designates 209.85.215.46 as permitted sender) Received: from [209.85.215.46] (HELO mail-la0-f46.google.com) (209.85.215.46) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jan 2014 16:40:11 +0000 Received: by mail-la0-f46.google.com with SMTP id eh20so9156942lab.5 for ; Sun, 05 Jan 2014 08:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Y9nk8Ch9Kfnu0UeE8iakLFbRugzemAUqSIO32/liSKE=; b=qY4z+jgdnqCXJaceGYOMeuZaBJ8SFhYSA4cADZcXLGrZxPOgy/XT39C7Uz9Rtj2u4u nawTg7d8XpXvM308qzxtRn53iHnS16fyMI8Z8T50p6IAPFZveKHjLGe3wHc0WkoYe/Nl YEUlqPZHysCmpifa5viSAqD9R69X1a5iynpv/vQ0dneAIZ2EFuZQgWX8Xi1l63HwUoKr aIMDelrGd+Rb4fNXrygQhpjUP4apQp4I4ppQAlBNJhIgP1mvLhaG11t0P6Ab6jGvn/cK V2USc9stlyh1dvyqSMVlrC+Xe6v6f0UWVaqrrM633e9lR7cR3YtTiKA52vEaaybtA1a8 7PfQ== MIME-Version: 1.0 X-Received: by 10.112.169.66 with SMTP id ac2mr6262979lbc.28.1388939989377; Sun, 05 Jan 2014 08:39:49 -0800 (PST) Received: by 10.112.183.231 with HTTP; Sun, 5 Jan 2014 08:39:49 -0800 (PST) In-Reply-To: <1388937502834-4054488.post@n3.nabble.com> References: <1388937502834-4054488.post@n3.nabble.com> Date: Sun, 5 Jan 2014 08:39:49 -0800 Message-ID: Subject: Re: a short introduction of simplehbase(hbase ORM) From: Ted Yu To: "user@hbase.apache.org" Content-Type: multipart/alternative; boundary=001a11c38da0ae660104ef3bca07 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c38da0ae660104ef3bca07 Content-Type: text/plain; charset=ISO-8859-1 There seems to be some overlap between your project and the following: HBASE-8089 Add type support Phoenix which becomes Apache incubator project Cheers On Sun, Jan 5, 2014 at 7:58 AM, zhang_xzhi wrote: > https://github.com/zhang-xzhi/simplehbase > https://github.com/zhang-xzhi/simplehbase/wiki > > I am writing a light weight hbase ORM now, search for some suggestion. > thanks. > > > # 3 mins on simplehbase > > ## Introduction to simplehbase > Simplehbase is a lightweight ORM framework between java app and hbase. > The main feature of it are following: > * data type mapping: mapping java type to hbase's bytes back and forth. > * hbase operation wrapping: warpping hbase's put get scan operation to > simple java interface. > * hbase query language: using hbase filter, simplehbase can use sql-like > style to operate on hbase. > * dynamic query: like myibatis, simplehbase can use xml config file to > define dynamic query to operate on hbase. > * insert update support: provide insert, update on top of checkAndPut. > * multiple version support: provide interface to operation on hbase's > multiple version. > * hbase native interface support. > > ## Simplehbase sample > > ### Init simplehbase > private static SimpleHbaseClient getSimpleHbaseClient() { > HBaseDataSource hbaseDataSource = new HBaseDataSource(); > List hbaseConfigFilePaths = new ArrayList(); > //hbase config file. > hbaseConfigFilePaths.add("sample\\hbase_site"); > //zk config file. > hbaseConfigFilePaths.add("sample\\zk_conf"); > hbaseDataSource.setHbaseConfigFilePaths(hbaseConfigFilePaths); > hbaseDataSource.init(); > > HBaseTableConfig hbaseTableConfig = new HBaseTableConfig(); > //simplehbase config file. > hbaseTableConfig.setConfigFilePath("sample\\myRecord.xml"); > hbaseTableConfig.init(); > > SimpleHbaseClient tClient = new SimpleHbaseClientImpl(); > tClient.setHBaseDataSource(hbaseDataSource); > tClient.setHbaseTableConfig(hbaseTableConfig); > > return tClient; > } > ### Simplehbase config xml > including htable's config and one dynamic query config. > > > defaultFamily="MyRecordFamily"> > > > > typeName="allen.sample.Gender" /> > > > > > > select where id greater #id# > > name equal #name# > > > age greater #age# > > > > > > ### Define Data Object > @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; > } > > ### Define RowKey of Data Object > public class PersonRowKey implements RowKey { > > private int row; > > public PersonRowKey(int row) { > this.row = row; > } > > @Override > public byte[] toBytes() { > return Bytes.toBytes(row); > } > } > ### Using SimpleHbaseClient to operate hbase > public static void main(String[] args) throws Exception { > > 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 rowkey. > Person result = simpleHbaseClient.findObject(new PersonRowKey(1), > Person.class); > log.info(result); > > //search by range. > List resultList = simpleHbaseClient.findObjectList( > new PersonRowKey(1), new PersonRowKey(3), Person.class); > log.info(resultList); > > //search by dynamic query. > Map para = new HashMap(); > para.put("id", 0); > resultList = simpleHbaseClient.findObjectList(new PersonRowKey(1), > new PersonRowKey(3), Person.class, "queryByNameAndAge", > para); > log.info(resultList); > > //search by dynamic query. > 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)); > > } > > > > > > > > > -- > View this message in context: > http://apache-hbase.679495.n3.nabble.com/a-short-introduction-of-simplehbase-hbase-ORM-tp4054488.html > Sent from the HBase User mailing list archive at Nabble.com. > --001a11c38da0ae660104ef3bca07--