M L A V W I L S O N
Home
Counter-Strike
Java Development
csjstats
J2EE Utilities
Go
Factory
DAOFactory
JQueueBrowser
Calendar (tag)
Java Toys
Network Games
FBall
PassMan
Classpath Manager
3D Chess
J2ME Toys
tic-tac-toe MIDLet
Java Reports
Latest javadoc
Latest JUnit
DAOFactory


This J2EE utility can be used to seperate the DAO layer from the Buisness layer. This pattern Factory Method is a common pattern. Documentation about this pattern can be found at J2EE Core Pattern. My implementation uses the Factory Method, but does not use the Abstract Factory Method. Instead of having a new implementation of the Factory for each data-source, there is a xml config file for each data-source. The source can be view here:com.mlw.util.dao.DAOFactory (download) . Below is a sample of how the Factory Method pattern is supported by the DAOFactory.

A jar file, that also contains the source can be downloded here: mlw-j2ee.jar.

There is a com.some.DaoEmployee interface. This class has two implementations: a com.some.OracleDaoEmployee and a com.some.MySqlDaoEmployee.

The Oracle config file:
The My SQL config file:

To retrieve the DAO from the factroy see the following example. In this example the actual Object returned is an implementation of com.some.DaoEmployee. Either the Oracle or the My SQL implementation if the expected interface. The Object returned depends on which config file was loaded.

The DAOFactory (download) extends Factory (download) , which extends Go (download) . Therefore there is a lot that can be done in the config file that is not discussed here. See documentation about Go for the details.