<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级毛片成人网站免费看| 亚洲日本久久久午夜精品| 久香草视频在线观看免费| 午夜dj免费在线观看| 色噜噜亚洲男人的天堂| 100部毛片免费全部播放完整| 亚洲成AV人在线观看天堂无码| 国产免费阿v精品视频网址| 国产亚洲精品一品区99热| 免费在线观影网站| 亚洲一区影音先锋色资源| 最近中文字幕完整版免费高清| 亚洲最新在线视频| 免费精品人在线二线三线区别| 亚洲色偷偷综合亚洲AV伊人蜜桃 | 亚洲乱码中文字幕在线| 女人18毛片水真多免费看| 狠狠综合亚洲综合亚洲色| 亚洲一级片免费看| 亚洲免费观看视频| 激情内射亚洲一区二区三区| 在线观看免费人成视频色| 亚洲AV无码国产精品永久一区| 亚洲国产综合精品中文字幕| 成人无码区免费A∨直播| 91亚洲一区二区在线观看不卡| 久久久久久精品免费免费自慰| 亚洲综合在线一区二区三区| 亚洲国产精品毛片av不卡在线| 免费无码一区二区三区蜜桃| 亚洲制服丝袜在线播放| 国产男女性潮高清免费网站 | 成人特黄a级毛片免费视频| 美女扒开尿口给男人爽免费视频| 国产成人精品亚洲精品| 91免费福利精品国产| 精品国产日韩亚洲一区在线| 国产亚洲精品美女久久久 | 真实国产乱子伦精品免费| 亚洲成AV人片高潮喷水| 亚洲精品无码av人在线观看 |