Februari 14, 2012

Using OrientDB - Tinkerpop Blueprints from NetBeans

Using OrientDB from NetBeans is pretty easy. Here I will give you some of the steps needed for the uninitiated. NetBeans version is not so important, although in this posting I use NetBeans 7.1. To follow this article, you need OrientDB (as this is about Tinkerpop Blueprints, of course you need orientdb-graphed package - mine is 1.0RC8), JDK (mine is JDK7_u2), and NetBeans (mine is 7.1). This article assume that we will use remote mode URL from OrientDB to connect to database. Here I just use tinkerpop database which already exist in $ORIENTDB_HOME/database/tinkerpop. So, first time is fire up your server:
$ server.sh

Open NetBeans and create your project (File - New Project - Java - Java Application) and put this:


Our project structure looks like this:


Next, we should manage OrientDB library. Choose Tools - Library Manager and put all of the jar files in $ORIENTDB_HOME/lib into one container like this (mine is called OrientDB-Tinkerpop):


After that, we put the library into our project by choosing File - Project Properties (FirstOrientDB) - Libraries then add OrientDB-Tinkerpop library into our project:


That's all the steps needed to prepare our project. For the source code part, it won't be too difficult also since we have the example from Tinkerpop Blueprints wiki (although they use Neo4J as an example). The class for OrientDB is OrientGraph. So, put this source code inside FirstOrientDB.java:
package firstorientdb;

import com.orientechnologies.common.exception.OException;
import com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph;

/**
 *
 * @author bpdp
 */
public class FirstOrientDB {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

 OrientGraph graph = null;

        try {

            graph = new OrientGraph("remote:localhost/tinkerpop", "admin", "admin");
            System.out.println("Success");

        } catch (OException e) {
  
            System.out.println("Not succeed - " + e.getMessage());
  
        } finally {

            if( graph != null )
                graph.shutdown();

        }

    }
    
}
In the firstime, usually you have error from NetBeans. This error comes from library which should be imported. Instead of writing import statement by myself, I let the error happened and then resolve it by using Ctrl-Shift-I. From the source code, you may see that the connection was done by OrientGraph class. Its parameters are URL, username, password. We can see also that we can catch error by catching OException, the base Exception class in OrientDB. Here is the result when you press F6 or run the project:


If you can make it until this step, then you may now use Tinkerpop with your OrientDB inside your NetBeans project. Happy hacking!

Introduction to Graph Database and OrientDB

Graph database is a kind of NOSQL database which simply a term to show about the database management system software which is not a part of relational database. Since the scalability issues have arise and become a very big concerns for any company, this kind of database is getting more and more attention. People usually call this kind of needs on data scalability as web scale.

You may see from the data needs and inherent characteristics of web application that web is usually comprise of many resources which can link each other. This characteric is inherent in a graph, just like mathematicians usually care about. While the discussion about graph theory is outside from the scope of this article, readers interested in background theory about graph database should find a good book in discrete mathematics and especially graph theory. Graph theory is one prime object study of discrete mathematics and become one prominent theory since the first publishing of Leonhard Euler paper entitled "Seven Bridges of Königsberg". A graph consists of vertices and edges, as explained in this picture:


Graph theory has a very broad range of application, not just in web and / or computer science. That said, I will not repeat the things that already written in Wikipedia, just have a look at the Wikipedia articles and found it by yourself.

There are some companies and open source projects that realize the importance of graph theory and start the development of graph database. To make you confuse, there are some software that you can use, for example Neo4J, OrientDB, Mulgara - a specialized version of Graph Database which deals with RDF, etc. Benchmarking and choosing which graph database is better is not in the scope of this article and I personally do not interested in all of those lies, so I just want to use OrientDB for all my graph database needs. :p

OrientDB comes with small size zipped file. It takes only around 2 MB for OrientDB or you may get OrientDB with all of Tinkerpop "standard" inside only with around 8 MB size.
...
-rw-r--r-- 1 bpdp users 2689843 Feb  3 06:06 orientdb-1.0rc8.zip
-rw-r--r-- 1 bpdp users 8584056 Feb  3 06:07 orientdb-graphed-1.0rc8.zip
...

