Polishing

This commit is contained in:
Juergen Hoeller 2017-11-04 01:07:09 +01:00
parent 996d747aed
commit db050ac38c
4 changed files with 15 additions and 12 deletions

View File

@ -901,7 +901,7 @@ public interface JdbcOperations {
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
@ -911,7 +911,7 @@ public interface JdbcOperations {
* (constants from {@code java.sql.Types})
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
/**
* Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
@ -924,7 +924,7 @@ public interface JdbcOperations {
* @return an array containing for each batch another array containing the numbers of rows affected
* by each update in the batch
*/
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;

View File

@ -398,6 +398,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL statement [" + sql + "]");
}
class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
@Override
@Nullable
@ -410,6 +411,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
execute(new ExecuteStatementCallback());
}
@ -421,6 +423,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL query [" + sql + "]");
}
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
@Override
@Nullable
@ -439,6 +442,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
return execute(new QueryStatementCallback());
}
@ -493,7 +497,6 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
class UpdateStatementCallback implements StatementCallback<Integer>, SqlProvider {
@Override
public Integer doInStatement(Statement stmt) throws SQLException {
int rows = stmt.executeUpdate(sql);
@ -502,7 +505,6 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
return rows;
}
@Override
public String getSql() {
return sql;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,30 +24,31 @@ import org.springframework.jdbc.core.BatchUpdateUtils;
import org.springframework.jdbc.core.JdbcOperations;
/**
* Generic utility methods for working with JDBC batch statements using named parameters. Mainly for internal use
* within the framework.
* Generic utility methods for working with JDBC batch statements using named parameters.
* Mainly for internal use within the framework.
*
* @author Thomas Risberg
* @since 3.0
*/
public class NamedParameterBatchUpdateUtils extends BatchUpdateUtils {
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
if (batchArgs.length <= 0) {
return new int[] {0};
}
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
return jdbcOperations.batchUpdate(
sqlToUse,
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]);
setStatementParameters(values, ps, columnTypes);
}
@Override
public int getBatchSize() {
return batchArgs.length;

View File

@ -348,8 +348,8 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
ParsedSql parsedSql = getParsedSql(sql);
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(
getParsedSql(sql), batchArgs, getJdbcOperations());
}
/**