JDBC parameter binding uses JDBC 3.0 ParameterMetaData (if available) for type determination
In sync with 3.2.1 now, containing minor modifications for defensiveness against the JDBC driver. Issue: SPR-10084
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -48,7 +48,7 @@ public class PreparedStatementCreatorFactory {
|
||||
/** The SQL, which won't change when the parameters change */
|
||||
private final String sql;
|
||||
|
||||
/** List of SqlParameter objects. May not be <code>null</code>. */
|
||||
/** List of SqlParameter objects. May not be {@code null}. */
|
||||
private final List<SqlParameter> declaredParameters;
|
||||
|
||||
private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
|
||||
@@ -144,15 +144,15 @@ public class PreparedStatementCreatorFactory {
|
||||
|
||||
/**
|
||||
* Return a new PreparedStatementSetter for the given parameters.
|
||||
* @param params list of parameters (may be <code>null</code>)
|
||||
* @param params list of parameters (may be {@code null})
|
||||
*/
|
||||
public PreparedStatementSetter newPreparedStatementSetter(List params) {
|
||||
public PreparedStatementSetter newPreparedStatementSetter(List<?> params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new PreparedStatementSetter for the given parameters.
|
||||
* @param params the parameter array (may be <code>null</code>)
|
||||
* @param params the parameter array (may be {@code null})
|
||||
*/
|
||||
public PreparedStatementSetter newPreparedStatementSetter(Object[] params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
|
||||
@@ -160,7 +160,7 @@ public class PreparedStatementCreatorFactory {
|
||||
|
||||
/**
|
||||
* Return a new PreparedStatementCreator for the given parameters.
|
||||
* @param params list of parameters (may be <code>null</code>)
|
||||
* @param params list of parameters (may be {@code null})
|
||||
*/
|
||||
public PreparedStatementCreator newPreparedStatementCreator(List<?> params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
|
||||
@@ -168,7 +168,7 @@ public class PreparedStatementCreatorFactory {
|
||||
|
||||
/**
|
||||
* Return a new PreparedStatementCreator for the given parameters.
|
||||
* @param params the parameter array (may be <code>null</code>)
|
||||
* @param params the parameter array (may be {@code null})
|
||||
*/
|
||||
public PreparedStatementCreator newPreparedStatementCreator(Object[] params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
|
||||
@@ -178,7 +178,7 @@ public class PreparedStatementCreatorFactory {
|
||||
* Return a new PreparedStatementCreator for the given parameters.
|
||||
* @param sqlToUse the actual SQL statement to use (if different from
|
||||
* the factory's, for example because of named parameter expanding)
|
||||
* @param params the parameter array (may be <code>null</code>)
|
||||
* @param params the parameter array (may be {@code null})
|
||||
*/
|
||||
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object[] params) {
|
||||
return new PreparedStatementCreatorImpl(
|
||||
@@ -225,7 +225,7 @@ public class PreparedStatementCreatorFactory {
|
||||
}
|
||||
|
||||
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
|
||||
PreparedStatement ps = null;
|
||||
PreparedStatement ps;
|
||||
if (generatedKeysColumnNames != null || returnGeneratedKeys) {
|
||||
try {
|
||||
if (generatedKeysColumnNames != null) {
|
||||
@@ -263,7 +263,7 @@ public class PreparedStatementCreatorFactory {
|
||||
int sqlColIndx = 1;
|
||||
for (int i = 0; i < this.parameters.size(); i++) {
|
||||
Object in = this.parameters.get(i);
|
||||
SqlParameter declaredParameter = null;
|
||||
SqlParameter declaredParameter;
|
||||
// SqlParameterValue overrides declared parameter metadata, in particular for
|
||||
// independence from the declared parameter position in case of named parameters.
|
||||
if (in instanceof SqlParameterValue) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -93,7 +93,7 @@ public abstract class StatementCreatorUtils {
|
||||
/**
|
||||
* Derive a default SQL type from the given Java type.
|
||||
* @param javaType the Java type to translate
|
||||
* @return the corresponding SQL type, or <code>null</code> if none found
|
||||
* @return the corresponding SQL type, or {@code null} if none found
|
||||
*/
|
||||
public static int javaTypeToSqlParameterType(Class javaType) {
|
||||
Integer sqlType = javaTypeToSqlTypeMap.get(javaType);
|
||||
@@ -233,7 +233,7 @@ public abstract class StatementCreatorUtils {
|
||||
try {
|
||||
pmd = ps.getParameterMetaData();
|
||||
}
|
||||
catch (AbstractMethodError err) {
|
||||
catch (Throwable ex) {
|
||||
// JDBC driver not compliant with JDBC 3.0
|
||||
// -> proceed with database-specific checks
|
||||
}
|
||||
@@ -381,7 +381,7 @@ public abstract class StatementCreatorUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given value is a <code>java.util.Date</code>
|
||||
* Check whether the given value is a {@code java.util.Date}
|
||||
* (but not one of the JDBC-specific subclasses).
|
||||
*/
|
||||
private static boolean isDateValue(Class inValueType) {
|
||||
@@ -394,7 +394,7 @@ public abstract class StatementCreatorUtils {
|
||||
/**
|
||||
* Clean up all resources held by parameter values which were passed to an
|
||||
* execute method. This is for example important for closing LOB values.
|
||||
* @param paramValues parameter values supplied. May be <code>null</code>.
|
||||
* @param paramValues parameter values supplied. May be {@code null}.
|
||||
* @see DisposableSqlTypeValue#cleanup()
|
||||
* @see org.springframework.jdbc.core.support.SqlLobValue#cleanup()
|
||||
*/
|
||||
@@ -407,7 +407,7 @@ public abstract class StatementCreatorUtils {
|
||||
/**
|
||||
* Clean up all resources held by parameter values which were passed to an
|
||||
* execute method. This is for example important for closing LOB values.
|
||||
* @param paramValues parameter values supplied. May be <code>null</code>.
|
||||
* @param paramValues parameter values supplied. May be {@code null}.
|
||||
* @see DisposableSqlTypeValue#cleanup()
|
||||
* @see org.springframework.jdbc.core.support.SqlLobValue#cleanup()
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user