/** * 经过测试证明存储过程中如果没有对插入/删除/修改操作做事务提交、回滚时,可以通过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(); } }
/** 针对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; } }