OT - how do you handle projects with different DB, code packages, etc?

I have a package that is being written to handle different persistence
technologies. How would your project be set-up to handle this? Would
you have different dependent modules (with the same package name) and
select the one that you want at this time? Or you write the layer that
you need and rewrite it when you need the new one.

Basically, I have a project that is being written with Commons DBUtils.
The persistence technology will probably go to Hibernate in less than a
year. Sometime after that, it will be implemented in EJB3.

All calls are handled by a delegate which makes calls to a data access
object. The data access object is the one that is aware that it is
written in dbutils, hibernate, etc.

--
Norris Shelton
Sun Certified Java Programmer

2 comments
Comment actions Permalink


Put the different persistence layer implementations in their own packages. Hide these behind a facade, using a factory to instantiate the chosen implementation and an interface to actually expose the functionality. Setup dependency rules so that nothing in your project is allowed to depend on any of the implementation packages, other than the factory. If you want to put the different implementations in their own modules, that might make it easier to ship them independently, but it's not really necessary. However it is a bad idea to have the persistence implementations in identically named packages, or (even worse) with identically named classes. You're just asking for issues that you don't need, and confusing any number of tools you might eventually want to use.

I've been meaning to write up inspections for duplicate class names in projects, and possibly for duplicate package names for precisely this reason. Java (and IDEA) makes it way to easy to build implementation variation points the right way without resorting to using naming confusion hacks to do it for you.

--Dave Griffith

0
Comment actions Permalink

When Dave answers, better listen :)

I think Dave pretty much summed it up neatly!

0

Please sign in to leave a comment.