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

    dao scenario 1

    /**
     * First scenario:transaction is often used in the system
     * we control connection outside service classes.
     */

    /**
     * -----ConnectionManager.class---------
     */
       public static Connection getConnection()
       {
        return getConnection(ModuleConfig.getDefaultJndi(),true);
       }

       public static Connection getConnection(final boolean auto)
       {
        return getConnection(ModuleConfig.getDefaultJndi(),auto);
       }
      
       public static Connection getConnection(final String jndi,final boolean auto)
       {
        Connection conn = null;
        try
        {       
         DataSource ds = dsMap.get(jndi);
            if(ds==null) return null;
           
            conn = ds.getConnection();       
            conn.setAutoCommit(auto);
        }
        catch(SQLException sqle)
        {
         SysLogger.error("Database fail to get connection 1",sqle);
        }
        catch(Exception sqle)
        {
         SysLogger.error("Database fail to get connection 2",sqle);
        }
        return conn;
       }
         
       public static void rollback(Connection conn)
       {
        try
        {
         if(conn==null || conn.isClosed())
          return;
        
         if(!conn.getAutoCommit())         
               conn.rollback();
        }
        catch(SQLException se)
        {
            SysLogger.error("Can not do rollback operation.",se);        
        }
       }  
    }  

    /**
     * -----ActionServlet.class---------
     */

       private void processHttpRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
       {   
        response.setContentType("text/html;charset=GB2312");  
        request.setCharacterEncoding("GB2312");  
       
        String beanId = extractBeanID(request.getRequestURI());
        String methodName = request.getParameter("method");   
        String targetJsp = null;
       
        if(beanId==null || methodName==null)
        {
         request.setAttribute(EXCEPTION_MESSAGE,"請求URI錯誤.");
         forward(request,response,targetJsp);
         return;
        }   
        BaseAction ba = BeanFactory.newAction(beanId);
        BaseService bs = BeanFactory.newService(beanId);
        if(ba==null || bs == null)
        {
         request.setAttribute(EXCEPTION_MESSAGE,"沒有Bean為" + beanId + "的action或service");
         forward(request,response,targetJsp);
         return;
        }
         
        ActionAnnotation ann = AnnotationExtractor.getAnnotation(ba.getClass(), methodName);
        ba.setRequest(request);
        ba.setService(bs);              
        Method method = SysUtil.lookupMethod(ba.getClass().getMethods(),methodName);   

        Connection conn = null;
        if(ann.isNeedDB())
        {

       /**
        * -----get connection and set autoCommit to false---------
        */ 
        
    conn = ConnectionManager.getConnection(false);
         bs.setConnection(conn);
         bs.setDao(BeanFactory.newDao(beanId,conn));
        }
        if(method!=null)
        {
            try
            {         
                targetJsp = (String)method.invoke(ba);
        /**
         * -----if method is executed successfully,commit connection---------
         */       

          if(ann.isNeedDB()) conn.commit();
            }
            catch(Exception e)
            {
             SysLogger.error("Error:" + bs.getClass().getName() + "." + method.getName(),e);
          /**
        * connection rollback when run into exception
        */
            
    if(ann.isNeedDB()) ConnectionManager.rollback(conn);
          targetJsp = null;
            }
           }
        if(ann.isNeedDB())
         ConnectionManager.close(conn);
           forward(request,response,targetJsp);
       }  
          
          /**
         * example:method in service
      * there has not code for operating conncetion
         */
     
    public void addTop(MenuDto dto) throws Exception
     {
      Connection conn = getConnection();
      MenuDao mDao = new MenuDao(conn);
      MenuRoleDao mrDao = new MenuRoleDao(conn);
      MenuDto menu = mDao.getNextMenu();
      menu.setTitle(dto.getTitle());
      mDao.save(menu);
      mrDao.saveMenu(menu.getId());
     }

    posted on 2007-05-13 14:09 afunms 閱讀(186) 評論(0)  編輯  收藏


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


    網(wǎng)站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 不卡精品国产_亚洲人成在线| 免费国产a国产片高清| 亚洲国产精品无码久久久秋霞2| 国产亚洲综合视频| 国产精品无码一区二区三区免费| 亚洲中文字幕无码亚洲成A人片| 99国产精品永久免费视频| 亚洲白嫩在线观看| 美女被cao免费看在线看网站| 亚洲欧洲在线播放| AV免费网址在线观看| 亚洲中文字幕无码久久2020 | 亚洲精品国产精品| 麻豆成人精品国产免费| 亚洲AV无码专区在线电影成人| 好爽好紧好大的免费视频国产 | 在线免费视频你懂的| 亚洲色婷婷一区二区三区| 久久免费精彩视频| 久久精品国产亚洲av麻豆蜜芽| 在线播放免费播放av片| 四虎成人精品国产永久免费无码| 亚洲综合无码AV一区二区 | 成人午夜大片免费7777| 色婷婷亚洲一区二区三区| 国产国拍亚洲精品福利 | 亚洲VA中文字幕不卡无码| 最近免费中文字幕mv在线电影| 亚洲日本久久一区二区va| 国产在线观看免费不卡| 在线观看免费无码专区| 亚洲国产综合第一精品小说| 日韩精品无码人妻免费视频| 国产做国产爱免费视频| 亚洲乱码一区二区三区国产精品| 亚洲 小说区 图片区 都市| 无码人妻AV免费一区二区三区| 自拍日韩亚洲一区在线| 中文字幕无码精品亚洲资源网| 日本h在线精品免费观看| 色多多免费视频观看区一区|