List of usage examples for org.springframework.jdbc.object BatchSqlUpdate BatchSqlUpdate
public BatchSqlUpdate()
From source file:anyframe.core.query.impl.QueryServiceImpl.java
/** * BatchSqlUpdate ? ? ? SQL? Batch ./* ww w. ja va 2 s. c o m*/ * * @param sql * query statement. * @param types * is matched with input parameters. A type must belong to fields * defined java.sql.Types package. * @param targets * object of class which is matched with specified table in XML * files. is the List type of Object Array. * @return an array of the number of rows affected by each statement. */ protected int[] batchExecutor(final String sql, int[] types, final List targets) throws QueryServiceException { if (targets.size() <= 0) throw new QueryServiceException(getMessageSource(), "error.query.runtime.batch"); BatchSqlUpdate sqlBatch = new BatchSqlUpdate(); sqlBatch.setJdbcTemplate(jdbcTemplate); sqlBatch.setSql(sql); for (int i = 0; types != null && i < types.length; i++) { SqlParameter sp = new SqlParameter(types[i]); sqlBatch.declareParameter(sp); } sqlBatch.compile(); for (int i = 0; i < targets.size(); i++) { Object obj = targets.get(i); if (obj instanceof Object[]) sqlBatch.update((Object[]) obj); } return sqlBatch.flush(); }