Introduced public ArgumentPreparedStatementSetter and ArgumentTypePreparedStatementSetter classes

Issue: SPR-10375
This commit is contained in:
Juergen Hoeller 2013-03-19 11:28:25 +01:00
parent 6b4c29cd24
commit cc4f1328ee
3 changed files with 25 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2013 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.
@ -20,12 +20,12 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* Simple adapter for PreparedStatementSetter that applies
* a given array of arguments.
* Simple adapter for {@link PreparedStatementSetter} that applies a given array of arguments.
*
* @author Juergen Hoeller
* @since 3.2.3
*/
class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
public class ArgumentPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
private final Object[] args;
@ -34,7 +34,7 @@ class ArgPreparedStatementSetter implements PreparedStatementSetter, ParameterDi
* Create a new ArgPreparedStatementSetter for the given arguments.
* @param args the arguments to set
*/
public ArgPreparedStatementSetter(Object[] args) {
public ArgumentPreparedStatementSetter(Object[] args) {
this.args = args;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2013 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.
@ -20,17 +20,17 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collection;
import java.util.Iterator;
import org.springframework.dao.InvalidDataAccessApiUsageException;
/**
* Simple adapter for PreparedStatementSetter that applies
* Simple adapter for {@link PreparedStatementSetter} that applies
* given arrays of arguments and JDBC argument types.
*
* @author Juergen Hoeller
* @since 3.2.3
*/
class ArgTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
public class ArgumentTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
private final Object[] args;
@ -42,7 +42,7 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
* @param args the arguments to set
* @param argTypes the corresponding SQL types of the arguments
*/
public ArgTypePreparedStatementSetter(Object[] args, int[] argTypes) {
public ArgumentTypePreparedStatementSetter(Object[] args, int[] argTypes) {
if ((args != null && argTypes == null) || (args == null && argTypes != null) ||
(args != null && args.length != argTypes.length)) {
throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match");
@ -59,12 +59,10 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
Object arg = this.args[i];
if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) {
Collection entries = (Collection) arg;
for (Iterator it = entries.iterator(); it.hasNext();) {
Object entry = it.next();
for (Object entry : entries) {
if (entry instanceof Object[]) {
Object[] valueArray = ((Object[])entry);
for (int k = 0; k < valueArray.length; k++) {
Object argValue = valueArray[k];
Object[] valueArray = ((Object[]) entry);
for (Object argValue : valueArray) {
doSetValue(ps, parameterPosition, this.argTypes[i], argValue);
parameterPosition++;
}
@ -94,6 +92,7 @@ class ArgTypePreparedStatementSetter implements PreparedStatementSetter, Paramet
*/
protected void doSetValue(PreparedStatement ps, int parameterPosition, int argType, Object argValue)
throws SQLException {
StatementCreatorUtils.setParameterValue(ps, parameterPosition, argType, argValue);
}

View File

@ -1291,24 +1291,26 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
/**
* Create a new ArgPreparedStatementSetter using the args passed in. This method allows the
* creation to be overridden by sub-classes.
* Create a new arg-based PreparedStatementSetter using the args passed in.
* <p>By default, we'll create an {@link ArgumentPreparedStatementSetter}.
* This method allows for the creation to be overridden by subclasses.
* @param args object array with arguments
* @return the new PreparedStatementSetter
* @return the new PreparedStatementSetter to use
*/
protected PreparedStatementSetter newArgPreparedStatementSetter(Object[] args) {
return new ArgPreparedStatementSetter(args);
return new ArgumentPreparedStatementSetter(args);
}
/**
* Create a new ArgTypePreparedStatementSetter using the args and argTypes passed in.
* This method allows the creation to be overridden by sub-classes.
* Create a new arg-type-based PreparedStatementSetter using the args and types passed in.
* <p>By default, we'll create an {@link ArgumentTypePreparedStatementSetter}.
* This method allows for the creation to be overridden by subclasses.
* @param args object array with arguments
* @param argTypes int array of SQLTypes for arguments
* @return the new PreparedStatementSetter
* @param argTypes int array of SQLTypes for the associated arguments
* @return the new PreparedStatementSetter to use
*/
protected PreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) {
return new ArgTypePreparedStatementSetter(args, argTypes);
return new ArgumentTypePreparedStatementSetter(args, argTypes);
}
/**