Polishing

This commit is contained in:
Juergen Hoeller
2017-11-14 12:31:01 +01:00
parent d52d9fd268
commit 640c8ff693
14 changed files with 85 additions and 99 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@@ -755,7 +755,7 @@ public interface JdbcOperations {
* list of arguments to bind to the query, expecting a SqlRowSet.
* <p>The results will be mapped to an SqlRowSet which holds the data in a
* disconnected fashion. This wrapper will translate any SQLExceptions thrown.
* <p>Note that that, for the default implementation, JDBC RowSet support needs to
* <p>Note that, for the default implementation, JDBC RowSet support needs to
* be available at runtime: by default, Sun's {@code com.sun.rowset.CachedRowSetImpl}
* class is used, which is part of JDK 1.5+ and also available separately as part of
* Sun's JDBC RowSet Implementations download (rowset.jar).
@@ -778,7 +778,7 @@ public interface JdbcOperations {
* list of arguments to bind to the query, expecting a SqlRowSet.
* <p>The results will be mapped to an SqlRowSet which holds the data in a
* disconnected fashion. This wrapper will translate any SQLExceptions thrown.
* <p>Note that that, for the default implementation, JDBC RowSet support needs to
* <p>Note that, for the default implementation, JDBC RowSet support needs to
* be available at runtime: by default, Sun's {@code com.sun.rowset.CachedRowSetImpl}
* class is used, which is part of JDK 1.5+ and also available separately as part of
* Sun's JDBC RowSet Implementations download (rowset.jar).
@@ -882,7 +882,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.
@@ -892,7 +892,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.
@@ -905,7 +905,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;
@@ -429,6 +429,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL statement [" + sql + "]");
}
class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
@Override
public Object doInStatement(Statement stmt) throws SQLException {
@@ -440,6 +441,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
execute(new ExecuteStatementCallback());
}
@@ -450,6 +452,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL query [" + sql + "]");
}
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
@Override
public T doInStatement(Statement stmt) throws SQLException {
@@ -471,6 +474,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
return execute(new QueryStatementCallback());
}
@@ -521,6 +525,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL update [" + sql + "]");
}
class UpdateStatementCallback implements StatementCallback<Integer>, SqlProvider {
@Override
public Integer doInStatement(Statement stmt) throws SQLException {
@@ -535,6 +540,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return sql;
}
}
return execute(new UpdateStatementCallback());
}
@@ -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;
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@@ -331,8 +331,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());
}
/**