This section shows how you can provide your own DAO implementations by using the DAO and Abstract Factory patterns. If you haven't done so already, we recommend that you first read the Persistence section in System Architecture to get an overview.
We will walk you through the necessary steps for creating the DAOs by making new DAOs that will use JDO (Java Data Object) as a persistence medium.
Note that it is not the point of this guide to show how to implement a DAO for a specific data source, so we will ommit the JDO specific parts and focus on what's necessary to create and where to plug it in.
Below you'll find the necessary steps you'll have to perform to provide your own DAO implementation.
Create a new file JDOBPELProcessDAO
which implements the
BPELProcessDAO
interface.
public interface BPELProcessDAO { /** * Inserts a new BPELProcess. */ public String insert(BPELProcess process) throws DAOException; /** * Finds a BPELProcess given its id. */ public BPELProcess find(String id) throws DAOException; /** * Finds a BPELProcess given the name of its Process. */ public BPELProcess findByName(String name) throws DAOException; /** * Deletes a BPELProcess given its id. */ public void delete(String id) throws DAOException; /** * Updates an existing BPELProcess. */ public void update(BPELProcess process) throws DAOException; }
Do the same for the ProcessContextDAO
, that is create a new
file called JDOProcessContextDAO
which implements the
interface.
public interface ProcessContextDAO { /** * Inserts a newProcessContext
. */ public String insert(ProcessContext ctx) throws DAOException; /** * Finds aProcessContext
given its key. */ public ProcessContext find(String key) throws DAOException; /** * Deletes aProcessContext
given its key. */ public void delete(String id) throws DAOException; /** * Updates an existingProcessContext
. */ public void update(ProcessContext ctx) throws DAOException; }
Now create a file called JDODAOFactory
which extends
the abstract DAOFactory
class.
public abstract class DAOFactory { /** * Creates a new DAOFactory. The actual type is defined by * the property bexee.dao.factory. * * If it is not set then MemoryDAOFactory will be created. */ public static DAOFactory getInstance() { // implementation omitted } /** * The concrete factories will have to implement this method. */ public abstract BPELProcessDAO createBPELProcessDAO(); /** * The concrete factories will have to implement this method. */ public abstract ProcessContextDAO createProcessContextDAO(); }
public class JDODAOFactory extends DAOFactory { public BPELProcessDAO createBPELProcessDAO() { return new JDOBPELProcessDAO(); } public ProcessContextDAO createProcessContextDAO() { return new JDOProcessContextDAO(); } }
If you are building bexee from source you probably know what you're doing and can jump to the next section.
If you've downloaded a bexee binary distribution, however, you'll have
to make sure that bexee will find your classes. Compile and JAR them and
then put them into a directory that is on the classpath. If you are
running Tomcat, then $TOMCAT_HOME$/common/lib
might be a
good place to drop your JAR.
As a last step you'll have to tell bexee about the new classes to use.
To do this, simply modify the bexee.dao.factory property in the
bexee.properties file appropriately. Assuming that you created the
classes in the bexee.dao
package, the property would
probably look something like this:
bexee.dao.factory=bexee.dao.JDODAOFactoy
Alternatively you can also set a system property with the -D
option:
java ... -Dbexee.dao.factory=my.package.JDOFactory