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

    /**
     * Second scenario:transaction is rare
     * we control connection inside service classes.
     */

    /**
     * -----ConnectionManager.class---------
     */

       public static Connection getConnection()
       {
        return getConnection(ModuleConfig.getDefaultJndi());
       }
      
       public static Connection getConnection(final String jndi)
       {
        Connection conn = null;
        try
        {       
         DataSource ds = dsMap.get(jndi);
            if(ds==null) return null;
           
            conn = ds.getConnection();       
            conn.setAutoCommit(true);
        }
        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())
        {

         conn = ConnectionManager.getConnection();
         bs.setConnection(conn);
         bs.setDao(BeanFactory.newDao(beanId,conn));
        }
        if(method!=null)
        {
            try
            {         
                targetJsp = (String)method.invoke(ba);
            }
            catch(Exception e)
            {
             SysLogger.error("Error:" + bs.getClass().getName() + "." + method.getName(),e);
         targetJsp = null;
            }
           }
        if(ann.isNeedDB())
         ConnectionManager.close(conn);
           forward(request,response,targetJsp);
       } 
         
       /**
        * example:method in service class
        * operating conncetion in service
        */

     /**
      * 這是兩個dao實現(xiàn)一個事處的最好例子
      */
     public void addTop(MenuDto dto) throws Exception
     {
      Connection conn = getConnection();
      try
                    {   
       conn.setAutoCommit(false);
       
       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());
       
       conn.commit();
      }
      catch(Exception e)
      {    
       ConnectionManager.rollback(conn);
                            throw e;        
      }  
     }

    posted on 2007-05-14 14:18 afunms 閱讀(162) 評論(0)  編輯  收藏


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


    網(wǎng)站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 理论亚洲区美一区二区三区| 亚洲一二成人精品区| 亚洲视频在线观看2018| 9277手机在线视频观看免费| 亚洲国产成人片在线观看| 污污污视频在线免费观看| 四虎国产精品免费视| 久久亚洲精品无码网站| 国产午夜免费福利红片| 粉色视频免费入口| www国产亚洲精品久久久| 日本黄页网址在线看免费不卡| 宅男666在线永久免费观看| 国产亚洲精品美女| 亚洲女同成人AⅤ人片在线观看 | 免费观看国产小粉嫩喷水| 亚洲精品无AMM毛片| 国产大片91精品免费观看男同 | 你懂的网址免费国产| 亚洲精品成人片在线观看精品字幕| a毛片全部播放免费视频完整18| 亚洲成av人片天堂网| 国产1000部成人免费视频| 精品亚洲456在线播放| 国产gav成人免费播放视频| 一级毛片大全免费播放下载| 亚洲精品无码国产| 四虎在线最新永久免费| 亚洲精品国产首次亮相| 亚洲人AV永久一区二区三区久久| 波霸在线精品视频免费观看| 久久亚洲国产精品成人AV秋霞| 久久久久久久免费视频| 亚洲AV成人一区二区三区观看| 国产综合精品久久亚洲| 最近免费最新高清中文字幕韩国| 中日韩亚洲人成无码网站| 亚洲一区二区精品视频| 91福利免费视频| 羞羞视频免费网站入口| 国产精品久久久亚洲|