Saturday, April 28, 2007

Some advice for Nettier or other ORM framework


There are many ORM (
Object Relational Mapping) framework , e.g. Nettier ,Hibernate etc

We can use them very clear for building our DB layer
.and then CodeSmith can generate all of the code according to the database structure very easy.

Our going project used Nettier as DB Layer , but i in addition to another Layer named "Adapter" . VersaTran's developer can't understand the reason . so I throw my view below:

This is the Framework for our project.

http://www.cbf107.com/images/LayerAdapter20070428_1.gif

  1. Nettier DBLayer is generated via CodeSmith according to Data Base design.
  2. Adapter wrap NettierDBLayer providers’ function and it’ll be extend other function which belong to DBLayer and can’t generate by CodeSmith.NettierDBLayer and TripTrackerAdapter will accomplish the Data Object convert to Database (ORM)
  3. BusinessLayer will provide Business requirements for the concrete operation (e.g. budget calculate , schedule conversion)
  4. TripTrackerUI is the package for user interfaces and bound classes, the classes will direct invoke the functions from BusinessLayer.

This is the develop workflow:


http://www.cbf107.com/images/LayerAdapter20070428_2.gif

1. The UI developers work for user interface, they need be familiar with HTML, Javascript, CSS and some knowledge about UE (User Experience).

Also the developers have to know how to invoke the interface (function) which business layer provided.

(Of course, the simple, the better for the interfaces and functions)

Notice: The UI developers maybe didn’t know anything about Nettier, even what is Database, they just need know which entity and interface will be used.

2. The same as UI developers, the business layer developers will pay more attention to business realization (e.g. how to calculate budget according the condition from user entered ) , they don’t care about how to insert the data to database , they just need know which function(/interface) can store objects. (The function or interface is provided by DBLayer)

The DBLayer interface need clearly and simplify.

3. DBLayer developers must implement the objects (Entity) to database; they’ll provide the functions to business layer.


But Netter had provided the interfaces and the functions for database operations. Why we add adapter layer to gild the lily.

http://www.cbf107.com/images/LayerAdapter20070428_3.gif

At present:
  • Simplest interface for business layer

We used Netters for interact with database, but Netters includes multiple functions, the DBLayer developer need wrap them and provide the simplest interface which business layer need.

  • Extend by ourselves

Also, Netters db codes can auto generated via CodeSmith, but sometimes we need ourselves functions for directly operate the database.

E.g. (We add the procedure for query by one column, which column not indicated index, pk, fk)

In addition, from the community we know the netters also have some bugs; it’s hard to say we’ll be happened. So the Adapter will help us Flexible deal with it .

See http://community.codesmithtools.com/forums/30/ShowForum.aspx for a list of 501 bugs that need to be worked around. Or here for 149 features not implemented by NetTiers http://community.codesmithtools.com/forums/31/ShowForum.aspx.

Why not add ourselves function to Nettier DBLayer:

One day we change the database structure and then auto generate the code via CodeSmith, the code maybe also not include the function we added. So the extend is better than modify.

By the way, we can’t just put our extends function on the folder (package), because the function not just a function, they live relate with the entity. (OO)

On the other hand: The UI developers and Business developers needn’t know how to implement the Database operations.

  • To the further

One day maybe the newest Nettier or other ORM can be done and the database operations more effective. We need promote our DBLayer .we just do the fix for Adapter and not involve Business Layer and UI.

So if you also use Nettier or others framework for your project , i suggest use a Adapter to release coupling

No comments: