From: Juergen H. <jho...@us...> - 2006-04-20 18:14:21
|
Update of /cvsroot/springframework/spring/src/org/springframework/jdbc/core/namedparam In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3908/src/org/springframework/jdbc/core/namedparam Modified Files: NamedParameterJdbcOperations.java NamedParameterJdbcTemplate.java NamedParameterUtils.java SqlParameterSource.java Added Files: MapSqlParameterSource.java Removed Files: SimpleSqlParameterSource.java Log Message: renamed SimpleSqlParameterSource to MapSqlParameterSource Index: NamedParameterJdbcTemplate.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NamedParameterJdbcTemplate.java 20 Apr 2006 10:32:10 -0000 1.4 --- NamedParameterJdbcTemplate.java 20 Apr 2006 18:14:10 -0000 1.5 *************** *** 109,113 **** public void query(String sql, Map paramMap, RowCallbackHandler rch) throws DataAccessException { ! query(sql, new SimpleSqlParameterSource(paramMap), rch); } --- 109,113 ---- public void query(String sql, Map paramMap, RowCallbackHandler rch) throws DataAccessException { ! query(sql, new MapSqlParameterSource(paramMap), rch); } *************** *** 124,128 **** public List query(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException { ! return query(sql, new SimpleSqlParameterSource(paramMap), rowMapper); } --- 124,128 ---- public List query(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException { ! return query(sql, new MapSqlParameterSource(paramMap), rowMapper); } *************** *** 140,144 **** public Object queryForObject(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException { ! return queryForObject(sql, new SimpleSqlParameterSource(paramMap), rowMapper); } --- 140,144 ---- public Object queryForObject(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException { ! return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper); } *************** *** 166,170 **** public long queryForLong(String sql, Map paramMap) throws DataAccessException { ! return queryForLong(sql, new SimpleSqlParameterSource(paramMap)); } --- 166,170 ---- public long queryForLong(String sql, Map paramMap) throws DataAccessException { ! return queryForLong(sql, new MapSqlParameterSource(paramMap)); } *************** *** 175,179 **** public int queryForInt(String sql, Map paramMap) throws DataAccessException { ! return queryForInt(sql, new SimpleSqlParameterSource(paramMap)); } --- 175,179 ---- public int queryForInt(String sql, Map paramMap) throws DataAccessException { ! return queryForInt(sql, new MapSqlParameterSource(paramMap)); } *************** *** 184,188 **** public List queryForList(String sql, Map paramMap, Class elementType) throws DataAccessException { ! return queryForList(sql, new SimpleSqlParameterSource(paramMap), elementType); } --- 184,188 ---- public List queryForList(String sql, Map paramMap, Class elementType) throws DataAccessException { ! return queryForList(sql, new MapSqlParameterSource(paramMap), elementType); } *************** *** 192,196 **** public List queryForList(String sql, Map paramMap) throws DataAccessException { ! return queryForList(sql, new SimpleSqlParameterSource(paramMap)); } --- 192,196 ---- public List queryForList(String sql, Map paramMap) throws DataAccessException { ! return queryForList(sql, new MapSqlParameterSource(paramMap)); } *************** *** 204,208 **** public SqlRowSet queryForRowSet(String sql, Map paramMap) throws DataAccessException { ! return queryForRowSet(sql, new SimpleSqlParameterSource(paramMap)); } --- 204,208 ---- public SqlRowSet queryForRowSet(String sql, Map paramMap) throws DataAccessException { ! return queryForRowSet(sql, new MapSqlParameterSource(paramMap)); } *************** *** 221,225 **** public int update(String sql, Map paramMap) throws DataAccessException { ! return update(sql, new SimpleSqlParameterSource(paramMap)); } --- 221,225 ---- public int update(String sql, Map paramMap) throws DataAccessException { ! return update(sql, new MapSqlParameterSource(paramMap)); } Index: SqlParameterSource.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/core/namedparam/SqlParameterSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SqlParameterSource.java 8 Apr 2006 22:51:00 -0000 1.1 --- SqlParameterSource.java 20 Apr 2006 18:14:10 -0000 1.2 *************** *** 36,40 **** * @see NamedParameterJdbcOperations * @see NamedParameterJdbcTemplate ! * @see SimpleSqlParameterSource * @see BeanPropertySqlParameterSource */ --- 36,40 ---- * @see NamedParameterJdbcOperations * @see NamedParameterJdbcTemplate ! * @see MapSqlParameterSource * @see BeanPropertySqlParameterSource */ Index: NamedParameterUtils.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NamedParameterUtils.java 20 Apr 2006 09:50:15 -0000 1.3 --- NamedParameterUtils.java 20 Apr 2006 18:14:10 -0000 1.4 *************** *** 260,264 **** public static Object[] buildValueArray(String sql, Map paramMap) { ParsedSql parsedSql = parseSqlStatement(sql); ! return buildValueArray(parsedSql, new SimpleSqlParameterSource(paramMap)); } --- 260,264 ---- public static Object[] buildValueArray(String sql, Map paramMap) { ParsedSql parsedSql = parseSqlStatement(sql); ! return buildValueArray(parsedSql, new MapSqlParameterSource(paramMap)); } --- SimpleSqlParameterSource.java DELETED --- Index: NamedParameterJdbcOperations.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NamedParameterJdbcOperations.java 20 Apr 2006 10:32:10 -0000 1.3 --- NamedParameterJdbcOperations.java 20 Apr 2006 18:14:10 -0000 1.4 *************** *** 413,417 **** * @return the number of rows affected * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update ! * @see SimpleSqlParameterSource * @see org.springframework.jdbc.support.GeneratedKeyHolder */ --- 413,417 ---- * @return the number of rows affected * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update ! * @see MapSqlParameterSource * @see org.springframework.jdbc.support.GeneratedKeyHolder */ *************** *** 428,432 **** * @return the number of rows affected * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update ! * @see SimpleSqlParameterSource * @see org.springframework.jdbc.support.GeneratedKeyHolder */ --- 428,432 ---- * @return the number of rows affected * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update ! * @see MapSqlParameterSource * @see org.springframework.jdbc.support.GeneratedKeyHolder */ --- NEW FILE: MapSqlParameterSource.java --- /* * Copyright 2002-2006 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.jdbc.core.namedparam; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.springframework.util.Assert; /** * {@link SqlParameterSource} implementation that holds a given Map of parameters. * * <p>This class is intended for passing in a simple Map of parameter values * to the methods of the {@link NamedParameterJdbcTemplate} class. * * <p>The <code>addValue</code> methods on this class will make adding several * values easier. The methods return a reference to the {@link MapSqlParameterSource} * itself, so you can chain several method calls together within a single statement. * * @author Thomas Risberg * @author Juergen Hoeller * @since 2.0 * @see #addValue(String, Object) * @see #addValue(String, Object, int) * @see #registerSqlType * @see NamedParameterJdbcTemplate */ public class MapSqlParameterSource extends AbstractSqlParameterSource { private final Map values = new HashMap(); /** * Create an empty MapSqlParameterSource, * with values to be added via <code>addValue</code>. * @see #addValue(String, Object) */ public MapSqlParameterSource() { } /** * Create a new MapSqlParameterSource, with one value * comprised of the supplied arguments. * @param paramName the name of the parameter * @param value the value of the parameter * @see #addValue(String, Object) */ public MapSqlParameterSource(String paramName, Object value) { addValue(paramName, value); } /** * Create a new MapSqlParameterSource based on a Map. * @param values a Map holding existing parameter values (can be <code>null</code>) */ public MapSqlParameterSource(Map values) { addValues(values); } /** * Add a parameter to this parameter source. * @param paramName the name of the parameter * @param value the value of the parameter * @return a reference to this parameter source, * so it's possible to chain several calls together */ public MapSqlParameterSource addValue(String paramName, Object value) { Assert.notNull(paramName, "Parameter name must not be null"); this.values.put(paramName, value); return this; } /** * Add a parameter to this parameter source. * @param paramName the name of the parameter * @param value the value of the parameter * @param sqlType the SQL type of the parameter * @return a reference to this parameter source, * so it's possible to chain several calls together */ public MapSqlParameterSource addValue(String paramName, Object value, int sqlType) { Assert.notNull(paramName, "Parameter name must not be null"); this.values.put(paramName, value); registerSqlType(paramName, sqlType); return this; } /** * Add a Map of parameters to this parameter source. * @param values a Map holding existing parameter values (can be <code>null</code>) * @return a reference to this parameter source, * so it's possible to chain several calls together */ public MapSqlParameterSource addValues(Map values) { if (values != null) { this.values.putAll(values); } return this; } /** * Expose the current parameter values as read-only Map. */ public Map getValues() { return Collections.unmodifiableMap(this.values); } public boolean hasValue(String paramName) { return this.values.containsKey(paramName); } public Object getValue(String paramName) { if (!hasValue(paramName)) { throw new IllegalArgumentException("No value registered for key '" + paramName + "'"); } return this.values.get(paramName); } } |