类 NamedParameterUtils
- java.lang.Object
- org.springframework.jdbc.core.namedparam.NamedParameterUtils
public abstract class NamedParameterUtils extends Object
Helper methods for named parameter parsing.Only intended for internal use within Spring's JDBC framework.
- 从以下版本开始:
- 2.0
- 作者:
- Thomas Risberg, Juergen Hoeller
构造器概要
构造器 构造器 说明 NamedParameterUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static List<SqlParameter>
buildSqlParameterList(ParsedSql parsedSql, SqlParameterSource paramSource)
Convert parameter declarations from an SqlParameterSource to a corresponding List of SqlParameters.static int[]
buildSqlTypeArray(ParsedSql parsedSql, SqlParameterSource paramSource)
Convert parameter types from an SqlParameterSource into a corresponding int array.static Object[]
buildValueArray(String sql, Map<String,?> paramMap)
Convert a Map of named parameter values to a corresponding array.static Object[]
buildValueArray(ParsedSql parsedSql, SqlParameterSource paramSource, List<SqlParameter> declaredParams)
Convert a Map of named parameter values to a corresponding array.static ParsedSql
parseSqlStatement(String sql)
Parse the SQL statement and locate any placeholders or named parameters.static String
parseSqlStatementIntoString(String sql)
Parse the SQL statement and locate any placeholders or named parameters.static String
substituteNamedParameters(String sql, SqlParameterSource paramSource)
Parse the SQL statement and locate any placeholders or named parameters.static String
substituteNamedParameters(ParsedSql parsedSql, SqlParameterSource paramSource)
Parse the SQL statement and locate any placeholders or named parameters.
构造器详细资料
NamedParameterUtils
public NamedParameterUtils()
方法详细资料
parseSqlStatement
public static ParsedSql parseSqlStatement(String sql)
Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for a JDBC placeholder.- 参数:
sql
- the SQL statement- 返回:
- the parsed statement, represented as ParsedSql instance
substituteNamedParameters
public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameterSource paramSource)
Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for a JDBC placeholder, and any select list is expanded to the required number of placeholders. Select lists may contain an array of objects, and in that case the placeholders will be grouped and enclosed with parentheses. This allows for the use of "expression lists" in the SQL statement like:select id, name, state from table where (name, age) in (('John', 35), ('Ann', 50))
The parameter values passed in are used to determine the number of placeholders to be used for a select list. Select lists should be limited to 100 or fewer elements. A larger number of elements is not guaranteed to be supported by the database and is strictly vendor-dependent.
- 参数:
parsedSql
- the parsed representation of the SQL statementparamSource
- the source for named parameters- 返回:
- the SQL statement with substituted parameters
- 另请参阅:
parseSqlStatement(java.lang.String)
buildValueArray
public static Object[] buildValueArray(ParsedSql parsedSql, SqlParameterSource paramSource, List<SqlParameter> declaredParams)
Convert a Map of named parameter values to a corresponding array.- 参数:
parsedSql
- the parsed SQL statementparamSource
- the source for named parametersdeclaredParams
- the List of declared SqlParameter objects (may benull
). If specified, the parameter metadata will be built into the value array in the form of SqlParameterValue objects.- 返回:
- the array of values
buildSqlTypeArray
public static int[] buildSqlTypeArray(ParsedSql parsedSql, SqlParameterSource paramSource)
Convert parameter types from an SqlParameterSource into a corresponding int array. This is necessary in order to reuse existing methods on JdbcTemplate. Any named parameter types are placed in the correct position in the Object array based on the parsed SQL statement info.- 参数:
parsedSql
- the parsed SQL statementparamSource
- the source for named parameters
buildSqlParameterList
public static List<SqlParameter> buildSqlParameterList(ParsedSql parsedSql, SqlParameterSource paramSource)
Convert parameter declarations from an SqlParameterSource to a corresponding List of SqlParameters. This is necessary in order to reuse existing methods on JdbcTemplate. The SqlParameter for a named parameter is placed in the correct position in the resulting list based on the parsed SQL statement info.- 参数:
parsedSql
- the parsed SQL statementparamSource
- the source for named parameters
parseSqlStatementIntoString
public static String parseSqlStatementIntoString(String sql)
Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for a JDBC placeholder.This is a shortcut version of
parseSqlStatement(String)
in combination withsubstituteNamedParameters(ParsedSql, SqlParameterSource)
.- 参数:
sql
- the SQL statement- 返回:
- the actual (parsed) SQL statement
substituteNamedParameters
public static String substituteNamedParameters(String sql, SqlParameterSource paramSource)
Parse the SQL statement and locate any placeholders or named parameters. Named parameters are substituted for a JDBC placeholder and any select list is expanded to the required number of placeholders.This is a shortcut version of
substituteNamedParameters(ParsedSql, SqlParameterSource)
.- 参数:
sql
- the SQL statementparamSource
- the source for named parameters- 返回:
- the SQL statement with substituted parameters
buildValueArray
public static Object[] buildValueArray(String sql, Map<String,?> paramMap)
Convert a Map of named parameter values to a corresponding array.This is a shortcut version of
buildValueArray(ParsedSql, SqlParameterSource, java.util.List)
.- 参数:
sql
- the SQL statementparamMap
- the Map of parameters- 返回:
- the array of values