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


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


    網站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 日本亚洲视频在线| 亚洲精品国偷自产在线| 亚洲mv国产精品mv日本mv| 免费女人高潮流视频在线观看| 日韩亚洲变态另类中文| 中文无码日韩欧免费视频| 亚洲中文字幕无码不卡电影| 精品国产污污免费网站入口| 亚洲人色婷婷成人网站在线观看| 91成人免费观看在线观看| 婷婷精品国产亚洲AV麻豆不片 | 亚洲AV一宅男色影视| 桃子视频在线观看高清免费视频| 亚洲国产精品久久久天堂| 99在线免费观看视频| 亚洲国产精品免费在线观看| 无码人妻久久一区二区三区免费丨 | 久久久亚洲裙底偷窥综合| 最近中文字幕mv免费高清在线 | 亚洲的天堂av无码| 国产免费不卡v片在线观看| 亚洲色丰满少妇高潮18p| 国产乱弄免费视频| 久久久精品午夜免费不卡| 亚洲日本国产精华液| 色吊丝最新永久免费观看网站| 成年免费a级毛片| 亚洲国产精品福利片在线观看| 7x7x7x免费在线观看| 色天使亚洲综合在线观看| 亚洲日本在线观看视频| h视频在线观看免费完整版| 国产精品亚洲天堂| 亚洲午夜视频在线观看| 噜噜嘿在线视频免费观看| 精品久久久久久无码免费| 亚洲午夜久久久精品影院| 国产无遮挡又黄又爽免费视频| 香蕉视频在线免费看| 亚洲一区中文字幕在线观看| 亚洲视频在线一区二区|