Ricardo de Souza Moura wrote:
> I have read about CMP and DAO, and Some people said that when I use
> CMP, DAO
> don't make sense...
> But
> What if I want to have the possibility to change to JDBC DAO for sample ?
> I would have to change all my business method, wouldn't I ?
> But If I make a DAO like this:
>
> public class EJBFamilyDAO implements IFamilyDAO {
>
> Context context = null;
> FamilyHome home = null;
>
> /*
> * (non-Javadoc)
> *
> * @see
> com.shoptime.integration.crmerp.persistence.IFamilyDAO#insertFamily(
java.lang.String)
>
> */
> public void insertFamily(String pFamilyName) {
> // TODO Auto-generated method stub
> home.create(pFamilyName);
> }
>
> /*
> * (non-Javadoc)
> *
> * @see
> com.shoptime.integration.crmerp.persistence.IFamilyDAO#findFamilyByName(
java.lang.String)
>
> */
> public FamilyVO findFamilyByName(String pName) {
> // TODO Auto-generated method stub
> return home.findBFamilyByName(pName);
> }
>
> public EJBFamilyDAO() {
> try {
> context = new InitialContext();
> home = context.lookup(...);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> }
> Wouldn't it be more easy to change my business method? I only need
> change my
> DAO Implementation, don't I ?
>
> Thanks in advance
>
> _________________________________________________________________
> MSN Messenger: converse com os seus amigos online.
> http://messenger.msn.com.br
>
> ====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
> List Archive:
> http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to
> listserv@(protected)
>
I am working on a project and I have same problem, but now I have a
problem: "transactions".
I want to start my project using only JDBC and in future switch to
entity bean (this is a requirement).
The problem is that my DAO may manage transaction inside their methods
or a DAO may partecipate to an external transaction.
So I have for each DAO impl. two constructor:
class MyDAOImpl extends DAO {
MyDAO() {}
MyDAO(Transaction t) {}
}
class MyDAOFActory {
DAO create();
DAO create(Transaction t);
}
where Transaction is a wrapper class of Connection.
Suppose my DAO should partecipate to a transaction in a business method
like this:
business() {
Transaction t = new Transaction();
DAO dao = factory.create(t);
DAO dao2 = factory.create(t);
...
dao.method1()
dao.method2();
dao2.method3();
...
t.commit();
}
the problem now is: when I switch to EJB CMP I do not need to manage
transaction, so Will I change all my business method?
I do not know how to solve this problem (the implementation of DAO
reported above has been extracted from Firestorm dao generator tool).
Any suggestion is welcome.
====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)