我用ibatis+spring中代码使用JDBC做了一个批量处理,网络中断为什么事物没有回滚?

这是我的代码:

spring-application.xml:

<bean id="txManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="tcb" />
 </bean>
 <!-- 支持  @Transactional 标记 -->
 <tx:annotation-driven transaction-manager="txManager"
  proxy-target-class="true" />

 

MyManagerImol.java

 

/**
  * 导出
  *
  * @throws SQLException
  * @throws IOException
  */
 @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
 public void cardDataExport() throws SQLException, IOException {
  String id = request.getParameter("id");
  String taskId = request.getParameter("taskId");
  String status = request.getParameter("status");
  String exportComment = request.getParameter("exprtComment");
  
  long aa = System.currentTimeMillis();
  log.info("卡数据导出时间:" + (System.currentTimeMillis() - aa) / 1000 + " 秒");
  // 卡数据入库
  cardApplyDto = findCardApplyById(id);
  //去除特殊号码的调用cardDataInsertTcbCard1(),不去除的调用cardDataInsertTcbCard()
  if(!"".equals(cardApplyDto.getSpecilNum())&&cardApplyDto.getSpecilNum()!=null&&null!=cardApplyDto.getIntercpetDigit()){
   cardDataInsertTcbCard1(cardApplyDto);
  }else{
   cardDataInsertTcbCard(cardApplyDto);
  }
  System.out.println("卡数据导出时间:" + (System.currentTimeMillis() - aa)
    / 1000 + " 秒");
  
  // 更新申请单
  cardApplyDto = new CardApplyDto();
  cardApplyDto.setId(id);
  cardApplyDto.setStatus(status);
  cardApplyDto.setExportComment(exportComment);
  cardApplyDto.setExportDate(Calendar.getInstance().getTime());
  cardApplyDto.setExportPerson(this.getLoginUserId());
  ServiceResult s = cardApplyManagement.cardDataExport(cardApplyDto);

  // 更新tcb_task
  tcbTask = new TcbTaskWithBLOBs();
  tcbTask.setLast_comment(cardApplyDto.getExportComment());
  tcbTask.setLast_action("导出");
  tcbTask.setWorkflow_id("card_data_exported");
  tcbTask.setStage("close");
  tcbTask.setBiz_info("".getBytes("utf-8"));
  tcbTask.setComments("".getBytes("utf-8"));
  tcbTask.setTask_id(taskId);
  tcbTask.setBiz_key(cardApplyDto.getId());
  tcbTaskManager.updateTcbTask(tcbTask);
 }

 

/**
  * 卡数据写入tcb_card
  *
  * @throws SQLException
  */
 @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
 public void cardDataInsertTcbCard(final CardApplyDto cardApplyDto1) throws SQLException {
  JdbcTemplate template = new JdbcTemplate(this.getTcb());//this.getTcb()数据源
  template.execute(new ConnectionCallback(){
   public Object doInConnection(Connection conn){
    PreparedStatement pstmt = null;
    try{
     pstmt = conn.prepareStatement(INSERT_CARD_SQL);

     response.setCharacterEncoding("utf-8");
     PrintWriter f = response.getWriter();
     f.write("磁卡卡号,通卡卡号,登录密码,交易密码");
     f.write("/r/n");
     long startCard = Long.valueOf(cardApplyDto1.getCardStartNum());
     for (long i = 0; i < cardApplyDto1.getCardAmount(); i++) {
      long aa = startCard + i;
      StringBuffer zero = new StringBuffer();
      for (int j = 0; j < 16 - (String.valueOf(aa)).length(); j++) {
       zero.append('0');
      }
      byte[] tempByte = (zero.toString() + aa + SEVEN_ZERO).getBytes();// 卡号+卡类型+保留字段
      // 卡号
      String intoCardNum = zero.toString() + aa;
      // 卡帐号
      String intoCardAccount = intoCardNum;
      // 初始密码
      String intoPsw = getRandomNumber(6);
      // 磁道信息
      int a = CRC8.calc(tempByte, 23);
      if (a < 0)
       a = 127 - a;
      String validCode = StringUtils.leftPad(String.valueOf(a), 3, '0');
      String intotrackInfo = FIVE_FOUR + intoCardNum + SEVEN_ZERO
        + validCode + FOUR_THREE;
 
      // 磁道号
      String cardDetail = EMPTY_STRING;
      String cardThirdmeg = EMPTY_STRING;
      if (TWO.equals(cardApplyDto1.getTrackNo()))
       cardDetail = intotrackInfo;
      else
       cardThirdmeg = intotrackInfo;
      pstmt.setString(1,intoCardNum);
      pstmt.setString(2,intoCardNum);
      pstmt.setString(3,null);
      pstmt.setString(4, com.tongcard.tcb.web.helper.StringUtils
        .getMD5(intoPsw));
      pstmt.setString(5, cardDetail);
      pstmt.setString(6, NEG_NE);
      pstmt.setString(7, cardApplyDto1.getMerchantCode());
      pstmt.setString(8, cardApplyDto1.getId());
      pstmt.setString(9, cardApplyDto1.getCardName());
      pstmt.setString(10, cardThirdmeg);
      
      pstmt.addBatch();
      
      if(i%10000 == 0){
       pstmt.executeBatch();
       pstmt.clearBatch();
      }
      f.write(cardDetail + cardThirdmeg+',');
      f.write(intoCardNum + ',');
      f.write(intoPsw + ',');
      f.write(intoPsw);
      f.write("/r/n");
     }
     pstmt.executeBatch();
     f.flush();
     f.close();
    }
    catch(SQLException e){
     e.printStackTrace();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
    finally{
     
     if(pstmt != null){
      try{
       pstmt.close();
      }
      catch(SQLException e){
       
      }
     }
    }
    return null;
   }
  });
 }

 

请高手指点为什么执行大批量写入时数据为什么没有回滚啊!急!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值