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


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


    網(wǎng)站導(dǎo)航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 国产在线一区二区综合免费视频| 日韩免费a级毛片无码a∨| 华人在线精品免费观看| 100000免费啪啪18免进| 可以免费观看一级毛片黄a | 亚洲&#228;v永久无码精品天堂久久| 亚洲精品午夜无码专区| 亚洲精品成人av在线| 久久久久久久久无码精品亚洲日韩| yellow免费网站| 99热在线精品免费全部my| 亚洲精品无码av天堂| 亚洲三级高清免费| 鲁丝片一区二区三区免费 | 亚洲精品福利网泷泽萝拉| 特级毛片全部免费播放a一级| 四虎免费影院ww4164h| 国产黄色一级毛片亚洲黄片大全| 亚洲国产成人久久综合一区| 一级毛片免费播放男男| 野花高清在线观看免费3中文| 国产亚洲一区二区三区在线| 真人无码作爱免费视频| 毛片a级三毛片免费播放| 久久亚洲免费视频| 四虎一区二区成人免费影院网址| 成人免费一级毛片在线播放视频| 久久亚洲国产精品一区二区| yellow视频免费看| 青青青国产色视频在线观看国产亚洲欧洲国产综合 | 亚洲精品无码成人片久久| 久久精品国产亚洲AV| 在线观看av永久免费| 亚洲欧洲国产日韩精品| 国产成人无码区免费网站| 亚洲精品456播放| 香蕉视频免费在线| 国产又大又长又粗又硬的免费视频| 亚洲熟妇无码爱v在线观看| 亚洲免费视频网站| 亚洲AV午夜福利精品一区二区|