Skip to content

Commit db050ac

Browse files
committed
Polishing
1 parent 996d747 commit db050ac

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
901901
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
902902
* @return an array containing the numbers of rows affected by each update in the batch
903903
*/
904-
public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
904+
int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
905905

906906
/**
907907
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
@@ -911,7 +911,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
911911
* (constants from {@code java.sql.Types})
912912
* @return an array containing the numbers of rows affected by each update in the batch
913913
*/
914-
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
914+
int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
915915

916916
/**
917917
* Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
@@ -924,7 +924,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
924924
* @return an array containing for each batch another array containing the numbers of rows affected
925925
* by each update in the batch
926926
*/
927-
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
927+
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
928928
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;
929929

930930

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ public void execute(final String sql) throws DataAccessException {
398398
if (logger.isDebugEnabled()) {
399399
logger.debug("Executing SQL statement [" + sql + "]");
400400
}
401+
401402
class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
402403
@Override
403404
@Nullable
@@ -410,6 +411,7 @@ public String getSql() {
410411
return sql;
411412
}
412413
}
414+
413415
execute(new ExecuteStatementCallback());
414416
}
415417

@@ -421,6 +423,7 @@ public <T> T query(final String sql, final ResultSetExtractor<T> rse) throws Dat
421423
if (logger.isDebugEnabled()) {
422424
logger.debug("Executing SQL query [" + sql + "]");
423425
}
426+
424427
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
425428
@Override
426429
@Nullable
@@ -439,6 +442,7 @@ public String getSql() {
439442
return sql;
440443
}
441444
}
445+
442446
return execute(new QueryStatementCallback());
443447
}
444448

@@ -493,7 +497,6 @@ public int update(final String sql) throws DataAccessException {
493497
}
494498

495499
class UpdateStatementCallback implements StatementCallback<Integer>, SqlProvider {
496-
497500
@Override
498501
public Integer doInStatement(Statement stmt) throws SQLException {
499502
int rows = stmt.executeUpdate(sql);
@@ -502,7 +505,6 @@ public Integer doInStatement(Statement stmt) throws SQLException {
502505
}
503506
return rows;
504507
}
505-
506508
@Override
507509
public String getSql() {
508510
return sql;

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,30 +24,31 @@
2424
import org.springframework.jdbc.core.JdbcOperations;
2525

2626
/**
27-
* Generic utility methods for working with JDBC batch statements using named parameters. Mainly for internal use
28-
* within the framework.
27+
* Generic utility methods for working with JDBC batch statements using named parameters.
28+
* Mainly for internal use within the framework.
2929
*
3030
* @author Thomas Risberg
31+
* @since 3.0
3132
*/
3233
public class NamedParameterBatchUpdateUtils extends BatchUpdateUtils {
3334

3435
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
3536
final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
37+
3638
if (batchArgs.length <= 0) {
3739
return new int[] {0};
3840
}
41+
3942
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
4043
return jdbcOperations.batchUpdate(
4144
sqlToUse,
4245
new BatchPreparedStatementSetter() {
43-
4446
@Override
4547
public void setValues(PreparedStatement ps, int i) throws SQLException {
4648
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
4749
int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]);
4850
setStatementParameters(values, ps, columnTypes);
4951
}
50-
5152
@Override
5253
public int getBatchSize() {
5354
return batchArgs.length;

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) {
348348

349349
@Override
350350
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
351-
ParsedSql parsedSql = getParsedSql(sql);
352-
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
351+
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(
352+
getParsedSql(sql), batchArgs, getJdbcOperations());
353353
}
354354

355355
/**

0 commit comments

Comments
 (0)