ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: day/night night config.
Date Fri, 11 Feb 2005 00:34:00 GMT
Just when I thought I had seen everything... ;-)

Yes, every time you call buildDaoManager() you'll get a new instance. 
The builder doesn't cache these instances.  You can easily cache it
yourself in a map or something.

Cheers,
Clinton


On Thu, 10 Feb 2005 15:10:40 -0000, Mark Ferguson
<mark.ferguson@port.ac.uk> wrote:
> I have a working Dao manager/SqlMap implementaion for a portal.
> 
> How would I change the configuration or implementation so that I can use a
> diferent dao.xml file at night than during the day without compromising
> connection pooling etc.
> 
> Originaly my dao config looed like this
> 
> public class DaoConfig {
> 
>         private static final DaoManager daoManager;
> 
>         static {
> 
>                 try {
>                         String resource = "com/uop/struts/dao/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;
>         }
> }
> 
> I then changed it to this :-
> 
> public class DaoConfig {
> 
> private static DaoManager daoManager;
> 
> public static DaoManager getDaomanager() {
>         try {
>                 String resource = null;
>                 Calendar date = new GregorianCalendar();
>                 if (date.get(Calendar.HOUR_OF_DAY) > 8 &&
> (date.get(Calendar.HOUR_OF_DAY) < 20) {
>                         resource = "com/uop/struts/dao/daoDay.xml";
>                 } else {
>                         resource = "com/uop/struts/dao/daoNight.xml";
>                 }
>                 Reader reader = Resources.getResourceAsReader(resource);
>                 daoManager = DaoManagerBuilder.buildDaoManager(reader);
> 
>                 } catch (Exception e) {
>                 throw new RuntimeException(
>                                 "Could not initialize DaoConfig.  Cause: " + e);
>         }
>         return daoManager;
> }
> 
> However each time I call
> DaoConfig.getDaomanager() it looks as though it creates a new DaoManager
> rather than returning the existing one for the current period.
> 
> does this make sense?
> any help greatfully received
> thanks
> 
> --
> Mark Ferguson
>

Mime
View raw message