ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Folashade Adeyosoye" <sharda...@gmail.com>
Subject RE: iBatis DAO Loading dao.xml
Date Mon, 02 May 2005 17:42:36 GMT
I do not think am mingling ibatis and my struts layer....

The iniSystem calls a Service class that loads the cache, I only noticed
that whenever super.init(config); is invoked rather than super.init();,
iBatis in the DaoConfig has problems with the ResourceReader...


Hope that clears it..

-----Original Message-----
From: Brandon Goodin [mailto:brandon.goodin@gmail.com] 
Sent: Monday, May 02, 2005 1:35 PM
To: ibatis-user-java@incubator.apache.org
Subject: Re: iBatis DAO Loading dao.xml

Why are you mingling iBatis with the servlet layer? Initialization
would be better placed in the service layer.

Brandon

On 5/2/05, Folashade Adeyosoye <shardayyy@gmail.com> wrote:
> I found it strange enough that it did make a diff if I pass in a
> ServletConfig config or not...
> 
>   public void init(ServletConfig config) throws ServletException {
>     logger.info("ExtendedActionServlet init()...");
>     super.init(config);               <----------------- THIS
>     initSystem(config);
>   }
> 
> If super.init(config) is called it has problems reading the dao.xml file,
I
> think this it's the ResourceReader. As soon as I took the config off, it
> went pass the ResourceReader line.
> 
> And this a class that extends the ActionServlet, this is called on startup
> of the application..
> 
> The initSystem calls methods to setup my cache...
> 
> 
> -----Original Message-----
> From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
> Sent: Monday, May 02, 2005 1:04 PM
> To: ibatis-user-java@incubator.apache.org
> Subject: RE: iBatis DAO Loading dao.xml
> 
> Calls to buildDaoManager resolve to this class:
> 
> http://tinyurl.com/9qymm
>
http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/mapper/mapper2/s
> rc/com/ibatis/dao/engine/builder/xml/XmlDaoManagerBuilder.java
> 
> Have you browsed the JPetstore source code:
> 
> http://tinyurl.com/bpgl7
>
http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/jpetstore/jpetst
> ore4/src/com/ibatis/jpetstore/persistence/DaoConfig.java
> 
> to see how everything fits together?
> 
> Is something not working? Are calls to buildDaoManager throwing an
> exception?
> 
> --- Folashade Adeyosoye <shardayyy@gmail.com> wrote:
> 
> > The best way to find this out is to use your IDE to step thru the
> > code and
> > but break points. I have resulted to that in the last couple of days
> > to
> > actually see how the framework works.... but sadly have not been able
> > to get
> > pass the daoManager = DaoManagerBuilder.buildDaoManager(reader); in
> > my big
> > project that am converting.....
> >
> > But able to do it on a small one class (service class) file.
> >
> >
> >
> >
> > -----Original Message-----
> > From: Gregg D Bolinger [mailto:gthought@gmail.com]
> > Sent: Monday, May 02, 2005 12:39 PM
> > To: Brandon Goodin
> > Cc: ibatis-user-java@incubator.apache.org
> > Subject: Re: iBatis DAO Loading dao.xml
> >
> > >The dao manager does not parse it every time. It only parses once.
> >
> > Is this documented somewhere?  How does that work if my code is
> > telling the builder to build everytime a service request is made?  Is
> > it cached somewhere in memory much like the hand made singleton class
> > I am using?  I don't want to perform extra logic if I don't have to
> > but I need proof it is doing as expected. :)
> >
> > Thanks.
> >
> >
> >
> > On 5/2/05, Brandon Goodin <brandon.goodin@gmail.com> wrote:
> > > It would be perfectly fine to instantiate the Service class in your
> > > web layer. But, you might want to follow a similar pattern as the
> > > service layer does with the Dao classes. Instantiate your service
> > > classes in the constructor and assign them to instance variables in
> > > your Servlet, Action(Struts) or whatever you are using on the web
> > > layer. Considering your Service classes and your Dao classes should
> > be
> > > thread safe you will have no problem setting them as instance
> > > variables in the constructor.
> > >
> > > Brandon
> > >
> > > On 5/1/05, Gregg D Bolinger <gthought@gmail.com> wrote:
> > > > Thanks for the reply.  I actually did something similar to this
> > before
> > > > I saw your response.  I made the following class
> > > >
> > > > DaoManagerLoader.java
> > > > public class DaoManagerLoader {
> > > >
> > > >     public static final String DAO_XML_PATH =
> > > > "com/intrust/anykey/database/dao/iBatis/dao.xml";
> > > >     public static DaoManager daoManager = null;
> > > >
> > > >     public static DaoManager getInstance() {
> > > >         if (daoManager == null){
> > > >             System.out.println("Need a new one");
> > > >              try{
> > > >                  final Reader reader =
> > > > Resources.getResourceAsReader(DAO_XML_PATH);
> > > >                  daoManager =
> > DaoManagerBuilder.buildDaoManager(reader);
> > > >             }catch(IOException e) {
> > > >                 e.printStackTrace();
> > > >             }
> > > >         }else{
> > > >             System.out.println("Don't need a new one");
> > > >         }
> > > >         return daoManager;
> > > >     }
> > > > }
> > > >
> > > > And then in my XxxxServiceImpl I do:
> > > >
> > > > daoManager = DaoManagerLoader.getInstance();
> > > >
> > > > That seems to work pretty good.  With that being said, can I ask
> > > > another question. If I have my UserService, UserServiceImpl,
> > UserDao,
> > > > and UserDaoImpl all setup like the documentation states, and then
> > in
> > > > my application/web application I need to access the UserDAO, is
> > it
> > > > appropriate to instantiate it like this....
> > > >
> > > >  UserService userDAO = new UserServiceImpl();
> > > >
> > > > Or am I supposed to do it a differnet way.  I have attached the
> > files.
> > > >  I'd really like to know if I am doing this correctly.  Thanks.
> > > >
> > > > Gregg
> > > >
> > > >
> > > > On 5/2/05, Brandon Goodin <brandon.goodin@gmail.com> wrote:
> > > > > Saw a typo! oopsie :-)
> > > > >
> > > > > " I would not place the dao in my base service class."
> > > > >
> > > > > Should be:
> > > > > "I would not place the dao manager in my base service class."
> > > > >
> > > > > On 5/1/05, Brandon Goodin <brandon.goodin@gmail.com> wrote:
> > > > > > Hi Gregg,
> > > > > >
> > > > > > The dao manager does not parse it every time. It only parses
> > once.
> > > > > >
> > > > > > Also, I would do things a bit different than you are doing.
I
> > would
> > > > > > not place the dao in my base service class. I would use a
> > DaoConfig
> > > > > > class that holds the DaoManager reference as an static final
> > instance
> > > > > > variable. I would setup my Service classes to contain
> > instance
> > > > > > variable DAO classes that are loaded via the DaoConfig class
> > in the
> > > > > > constructor. See the examples below.
> > > > > >
> > > > > > --- DaoConfig.java ---
> > > > > > public class DaoConfig {
> > > > > >
> > > > > >   private static final DaoManager daoManager;
> > > > > >
> > > > > >   static {
> > > > > >
> > > > > >     try {
> > > > > >       String resource =
> > "org/apache/ibatis/jgamestore/dao/sqlmap/dao.xml";
> > > > > >       Reader reader =
> > Resources.getResourceAsReader(resource);
> > > > > >       daoManager = DaoManagerBuilder.buildDaoManager(reader);
> > > > > >     } catch (Exception e) {
> > > > > >       throw new RuntimeException("Could not initialize
> > DaoConfig.
> > > > > > Cause: " + e);
> > > > > >     }
> > > > > >   }
> > > > > >
> > > > > >   public static DaoManager getDaoManager() {
> > > > > >     return daoManager;
> > > > > >   }
> > > > > >
> > > > > > }
> > > > > >
> > > > > > --- CatalogServiceImpl.java ---
> > > > > >
> > > > > > public class CatalogServiceImpl implements CatalogService {
> > > > > >
> > > > > >   private DaoManager daoManager;
> > > > > >   private CategoryDao categoryDao;
> > > > > >   private ProductDao productDao;
> > > > > >   private ProductImageDao productImageDao;
> > > > > >   private ImageDao imageDao;
> > > > > >
> > > > > >   /**
> > > > > >    * regular empty constructor
> > > > > >    */
> > > > > >   public CatalogServiceImpl() {
> > > > > >     this.daoManager = DaoConfig.getDaoManager();
> > > > > >     this.categoryDao = (CategoryDao)
> > daoManager.getDao(CategoryDao.class);
> > > > > >     this.productDao = (ProductDao)
> > daoManager.getDao(ProductDao.class);
> > > > > >     this.productImageDao = (ProductImageDao)
> > > > > > daoManager.getDao(ProductImageDao.class);
> > > > > >     this.imageDao = (ImageDao)
> > daoManager.getDao(ImageDao.class);
> > > > > >   }
> > > > > > ...
> > > > > >
> > > > > > public void addProduct(Product product) {
> > > > > >     try {
> > > > > >       daoManager.startTransaction();
> > > > > >
> > > > > >       // save product
> > > > > >       productDao.addProduct(product);
> > > > > > ...
> > > > > >       daoManager.commitTransaction();
> > > > > >     } finally {
> > > > > >       daoManager.endTransaction();
> > > > > >     }
> > > > > > }
> > > > > >
> > > > > > Hope that helps,
> > > > > >
> > > > > > It is a BAD policy to make your service layer dependent on
> > the
> > > > > > view/web layer. Your web layer can depend on your service
> > layer.
> > But,
> > > > > > your service layer should never depend on your web layer.
> > Likewise
> > > > > > your Service Layer can depend on your DAO layer. But, your
> > DAO layer
> >
> === message truncated ===
> 
>


Mime
View raw message