You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by mfs <fa...@gmail.com> on 2008/06/24 00:48:55 UTC

DAO Framework - question on thread-safety

Guys,

I am using ibatis DAO Framework and i had certain questions/concerns, that
whether my current DAO Manager implementation is thread safe, since
apparently the getDAO(MyDAOClass.class) method (which i am using to retrieve
the dao implementation) isn't thread safe. Also Larry mentioned in one some
other thread that there is one instance maintained of each DAO
implementation and thats yet another reason which made to me ask this...

class MyDAOManager
{
    private static DaoManager s_daoManager;

    public static synchronized DaoManager getDaoManager()
    {
      Log log = LogFactory.getLog(DAOManager.class);
      if (null == s_daoManager)
      {
          try
          {
              String daoXMLresource = "[path]/dao.xml";
              Reader reader = Resources.getResourceAsReader(daoXMLresource);
              s_daoManager = DaoManagerBuilder.buildDaoManager(reader);
              log.info("DAOManager Initialized");
          }
          catch (IOException ioe)
          {
              throw new RuntimeException("Could not initialize DaoConfig. 
Cause: " + ioe);
          }
      }
      return s_daoManager;
    }

    public static AccountDAO getAccountDao()
    {
        return (AccountDAO) getDaoManager().getDao(AccountDAO.class);
    }

    public static UserDAO getUserDao(Class interfaceClass)
    {
        return (UserDAO) getDaoManager().getDao(UserDAO.class);
    }

Thanks and Regards,


    
-- 
View this message in context: http://www.nabble.com/DAO-Framework---question-on-thread-safety-tp18080103p18080103.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: DAO Framework - question on thread-safety

Posted by mfs <fa...@gmail.com>.
Thanks for the quick followup Clinton. That does handle my concerns..

Clinton Begin wrote:
> 
> It's all thread safe, including getDao(Class).  Each instance will be
> thread
> safe as well.
> 
> Clinton
> 
> On Mon, Jun 23, 2008 at 4:48 PM, mfs <fa...@gmail.com> wrote:
> 
>>
>> Guys,
>>
>> I am using ibatis DAO Framework and i had certain questions/concerns,
>> that
>> whether my current DAO Manager implementation is thread safe, since
>> apparently the getDAO(MyDAOClass.class) method (which i am using to
>> retrieve
>> the dao implementation) isn't thread safe. Also Larry mentioned in one
>> some
>> other thread that there is one instance maintained of each DAO
>> implementation and thats yet another reason which made to me ask this...
>>
>> class MyDAOManager
>> {
>>    private static DaoManager s_daoManager;
>>
>>    public static synchronized DaoManager getDaoManager()
>>    {
>>      Log log = LogFactory.getLog(DAOManager.class);
>>      if (null == s_daoManager)
>>      {
>>          try
>>          {
>>              String daoXMLresource = "[path]/dao.xml";
>>              Reader reader =
>> Resources.getResourceAsReader(daoXMLresource);
>>              s_daoManager = DaoManagerBuilder.buildDaoManager(reader);
>>              log.info("DAOManager Initialized");
>>          }
>>          catch (IOException ioe)
>>          {
>>              throw new RuntimeException("Could not initialize DaoConfig.
>> Cause: " + ioe);
>>          }
>>      }
>>      return s_daoManager;
>>    }
>>
>>    public static AccountDAO getAccountDao()
>>    {
>>        return (AccountDAO) getDaoManager().getDao(AccountDAO.class);
>>    }
>>
>>    public static UserDAO getUserDao(Class interfaceClass)
>>    {
>>        return (UserDAO) getDaoManager().getDao(UserDAO.class);
>>    }
>>
>> Thanks and Regards,
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/DAO-Framework---question-on-thread-safety-tp18080103p18080103.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/DAO-Framework---question-on-thread-safety-tp18080103p18081126.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: DAO Framework - question on thread-safety

Posted by Clinton Begin <cl...@gmail.com>.
It's all thread safe, including getDao(Class).  Each instance will be thread
safe as well.

Clinton

On Mon, Jun 23, 2008 at 4:48 PM, mfs <fa...@gmail.com> wrote:

>
> Guys,
>
> I am using ibatis DAO Framework and i had certain questions/concerns, that
> whether my current DAO Manager implementation is thread safe, since
> apparently the getDAO(MyDAOClass.class) method (which i am using to
> retrieve
> the dao implementation) isn't thread safe. Also Larry mentioned in one some
> other thread that there is one instance maintained of each DAO
> implementation and thats yet another reason which made to me ask this...
>
> class MyDAOManager
> {
>    private static DaoManager s_daoManager;
>
>    public static synchronized DaoManager getDaoManager()
>    {
>      Log log = LogFactory.getLog(DAOManager.class);
>      if (null == s_daoManager)
>      {
>          try
>          {
>              String daoXMLresource = "[path]/dao.xml";
>              Reader reader = Resources.getResourceAsReader(daoXMLresource);
>              s_daoManager = DaoManagerBuilder.buildDaoManager(reader);
>              log.info("DAOManager Initialized");
>          }
>          catch (IOException ioe)
>          {
>              throw new RuntimeException("Could not initialize DaoConfig.
> Cause: " + ioe);
>          }
>      }
>      return s_daoManager;
>    }
>
>    public static AccountDAO getAccountDao()
>    {
>        return (AccountDAO) getDaoManager().getDao(AccountDAO.class);
>    }
>
>    public static UserDAO getUserDao(Class interfaceClass)
>    {
>        return (UserDAO) getDaoManager().getDao(UserDAO.class);
>    }
>
> Thanks and Regards,
>
>
>
> --
> View this message in context:
> http://www.nabble.com/DAO-Framework---question-on-thread-safety-tp18080103p18080103.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>