You will ask then, what is the difference between those two zip files? orientdb-version is the graph database software and only OrientDB, while for orientdb-graphed, is also consists of Tinkerpop thingie beside the graph database. Tinkerpop builds some software (open source) related with graph. You can use this graphed edition if you want to enable Tinkerpop abilities in your OrientDB database. It provides wrapper for OrientDB database so that you can use Tinkerpop related API in your software. There are 4 API supported by OrientDB: Blueprints, Gremlin, Rexster, and Pipes.

In this article, we will use the graphed version. Installation is pretty easy, as long as you have JDK, then it should not be a problem at all. What you need to do is only unzip the file and set some enviroment variables.
$ unzip orientdb-graphed-1.0rc8.zip
$ cd orientdb-graphed-1.0rc8

I put this in my $HOME/.bashrc file:
export ORIENTDB_HOME=/home/bpdp/software/orientdb/orientdb-graphed
export PATH=$PATH:$ORIENTDB_HOME/bin

One more thing, we should also change the configuration in $ORIENTDB_HOME/config/orientdb-server-log.properties to reflect the location of the log file:
java.util.logging.FileHandler.pattern=/home/bpdp/software/orientdb/orientdb-graphed/log/orient-server.log

You may of course change the location to any other place in filesystem that you want. To execute the server, use $ORIENTDB_HOME/bin/server.sh shell script:
$ server.sh 
           .                                              
          .`        `                                     
          ,      `:.                                      
         `,`    ,:`                                       
         .,.   :,,                                        
         .,,  ,,,                                         
    .    .,.:::::  ````                                   
    ,`   .::,,,,::.,,,,,,`;;                      .:      
    `,.  ::,,,,,,,:.,,.`  `                       .:      
     ,,:,:,,,,,,,,::.   `        `         ``     .:      
      ,,:.,,,,,,,,,: `::, ,,   ::,::`   : :,::`  ::::     
       ,:,,,,,,,,,,::,:   ,,  :.    :   ::    :   .:      
        :,,,,,,,,,,:,::   ,,  :      :  :     :   .:      
  `     :,,,,,,,,,,:,::,  ,, .::::::::  :     :   .:      
  `,...,,:,,,,,,,,,: .:,. ,, ,,         :     :   .:      
    .,,,,::,,,,,,,:  `: , ,,  :     `   :     :   .:      
      ...,::,,,,::.. `:  .,,  :,    :   :     :   .:      
           ,::::,,,. `:   ,,   :::::    :     :   .:      
           ,,:` `,,.                                      
          ,,,    .,`                                      
         ,,.     `,                     GRAPH-DB Server   
       ``        `.                                       
                 ``                                       
                 `                                        

2012-02-11 10:34:02:864 INFO [OLogManager] OrientDB Server v1.0rc8 (build @BUILD@) is starting up...
2012-02-11 10:34:03:336 INFO [OLogManager] -> Loaded memory database 'temp'
2012-02-11 10:34:03:372 INFO [OLogManager] Listening binary connections on 0.0.0.0:2424
2012-02-11 10:34:03:375 INFO [OLogManager] Listening cluster connections on 0.0.0.0:2434
2012-02-11 10:34:03:377 INFO [OLogManager] Listening http connections on 0.0.0.0:2480
2012-02-11 10:34:03:402 INFO [OLogManager] Installing GREMLIN language v.1.4
2012-02-11 10:34:03:437 INFO [OLogManager] OrientDB Server v1.0rc8 is active.

From another terminal, we may use $ORIENTDB_HOME/bin/console.sh shell script to access the server:
$ console.sh 
OrientDB console v.1.0rc8 (build @BUILD@) www.orientechnologies.com
Type 'help' to display all the commands supported.

Installing extensions for GREMLIN language v.1.4

> 

The database usually located in $ORIENTDB_HOME/database. Although you may have filesystem and memory as a URL for connection, this time we will use only remote to connect to the database. Here is how you will do it and how you will display information about the database:
> connect remote:localhost/tinkerpop admin admin
Connecting to database [remote:localhost/tinkerpop] with user 'admin'...OK

> info
Current database: tinkerpop (url=remote:localhost/tinkerpop)

Total size: 1.48Mb

Cluster configuration: {
    }

