using System;

namespace  PostCardHitsuji.DataClient.DAO
{
    public class DaoFactory : IDisposable
    {

        private DaoEssenceAdapter daoEssence_ ;
        
        public DaoFactory()
        {
            daoEssence_ = new DaoEssenceAdapter();
            daoEssence_.getConnection();
            daoEssence_.openConnection();
        }

        public IDao getDao<T>(string daoClassURI)
        {
            var daoType = Type.GetType(daoClassURI);
            IDao dao = (IDao)Activator.CreateInstance(daoType);
            dao.setDaoHelper(this.daoEssence_);
            return dao;
        }

        public void Dispose()
        {
            daoEssence_.closeConnection();
            daoEssence_ = null;
        }

        public void beginTransaction()
        {
            daoEssence_.beginTransaction();
        }

        public void commitTransaction()
        {
            daoEssence_.commit();
        }

        public void rollbackTransaction()
        {
            daoEssence_.rollback();
        }

    }
}
