Tuesday, February 12, 2008

Hierarchical Queries


From my childhood days I always wanted to make sure that I kept things simple . My affair with Oracle started from my high school days but there was one thing that kept me away all the time , "Hierarchical Queries " . It took around 8 long years for me to take a look at it again , of course when one of my friends was taking a look at the production query which was simply taking a lot of time to execute .

Lets take the look at the tree (hierarchical) image in the right . Suppose my table has been designed in such a way and I would like to display my records in the following manner . Then we would have to go for Hierarchical Queries.

• KING PRESIDENT
• BLAKE MANAGER
• ALLEN SALESMAN
• JAMES CLERK
• MARTIN SALESMAN
• TURNER SALESMAN
• WARD SALESMAN
• CLARK MANAGER
• MILLER CLERK
• JONES MANAGER
• FORD ANALYST
• SMITH CLERK
• SCOTT ANALYST
• ADAMS CLERK

Description of hierarchical_query_clause.gif follows

START WITH specifies the root row(s) of the hierarchy.

CONNECT BY specifies the relationship between parent rows and child rows of the hierarchy. PRIOR is most commonly used when comparing column values with the equality operator.

say :
SELECT ENAME, JOB, EMPNO, MGR, LEVEL
FROM EMP
CONNECT BY MGR = PRIOR EMPNO
START WITH MGR IS NULL
ORDER SIBLINGS BY ENAME;



Saturday, January 26, 2008

Looking to PROBE your tomcat ?
















Are you looking to probe into your tomcat application ? I always believe that one shouldn't reinvent the wheel . So showing the system level information in my applications was never a part of my design . I came across Lambda Probe , this gives a complete picture of your application running in tomcat .

LambdaProbe to me became the right tool to do all the diagnostic checks like JVM memory usage , detailed reports on Connection parameters , list of sessions in the applications . This could be particularly useful when one wants to keep track of system information . So at the right time one can immediately increase the heap size when our application has exceeded the memory specified. This could prevent the application from going down and resulting in bazaare consequences .

Its time you try a demo.



Sunday, January 13, 2008

Flex - Whats the hype all about ???!!!!

Though I couldn't make it to Java Polis in Belgium , my friends did and they had just one mantra when they came back 'FLEX' . We were in the planning stages of our new project for Source Governance and except for me everyone what we were going to use for the User Interface.
Its almost been an year around in Competence Center , we always make it a point that the chosen technology is based on our business needs but making sure that we are always are aligned with the industry . With my Mac IBook G4 I started my journey and at this point I was reminded of the famous lines
"The Woods are dark and lovely
and miles to go before I sleep "

My idea was very clear , I was planning to work on a prototype where I could use Hibernate and a quick search in google (we all know the obvious choice but I also would recommend Live Search) gave me the answer to what I wanted "Flex Data services with Spring and Hibernate
The eclipse builder for Flex also amazing , one can start with the examples immediately . It would create an .mxml file and we will be using this to develop a prototype . Once we are ready with the design and the mxml just needs to be imported to the tomcat folder (Lets start with tomcat , I know you would be thinking about Transactions . Dont worry jta is always there for the rescue).

At this point it becomes very important for me tell you why Flex-Spring is such a lovely combination .

RemoteObject component directly invokes methods of Java objects deployed in your application server, and consume the return value. The return value can be a value of a primitive data type, an object, a collection of objects, an object graph, etc. In distributed computing terminology, this approach is generally referred to as remoting. This is also the terminology used in Spring to describe how different clients can access Spring beans remotely.

Best part about Spring is that , Spring IoC is to let the container instantiate components (and inject their dependencies). By default, however, components accessed remotely by a Flex client are instantiated by Flex destinations at the server side. The Flex Data Services support the concept of factory to enable this type of custom component instantiation. The role of a factory is simply to provide ready-to-use instances of components to a Flex destination, instead of letting the Flex destination instantiate these components itself.

In just five steps , I will tell you how to integrate Flex with Spring .

Step 1: Install the supporting files
  1. Download flex-spring.zip from coenraets.org.
  2. Expand the ZIP file.
Step 2: Install Flex Data Services

To use the Remoting and Data Management Services data access strategies described above, you need to install the Flex Data Services.

Step 3: Install Spring
  1. Expand the downloaded file.
  2. Locate spring.jar in the dist directory and copy it in the {context-root}\WEB-INF\lib directory of your web application.
  3. Modify the web.xml file of your web application. Add the context-param and listener definitions as follows:
  4. contextConfigLocation
      /WEB-INF/applicationContext.xml
    org.springframework.web.context.ContextLoaderListener
Step 4: Register the Spring factory
  1. Copy SpringFactory.class and SpringFactory$SpringFactoryInstance.class from flex-spring-sdk\bin\flex\samples\factories to {context-root}\WEB-INF\classes\flex\samples\factories.
  2. Register the Spring factory in {context-root}\WEB-INF\flex\services-config.xml:

Step 5:
In Main.mxml(our sample mxml file) with this new destination:


private var _order : Order;



