<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)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 两个人看的www免费视频中文| 四虎影视在线永久免费看黄| 日韩成人毛片高清视频免费看| 亚洲精品免费在线视频| 亚洲精品国自产拍在线观看| 黄色片在线免费观看| 3344在线看片免费| av网站免费线看| 亚洲aⅴ天堂av天堂无码麻豆| 亚洲最新黄色网址| 亚洲av午夜成人片精品网站| 亚洲国产成人五月综合网| 女性自慰aⅴ片高清免费| 久久99精品免费视频| aa级女人大片喷水视频免费| 亚洲av日韩专区在线观看| 亚洲国产精品日韩在线| 亚洲欧洲在线观看| 亚洲乱码国产乱码精品精| 亚洲精品456播放| 亚洲国产精品13p| 免费在线黄色网址| 国产精品极品美女免费观看| 在线免费一区二区| 成人毛片免费在线观看| 青青青国产在线观看免费网站 | 毛片免费vip会员在线看| 91久久精品国产免费一区| 中文字幕不卡免费高清视频| 免费高清A级毛片在线播放| 精品在线视频免费| 四虎精品成人免费视频| 黄色毛片视频免费| 一级做a爰片久久毛片免费陪 | 国产成人精品男人免费| 国产午夜影视大全免费观看| 青草草在线视频永久免费| 午夜老司机免费视频| 麻豆国产人免费人成免费视频| 全免费a级毛片免费看无码| 青青草国产免费久久久91|