批处理对大量数据的insert或着udpate有着时间上的优越性
看代码
这个主要用的是回调
这个主要是要用事物
看代码
这个主要用的是回调
public void insertPropSluiceLogList(final List<PropSluiceLog> propSluiceLogList) {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for(PropSluiceLog propSluiceLog : propSluiceLogList){
executor.insert("T_PROP_SLUICE_LOG.insertPropSluiceLog", propSluiceLog);
}
executor.executeBatch();
return null;
}
});
}
这个主要是要用事物
public List<HotelInfo> findHotelInfoFogPaginatedList(HotelSearchVO hotelSearchVO,int fromPage,int toPage) {
List<HotelInfo> list = new ArrayList<HotelInfo>();
List<String> props = new ArrayList<String>();
props = hotelSearchVO.getProps();
SqlMapClient sqlMapClient = this.getSqlMapClient();
Map map = new HashMap();
map.put("hotelSearchVO", hotelSearchVO);
map.put("row_from", fromPage);
map.put("row_to", toPage);
map.put("tp_flag", "1");
try{
sqlMapClient.startTransaction();
sqlMapClient.startBatch();
for(int i = 0 ; i < props.size(); i ++){
String propId = props.get(i);
sqlMapClient.insert("Prop.insertTpPropid",propId);
}
sqlMapClient.executeBatch();
list = sqlMapClient.queryForList("Prop.findHotelInfoAll", map);
sqlMapClient.endTransaction();
}catch(Exception e){
logger.info("class name TPDAO--method findHotelInfoFogPaginatedList error!"+e);
}
return list;
}