Wednesday, August 16, 2006

java learnings from subu -2

HibernateORM
ORM- object relationship mapping is a technology whihc manages persistence of objects by converting the object fields to db fields.
Hibernate is a ORM implementation whihc is now part of the apache project. There are other implementations that exist and each app server hjas adopted one of their own. Oracle app serer uses inhouse developed technology.

How to use: There is a main service class factory which needs to be mapped to a datasource name

Passing DTO/entities across containers
An often bad design is that the servlet objects use their own data model (fields) while beans use their own, thus requiring transitional message objects to be created which are often called DTO's. A better option is to align the DTO's to the entities (beans) themselves and populate them from teh servlet layer.

Transaction Control

The concept of transaction control is simple, essentially to identify a block as an atomic transaction and if any operation fails then to roll back the whole

The same can logically be achieved using multiple try catch blocks and maintaining a central global shared varible to maintain thr transaction. However there are two diadvantages compared to use of a container managerd transaction control.
1. Multithreaded bcoz prob
2. In case of a complete system crash there is no form of recovery

On ther other hand the container manages a log of these transaction and on sys crash it ffirst rolls back the old transactions with support of the db transaction manager. Ie it essentially requests the db to rollback.

How to use:

Define a transaction object=t1

set t1.begin
try{
//do transactions
t1.commit
}catch ()
{ t1.rollback}

Corba


Corba is like DCOM. And although a language idependent protocol, needs to be supported by languages.

For any method/class to be exposed as a corba call, we have to create a stub and a skelton of it using a CORBA compiler. This essentially understand the binary format of the compiled code and creates a skeleton which can call the method appropriately.

IOR: this is a an xml format descriptor for the method call, specifying the machine name, port, class name etc and all details required to identify the object and method. This is normally stored in a centralized corba registry on the server machine (which can be anywhere)

IIOP:this is the base oprotocol which is like soap and is used to marshat and transport objects.



Simple Design:


Lets take a simple scenario:1. SImple website Ui 2. Calculation intensive insuarance policy app

For both the recommended way is to use a heavier servlet layer (as control logic is more) and only a session facade for the Bean layer. For the insurance one, if transaction control is required then doing it at the bean layer may be more useful. Note hibernate comes with its own low level transaction contorl mechanism and sometimes use of it is enough.

Saturday, August 05, 2006

Java learnings and discussions with Subbu-1

Java Bean:
Nothing but a pojo ( plain old java object) with only difference in naming and use of methods. For every field to be catered to, there needs to be a set,get method. Eg setFirstName, getFirstName.

What this helps out is in file level persistence. As the methods are clearly named, the Java framework can save files (in a standard format) from the objects (persistence). This thus enables uses of beans as good interface and UI objects as they can store 'properties' very well. This can be likened to the VB programming paradigm of dragging buttons into forms and filling the correct set of properties. This is possibly the reason why Java Beans are used a plug and play type situations (acting as a facade) and in similar way in UI design via drag-and-drop.

Enterprise Jave Bean

The enterprise Java Bean essentially extens this concept to the enterprise level, taking persistence to the Database.

Types of beans
1. Session
2. Entity
3. MDB

Session beans are used via the session facade design pattern. They provide two interfaces:Home and remote. The home is used to locate the bean ? while the remote is the actual interface exposed.The way they manage persistence is using ORM technology like Hibernate.

Hibernate

In this the elements of the class to be ORMized are mapped to correspinding sql table columns and defined in a mapping file. Hibernate also provides for basic transaction control, in the form of database rollback in case of non-commit.

There is a standard sessionfactory class to be used to get the handle of a 'service' object. This service object can be used to load and save the parameters in a hibernate session. eg:

1.

Friday, August 04, 2006

golf

Chris DiMarco
Geoff Ogilvy
Zach Johnson:
John Daly:
Tiger
vijay singh
jim furyk