Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 5
Given these requirements, the Object query language (OQL) is an ideal candidate from which to model the DAOQL, as the OQL is a comprehensive, object-based query language, already familiar to many business developers.
The DaoFactory class's plug-and-play nature and the added abstraction layer between the business objects and the data store provide us with
a service provider interface, or SPI (to borrow a term from the JNDI provider architecture), for third-party (or in-house)
DAO providers to use. The beauty of this new SPI: it matches exactly the API business objects use. A DAO provider must subclass
only the DaoFactory class and implement the Dao interface as necessary for its data source type. Thus, a DAO provider must implement only five methods from the Dao interface and one method from the DaoFactory abstract class. This obligates our DAO provider to a whopping six methods! Admittedly, this is easier said than done, but
as you will see, implementing your own DAO provider doesn't have to be such a daunting task, provided you use the right tools.
In this section, I show how easily you can implement your own JDBC DAO provider, using a few open source utilities. All the
classes you use to implement the JDBC DAO provider are contained in the com.carmanconsulting.dao.jdbc package. First, I devise an object-to-relational mapping model for use throughout the framework. Then, I implement one persistence
method, delete(). Finally, I construct a portion of the DAOQL query-processing engine. The primary classes for this provider are JdbcDaoFactory and JdbcDao:
public class JdbcDaoFactory extends DaoFactory
{
public Dao createDao();
void setDomainMapFileName( String domainMapFileName );
void setDebug( int debug );
void setDataSourceName( String dataSource );
}
class JdbcDao implements Dao
{
public void create( Object o );
public Collection retrieve( String queryString );
public void update( Object o );
public void delete( Object o );
public void close();
}
The JdbcDaoFactory class uses a javax.sql.DataSource object to establish connections to the database. The dataSourceName property represents a JNDI name used to look up the javax.sql.DataSource instance within the default JNDI initial context. The domainMapFileName property locates the configuration file for the object-to-relational mapping model.
The object-to-relational mapping model involves only a few classes: