<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 閱讀(143) 評論(0)  編輯  收藏


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


    網站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 国产福利电影一区二区三区,亚洲国模精品一区 | 中文字幕亚洲第一在线| 你懂的在线免费观看| 亚洲中文无韩国r级电影| 特级毛片aaaa级毛片免费| 国产免费av一区二区三区| 亚洲AV成人无码网天堂| 国产人成免费视频| 特级毛片爽www免费版| 国产中文字幕免费观看| 永久免费无码日韩视频| 久久亚洲色一区二区三区| a毛片在线免费观看| 久久久久亚洲精品天堂| 台湾一级毛片永久免费| 亚洲无吗在线视频| 国产在线观看免费不卡| 免费国产va视频永久在线观看| 亚洲国产精品碰碰| 成人久久免费网站| 亚洲视频免费在线看| 毛片在线免费视频| 国产亚洲综合视频| 精品国产_亚洲人成在线高清| 亚洲日韩国产成网在线观看| 伊人免费在线观看| 亚洲精品自在线拍| 国产福利免费在线观看| 成人妇女免费播放久久久| 亚洲精品福利网泷泽萝拉| 日产乱码一卡二卡三免费| 亚洲 日韩 色 图网站| 久久aⅴ免费观看| 亚洲xxxx视频| 亚洲色婷婷一区二区三区| 中文免费观看视频网站| 精品亚洲成a人在线观看| 午夜两性色视频免费网站| 亚洲av极品无码专区在线观看| 日本不卡视频免费| 久久大香香蕉国产免费网站|