<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    gembin

    OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

    HBase, Hadoop, ZooKeeper, Cassandra

    Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

    There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

    About Me

     

    Try ORM for HBase with DataNucleus hbase plugin

     
    Try ORM for HBase with DataNucleus HBase datastore

    suppose you have read the last blog entry or you have already setup the env for hbase

    1. download required jars datanucleus-core-2.0.0.m1.jar and datanucleus-hbase-1.0.1.jar
          hadoop-0.19.1-core.jar
          hbase-0.19.3.jar
          jdo2-api-2.3-eb.jar
          commons-logging-1.0.4.jar
          commons-cli-1.2.jar
         
         datanucleus.properties
         javax.jdo.option.ConnectionURL=hbase
         javax.jdo.option.ConnectionUserName=
         javax.jdo.option.ConnectionPassword= 


    2. create a data model
         

    package net.blogjava.gembin.hbase.model;

    import java.util.Date;

    import javax.jdo.annotations.IdGeneratorStrategy;
    import javax.jdo.annotations.IdentityType;
    import javax.jdo.annotations.PersistenceCapable;
    import javax.jdo.annotations.Persistent;

    @PersistenceCapable(identityType 
    = IdentityType.APPLICATION)
    public class Entry {

        @Persistent(primaryKey 
    = "true", valueStrategy = IdGeneratorStrategy.UUIDHEX)
        
    private String id;
        @Persistent
        
    private String title;
        @Persistent
        
    private String content;
        @Persistent
        
    private String description;
        @Persistent
        
    private Date postDate;

        
    public String getId() {
            
    return id;
        }

        
    public void setId(String id) {
            
    this.id = id;
        }

        
    public String getTitle() {
            
    return title;
        }

        
    public void setTitle(String title) {
            
    this.title = title;
        }

        
    public String getContent() {
            
    return content;
        }

        
    public void setContent(String content) {
            
    this.content = content;
        }

        
    public String getDescription() {
            
    return description;
        }

        
    public void setDescription(String description) {
            
    this.description = description;
        }

        
    public Date getPostDate() {
            
    return postDate;
        }

        
    public void setPostDate(Date postDate) {
            
    this.postDate = postDate;
        }

        
    public String toString() {
            
    return new StringBuilder()
            .append(
    "{id=")
            .append(id 
    + "\n")
            .append(
    "title=")
            .append(title 
    + "\n")
            .append(
    "content=")
            .append(content 
    + "\n")
            .append(
    "postDate=")
            .append(postDate 
    + "\n")
            .append(
    "description=")
            .append(description 
    + "\n}")
            .toString();
        }
    }


    3. create persistence service

    package net.blogjava.gembin.hbase.service;

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;

    import javax.jdo.Extent;
    import javax.jdo.JDOHelper;
    import javax.jdo.PersistenceManager;
    import javax.jdo.PersistenceManagerFactory;
    import javax.jdo.Query;
    import javax.jdo.Transaction;

    import net.blogjava.gembin.hbase.model.Entry;

    public class EntryPersistenceService {
        
    private static final String DATANUCLEUS_PROPERTIES = "datanucleus.properties";
        
    static PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(DATANUCLEUS_PROPERTIES);
        
    private PersistenceManager persistenceManager;

        
    public EntryPersistenceService() {
            persistenceManager 
    = pmf.getPersistenceManager();
        }
        
    /**
         * 
         * 
    @param entry
         
    */
        
    public void saveEntry(Entry entry) {
            Transaction tx 
    = persistenceManager.currentTransaction();
            
    try {
                tx.begin();
                persistenceManager.makePersistent(entry);
                tx.commit();
            } 
    finally {
                
    if (tx.isActive()) {
                    tx.rollback();
                }
            }
        }
        
        
    /**
         * 
         * 
    @param entry
         
    */
        
    public void removeEntry(Entry entry){
            Transaction tx 
    = persistenceManager.currentTransaction();
            
    try {
                tx.begin();
                persistenceManager.deletePersistent(entry);
                tx.commit();
            } 
    finally {
                
    if (tx.isActive()) {
                    tx.rollback();
                }
            }
        
        }
        
    /**
         * 
         * 
    @param id
         * 
    @return
         
    */
        
    public Entry getEntry(String id){
            Transaction tx 
    = persistenceManager.currentTransaction();
            Entry e
    =null;
            
    try {
                tx.begin();
                e
    = persistenceManager.getObjectById(Entry.class,id);
                tx.commit();
            } 
    finally {
                
    if (tx.isActive()) {
                    tx.rollback();
                }
            }
            
    return e;
        }
        
    /**
         * 
         * 
    @return
         
    */
        
    public Collection<Entry> getEntries() {
            Collection
    <Entry>entries = new ArrayList<Entry>();
            Transaction tx 
    = persistenceManager.currentTransaction();
            
    try {
                tx.begin();
                Extent
    <Entry>extent = persistenceManager.getExtent(Entry.class);
                Query q 
    = persistenceManager.newQuery(extent);
                Collection
    <Entry> c = (Collection<Entry>) q.execute();
                
    if (c == null)
                    
    return null;
                Iterator
    <Entry> iter = c.iterator();
                
    while (iter.hasNext()) {
                    Entry p 
    = iter.next();
                    entries.add(p);
                }
                tx.commit();
            } 
    finally {
                
    if (tx.isActive()) {
                    tx.rollback();
                }
            }
            
    return entries;
        }
        
    /**
         * 
         
    */
        
    public void close() {
            
    if (pmf != null && !pmf.isClosed())
                pmf.close();
            
    if (persistenceManager != null && !persistenceManager.isClosed())
                persistenceManager.close();
        }
        
    }



    4. create test client

    persist a Entry
            EntryPersistenceService mp=new EntryPersistenceService();
            Entry entry
    =new Entry();
            entry.setTitle(
    "first entry");
            entry.setPostDate(
    new Date());
            entry.setDescription(
    "it's first entry!!");
            entry.setContent(
    "It's first content of this entry");
            mp.saveEntry(entry);


    retrieve entries
            EntryPersistenceService mp=new EntryPersistenceService();
            Collection
    <Entry> entries=mp.getEntries();
            Iterator
    <Entry>it=entries.iterator();
            
    while(it.hasNext()){
                System.out.println(it.next());
            }

    output:
    {id=4aea47a52328c7a0012328c7a0380000
    title=first entry
    content=It's first content of this entry
    postDate=Mon Aug 17 22:34:14 CST 2009
    description=it's first entry!!
    }


     enjoy it!!!

    how to setup hbase env: http://m.tkk7.com/gembin/archive/2009/08/16/291290.html

    posted on 2009-08-17 23:33 gembin 閱讀(2424) 評論(1)  編輯  收藏 所屬分類: Databasehbase

    評論

    # re: Try ORM for HBase with DataNucleus hbase plugin 2009-08-18 09:51 99讀書人

    不錯哦  回復(fù)  更多評論   

    導(dǎo)航

    統(tǒng)計

    常用鏈接

    留言簿(6)

    隨筆分類(440)

    隨筆檔案(378)

    文章檔案(6)

    新聞檔案(1)

    相冊

    收藏夾(9)

    Adobe

    Android

    AS3

    Blog-Links

    Build

    Design Pattern

    Eclipse

    Favorite Links

    Flickr

    Game Dev

    HBase

    Identity Management

    IT resources

    JEE

    Language

    OpenID

    OSGi

    SOA

    Version Control

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    free counters
    主站蜘蛛池模板: 国产视频精品免费视频| 99re热免费精品视频观看| 久久国产精品成人免费| 成人免费视频小说| 亚洲精品无码乱码成人 | 免费无码精品黄AV电影| 亚洲午夜无码AV毛片久久| 亚洲一区精彩视频| 免费国产成人午夜在线观看| 亚洲精品色午夜无码专区日韩| 爽爽爽爽爽爽爽成人免费观看 | 亚洲成AⅤ人影院在线观看| 亚洲影视一区二区| 国产一级片免费看| 久久精品国产亚洲av麻豆色欲| 精品国产呦系列在线观看免费| 亚洲无人区午夜福利码高清完整版 | 在线亚洲精品福利网址导航| 亚洲精品色播一区二区 | 激情吃奶吻胸免费视频xxxx| 日韩av无码成人无码免费| 亚洲一日韩欧美中文字幕在线| 日韩在线播放全免费| 亚洲卡一卡2卡三卡4卡无卡三| 两个人看的www免费视频| 91亚洲国产在人线播放午夜| 免费人成在线观看网站| 亚洲人和日本人jizz| 免费精品国偷自产在线在线| 亚洲自偷自拍另类图片二区| 国产精品免费观看久久| 一级做a爰片性色毛片免费网站| 又大又黄又粗又爽的免费视频| 亚洲欧洲无码AV不卡在线| 午夜影视在线免费观看| 色噜噜的亚洲男人的天堂| 免费在线视频一区| 99re这里有免费视频精品| 狠狠色香婷婷久久亚洲精品| 亚洲色偷偷综合亚洲AV伊人| 亚洲成年人免费网站|