Saturday, September 06, 2008

Bringing Database application to Grid Computing in one day

So you have a Database application with Tables and Relations. Application is poorly performing, and not scaling and it is time to move. But it is so critical that rewriting it should be taken with precise planning. This is a common scenario at numerous clients. "Is there a way I can use Coherence Grid without too much programming effort by the time my IT staff learns the new technology?" Yes! as long as you know what a Map is. Follow the following steps and you are ready to Griditize your application in no time:


    Set up the tools:
  1. Download jDeveloper 10g (or latest) from Oracle.

  2. If jDev is not already enabled, Download AspectJ plugin from this link. Drop the jar in $JDEV_HOME/jdev/extenstions.


  3. Create Java Objects from Database tables:
  4. Start jDeveloper and go to Connections Tab. If Connection Tab does not appear, click the "View" Menu option and select Connection Navigator.

  5. Right click on Database connection and create a new connection. Test the connection for Success.

  6. Create a new jDeveloper project and give it a name.

  7. Right click on the Project and select Project Properties. Under Technology Scope, select Toplink to add. Don't worry, we are not mandating to use Toplink even though highly recommending it when you need database persistence and data load (Cache Stores etc). Click OK.

  8. Right click on the project and select New. A new Window appears, select Toplink option under Business Tier. Select the first option - "Java Objects from Tables". Give a name to Toplink Map and select the Database Platform and Database Connection you had created in step (3/4). Select the appropriate schema and import Tables. Select Tables that you want to create Java POJOs from. Move them from Available area to the Selected area. Click Next-> and provide a Java package name, say pkgname. Note this package name, you will have to use it later. After finishing the process you would see a bunch of Java classes in your project. You are half way there. Go and grab a cup of coffee.


  9. Kill some time:
    While you are finishing your coffee read this: Aspect programming with Coherence

    Make the Java POJOs Grid Ready:
  10. Create a new empty Java class under <pkgname>.root package. I would name it EzRoot (Motto is if it is not EZ (easy) it is useless). Copy the ELHelper class from the blog that you just read.

  11. Create a new Aspect by name EzRootAspect with the code copied from TestAspect.aj as was shown in the earlier blog. Replace all "Test." strings to "EzRoot." and add the following:
    declare parents: <pkgname>.* extends EzRoot; right below the aspect declaration. Don't forget to import EzRoot. Make sure package names of ELHelper and EzRootAspect are correct.

  12. Right click on the Project and select Rebuild. Or you can also create a new Deployment Profile and build a jar file. The compiled jar contains Coherence Grid ready Java classes. Each Java class represents a Table from your data model and now can also directly be used with Coherence.


In ten steps you have cut your week's work to half hour. The rest is your creativity. Whats next? Lets see.. I would love to give you a way to generate dirty but quickly a Coherence Cache configuration and you can go live in one day ;). May be some seasoned Domain Modeler can tell me the best way to tell a difference between an Entity and a Value Object without searching for an "ID" attribute. That way I can make an intelligent decision on how many caches should be created. The fun begins now...

1 comment:

Sanjana said...

Hey ashish very good blog about the technology
I am really very much amazed with your ideas

I have also implemented my project as a social networking website
in java JSP
https://www.fabgabs.com
Keep it up with ur knowledge sharing
we young indians will make every indians proud