/** **/
private function onCreationComplete() : void
{
CursorManager.setBusyCursor();
this.orderService.addEventListener(ResultEvent.RESULT, removeBusyCursor);

// call the method we want from the OrderAssembler (our service)
this.orderService.fill(this._orders);
this.productService.fill(this._products);
this.orderService.addEventListener(ResultEvent.RESULT, lookAtResults);
}

private function lookAtResults(event : ResultEvent) : void
{
var order : Order = this._orders.getItemAt(0) as Order;
var item : LineItem = order.lineItems.getItemAt(0) as LineItem;
}

private function createOrder() : void
{
CursorManager.setBusyCursor();
var order : Order = new Order();
this.orderService.createItem(order);
}

private function addItemToOrder() : void
{
CursorManager.setBusyCursor();
// create new LineItem object to add to Order
var item : LineItem = new LineItem();
item.product = Product(this.productsGrid.selectedItem);
//item.order = this._order;
item.quantity = int(this.productQuantity.text);
item.unitPrice = item.product.price;

this._order.lineItems.addItem(item);
}

private function removeItemFromOrder() : void
{
CursorManager.setBusyCursor();
var item : LineItem = LineItem(this.lineItemGrid.selectedItem);
var index : int = this._order.lineItems.getItemIndex(item);
this._order.lineItems.removeItemAt(index);
}

private function removeBusyCursor(event : ResultEvent) : void
{
CursorManager.removeBusyCursor();
}

private function formatCurrency(item : Object, col : DataGridColumn) : String
{
return this.usdFormatter.format(item[col.dataField]);
}

private function handleFault(event : FaultEvent) : void
{
Alert.show(event.message.toString());
}
]]>


I would like end my blog by saying that this entire prototype took not more than 3 hours from scratch . The coing has been reduced drastically with Flex on the User Interface front . Remoting has taken Flex to the next level where in one can easily connect to the back end for any database operation . Lets move to Web2.0 , its going to be FLASHY here after !!!!










Wednesday, January 9, 2008

Concurrent Programming in Java - Its a whole new world out there !!!

Concurrent Programming in Java , writing code that effectively exploits multiple processors can be very challenging . Effectively exploiting concurrency is becoming more and more important now that Moore's Law is delivering more cores but not faster cores . Have you wondered if a program with as many as five threads in a single processor system can die a catastrophic death in multiple processor systems , showing up 100% CPU usage . Well I found out just that .

A code that was running perfectly fine after a migration to multiple processor system seemed to look choke . Simple reason being IT WAS TIME TO PUT MORE THOUGHTS ON java.util.concurrency package adopted from edu.emory.mathcs.backport.java.util.concurrent . What struck me instantly was CountDownLatch class . My mentor who I believe is the ultimate person and Mr Reliable to fall back during crisis times Mr. Murali , knew exactly where the problem was !

The typical scenario was that , we had to make sure that all the threads we were using do concurrent jobs and we can't have one racer stop while the system processes someone else's time ,we need all the racers to start at the same time and stop when the leader has finished . The best example I can think of now is that of preparing lemon Rice , though I must agree that I am not a great cook . Lets say we just require 5 main ingredients . The idea is to keep each one of the worker busy . So the ingredients :
1. Rice
2. Lemon
3. Salt
4. Turmeric powder
5 Oil

Imagine that we have run out of all these items at home . We have five servants and we need to prepare the Lemon rice by lunch and we all know that we can start cooking only after all these items arrive . So what we do is we send our five servants to get one item each . Now can we picturize this with our scenario ?

class LemonRicePreparation implements Runnable {
private final CountDownLatch startSignal;
private final CountDownLatch doneSignal;
LemonRicePreparation(CountDownLatch startSignal,
CountDownLatch doneSignal) {
this.startSignal = startSignal;
this.doneSignal = doneSignal;
}
public void run() {
try {
startSignal.await();
doShopping();
doneSignal.countDown();
} catch (InterruptedException ex) {}
}

void doShopping() { ... }
}

  • The first is a start signal that prevents any worker from proceeding until the all of them to proceed.
  • The second is a completion signal that allows the Cook to wait until all workers have completed buying the items assigned to them .

Trust me what ever code we write cannot be called 100% complete and perfect . There is scope of improvement required everytime .

Wednesday, November 14, 2007

Reasons to Invest in BPMS

BPM is it a purely a management discipline ?!!!

Well , this is what you will find in most of the sites when you google about BPM . Apart from acting as a bridge for business IT alignment , efficiency and compliance ; its all about Rapid development and we know the world is all about changes . This BPM is all about handling changes quicker , faster and better . In simple terms its how a business analyst can design a workflow for a project and set up his notion with the help of a designer tools and BPM engine .

BPMS is more then just Orchestration , lets say its a bundle of Human task management , Business rule management and Integration middle ware .

Have a look at the Eclipse designer for BPM ( All the vendors like JBPM , Intalio and bea , websphere do provide plugins for Eclipse ) .
We can actually view this BPM from 0 level , 100 ft level , 1000 ft level and it just goes on ... In my subscequent blogs I would like to share with you my experiences with JBPM , Intalio and lets try to integrate them with an application .

This is where I belong

This is where I belong