<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    afunms

    My Software,My Dream—Forge a more perfect NMS product.

    perfect DAO design

    perfect DAO solution

    ------BaseDao------
    public abstract class BaseDao
    {  
       private static final int maxRow = 1000;
       protected Connection conn;
       protected String table;
       protected Class<? extends DtoInterface> dtoClass;
       protected JspPage jspPage;
       protected boolean insideConnection;
               
       public BaseDao(Connection conn)
       { 
        init();
        if(conn==null)
        {
         this.conn = ConnectionManager.getConnection();
         insideConnection = true;        
        }
        else
        {
            this.conn = conn;   
            insideConnection = false;
        }
       }

       public BaseDao()
       { 
        init();
        this.conn = ConnectionManager.getConnection();
        insideConnection = true;   
       }

       public void close(Statement stmt,ResultSet rs)
       {
        try
           {
              if(rs!= null)
                 rs.close();
              if(stmt!=null)
                 stmt.close();
              /**
               * if the connection is passed from outside
               * do not close it.
               */
              if(insideConnection)
              ConnectionManager.close(conn);
           }
           catch(SQLException se)
           {   
           }
       }

       protected abstract void init();
    }

    ------sub dao class example------
    public class ProducerDao extends BaseDao
    {
     public ProducerDao(Connection conn)
     {
      super(conn);
     } 
     
     protected void init()
        {
         super.dtoClass = ProducerDto.class;
         super.table = "nms_producer";
        } 

    ------client code-----
    For the first scenario

       ProducerDao dao = new ProducerDao(null);
    or ProducerDao dao = (ProducerDao)BeanFactory.newDao("producer");
       dao.method();

    For the second scenario
       Connection conn = ConnectionManager.createConnection();
       ProducerDao dao1 = new ProducerDao(conn);
       AnOtherDao dao2 = new AnOtherDao(conn);
       dao1.method1();
       dao2.method2();
       dao2.method3();
       ConnectionManager.close(conn);   

    or Connection conn = ConnectionManager.createConnection();
       ProducerDao dao = (ProducerDao)BeanFactory.newDao("producer",conn);
       AnOtherDao dao = (AnOtherDao)BeanFactory.newDao("another",conn);
       dao1.method1();
       dao2.method2();
       dao2.method3();
       ConnectionManager.close(conn);   

    posted on 2007-05-11 10:35 afunms 閱讀(144) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 69式互添免费视频| 久久精品视频免费| 免费少妇a级毛片| 亚洲国产精品日韩av不卡在线| 亚洲国产情侣一区二区三区| 久久99青青精品免费观看| 国产亚洲综合久久系列| GOGOGO高清免费看韩国| 色噜噜亚洲精品中文字幕 | 亚洲综合国产一区二区三区| 日本一区二区三区免费高清在线 | 国产99视频精品免费视频76| 国产精品免费观看调教网| 亚洲国产精品VA在线观看麻豆| 日韩成人免费视频| 亚洲欧洲在线播放| 韩国18福利视频免费观看| 国产偷国产偷亚洲高清人| 中文字幕精品亚洲无线码一区| a毛看片免费观看视频| 国内自产少妇自拍区免费| 精品久久亚洲一级α| 久久久久亚洲AV无码专区桃色| 亚洲an日韩专区在线| 女人被男人躁的女爽免费视频| 最新亚洲人成网站在线观看 | 免费观看四虎精品成人| 狠狠色婷婷狠狠狠亚洲综合| 久久国产乱子伦精品免费不卡| 亚洲天堂一区在线| 四虎影视永久免费观看地址| 亚洲三级在线视频| 国产无遮挡吃胸膜奶免费看视频 | 国内精品一级毛片免费看| 67pao强力打造67194在线午夜亚洲 | 亚洲a一级免费视频| 亚洲免费福利在线视频| 亚洲av无码成人精品区在线播放| 久久免费精品一区二区| 亚洲午夜福利在线视频| 亚洲一区二区女搞男|