简体   繁体   English

使用HBase配置Kundera

[英]Configuring Kundera with HBase

I currently have an HBase/Hadoop cluster running without issues, and I am fairly familiar with these products. 我目前有一个没有问题的HBase / Hadoop集群,我对这些产品非常熟悉。 I recently heard about Kundera, and it looks to be a very powerful tool that I would like to use. 我最近听说过昆德拉,它看起来是一个非常强大的工具,我想用它。

However, I cannot seem to find any documentation/tutorials/examples for setting up Kundera with HBase. 但是,我似乎无法找到任何用于使用HBase设置Kundera的文档/教程/示例。 I have tried some of the materials I happened to come across, but they have failed so egregiously that I am under the impression that it wasn't relevant. 我曾尝试过碰巧遇到的一些材料,但是他们失败得如此之大,以至于我觉得它不相关。

Essentially I don't know where to begin. 基本上我不知道从哪里开始。 I'm not worried about somebody explaining to me any kind of advanced level stuff, but I just cannot get this thing configured. 我并不担心有人向我解释任何类型的高级内容,但我只是无法配置这个东西。

If anybody can point me in the right direction I would greatly appreciate it. 如果有人能指出我正确的方向,我将非常感激。

TLDR: I have an HBase cluster running and want to use Kundera with it and I have no clue where to begin whatsoever. TLDR:我有一个HBase集群正在运行,并希望使用Kundera,我不知道从哪里开始。 Thanks. 谢谢。

You can start here https://github.com/impetus-opensource/Kundera and https://github.com/impetus-opensource/Kundera/wiki 你可以从这里开始https://github.com/impetus-opensource/Kunderahttps://github.com/impetus-opensource/Kundera/wiki

Kundera is JPA compliant , it's pretty easy and straight forward to setup. Kundera符合JPA标准,设置非常简单直接。 wiki has enough documentation / examples to get you started. wiki有足够的文档/示例来帮助您入门。 Kundera dev team is very active here as well. Kundera开发团队在这里也非常活跃。

Just create your persistence.xml as shown https://github.com/impetus-opensource/Kundera/wiki/Common-Configuration 只需创建你的persistence.xml,如图所示https://github.com/impetus-opensource/Kundera/wiki/Common-Configuration

and hbase specific options https://github.com/impetus-opensource/Kundera/wiki/HBase-Specific-Features 和hbase特定选项https://github.com/impetus-opensource/Kundera/wiki/HBase-Specific-Features

Kundera + Hbase Configuration in Eclipse Eclipse中的Kundera + Hbase配置

Start your Hbase configuration on linux or others 在linux或其他设备上启动Hbase配置

create Dynamic web project 创建动态Web项目

Add the following jar into Libraries of the project 将以下jar添加到项目的库中

        1)asm-4.0.jar
        2)cglib-2.1.jar
        3)commons-lang-2.5.jar
        4)commons-logging-1.1.1.jar
        5)hadoop-core-1.0.0.jar
        6)hbase-0.94.4.jar
        7)jts-1.11.jar
        8)kundera-core-2.5.1.jar
        9)kundera-hbase-2.5.jar
        10)log4j-1.2.16.jar
        11)lucene-core-3.5.0.jar
        12)xstream-1.3.1.jar
        13)zookeeper-3.3.2.jar

Add the persistence.xml file as following 添加persistence.xml文件,如下所示

        <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
            http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
            version="2.0">
            <persistence-unit name="hbase_pu">
                <provider>com.impetus.kundera.KunderaPersistence</provider> 
                <class>com.fvrl.MyObject</class>    
                <properties>            
                    <property name="kundera.nodes" value="your host ip"/>
                    <property name="kundera.port" value="port"/>
                    <property name="kundera.keyspace" value="KunderaExamples"/>
                    <property name="kundera.dialect" value="hbase"/>
                    <property name="kundera.client.lookup.class" value="com.impetus.client.hbase.HBaseClientFactory" />
                    <property name="kundera.client.property" value="yourxmlfilepath" />  
                            <property name="kundera.ddl.auto.prepare" value="update" />             
                </properties>       
            </persistence-unit>
        </persistence>

Above xml file path must be place in proper place. 上面的xml文件路径必须放在适当的位置。

Make your Entity Class as below 使您的实体类如下

        @Entity
        @Table(name = "MyObject", schema = "KunderaExamples@hbase_pu")
        @NamedQueries({
          @NamedQuery(name="findAll", query="select c from MyObject c")
        })
        public class MyObject
        {

            @Id
            private String id;
            public String getId() {
                return id;
            }
            public void setId(String id) {
                this.id = id;
            }
            public String getFirstname() {
                return firstname;
            }
            public void setFirstname(String firstname) {
                this.firstname = firstname;
            }
            public String getSecondname() {
                return secondname;
            }
            public void setSecondname(String secondname) {
                this.secondname = secondname;
            }
            private String firstname;
            private String secondname;
        }

Run Your Project through main method 通过main方法运行项目

        public static void main(String[] args) {

                MyObject myObject = new MyObject();
                myObject.setId("0006");
                myObject.setFirstname("Nirav");
            myObject.setSecondname("shah");

                EntityManagerFactory emf = Persistence.createEntityManagerFactory("hbase_pu");
                EntityManager em = emf.createEntityManager();

               //Save  
                HBaseJPAImpl hBaseJPAImpl =new HBaseJPAImpl(em);
                hBaseJPAImpl.save(myObject);

                //retrive
                List<MyObject> list= hBaseJPAImpl.findAllDetails();

                for(MyObject myObject1 : list){
                   System.out.println("Row Id : "+myObject1.getId());
                   System.out.println("First Name : "+myObject1.getFirstname());
                   System.out.println("Last Name : "+myObject1.getSecondname());
                }
        }

HBaseJPAImpl Class is following HBaseJPAImpl类如下

        public class HBaseJPAImpl implements IHBaseJPA
        {
            public HBaseJPAImpl(EntityManager em) {
                // TODO Auto-generated constructor stub
                this.em = em;
            }
          @Inject protected EntityManager em;

          @Transactional
          public void save(MyObject myObject)
          {

           // em.persist(myObject));

            EntityTransaction entityTransaction = this.em.getTransaction();
            entityTransaction.begin();

            em.persist(myObject));   

            entityTransaction.commit();

          }

          @SuppressWarnings("unchecked")
          @Override
          @Transactional
          public List<MyObject> findAllDetails()
          {
            Query query = em.createNamedQuery("findAll");
            List<MyObject> results = (List<MyObject>) query.getResultList();
            return results;
          }  
        }

        interface IHBaseJPA is below

        public interface IHBaseJPA
        {
          void save(MyObject contact);`enter code here`
          List<MyObject> findAllDetails();
        }

if find any queries on the above then contact me 如果对上述内容有任何疑问,请与我联系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM