首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

Ibatis 批量平添修改删除-batch-insert-update-delete

2012-09-20 
Ibatis 批量添加修改删除-batch-insert-update-delete转载出处:http://www.javadn.com/read.php?tid-790.h

Ibatis 批量添加修改删除-batch-insert-update-delete

转载出处:http://www.javadn.com/read.php?tid-790.html

?

public void batchUpdate(final String statementName, final List list) {
?????? try {
?????????? if (list != null) {
????????????? this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
????????????????? public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
???????????????????? executor.startBatch();
???????????????????? for (int i = 0, n = list.size(); i < n; i++) {
???????????????????????? executor.update(statementName, list.get(i));
???????????????????? }
???????????????????? executor.executeBatch();
???????????????????? return null;
????????????????? }
????????????? });
?????????? }
?????? } catch (Exception e) {
?????????? if (log.isDebugEnabled()) {
????????????? e.printStackTrace();
????????????? log.debug("batchUpdate error: id [" + statementName + "], parameterObject ["+ list + "].? Cause: "+ e.getMessage());
?????????? }
?????? }
?
??? }
??? public void batchInsert(final String statementName, final List list) {
?????? try {
?????????? if (list != null) {
????????????? this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
????????????????? public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
???????????????????? executor.startBatch();
???????????????????? for (int i = 0, n = list.size(); i < n; i++) {
???????????????????????? executor.insert(statementName, list.get(i));
???????????????????? }
???????????????????? executor.executeBatch();
???????????????????? return null;
????????????????? }
????????????? });
?????????? }
?????? } catch (Exception e) {
?????????? if (log.isDebugEnabled()) {
????????????? e.printStackTrace();
????????????? log.debug("batchInsert error: id [" + statementName + "], parameterObject ["+ list + "].? Cause: "+ e.getMessage());
?????????? }
?????? }
?
??? }
??? public void batchDelete(final String statementName, final List list) {
?????? try {
?????????? if (list != null) {
????????????? this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
????????????????? public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
???????????????????? executor.startBatch();
???????????????????? for (int i = 0, n = list.size(); i < n; i++) {
???????????????????????? executor.delete(statementName, list.get(i));
???????????????????? }
???????????????????? executor.executeBatch();
???????????????????? return null;
????????????????? }
????????????? });
?????????? }
?????? } catch (Exception e) {
?????????? if (log.isDebugEnabled()) {
????????????? e.printStackTrace();
????????????? log.debug("batchDelete error: id [" + statementName + "], parameterObject ["+ list + "].? Cause: "+ e.getMessage());
?????????? }
?????? }
?

??? }

1 楼 wang4674890 2011-11-07   天下文章一般抄!

热点排行