Khangharoth

September 29, 2009

FrameWork: Spring-JPA-Hibernate (Annoation Based)

Filed under: Architecture,Java,JEE — khangharoth @ 4:56 pm

This skeleton web framework I wrote for Quarks , as they wanted a core framework on top of which they can build the applications.

As I had a luxury to design a Framework from scratch and so decided with these technologies.This dev stack is now becoming a vary dominant framework or to say in developers words “The next Popular Stack”.

Testing env I have used in this framework is TestNg , which I feel is much more suited to present day testing needs than our old JUnit(even after realese of Junit 4).

And with JDK 5+ , Spring 2.5+ which give support for Annoatations , you can have a very Simple yet very powerful framework to work with.So with this what we have is

  • Spring as a Application Framework
  • JPA as Persistence Framework (Hibernate as JPA impl)
  • Annotation based Transactional Control.
  • Spring Dependency injection with Annotation.
  • Spring MVC : This can be changed if you want to use something else.
  • Annotation based Validation framework.

These all elements give us enough power to create a generic and robust framework ,which can be customized for various needs.

Now let’s get to the actual work ……

Core Design Principle : The whole framework is desigend in Layers.Each Layer can only be called by layer above it and no skip hierarcy call’s are allowed.

Various Layers are

  • Web : Comprises of Spring MVC & JSP , this is due to the fact that most developer in quarks are quite familiar with JSp and so we wanted to start with this.Although I am not really happy with technology choice and wanted to have GWT or Flex based GUI.
  • Delegate : This is logical seperation between Web(Front End) and Service (back End).If you think that GWT or you something else suits you then this is the place where you should take a detour.
  • Service : Spring based beans, annotation based Dependency & Transaction management.
  • DAO : Db access layer , based on JPA and using hibernate as Persistence provider.
  • Persistence Domain model : Java Beans on lines of JPA Entities.

So the principle is that a layer can only call layer below it so in this Web —-> Delegate and any call direct to say services or DAO’s should be discourged.

Another way to see this is that if we just delete a particular Layer then code below it should compile just as fine without any problem.

I wanted the package structure to reinforce this idea  .Also its easier for a new person to see as how the packages are organized . The package structure is

  • com.quarks.a.web.controller
  • com.quarks.b.delegate
  • com.quarks.c.service
  • com.quarks.d.dao
  • com.quarks.e.persistence

Used a,b,c,d,e so that packages are shown in order in project view and aslo it gives clear idea of dependency in project.

Now looking at this I can easily say that DAO is only dependent on persistence pacakge.

Note : Still in edit , I’ll upload code as well . Please do give your valuable opinion about how can we have a Generic framework on this Dev Stack .

September 28, 2009

Type Safety in Api’s

Filed under: Uncategorized — khangharoth @ 2:26 pm

As of now am working on a fairly big  project which intended to have impact on entire bank level architecture and should be in use for more than 10 yrs .We didn’t got number 10 yrs from any mathematical calculation but it was a way to convey the message, that return on this sort of project typically comes after 5-6 yrs.

So after knowing very well that their will be many systems using your System and for  fairly long lifesapn , How do you design you Api’s ?

This particular  system is supposed to be a Cluster on Distributed Grid and will give option to other Systems to get data from Cache rather than hitting RDBMS and going forward the plan is that all System just work on top of this grid and so for them no Db calls !!

Now this systems will have fairly big outward facing Api’s and question in our mind was how to design these sort of Api’s. One important aspect of this design analysis is

What level of type safety we should have ?

Although with introduction of Ruby etc in mainstream programming , java static type saftey is preety much under attack.But my experience suggest that if you have a project on which more than 10 people will code than this is really a very important aspect to see while choosing a language . And this can be seen in Java’s success in big server side projects.

Now coming back to the point , how important is Type Safety in you Api’s which are exposed to outside world(other than your team) ?

Well answer from my side is very much , don’t give user a chance to call your Api’s with Generic Arguments.So while designing you Api’s try to be as as type safe as possible .

  • Don’t take generic String as argument’s for everything and then do conversion’s .
  • It really difficult to find a usecase where a method takes a argument as Object or return’s a Object.
  • If you have such methods then examine them closely or this may be perfect case to show your Generics knowledge.

While pondering over this i came across this article and really enjoyed reading it ,as it reinforces the concept that your api’s should be type safe and this should happen at compile time.

Also its a good news that Criteria queries will be part of JPA 2.0 which i think was most missed feature in JPA especially when you have hibernate as persistence provider.

September 11, 2009

Evolvoblity in Software System …

Filed under: Uncategorized — khangharoth @ 4:20 pm

Right now working on this and its kind of really interesting problem

So what’s the problem we want to solve :

  • Say We have a central Server/Cluster/DataStore.
  • Many Clients accessing this Central thing.

Let’s take a specific case for better understanding.

You want to have a trading platform : It will consist of

  • Trade booking applications : We can have mutiple apps say for Equity/Derivatives/FX etc.
  • Central Data store : Resonsible for data storage and single source of data for other applications
  • Middle office Systems like Confirmation Systems ,Settlements Systems etc.
  • Back Office Systems.

And in out System we have a class defination of Trade : a,b,c as attributes.

Currently everybody has this Class defination and they are able to Read/Write happily.

But what if  a Client want’s to add a new field( d )to this Trade class and want to use that ?

Do all the other Clients/Central thing needs to be Upgraded as well ? For practical purposes this may not be desirable.

So then how do you design your System where a Single client upgrades to new version and its using new fields but other clients are still running on older version , its just that they don’t see the d field but can work with a,b,c .

It turned out that this is not so difficult to achieve!

The real problem is if a Client adds a New SubClass (new trade type,having extra field d ) and still other clients can read this ,same as before ,able to work on as Trade class (on  field a,b,c without knowledge of d).

Blog at WordPress.com.