/** * 获取频道评论 前n条数据 * * @param n * @return * @throws SQLException */ public NComentList getChannelCommnetList(String channel, int n) throws Exception { Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("channel", channel); paramMap.put("n", n + 1); TransactionManager tm = new TransactionManager(); try { tm.begin(tm.RW_TRANSACTION); NComentList nComentList = new NComentList(); nComentList.setComments( executor.queryListBean(DocComment.class, "getChannelCommnetNList", paramMap)); // Container container = new ContainerImpl(); // container.in /* if (!CollectionUtils.isEmpty(nComentList.getComments())) { for (DocComment docComment : nComentList.getComments()) { String documentUrl= container.getPublishedDocumentUrl(new Integer(docComment.getDocId()).toString()); docComment.setDocUrl(documentUrl); } }*/ nComentList.setTotal(getChannelCommentPublishedCount(channel)); return nComentList; } catch (SQLException e) { throw e; } catch (Exception e) { throw e; } finally { tm.releasenolog(); } }
/** * 经过测试证明存储过程中如果没有对插入/删除/修改操作做事务提交、回滚时,可以通过poolman * 的事务框架来管理事务;如果存储过程中对插入/删除/修改操作已经做了事务提交或者回滚时,那么应用的事务和存储过程中 中的事务就是分离的两个事务。 * * @param i 为0时回滚事务,1时提交事务 */ public @Test void testTest_fWithNameIndexForObjectTx() { int i = 1; TransactionManager tm = new TransactionManager(); try { tm.begin(); CallableDBUtil callableDBUtil = new CallableDBUtil(); callableDBUtil.prepareCallable("{? = call Test_f(?,?,?)}"); callableDBUtil.registerOutParameter(1, java.sql.Types.INTEGER); // 不允许的操作: Ordinal binding and Named binding cannot be combined! callableDBUtil.setInt(2, 10); callableDBUtil.registerOutParameter(3, java.sql.Types.VARCHAR); callableDBUtil.registerOutParameter(4, java.sql.Types.VARCHAR); Test_f tets = (Test_f) callableDBUtil.executeCallableForObject(Test_f.class); // System.out.println("name1:" + callableDBUtil.getString("name")); // System.out.println("name2:" + callableDBUtil.getString("name1")); System.out.println("Test_f is " + tets); callableDBUtil.executeInsert("insert into test(id,name) values('11','name11')"); if (i == 0) tm.rollback(); else tm.commit(); } catch (Exception e) { e.printStackTrace(); } finally { tm.release(); } }
public String showAllComments( String siteId, int docId, long channelId, HttpServletRequest request, HttpServletResponse response) throws Exception { Container container = new ContainerImpl(); container.initWithSiteid(siteId, request, request.getSession(false), response); TransactionManager tm = new TransactionManager(); try { tm.begin(tm.RW_TRANSACTION); // 获得该文档所在的频道评论开关 int channelCommentSwitch = docCommentManager.getDocCommentSwitch(String.valueOf(docId), "chnl"); if (channelCommentSwitch != 0) { // 首先判断频道的评论开关 request.setAttribute("commentSwitch", channelCommentSwitch); } else { int documentCommentSwitch = docCommentManager.getDocCommentSwitch(String.valueOf(docId), "doc"); request.setAttribute("commentSwitch", documentCommentSwitch); } // 获得该文档所在频道的评论审核开关 Integer aduitSwitchFlag = docCommentManager.getChannelCommentAduitSwitch((int) channelId); if (aduitSwitchFlag != null) { request.setAttribute("aduitSwitchFlag", aduitSwitchFlag); } else { request.setAttribute("aduitSwitchFlag", 1); } Document doc = CMSUtil.getCMSDriverConfiguration() .getCMSService() .getDocumentManager() .getPartDocInfoById(docId + ""); String docurl = container.getPublishedDocumentUrl(doc); request.setAttribute("docId", docId); request.setAttribute("channelId", channelId); request.setAttribute("docurl", docurl); request.setAttribute("docTitle", doc.getTitle()); request.setAttribute("doc", doc); return "path:showAllComments"; } finally { tm.releasenolog(); } }
/** 针对oracle Clob字段的插入操作 */ @Test public void testBigClobWrite() { PreparedDBUtil dbUtil = new PreparedDBUtil(); TransactionManager tm = new TransactionManager(); try { // 启动事务 tm.begin(); // 先插入一条记录,blob字段初始化为empty_lob dbUtil.preparedInsert("insert into test(id,clobname) values(?,?)"); String id = DBUtil.getNextStringPrimaryKey("test"); dbUtil.setString(1, id); dbUtil.setClob(2, CLOB.empty_lob()); // 先设置空的blob字段 dbUtil.executePrepared(); // 查找刚才的插入的记录,修改blob字段的值为一个文件 dbUtil = new PreparedDBUtil(); dbUtil.preparedSelect("select clobname from test where id = ?"); dbUtil.setString(1, id); dbUtil.executePrepared(); CLOB clob = (CLOB) dbUtil.getClob(0, "clobname"); if (clob != null) { DBUtil.updateCLOB(clob, new java.io.File("d:\\route.txt")); } tm.commit(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); try { tm.rollback(); } catch (RollbackException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } finally { tm = null; dbUtil = null; } }
/** * 获取站点评论 前n条数据 * * @param n * @return * @throws SQLException */ public NComentList getSiteCommnetList(int n) throws Exception { Map<String, Object> paramMap = new HashMap<String, Object>(); // paramMap.put("docId", docId); paramMap.put("n", n + 1); TransactionManager tm = new TransactionManager(); try { tm.begin(tm.RW_TRANSACTION); NComentList nComentList = new NComentList(); nComentList.setComments( executor.queryListBean(DocComment.class, "getSiteCommnetNList", paramMap)); nComentList.setTotal(getSiteCommentPublishedCount()); return nComentList; } catch (SQLException e) { throw e; } catch (Exception e) { throw e; } finally { tm.releasenolog(); } }
/** * 展示文档评论 * * @param docId 文档ID * @param request HttpServletRequest * @param response HttpServletResponse * @return String * @throws Exception */ public String showDocumentCommentList( int docId, long channelId, HttpServletRequest request, HttpServletResponse response) throws Exception { TransactionManager tm = new TransactionManager(); try { tm.begin(tm.RW_TRANSACTION); // 获得该文档所在的频道评论开关 int channelCommentSwitch = docCommentManager.getDocCommentSwitch(String.valueOf(docId), "chnl"); if (channelCommentSwitch != 0) { // 首先判断频道的评论开关 request.setAttribute("commentSwitch", channelCommentSwitch); } else { int documentCommentSwitch = docCommentManager.getDocCommentSwitch(String.valueOf(docId), "doc"); request.setAttribute("commentSwitch", documentCommentSwitch); } // 获得该文档所在频道的评论审核开关 Integer aduitSwitchFlag = docCommentManager.getChannelCommentAduitSwitch((int) channelId); if (aduitSwitchFlag != null) { request.setAttribute("aduitSwitchFlag", aduitSwitchFlag); } else { request.setAttribute("aduitSwitchFlag", 1); } request.setAttribute("docId", docId); request.setAttribute("total", docCommentManager.getTotalCommnet(docId)); request.setAttribute("channelId", channelId); return "path:showDocumentCommentList"; } finally { tm.releasenolog(); } }
public NComentList getCommnetList(int docId, int n) throws Exception { // TODO Auto-generated method stub // throw new DocCommentManagerException("未实现!"); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("docId", docId); paramMap.put("n", n + 1); TransactionManager tm = new TransactionManager(); try { tm.begin(tm.RW_TRANSACTION); NComentList nComentList = new NComentList(); nComentList.setComments( executor.queryListBean(DocComment.class, "getCommnetNList", paramMap)); nComentList.setTotal(getTotalCommnet(docId)); return nComentList; } catch (SQLException e) { throw e; } catch (Exception e) { throw e; } finally { tm.releasenolog(); } }