This content has been marked as final.
Show 1 reply
-
1. Re: Question about DAO's
milx Sep 13, 2005 12:37 PM (in response to fourierxform)I suppose your DAOs are stateless session beans.
I?m currently using the latter approach of your post, where I have a DAOFactory interface, with local, remote and embedded implementations:public interface DAOFactory{ public DAO1 getDAO1(); public DAO2 getDAO2(); }
public DAOFactoryLocal implements DAOFactory{ public DAO1 getDAO1(){ return (DAO1)lookup(DAO1Local.class.getName()); } public DAO2 getDAO2(){ return (DAO2)lookup(DAO2Local.class.getName()); } private Object lookup(String name){ InitialContext ctx = new InitialContext(); return ctx.lookup(name); } }
The remote implementation is simply a copy of the local, the only difference is that is uses the classname of the remote interface instead of the local for the JNDI lookup. The embedded implementation obtains the InitialContext from a class that makes sure the embeddable Jboss EJB3 system is up and running before returning it.
This approach is rather ugly, and leads to a lot of copy & paste of code. It would be nice to be able to inject session beans into servlets running in the same container (VM) as the DAOs, thereby eliminating the need for the local implementation of the DAOFactory, but I think this is not supported by the specification yet.