@Override public <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType) throws DataAccessException { return queryForList(sql, new MapSqlParameterSource(paramMap), elementType); }
/** * Convert a Map of named parameter values to a corresponding array. * <p>This is a shortcut version of * {@link #buildValueArray(ParsedSql, SqlParameterSource, java.util.List)}. * @param sql the SQL statement * @param paramMap the Map of parameters * @return the array of values */ public static Object[] buildValueArray(String sql, Map<String, ?> paramMap) { ParsedSql parsedSql = parseSqlStatement(sql); return buildValueArray(parsedSql, new MapSqlParameterSource(paramMap), null); }
@Override public <T> List<T> query(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper) throws DataAccessException { return query(sql, new MapSqlParameterSource(paramMap), rowMapper); }
@Override public int update(String sql, Map<String, ?> paramMap) throws DataAccessException { return update(sql, new MapSqlParameterSource(paramMap)); }
@Override @Nullable public <T> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T>rowMapper) throws DataAccessException { return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper); }
/** * Create a NamedParameterJdbcTemplate based on the configured JdbcTemplate. */ @Override protected void initTemplateConfig() { JdbcTemplate jdbcTemplate = getJdbcTemplate(); if (jdbcTemplate != null) { this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); } }
@Override @Nullable public <T> T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action) throws DataAccessException { return execute(sql, new MapSqlParameterSource(paramMap), action); }
@Override public SqlRowSet queryForRowSet(String sql, Map<String, ?> paramMap) throws DataAccessException { return queryForRowSet(sql, new MapSqlParameterSource(paramMap)); }
@Override public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException { return query(sql, EmptySqlParameterSource.INSTANCE, rowMapper); }
@Override public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder) throws DataAccessException { return update(sql, paramSource, generatedKeyHolder, null); }
@Test(expected = IllegalArgumentException.class) public void getValueWhereTheUnderlyingBeanPropertyIsNotReadable() throws Exception { BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(new NoReadableProperties()); source.getValue("noOp"); }
/** * Parse the SQL statement and locate any placeholders or named parameters. * Named parameters are substituted for a JDBC placeholder. * <p>This is a shortcut version of * {@link #parseSqlStatement(String)} in combination with * {@link #substituteNamedParameters(ParsedSql, SqlParameterSource)}. * @param sql the SQL statement * @return the actual (parsed) SQL statement */ public static String parseSqlStatementIntoString(String sql) { ParsedSql parsedSql = parseSqlStatement(sql); return substituteNamedParameters(parsedSql, null); }
@Override public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) { return batchUpdate(sql, SqlParameterSourceUtils.createBatch(batchValues)); }
@Override public void setValues(PreparedStatement ps, int i) throws SQLException { Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]); setStatementParameters(values, ps, columnTypes); } @Override
@Override protected boolean removeEldestEntry(Map.Entry<String, ParsedSql> eldest) { return size() > getCacheLimit(); } };
/** * Build a {@link PreparedStatementCreator} based on the given SQL and named parameters. * <p>Note: Directly called from all {@code query} variants. Delegates to the common * {@link #getPreparedStatementCreator(String, SqlParameterSource, Consumer)} method. * @param sql the SQL statement to execute * @param paramSource container of arguments to bind * @return the corresponding {@link PreparedStatementCreator} * @see #getPreparedStatementCreator(String, SqlParameterSource, Consumer) */ protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource) { return getPreparedStatementCreator(sql, paramSource, null); }
@Override public void query(String sql, Map<String, ?> paramMap, RowCallbackHandler rch) throws DataAccessException { query(sql, new MapSqlParameterSource(paramMap), rch); }
@Override public List<Map<String, Object>> queryForList(String sql, Map<String, ?> paramMap) throws DataAccessException { return queryForList(sql, new MapSqlParameterSource(paramMap)); }
@Override public void query(String sql, RowCallbackHandler rch) throws DataAccessException { query(sql, EmptySqlParameterSource.INSTANCE, rch); }
@Override @Nullable public <T> T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse) throws DataAccessException { return query(sql, new MapSqlParameterSource(paramMap), rse); }