SPRING事务管理的一个例子
JAVA:
- /***
- *
- * 删除TAGS 需要同时删除tree_posts_tags表中的相关信息
- */
- String countTags = "";
- final InvocationResult result = new InvocationResult();
- DataSourceTransactionManager tran = new DataSourceTransactionManager(
- getDataSource());
- TransactionTemplate trantemplate = new TransactionTemplate(tran);
- try {
- String sqlTags = "delete from tree_tags t where t.t_id = "
- + NumberUtils.toLong(tagsID);
- String sqlPostTags = "delete from tree_posts_tags t where t.t_id = "
- + NumberUtils.toLong(tagsID);
- int count = getJdbcTemplate().update(sqlTags,
- int countPostTags = getJdbcTemplate().update(sqlPostTags,
- } catch (TransactionException te) {
- status.setRollbackOnly();
- if (result.getException() == null) {
- throw te;
- } else {
- }
- return 0;
- }
- }
- });
- return NumberUtils.toInt(countTags);