/** * 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. * @param parsedSql the parsed SQL statement * @param paramSource the source for named parameters */ public static List<SqlParameter> buildSqlParameterList(ParsedSql parsedSql, SqlParameterSource paramSource) { List<String> paramNames = parsedSql.getParameterNames(); List<SqlParameter> params = new ArrayList<>(paramNames.size()); for (String paramName : paramNames) { params.add(new SqlParameter( paramName, paramSource.getSqlType(paramName), paramSource.getTypeName(paramName))); } return params; }
/** * Create a wrapped value if parameter has type information, plain object if not. * @param source the source of parameter values and type information * @param parameterName the name of the parameter * @return the value object */ @Nullable public static Object getTypedValue(SqlParameterSource source, String parameterName) { int sqlType = source.getSqlType(parameterName); if (sqlType != SqlParameterSource.TYPE_UNKNOWN) { if (source.getTypeName(parameterName) != null) { return new SqlParameterValue(sqlType, source.getTypeName(parameterName), source.getValue(parameterName)); } else { return new SqlParameterValue(sqlType, source.getValue(parameterName)); } } else { return source.getValue(parameterName); } }
/** * 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. * @param parsedSql the parsed SQL statement * @param paramSource the source for named parameters */ public static List<SqlParameter> buildSqlParameterList(ParsedSql parsedSql, SqlParameterSource paramSource) { List<String> paramNames = parsedSql.getParameterNames(); List<SqlParameter> params = new ArrayList<>(paramNames.size()); for (String paramName : paramNames) { params.add(new SqlParameter( paramName, paramSource.getSqlType(paramName), paramSource.getTypeName(paramName))); } return params; }
/** * 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. * @param parsedSql the parsed SQL statement * @param paramSource the source for named parameters */ public static List<SqlParameter> buildSqlParameterList(ParsedSql parsedSql, SqlParameterSource paramSource) { List<String> paramNames = parsedSql.getParameterNames(); List<SqlParameter> params = new LinkedList<SqlParameter>(); for (String paramName : paramNames) { params.add(new SqlParameter(paramName, paramSource.getSqlType(paramName), paramSource.getTypeName(paramName))); } return params; }
/** * 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. * @param parsedSql the parsed SQL statement * @param paramSource the source for named parameters */ public static List<SqlParameter> buildSqlParameterList(ParsedSql parsedSql, SqlParameterSource paramSource) { List<String> paramNames = parsedSql.getParameterNames(); List<SqlParameter> params = new LinkedList<SqlParameter>(); for (String paramName : paramNames) { SqlParameter param = new SqlParameter( paramName, paramSource.getSqlType(paramName), paramSource.getTypeName(paramName)); params.add(param); } return params; }
/** * Create a wrapped value if parameter has type information, plain object if not. * @param source the source of paramer values and type information * @param parameterName the name of the parameter * @return the value object */ public static Object getTypedValue(SqlParameterSource source, String parameterName) { int sqlType = source.getSqlType(parameterName); if (sqlType != SqlParameterSource.TYPE_UNKNOWN) { if (source.getTypeName(parameterName) != null) { return new SqlParameterValue(sqlType, source.getTypeName(parameterName), source.getValue(parameterName)); } else { return new SqlParameterValue(sqlType, source.getValue(parameterName)); } } else { return source.getValue(parameterName); } }