CLUSTERS:
----------------------------------------------+------+---------------------+-----------+-----------+
 NAME                                         |  ID  | TYPE                | RECORDS   | SIZE      |
----------------------------------------------+------+---------------------+-----------+-----------+
 index                                        |     1| PHYSICAL            |        11 |Not supported |
 orole                                        |     3| PHYSICAL            |         3 |Not supported |
 ouser                                        |     4| PHYSICAL            |         3 |Not supported |
 default                                      |     2| PHYSICAL            |         0 |Not supported |
 ographvertex                                 |     6| PHYSICAL            |       813 |Not supported |
 ographedge                                   |     7| PHYSICAL            |      8051 |Not supported |
 orids                                        |     5| PHYSICAL            |      3080 |Not supported |
 internal                                     |     0| PHYSICAL            |         3 |Not supported |
----------------------------------------------+------+---------------------+-----------+-----------+
 TOTAL                                                                               0 |        0b |
--------------------------------------------------------------------------------------- -----------+

CLASSES:
----------------------------------------------+---------------------+-----------+
 NAME                                         | CLUSTERS            | RECORDS   |
----------------------------------------------+---------------------+-----------+
 ORIDs                                        | 5                   |      3080 |
 OUser                                        | 4                   |         3 |
 OGraphEdge                                   | 7                   |      8051 |
 ORole                                        | 3                   |         3 |
 OGraphVertex                                 | 6                   |       813 |
----------------------------------------------+---------------------+-----------+
 TOTAL                                                                    11950 |
--------------------------------------------------------------------------------+

INDEXES:
----------------------------------------------+------------+-----------------------+----------------+-----------+
 NAME                                         | TYPE       |         CLASS         |     FIELDS     | RECORDS   |
----------------------------------------------+------------+-----------------------+----------------+-----------+
 edges                                        | NOTUNIQUE  |                       |                |        89 |
 vertices                                     | NOTUNIQUE  |                       |                |       977 |
 dictionary                                   | DICTIONARY |                       |                |         0 |
----------------------------------------------+------------+-----------------------+----------------+-----------+
 TOTAL = 3                                                                                                 1066 |
----------------------------------------------------------------------------------------------------------------+


> 

To shutdown the server, give shutdown.sh command from the shell:
$ shutdown.sh 
Sending shutdown command to remote OrientDB Server instance...
Shutdown executed correctly

You will see this one from server console:
2012-02-14 10:47:50:750 INFO [OLogManager] Received shutdown command from the remote client /127.0.0.1:57411
2012-02-14 10:47:50:750 INFO [OLogManager] Remote client /127.0.0.1:57411 authenticated. Starting shutdown of server...
2012-02-14 10:47:50:751 INFO [OLogManager] OrientDB Server is shutdowning...
2012-02-14 10:47:51:497 INFO [OLogManager] Shutdowning handler graph...
2012-02-14 10:47:51:498 INFO [OLogManager] Shutdowning handler default...
2012-02-14 10:47:51:499 INFO [OLogManager] Shutdowning handler automaticBackup...
2012-02-14 10:47:51:499 INFO [OLogManager] Shutdowning connection listener 'ONetworkProtocolBinary /0.0.0.0:2424:'...
2012-02-14 10:47:51:499 INFO [OLogManager] Shutdowning connection listener 'OClusterNetworkProtocol /0.0.0.0:2434:'...
2012-02-14 10:47:51:500 INFO [OLogManager] Shutdowning connection listener 'ONetworkProtocolHttpDb /0.0.0.0:2480:'...
2012-02-14 10:47:51:500 INFO [OLogManager] OrientDB Server shutdown complete

To conclude, there are still some areas that maybe need more attention. People in IT love standardization, although sometimes they create more than one standard for one purpose. UnQL, the standard for document-oriented is alredy discussed while there are still a little bit flux in Graph Database world. Someday maybe people start to discuss this issue and come up with the result. Well, hopefully :)

Februari 13, 2012

Apache OFBiz - ASF Solution for Enterprise Automation

