ibatis 的批量插入 批量更新数据
2012-11-30 09:48
471 查看
首先批量更新 插入数据要放到一个事务里面,这也是配出来的,源码
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:advisor pointcut="execution(* *..business..*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="New*" />
<tx:method name="Edit*" />
<tx:method name="Del*" />
<tx:method name="new*" />
<tx:method name="edit*" />
<tx:method name="del*" />
<tx:method name="insert*" />
<tx:method name="Insert*" />
<tx:method name="update*" />
<tx:method name="GetProcList*" />
<tx:method name="Update*" />
<tx:method name="charge*" />
<tx:method name="GetProcList*" />
<tx:method name="audit*" />
<tx:method name="bus*" />
<tx:method name="Audit*" />
<tx:method name="regist*" />
<tx:method name="reg*" />
<tx:method name="Upt*" />
<tx:method name="Window*" />
<tx:method name="subtract*" />
<tx:method name="Check*" />
<tx:method name="check*" />
<tx:method name="Save*" />
<tx:method name="Out*" />
<tx:method name="Return*" />
<tx:method name="com*" />
<tx:method name="exec*" />
<tx:method name="query*" />
<tx:method name="pro*" />
<tx:method name="allow*" />
<tx:method name="upload*" />
<tx:method name="Upload*" />
<tx:method name="reAudit*" />
<tx:method name="confirm*" />
<tx:method name="arrange*" />
<tx:method name="apply*" />
<tx:method name="prescrip*" />
<tx:method name="rePrescrip*" />
<tx:method name="exist*" />
<tx:method name="is*" />
<tx:method name="grant*" />
<tx:method name="unGrant*" />
<tx:method name="init*" />
<tx:method name="day*" />
<tx:method name="all*" />
<tx:method name="notrans*" propagation="NEVER" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
只要在包
business下面的 方法名字以 上面这些开头的 都配成事务了,对数据库的操作会,整体的提交,如果其中一条数据错误,就回滚,
第2,DAO层 这样写 会逐条更新,然后整体提交
public void updateACPHzRjpgList(final List<HashMap> cphzrjpglist) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (Map cphzrjpg:cphzrjpglist) {
executor.insert("HIS_CPINF.updateACPHzRjpgList", cphzrjpg);
}
executor.executeBatch();
return null;
}
});
}
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:advisor pointcut="execution(* *..business..*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="New*" />
<tx:method name="Edit*" />
<tx:method name="Del*" />
<tx:method name="new*" />
<tx:method name="edit*" />
<tx:method name="del*" />
<tx:method name="insert*" />
<tx:method name="Insert*" />
<tx:method name="update*" />
<tx:method name="GetProcList*" />
<tx:method name="Update*" />
<tx:method name="charge*" />
<tx:method name="GetProcList*" />
<tx:method name="audit*" />
<tx:method name="bus*" />
<tx:method name="Audit*" />
<tx:method name="regist*" />
<tx:method name="reg*" />
<tx:method name="Upt*" />
<tx:method name="Window*" />
<tx:method name="subtract*" />
<tx:method name="Check*" />
<tx:method name="check*" />
<tx:method name="Save*" />
<tx:method name="Out*" />
<tx:method name="Return*" />
<tx:method name="com*" />
<tx:method name="exec*" />
<tx:method name="query*" />
<tx:method name="pro*" />
<tx:method name="allow*" />
<tx:method name="upload*" />
<tx:method name="Upload*" />
<tx:method name="reAudit*" />
<tx:method name="confirm*" />
<tx:method name="arrange*" />
<tx:method name="apply*" />
<tx:method name="prescrip*" />
<tx:method name="rePrescrip*" />
<tx:method name="exist*" />
<tx:method name="is*" />
<tx:method name="grant*" />
<tx:method name="unGrant*" />
<tx:method name="init*" />
<tx:method name="day*" />
<tx:method name="all*" />
<tx:method name="notrans*" propagation="NEVER" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
只要在包
business下面的 方法名字以 上面这些开头的 都配成事务了,对数据库的操作会,整体的提交,如果其中一条数据错误,就回滚,
第2,DAO层 这样写 会逐条更新,然后整体提交
public void updateACPHzRjpgList(final List<HashMap> cphzrjpglist) {
this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (Map cphzrjpg:cphzrjpglist) {
executor.insert("HIS_CPINF.updateACPHzRjpgList", cphzrjpg);
}
executor.executeBatch();
return null;
}
});
}
相关文章推荐
- Yii2 批量插入、更新数据实例
- PreparedStatement 批量更新,插入数据到Oracle mysql
- php+mysqli实现批量执行插入、更新及删除数据的方法
- sql批量插入:存在id相同则更新数据
- 批量更新数据(batches update )插入数据(batches insert)
- java,大数据批量插入、更新
- Yii2 购物车 批量插入,更新数据
- PHP框架 Laravel Eloquent ORM 批量插入数据 && 批量更新目前没有
- Hibernate 数据的批量插入、更新和删除
- 实例讲解Java批量插入、更新数据
- C#中海量数据的批量插入和更新
- ibatis 对数据批量插入方法
- mybatis 注解的方式批量插入,更新数据
- ibatis 批量插入数据
- IBatis 批量插入数据
- ibatis对oracle数据库的批量更新和批量插入的操作
- Hibernate 数据的批量插入、更新和删除
- C# 批量插入和更新数据
- C#中海量数据的批量插入和更新
- IBatis 批量插入数据之SqlBulkCopy