<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)  編輯  收藏


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


    網站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 女人张开腿等男人桶免费视频| 新最免费影视大全在线播放| 一级毛片直播亚洲| 思思re热免费精品视频66| 91免费在线视频| 亚洲av无码专区国产不乱码| 亚洲黄色三级视频| 精品久久香蕉国产线看观看亚洲| 国产成人久久AV免费| 久久久久亚洲AV无码去区首| 亚洲一卡二卡三卡| 自怕偷自怕亚洲精品| 国产亚洲色婷婷久久99精品| 亚洲国产成人久久综合区| 在线观看国产情趣免费视频| 免费视频专区一国产盗摄| 18禁美女裸体免费网站 | 激情吃奶吻胸免费视频xxxx| 久久综合亚洲色HEZYO社区| 亚洲AV午夜成人影院老师机影院| 97碰公开在线观看免费视频| 久久久久久影院久久久久免费精品国产小说 | 免费看www视频| 可以免费看黄的网站| 一区二区三区观看免费中文视频在线播放| 亚洲免费黄色网址| 中文字幕亚洲综合久久2| 亚洲AV无码一区二区二三区入口| 国语成本人片免费av无码| a毛片基地免费全部视频| 精品香蕉在线观看免费| 麻豆国产精品免费视频| 久久成人国产精品免费软件| 亚洲免费人成视频观看| 久久久久国色AV免费观看性色| 一级做a爰片性色毛片免费网站| 久久精品国产亚洲AV嫖农村妇女| 永久黄网站色视频免费直播| 色吊丝永久在线观看最新免费| 成全视频在线观看免费| 最好免费观看高清在线 |