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


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


    網(wǎng)站導(dǎo)航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 黄网址在线永久免费观看| 无码国产精品一区二区免费虚拟VR| 日韩成全视频观看免费观看高清| 亚洲依依成人精品| 久久国产免费福利永久| 亚洲av午夜精品无码专区| 五月婷婷在线免费观看| 亚洲天堂一区在线| 999久久久免费精品国产| 亚洲av无码片在线观看| 成年女人午夜毛片免费看| 亚洲AV永久无码精品放毛片| 国产小视频免费观看| 本道天堂成在人线av无码免费| 亚洲中文字幕日产乱码高清app| 99在线免费视频| 亚洲美女激情视频| 毛片免费观看的视频| 国产成人亚洲精品蜜芽影院| 亚洲AV无码成H人在线观看| 中国一级特黄的片子免费 | 国产免费变态视频网址网站| 美女羞羞免费视频网站| 亚洲乱码国产乱码精品精| 免费人成视频在线观看网站| 亚洲一线产品二线产品| 国产亚洲精品不卡在线| 久久久久免费看成人影片| 亚洲人成电影网站色| 在线观看亚洲成人| 0588影视手机免费看片| 污污污视频在线免费观看| 91大神亚洲影视在线| 日本视频免费在线| 日本免费污片中国特一级| 亚洲精品无码成人| 亚洲国产精品成人精品无码区在线| 少妇高潮太爽了在线观看免费| 无码精品人妻一区二区三区免费| 亚洲综合久久1区2区3区| 亚洲人妻av伦理|