Skip to content

Commit cc4f132

Browse files
committed
Introduced public ArgumentPreparedStatementSetter and ArgumentTypePreparedStatementSetter classes
Issue: SPR-10375
1 parent 6b4c29c commit cc4f132

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgPreparedStatementSetter.java renamed to spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -20,12 +20,12 @@
2020
import java.sql.SQLException;
2121

2222
/**
23-
* Simple adapter for PreparedStatementSetter that applies
24-
* a given array of arguments.
23+
* Simple adapter for {@link PreparedStatementSetter} that applies a given array of arguments.
2524
*
2625
* @author Juergen Hoeller
26+
* @since 3.2.3
2727
*/
28-
class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
28+
public class ArgumentPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
2929

3030
private final Object[] args;
3131

@@ -34,7 +34,7 @@ class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDi
3434
* Create a new ArgPreparedStatementSetter for the given arguments.
3535
* @param args the arguments to set
3636
*/
37-
public ArgPreparedStatementSetter(Object[] args) {
37+
public ArgumentPreparedStatementSetter(Object[] args) {
3838
this.args = args;
3939
}
4040

spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgTypePreparedStatementSetter.java renamed to spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -20,17 +20,17 @@
2020
import java.sql.SQLException;
2121
import java.sql.Types;
2222
import java.util.Collection;
23-
import java.util.Iterator;
2423

2524
import org.springframework.dao.InvalidDataAccessApiUsageException;
2625

2726
/**
28-
* Simple adapter for PreparedStatementSetter that applies
27+
* Simple adapter for {@link PreparedStatementSetter} that applies
2928
* given arrays of arguments and JDBC argument types.
3029
*
3130
* @author Juergen Hoeller
31+
* @since 3.2.3
3232
*/
33-
class ArgTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
33+
public class ArgumentTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
3434

3535
private final Object[] args;
3636

@@ -42,7 +42,7 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
4242
* @param args the arguments to set
4343
* @param argTypes the corresponding SQL types of the arguments
4444
*/
45-
public ArgTypePreparedStatementSetter(Object[] args, int[] argTypes) {
45+
public ArgumentTypePreparedStatementSetter(Object[] args, int[] argTypes) {
4646
if ((args != null && argTypes == null) || (args == null && argTypes != null) ||
4747
(args != null && args.length != argTypes.length)) {
4848
throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match");
@@ -59,12 +59,10 @@ public void setValues(PreparedStatement ps) throws SQLException {
5959
Object arg = this.args[i];
6060
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
6161
Collection entries = (Collection) arg;
62-
for (Iterator it = entries.iterator(); it.hasNext();) {
63-
Object entry = it.next();
62+
for (Object entry : entries) {
6463
if (entry instanceof Object[]) {
65-
Object[] valueArray = ((Object[])entry);
66-
for (int k = 0; k < valueArray.length; k++) {
67-
Object argValue = valueArray[k];
64+
Object[] valueArray = ((Object[]) entry);
65+
for (Object argValue : valueArray) {
6866
doSetValue(ps, parameterPosition, this.argTypes[i], argValue);
6967
parameterPosition++;
7068
}
@@ -94,6 +92,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
9492
*/
9593
protected void doSetValue(PreparedStatement ps, int parameterPosition, int argType, Object argValue)
9694
throws SQLException {
95+
9796
StatementCreatorUtils.setParameterValue(ps, parameterPosition, argType, argValue);
9897
}
9998

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,24 +1291,26 @@ protected void applyStatementSettings(Statement stmt) throws SQLException {
12911291
}
12921292

12931293
/**
1294-
* Create a new ArgPreparedStatementSetter using the args passed in. This method allows the
1295-
* creation to be overridden by sub-classes.
1294+
* Create a new arg-based PreparedStatementSetter using the args passed in.
1295+
* <p>By default, we'll create an {@link ArgumentPreparedStatementSetter}.
1296+
* This method allows for the creation to be overridden by subclasses.
12961297
* @param args object array with arguments
1297-
* @return the new PreparedStatementSetter
1298+
* @return the new PreparedStatementSetter to use
12981299
*/
12991300
protected PreparedStatementSetter newArgPreparedStatementSetter(Object[] args) {
1300-
return new ArgPreparedStatementSetter(args);
1301+
return new ArgumentPreparedStatementSetter(args);
13011302
}
13021303

13031304
/**
1304-
* Create a new ArgTypePreparedStatementSetter using the args and argTypes passed in.
1305-
* This method allows the creation to be overridden by sub-classes.
1305+
* Create a new arg-type-based PreparedStatementSetter using the args and types passed in.
1306+
* <p>By default, we'll create an {@link ArgumentTypePreparedStatementSetter}.
1307+
* This method allows for the creation to be overridden by subclasses.
13061308
* @param args object array with arguments
1307-
* @param argTypes int array of SQLTypes for arguments
1308-
* @return the new PreparedStatementSetter
1309+
* @param argTypes int array of SQLTypes for the associated arguments
1310+
* @return the new PreparedStatementSetter to use
13091311
*/
13101312
protected PreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) {
1311-
return new ArgTypePreparedStatementSetter(args, argTypes);
1313+
return new ArgumentTypePreparedStatementSetter(args, argTypes);
13121314
}
13131315

13141316
/**

0 commit comments

Comments
 (0)