with iabtis
<iterate conjunction="">
Batch submission, the disadvantage is that the number of submissions is limited, size<1000;
Batch submission: http://fengxiaoshuang429201406254717.iteye.com/blog/2392798
For a large amount of data, use transaction submission:
What I set here is, insert one by one, when it is full 5000, the transaction is submitted;
If 10,000 pieces of data come, things will be submitted in two batches;
Service impl implementation layer:
/** 5000 submissions once */ public static final int BATCH_SIZE = 5000; /** Transaction template */ protected TransactionTemplate transactionTemplate; /** sql execution template */ protected SqlMapClientTemplate sqlMapClientTemplate = new SqlMapClientTemplate(); private SqlMapClient sqlMapClient; public SqlMapClientTemplate getSqlMapClientTemplate() { return sqlMapClientTemplate; } public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) { this.sqlMapClientTemplate = sqlMapClientTemplate; } public SqlMapClient getSqlMapClient() { return sqlMapClient; } public void setSqlMapClient(SqlMapClient sqlMapClient) { this.sqlMapClient = sqlMapClient; this.sqlMapClientTemplate.setSqlMapClient(sqlMapClient); } public void setTransactionTemplate(TransactionTemplate transactionTemplate) { this.transactionTemplate = transactionTemplate; } @Override public void getBankHandlingCharge(final List<PostAccountVO> vo) { sqlMapClientTemplate.execute(new SqlMapClientCallback() { public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { executor.startBatch(); int indexInBatch = 0; List<PostAccountInfoDO> infoDOList = new LinkedList<PostAccountInfoDO>(); for (PostAccountVO poa: vo) { PostAccountInfoDO infoDO = new PostAccountInfoDO (); infoDO.setAmount(poa.getAmount()); infoDO.setFundCategory(poa.getFundCategory()); infoDO.setPostStaus(poa.getPostStaus()); infoDO.setFundChannelCode(poa.getFundChannelCode()); infoDO.setHappenDate (poa.getHappenDate ()); infoDO.setRemarks(poa.getRemarks()); infoDO.setCreater(poa.getCreater()); infoDO.setCreateTime(poa.getCreateTime()); infoDO.setAuditor(poa.getCreater()); infoDO.setAuditorTime(poa.getCreateTime()); infoDO.setDeleteFlag(poa.getDeleteFlag()); infoDO.setInstOrder(poa.getInstOrder()); infoDOList.add(infoDO); } for (PostAccountInfoDO postAccountInfoDO: infoDOList) { if (indexInBatch > BATCH_SIZE) {//5000 items are processed as a batch. If it exceeds 5000, it will be used as the next batch. executor.executeBatch(); executor.startBatch(); indexInBatch = 0; } executor.insert("MS-POST-ACCOUNT-INFO-INSERT", postAccountInfoDO); indexInBatch++; } return executor.executeBatch(); } }); }
The insert method is not the implementation method of the dao layer, but the insert method in the executor, which means that the method with id=" MS-POST-ACCOUNT-INFO-INSERT " in the mapping.xml file is directly accessed here ;
mapping.xml layer:
<insert id="MS-POST-ACCOUNT-INFO-INSERT"> <selectKey resultClass="java.lang.String" keyProperty="accountSeqNo"> <![CDATA[ select seq_post_account_info.nextval from dual ]]> </selectKey> <![CDATA[ insert into TB_POST_TABLE(ACCOUNT_SEQ_NO,AMOUNT,FUND_CATEGORY,POST_STAUS,FUND_CHANNEL_CODE,HAPPEN_DATE,REMARKS,CREATER,CREATE_TIME,AUDITOR,AUDITOR_TIME,DELETE_FLAG,INST_ORDER) values ( #accountSeqNo#, #amount#, #fundCategory#, #postStaus#, #fundChannelCode#, #happenDate#, #remarks#, #creater#, #createTime#, #auditor#, #auditorTime#, #deleteFlag#, #instOrder#) ]]> </insert>
Transaction commit failed rollback:
I throw an exception (as shown below) before the transaction is submitted, the data is not added to the database, there should be a rollback mechanism in it