Hi All,

My company is going to be using a HBase for a project of ours. To be
able to use this I have had to write a lightweight ORM for Hbase to
simplify integration with various parts of our systems. Anyway I was
thinking it might be useful to others, if there is some interest in it
I could package it up and release it as an Open Source project.

The ORMs main goal is to handle Type conversions and Secondary Column
Indexing which in Hbase normally has to be done client side. The ORM
also hase a table scanner which provides Hbase style table scanning.
The ORM has a specification file format which describes each table.
This spec file is fed in to a Java based complier which uses Java CC
pased syntax parser and then manually generates source code for the
ORM.

This generated source code is then compiled against the a base library
to produce the ORM code which the client application uses to interface
with Hbase. The generated source uses the Thrift api to communicate
with HBase. Currently there is only a source code generator for C#
however our project has a Java based web application so I will have to
make a Java source code generator as well. Since Java and C# are very
similar that should be quite straight forward. I have been waiting for
the feature set to stablise a bit first, which it nearly has.

Below is a sample spec file which the compiler will accept and
generate source for.

[EntityName="User"]
HBaseTable Users
{
        String userID;
        
        ColumnFamily auth
        {
                String password;
                String salt;
                Boolean enabled;
        }
        
        ColumnFamily info
        {
                String firstName;
                String lastName;
                
                [Indexed]
                String email;
        }

        DynamicColumnFamily String roles;
}

[EntityName="GeoIPLookUp"]
HBaseTable GeoIPLookUp
{
        //The IP address of the start range
        String ip;
        
        ColumnFamily geo
        {
                String countryCode;
        }
}

[EntityName="GeoIPCountry"]
HBaseTable GeoIPCountry
{
        //The two char country code
        String code;
        
        ColumnFamily info
        {
                String countryName;
                UInt regionID;
        }
}

Below is some sample C# code for using the user table

                        //Create a new connection and connect
                        HbaseConnection connection = new 
HbaseConnection("localhost", 9090);
                        connection.connect();

                        //Create a new user
                        User user = new User(connection, "charlie");

                        //Get just the auth info
                        user.loadAuth();

                        //Display the output
                        displayUser(user);

                        //Get all columns
                        user.loadAll();

                        //Display the output
                        displayUser(user);

                        //Change some details
                        user.FirstName = "Bob";
                        user.LastName = "The Other Guy";
                        user.Enabled = true;
                        user.Email = "[EMAIL PROTECTED]";

                        //Save the changes
                        user.save();

                        User user2;

                        Console.WriteLine("Getting by Email");

                        if(User.tryGetFromEmail("[EMAIL PROTECTED]", 
connection, out user2))
                        {
                                //Get all user info
                                user2.loadAll();
        
                                //Change the details back
                                user2.FirstName = "Charlie";
                                user2.LastName = "M";
        
                                //Save the details back
                                user2.save();
                        }


The ORM still has a few rough edges but its proving quite useful for
our projects development.It should be quite straight forward to add
other language generation to the compiler based on the syntax tree the
parser generates. I haven't decided what license to use probably the
Apache or another which allows commercial use of the generated source
code at least.

 I was wondering if anyone else would be interested in using it ?

Charlie M

Reply via email to