As my daily jobs require me to pay attention only to the development tools, I don't pay attention to this software in the first place. What I mean by this is, I realized that there is an ERP solution from Apache Software Foundation before but after I promise my students to give them a free and open source software in my "Business Information Systems" class, then I started to look for free and open source ERP package. Then I remember about Apache OFBiz Project which provide with a complete ERP package for free (in the sense of free beer and free speech). In the list below, you may have these functionalities inside (taken from the website):
  1. Advanced e-commerce 
  2. Catalog management 
  3. Promotion and pricing management 
  4. Order management (sales and purchase) 
  5. Customer management (part of general party management) 
  6. Warehouse management 
  7. Fulfillment (auto stock moves, batched pick, pack and ship) 
  8. Accounting (invoice, payment and billing accounts, fixed assets)
  9. Manufacturing management 
  10. General work effort management (events, tasks, projects, requests, etc)
  11. Content management (for product content, web sites, general content, blogging, forums, etc) 
  12. A maturing Point Of Sales (POS) module using a rich client interface 
  13. /etc
The installation is pretty straightforward as it was written in README files that goes inside the tarball (or actually the zipped file) that you can download. Unfortunately, you have to build and populate the database first (at first, it uses only JavaDB, but you may change it to another DBMS software.

To install the software, just unpack and then build and populate database by using Apache Ant which is already included in the distribution, and you are good to go:


$ unzip apache-ofbiz-10.04.zip
$ cd apache-ofbiz-10.04
$ ./ant run-install

Notes
 You can not use JDK7 with Apache OFBiz, instead use JDK6 (latest version is 1.6.0_29). I use 1.6.0_27 and it still works correctly. If you use Windows, read the README file. If you are too lazy, wipe away your Windows OS, install Linux, follow the instruction in this blog and you are all set. :p

After finish with "BUILD SUCCESS" notification, run Apache OFBiz using the shell script (startofbiz.sh) or batch file (startofbiz.bat) if you use Windows. At first you will be overwhelmed by too many messages in console:

$ ./startofbiz.sh 
Set OFBIZ_HOME to - /home/bpdp/master/apache-ofbiz/apache-ofbiz-10.04
Admin socket configured on - /127.0.0.1:10523
2012-02-14 01:34:02,569 (main) [    ContainerLoader.java:50 :INFO ] [Startup] Loading containers...
2012-02-14 01:34:02,966 (main) [ ComponentContainer.java:177:INFO ] Auto-Loading component directory : [/home/bpdp/master/apache-ofbiz/apache-ofbiz-10.04/framework]
2012-02-14 01:34:03,007 (main) [ ComponentContainer.java:238:INFO ] Loading component : [geronimo]
2012-02-14 01:34:03,062 (main) [ ComponentContainer.java:238:INFO ] Loading component : [sql]
..........
..........
..........
..........
..........
2012-02-14 01:35:00,935 (default-invoker-Thread-11) [                Log.java:111:INFO ] [CommonPermissionServices.xml#genericBasePermissionCheck] Checking for primary permission ACCOUNTING_CREATE
2012-02-14 01:35:00,961 (default-invoker-Thread-11) [     ServiceEcaRule.java:134:INFO ] For Service ECA [fixedAssetPermissionCheck] on [return] got false for condition: [hasPermission][equals][false][true][Boolean]
2012-02-14 01:35:00,972 (default-invoker-Thread-11) [  ServiceDispatcher.java:599:INFO ] Sync service [JobDispatcher/fixedAssetPermissionCheck] finished in [3751] milliseconds
2012-02-14 01:35:01,000 (default-invoker-Thread-8) [  ServiceDispatcher.java:599:INFO ] Sync service [JobDispatcher/sendEmailDated] finished in [4124] milliseconds
2012-02-14 01:35:01,105 (default-invoker-Thread-11) [  ServiceDispatcher.java:599:INFO ] Sync service [JobDispatcher/createMaintsFromTimeInterval] finished in [3898] milliseconds

To see your e-Commerce site (the front page of your Apache OFBiz application), go to http://server:8080/ecommerce.




The backend can be accessed by using http://server:8443/webtools.





For the first time, you may login using "admin" as username and "ofbiz" as password.




Here is the result of backend login:





You may see that this kind of software can be a good example of free and open source software for your business need. If you are a technopreneur, why don't you get involved in the project and sell the service to customers? It's up to you now, you have all you need.

Enjoy!