You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ja...@sordino.fi on 2003/07/11 11:55:05 UTC

J2EE DAO Pattern & Connection Pooling (struts-newbie)

Hello,

I'm planning an application for Lotus Domino that (hopefully) will be
ported to Tomcat/Struts too (MySQL/PostgreSQL). I'm trying to apply J2EE
DAO Pattern to hide db specific stuff (testing the concept). J2EE DAO
Pattern implies:

package dao;

import java.sql.Connection;

import dao.interfaces.*;
import dao.mysql.*;

public class MySQLDAOFactory extends DAOFactory {

     private static final String DRIVER = "org.gjt.mm.mysql.Driver";
     private static final String DBURL
= "jdbc:mysql://localhost:3306/somedb";

     public static UnifiedConnection getConnection() {
          // how to access Struts connection pooling?
     }

     public Object1DAO getObject1DAO() {
          return new MySQLObject1DAO();
     }

     public Object2DAO getObject2DAO() {
          return new MySQLObject2DAO();
     }
}

How do I access Struts connection pooling from data access layer? Is it
even possible to implement getConnection at dao level in Struts framework?

In Struts action I would like to write:

Business business = new Business(pk); // create business object and load
data from db

which calls the constructor:

public Business(String pk) {
     DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MySQL);
     this.dao = factory.getObject1DAO();
     this.data = (Object1VO) dao.load(pk);
}

But mayby I'm forced to write something like:

DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MySQL);
factory.setConnection( new JDBCConnection( struts_pooled_conn ) );
Business business = new Business(factory, pk); // does this brake layer
skipping rule?

Or should I create the connected DAO object  in Struts action and pass it
to the business object? Isn't it braking the layer skipping rule also? I
want to keep my business objects as neutral as possible as they are reused
in a completely different platform.

Btw, I cannot use JDBC to access Lotus Domino (for reasons out of scope) so
I must do something like UnifiedConnection that is being extended by
different connection types (JDBCConnection, DominoConnection). I'm sorry if
this has been asked and answered previously, I just couldn't find any
suitable as Domino makes it more tricky I guess...

Many TIA,
Jan



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org