近期项目总结之批量增删改

来源:互联网 发布:淘宝装修全屏视频 编辑:程序博客网 时间:2024/05/18 01:45

public void insertUpSmsRecvInBatch(List<SmsUpRecvVo> uplist)
   throws UpSmsException {
  final List<SmsUpRecvVo> newLst = uplist;
  try {
   this.getSqlMapClientTemplate().execute(
     new SqlMapClientCallback<Object>() {
      public Object doInSqlMapClient(SqlMapExecutor executor)
        throws SQLException {
       executor.startBatch();
       int currentIndex = 0;
       for (SmsUpRecvVo temp : newLst) {
        executor.insert("upsms.insert_tblSmsUpResv", temp);
        currentIndex++;

        //批量处理不超过500条

        if (currentIndex % AppCode.MAX_BATCH_SIZE == 0) {
         executor.executeBatch();
         executor.startBatch();
        }
       }
       executor.executeBatch();
       return null;
      }
     });
  } catch (Exception e) {
   throw new UpSmsException(AppCode.ERR_UP_RECV_INSERT_FAIL, e);
  }
 }

 

 

 

 

PS:数据库中缓存的应用IBATIS版

<!-- 配置一个缓存,10分钟 -->

<cacheModel type="MEMORY" id="templateModel" readOnly="true" serialize="true">
  <flushInterval minutes="10"/>
 </cacheModel>
 <!-- 查询 TBL_SMS_TEMPLATE -->
 <select id="select_tblSmsTemplate" resultClass="smsTemplateVo" cacheModel="templateModel">
  select  t.TXN_CODE as txnCode,
   t.SMS_NM as smsNm,
   t.VAILD_FLG as vaildFlg,
   t.USER_TYPE as userType,
   t.SMS_CONT as smsCont,
   t.RESERVED1 as reserved1,
   t.RESERVED2 as reserved2,
   t.RESERVED3 as reserved3,
   t.RESERVED4 as reserved4,
   t.RESERVED5 as reserved5
   from TBL_SMS_NOTI_MODEL_SECOND t
 </select>

原创粉丝点击