org.springframework.jdbc.core
Class StatementCreatorUtils

java.lang.Object
  extended by org.springframework.jdbc.core.StatementCreatorUtils

public abstract class StatementCreatorUtils
extends java.lang.Object

Utility methods for PreparedStatementSetter/Creator and CallableStatementCreator implementations, providing sophisticated parameter management (including support for LOB values).

Used by PreparedStatementCreatorFactory and CallableStatementCreatorFactory, but also available for direct use in custom setter/creator implementations.

Since:
1.1
Author:
Thomas Risberg, Juergen Hoeller
See Also:
PreparedStatementSetter, PreparedStatementCreator, CallableStatementCreator, PreparedStatementCreatorFactory, CallableStatementCreatorFactory, SqlParameter, SqlTypeValue, SqlLobValue

Field Summary
private static java.util.Map<java.lang.Class,java.lang.Integer> javaTypeToSqlTypeMap
           
private static Log logger
           
 
Constructor Summary
StatementCreatorUtils()
           
 
Method Summary
static void cleanupParameters(java.util.Collection paramValues)
          Clean up all resources held by parameter values which were passed to an execute method.
static void cleanupParameters(java.lang.Object[] paramValues)
          Clean up all resources held by parameter values which were passed to an execute method.
private static boolean isDateValue(java.lang.Class inValueType)
          Check whether the given value is a java.util.Date (but not one of the JDBC-specific subclasses).
private static boolean isStringValue(java.lang.Class inValueType)
          Check whether the given value can be treated as a String value.
static int javaTypeToSqlParameterType(java.lang.Class javaType)
          Derive a default SQL type from the given Java type.
private static void setNull(java.sql.PreparedStatement ps, int paramIndex, int sqlType, java.lang.String typeName)
          Set the specified PreparedStatement parameter to null, respecting database-specific peculiarities.
static void setParameterValue(java.sql.PreparedStatement ps, int paramIndex, int sqlType, java.lang.Object inValue)
          Set the value for a parameter.
static void setParameterValue(java.sql.PreparedStatement ps, int paramIndex, int sqlType, java.lang.String typeName, java.lang.Object inValue)
          Set the value for a parameter.
static void setParameterValue(java.sql.PreparedStatement ps, int paramIndex, SqlParameter param, java.lang.Object inValue)
          Set the value for a parameter.
private static void setParameterValueInternal(java.sql.PreparedStatement ps, int paramIndex, int sqlType, java.lang.String typeName, java.lang.Integer scale, java.lang.Object inValue)
          Set the value for a parameter.
private static void setValue(java.sql.PreparedStatement ps, int paramIndex, int sqlType, java.lang.String typeName, java.lang.Integer scale, java.lang.Object inValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Log logger

javaTypeToSqlTypeMap

private static java.util.Map<java.lang.Class,java.lang.Integer> javaTypeToSqlTypeMap
Constructor Detail

StatementCreatorUtils

public StatementCreatorUtils()
Method Detail

javaTypeToSqlParameterType

public static int javaTypeToSqlParameterType(java.lang.Class javaType)
Derive a default SQL type from the given Java type.

Parameters:
javaType - the Java type to translate
Returns:
the corresponding SQL type, or null if none found

setParameterValue

public static void setParameterValue(java.sql.PreparedStatement ps,
                                     int paramIndex,
                                     SqlParameter param,
                                     java.lang.Object inValue)
                              throws java.sql.SQLException
Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.

Parameters:
ps - the prepared statement or callable statement
paramIndex - index of the parameter we are setting
param - the parameter as it is declared including type
inValue - the value to set
Throws:
java.sql.SQLException - if thrown by PreparedStatement methods

setParameterValue

public static void setParameterValue(java.sql.PreparedStatement ps,
                                     int paramIndex,
                                     int sqlType,
                                     java.lang.Object inValue)
                              throws java.sql.SQLException
Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.

Parameters:
ps - the prepared statement or callable statement
paramIndex - index of the parameter we are setting
sqlType - the SQL type of the parameter
inValue - the value to set (plain value or a SqlTypeValue)
Throws:
java.sql.SQLException - if thrown by PreparedStatement methods
See Also:
SqlTypeValue

setParameterValue

public static void setParameterValue(java.sql.PreparedStatement ps,
                                     int paramIndex,
                                     int sqlType,
                                     java.lang.String typeName,
                                     java.lang.Object inValue)
                              throws java.sql.SQLException
Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.

Parameters:
ps - the prepared statement or callable statement
paramIndex - index of the parameter we are setting
sqlType - the SQL type of the parameter
typeName - the type name of the parameter (optional, only used for SQL NULL and SqlTypeValue)
inValue - the value to set (plain value or a SqlTypeValue)
Throws:
java.sql.SQLException - if thrown by PreparedStatement methods
See Also:
SqlTypeValue

setParameterValueInternal

private static void setParameterValueInternal(java.sql.PreparedStatement ps,
                                              int paramIndex,
                                              int sqlType,
                                              java.lang.String typeName,
                                              java.lang.Integer scale,
                                              java.lang.Object inValue)
                                       throws java.sql.SQLException
Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.

Parameters:
ps - the prepared statement or callable statement
paramIndex - index of the parameter we are setting
sqlType - the SQL type of the parameter
typeName - the type name of the parameter (optional, only used for SQL NULL and SqlTypeValue)
scale - the number of digits after the decimal point (for DECIMAL and NUMERIC types)
inValue - the value to set (plain value or a SqlTypeValue)
Throws:
java.sql.SQLException - if thrown by PreparedStatement methods
See Also:
SqlTypeValue

setNull

private static void setNull(java.sql.PreparedStatement ps,
                            int paramIndex,
                            int sqlType,
                            java.lang.String typeName)
                     throws java.sql.SQLException
Set the specified PreparedStatement parameter to null, respecting database-specific peculiarities.

Throws:
java.sql.SQLException

setValue

private static void setValue(java.sql.PreparedStatement ps,
                             int paramIndex,
                             int sqlType,
                             java.lang.String typeName,
                             java.lang.Integer scale,
                             java.lang.Object inValue)
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

isStringValue

private static boolean isStringValue(java.lang.Class inValueType)
Check whether the given value can be treated as a String value.


isDateValue

private static boolean isDateValue(java.lang.Class inValueType)
Check whether the given value is a java.util.Date (but not one of the JDBC-specific subclasses).


cleanupParameters

public static void cleanupParameters(java.lang.Object[] paramValues)
Clean up all resources held by parameter values which were passed to an execute method. This is for example important for closing LOB values.

Parameters:
paramValues - parameter values supplied. May be null.
See Also:
DisposableSqlTypeValue.cleanup(), SqlLobValue.cleanup()

cleanupParameters

public static void cleanupParameters(java.util.Collection paramValues)
Clean up all resources held by parameter values which were passed to an execute method. This is for example important for closing LOB values.

Parameters:
paramValues - parameter values supplied. May be null.
See Also:
DisposableSqlTypeValue.cleanup(), SqlLobValue.cleanup()