(转)Spring的编程式事务例子
纯JDBC操作, 对某些项目来说, 也许更好, Spring JDBC Framework让你不用关心Connection, Statement, ResultSet. 定义数据源
spring事务编程的例子<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
spring事务编程的例子 <property name="jndiName">
spring事务编程的例子 <value>java:/comp/env/jdbc/oracle</value>
spring事务编程的例子 </property>
spring事务编程的例子</bean> 定义事务管理器
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> 定义dao
spring事务编程的例子<bean id="customerDAO" class="com.waterye.dao.impl.CustomerDAOImpl">
spring事务编程的例子 <property name="dataSource" ref="dataSource" />
spring事务编程的例子 <property name="transactionManager" ref="transactionManager" />
spring事务编程的例子</bean> public class CustomerDaoImpl extends JdbcDaoSupport implements CustomerDAO {
private DataSource dataSource;
pirvate TransactionManager transactionManager; public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
} public void setTransactionManager(DataSourceTransactionManager transactionManager) {
this.transactionManager = transactionManager;
} public Map get(Integer id) throws Exception {
String querySql = "select * from customer where id = ?"; return getJdbcTemplate().queryForMap(querySql, new Object[] { id });
} public void insert(final Map customer) throws Exception {
String seqSql = "select customer_seql.nextval from dual";
String insertSql = "insert into customer (id, code, name, status) values (?, ?, ?, ?)"; TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
JdbcTemplate jdbcTemplate = getJdbcTemplate();
int id = jdbcTemplate.queryForInt(seqSql);
Object[] params = new Object[] { new Integer(id), customer.get("code"), customer.get("name"), map.get("status") };
jdbcTemplate.update(insertSql, params);
}
}
} public void update(final Map customer) throws Exception {
//
} public void delete(Integer id) throws Exception {
String deleteSql = "delete from customer where id = ?"; TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
getJdbcTemplate().update(deleteSql, new Object[] { id });
}
}
} public List findValidCustomers() throws Exception {
String querySql = "select * from customer where status = 'valid' order by code"; return getJdbcTemplate().query(querySql, new OracleColumnMapRowMapper());
}
}
(转)Spring的编程式事务例子的更多相关文章
- 全面分析 Spring 的编程式事务管理及声明式事务管理
开始之前 关于本教程 本教程将深入讲解 Spring 简单而强大的事务管理功能,包括编程式事务和声明式事务.通过对本教程的学习,您将能够理解 Spring 事务管理的本质,并灵活运用之. 先决条件 本 ...
- 全面分析 Spring 的编程式事务管理及声明式事务管理--转
开始之前 关于本教程 本教程将深入讲解 Spring 简单而强大的事务管理功能,包括编程式事务和声明式事务.通过对本教程的学习,您将能够理解 Spring 事务管理的本质,并灵活运用之. 先决条件 本 ...
- Spring的编程式事务和声明式事务
事务管理对于企业应用来说是至关重要的,当出现异常情况时,它也可以保证数据的一致性. Spring事务管理的两种方式 spring支持编程式事务管理和声明式事务管理两种方式. 编程式事务使用Transa ...
- 【Spring】编程式事务和声明式事务
一.概述 二.准备工作 1. 创建表 2. 创建项目并引入Maven依赖 3. 编写实体类 4. 编写Dao层 5. 业务层 6. XML中的配置 7. 测试 三.编程式事务 1. 在业务层代码上使用 ...
- Spring笔记(4) - Spring的编程式事务和声明式事务详解
一.背景 事务管理对于企业应用而言至关重要.它保证了用户的每一次操作都是可靠的,即便出现了异常的访问情况,也不至于破坏后台数据的完整性.就像银行的自助取款机,通常都能正常为客户服务,但是也难免遇到操作 ...
- spring 采用编程式事务
1.getCurrentSession()与openSession()的区别? * 采用getCurrentSession()创建的session会绑定到当前线程中,而采用openSession() ...
- spring中编程式事务控制
step1:配置xml文件 <!-- 事务管理bean --> <bean id="transactionManager" class="org.spr ...
- 转:全面分析 Spring 的编程式事务管理及声明式事务管理
转:from: https://www.ibm.com/developerworks/cn/education/opensource/os-cn-spring-trans/
- spring 编程式事务管理和声明式事务管理
编程式事务管理 Spring 的编程式事务管理概述 在 Spring 出现以前,编程式事务管理对基于 POJO 的应用来说是唯一选择.用过 Hibernate 的人都知道,我们需要在代码中显式调用be ...
随机推荐
- 【转】常用插件和mvn test命令
自定义构建Maven项目,需要包括额外的插件或者配置已存在的插件参数. 1. maven-compiler-plugin 指定JDK版本和编码方式 compiler插件能解决2个问题: 第一: mav ...
- WPF中的瀑布流布局(TilePanel)控件
最近在用wpf做一个metro风格的程序,需要用到win8风格的布局容器,只能自己写一个了.效果如下 用法 : <local:TilePanel ...
- 进程和cpu绑定
#include<stdlib.h> #include<stdio.h> #include<sys/types.h> #include<sys/sysinfo ...
- View模版的设计
一个Action多套View模版的设计 回到目录 模块化 这个问题是在做模块化设计时出现的,在Lind.DDD.Plugins模块里,需要对应的模块实体,模块管理者,模块标识接口等,开发时,如果你 ...
- iPhone OS 开发 - 了解并解决代码签名问题
译者:Jestery 发表时间:2010-04-24浏览量:21082评论数:0挑错数:0 了解并解决代码签名问题 (为保持跟开发环境以及APPLE开发者社区网站结构对应,一些名词未作翻译) 绝大多数 ...
- VBS基础篇 - 动态数组
VBS中的动态数组需要使用System.Collections.ArrayList '建立动态数组 Dim Arrl : Set Arrl = CreateObject("System.Co ...
- Notes of the scrum meeting(2013/10/27)
软工项目组buaa_smile确定自由项目主题及实现功能的scrum meeting meeting time:1:00~2:00p.m.,October 27th,2013 meeting plac ...
- sql replace
update dbo.EquipmentAttribute set AttributeName=replace(AttributeName,' ','') where EquipmentID=8 ...
- 循序渐进Java Socket网络编程(多客户端、信息共享、文件传输)
目录[-] 一.TCP/IP协议 二.TCP与UDP 三.Socket是什么 四.Java中的Socket 五.基本的Client/Server程序 六.多客户端连接服务器 七.信息共享 八.文件传输 ...
- listview中getview异步加载网络图片
前言:本以为异步加载挺简单,因为网上代码多,但真想要做好,还真不那么简单,从看代码到弄懂再到自己写,实在是有太多的东西需要学了,用了两天的时间,终于弄出来了,因为用到回调函数,所以理解起来可能难度有点 ...