changed NamedParameter/SimpleJdbcOperations parameter signatures to accept any Map value type (SPR-6046)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1781 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2009-08-27 13:53:00 +00:00
parent d0380c25d3
commit 2147e66d7c
7 changed files with 67 additions and 88 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -85,7 +85,7 @@ public interface NamedParameterJdbcOperations {
* @return a result object returned by the action, or <code>null</code> * @return a result object returned by the action, or <code>null</code>
* @throws DataAccessException if there is any problem * @throws DataAccessException if there is any problem
*/ */
<T> T execute(String sql, Map<String, Object> paramMap, PreparedStatementCallback<T> action) <T> T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action)
throws DataAccessException; throws DataAccessException;
/** /**
@ -112,7 +112,7 @@ public interface NamedParameterJdbcOperations {
* @return an arbitrary result object, as returned by the ResultSetExtractor * @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
*/ */
<T> T query(String sql, Map<String, Object> paramMap, ResultSetExtractor<T> rse) <T> T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
throws DataAccessException; throws DataAccessException;
/** /**
@ -137,7 +137,7 @@ public interface NamedParameterJdbcOperations {
* @param rch object that will extract results, one row at a time * @param rch object that will extract results, one row at a time
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
*/ */
void query(String sql, Map<String, Object> paramMap, RowCallbackHandler rch) throws DataAccessException; void query(String sql, Map<String, ?> paramMap, RowCallbackHandler rch) throws DataAccessException;
/** /**
* Query given SQL to create a prepared statement from SQL and a list * Query given SQL to create a prepared statement from SQL and a list
@ -163,7 +163,7 @@ public interface NamedParameterJdbcOperations {
* @return the result List, containing mapped objects * @return the result List, containing mapped objects
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
*/ */
<T> List<T> query(String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) <T> List<T> query(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
throws DataAccessException; throws DataAccessException;
/** /**
@ -196,7 +196,7 @@ public interface NamedParameterJdbcOperations {
* one column in that row * one column in that row
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
*/ */
<T> T queryForObject(String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) <T> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
throws DataAccessException; throws DataAccessException;
/** /**
@ -233,7 +233,7 @@ public interface NamedParameterJdbcOperations {
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
*/ */
<T> T queryForObject(String sql, Map<String, Object> paramMap, Class<T> requiredType) <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
throws DataAccessException; throws DataAccessException;
/** /**
@ -272,7 +272,7 @@ public interface NamedParameterJdbcOperations {
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String) * @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
* @see org.springframework.jdbc.core.ColumnMapRowMapper * @see org.springframework.jdbc.core.ColumnMapRowMapper
*/ */
Map<String, Object> queryForMap(String sql, Map<String, Object> paramMap) throws DataAccessException; Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException;
/** /**
* Query given SQL to create a prepared statement from SQL and a * Query given SQL to create a prepared statement from SQL and a
@ -305,7 +305,7 @@ public interface NamedParameterJdbcOperations {
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForLong(String) * @see org.springframework.jdbc.core.JdbcTemplate#queryForLong(String)
*/ */
long queryForLong(String sql, Map<String, Object> paramMap) throws DataAccessException; long queryForLong(String sql, Map<String, ?> paramMap) throws DataAccessException;
/** /**
* Query given SQL to create a prepared statement from SQL and a * Query given SQL to create a prepared statement from SQL and a
@ -336,7 +336,7 @@ public interface NamedParameterJdbcOperations {
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForInt(String) * @see org.springframework.jdbc.core.JdbcTemplate#queryForInt(String)
*/ */
int queryForInt(String sql, Map<String, Object> paramMap) throws DataAccessException; int queryForInt(String sql, Map<String, ?> paramMap) throws DataAccessException;
/** /**
* Query given SQL to create a prepared statement from SQL and a * Query given SQL to create a prepared statement from SQL and a
@ -370,7 +370,7 @@ public interface NamedParameterJdbcOperations {
* @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class) * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class)
* @see org.springframework.jdbc.core.SingleColumnRowMapper * @see org.springframework.jdbc.core.SingleColumnRowMapper
*/ */
<T> List<T> queryForList(String sql, Map<String, Object> paramMap, Class<T> elementType) <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType)
throws DataAccessException; throws DataAccessException;
/** /**
@ -402,7 +402,7 @@ public interface NamedParameterJdbcOperations {
* @throws org.springframework.dao.DataAccessException if the query fails * @throws org.springframework.dao.DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String) * @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String)
*/ */
List<Map<String, Object>> queryForList(String sql, Map<String, Object> paramMap) throws DataAccessException; List<Map<String, Object>> queryForList(String sql, Map<String, ?> paramMap) throws DataAccessException;
/** /**
* Query given SQL to create a prepared statement from SQL and a * Query given SQL to create a prepared statement from SQL and a
@ -443,7 +443,7 @@ public interface NamedParameterJdbcOperations {
* @see org.springframework.jdbc.core.SqlRowSetResultSetExtractor * @see org.springframework.jdbc.core.SqlRowSetResultSetExtractor
* @see javax.sql.rowset.CachedRowSet * @see javax.sql.rowset.CachedRowSet
*/ */
SqlRowSet queryForRowSet(String sql, Map<String, Object> paramMap) throws DataAccessException; SqlRowSet queryForRowSet(String sql, Map<String, ?> paramMap) throws DataAccessException;
/** /**
* Issue an update via a prepared statement, binding the given arguments. * Issue an update via a prepared statement, binding the given arguments.
@ -462,7 +462,7 @@ public interface NamedParameterJdbcOperations {
* @return the number of rows affected * @return the number of rows affected
* @throws org.springframework.dao.DataAccessException if there is any problem issuing the update * @throws org.springframework.dao.DataAccessException if there is any problem issuing the update
*/ */
int update(String sql, Map<String, Object> paramMap) throws DataAccessException; int update(String sql, Map<String, ?> paramMap) throws DataAccessException;
/** /**
* Issue an update via a prepared statement, binding the given arguments, * Issue an update via a prepared statement, binding the given arguments,
@ -499,7 +499,7 @@ public interface NamedParameterJdbcOperations {
* @param batchValues the array of Maps containing the batch of arguments for the query * @param batchValues the array of Maps containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch * @return an array containing the numbers of rows affected by each update in the batch
*/ */
public int[] batchUpdate(String sql, Map<String, Object>[] batchValues); public int[] batchUpdate(String sql, Map<String, ?>[] batchValues);
/** /**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments. * Execute a batch using the supplied SQL statement with the batch of supplied arguments.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -103,7 +103,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action); return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action);
} }
public <T> T execute(String sql, Map<String, Object> paramMap, PreparedStatementCallback<T> action) public <T> T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action)
throws DataAccessException { throws DataAccessException {
return execute(sql, new MapSqlParameterSource(paramMap), action); return execute(sql, new MapSqlParameterSource(paramMap), action);
@ -115,7 +115,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse); return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse);
} }
public <T> T query(String sql, Map<String, Object> paramMap, ResultSetExtractor<T> rse) public <T> T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
throws DataAccessException { throws DataAccessException {
return query(sql, new MapSqlParameterSource(paramMap), rse); return query(sql, new MapSqlParameterSource(paramMap), rse);
@ -127,7 +127,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rch); getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rch);
} }
public void query(String sql, Map<String, Object> paramMap, RowCallbackHandler rch) public void query(String sql, Map<String, ?> paramMap, RowCallbackHandler rch)
throws DataAccessException { throws DataAccessException {
query(sql, new MapSqlParameterSource(paramMap), rch); query(sql, new MapSqlParameterSource(paramMap), rch);
@ -139,7 +139,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper); return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
} }
public <T> List<T> query(String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) public <T> List<T> query(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
throws DataAccessException { throws DataAccessException {
return query(sql, new MapSqlParameterSource(paramMap), rowMapper); return query(sql, new MapSqlParameterSource(paramMap), rowMapper);
@ -152,7 +152,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return DataAccessUtils.requiredSingleResult(results); return DataAccessUtils.requiredSingleResult(results);
} }
public <T> T queryForObject(String sql, Map<String, Object> paramMap, RowMapper<T>rowMapper) public <T> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T>rowMapper)
throws DataAccessException { throws DataAccessException {
return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper); return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper);
@ -164,7 +164,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return queryForObject(sql, paramSource, new SingleColumnRowMapper<T>(requiredType)); return queryForObject(sql, paramSource, new SingleColumnRowMapper<T>(requiredType));
} }
public <T> T queryForObject(String sql, Map<String, Object> paramMap, Class<T> requiredType) public <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
throws DataAccessException { throws DataAccessException {
return queryForObject(sql, paramMap, new SingleColumnRowMapper<T>(requiredType)); return queryForObject(sql, paramMap, new SingleColumnRowMapper<T>(requiredType));
@ -174,7 +174,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return queryForObject(sql, paramSource, new ColumnMapRowMapper()); return queryForObject(sql, paramSource, new ColumnMapRowMapper());
} }
public Map<String, Object> queryForMap(String sql, Map<String, Object> paramMap) throws DataAccessException { public Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException {
return queryForObject(sql, paramMap, new ColumnMapRowMapper()); return queryForObject(sql, paramMap, new ColumnMapRowMapper());
} }
@ -183,7 +183,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return (number != null ? number.longValue() : 0); return (number != null ? number.longValue() : 0);
} }
public long queryForLong(String sql, Map<String, Object> paramMap) throws DataAccessException { public long queryForLong(String sql, Map<String, ?> paramMap) throws DataAccessException {
return queryForLong(sql, new MapSqlParameterSource(paramMap)); return queryForLong(sql, new MapSqlParameterSource(paramMap));
} }
@ -192,7 +192,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return (number != null ? number.intValue() : 0); return (number != null ? number.intValue() : 0);
} }
public int queryForInt(String sql, Map<String, Object> paramMap) throws DataAccessException { public int queryForInt(String sql, Map<String, ?> paramMap) throws DataAccessException {
return queryForInt(sql, new MapSqlParameterSource(paramMap)); return queryForInt(sql, new MapSqlParameterSource(paramMap));
} }
@ -202,7 +202,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return query(sql, paramSource, new SingleColumnRowMapper<T>(elementType)); return query(sql, paramSource, new SingleColumnRowMapper<T>(elementType));
} }
public <T> List<T> queryForList(String sql, Map<String, Object> paramMap, Class<T> elementType) public <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType)
throws DataAccessException { throws DataAccessException {
return queryForList(sql, new MapSqlParameterSource(paramMap), elementType); return queryForList(sql, new MapSqlParameterSource(paramMap), elementType);
@ -214,7 +214,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return query(sql, paramSource, new ColumnMapRowMapper()); return query(sql, paramSource, new ColumnMapRowMapper());
} }
public List<Map<String, Object>> queryForList(String sql, Map<String, Object> paramMap) public List<Map<String, Object>> queryForList(String sql, Map<String, ?> paramMap)
throws DataAccessException { throws DataAccessException {
return queryForList(sql, new MapSqlParameterSource(paramMap)); return queryForList(sql, new MapSqlParameterSource(paramMap));
@ -225,7 +225,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
getPreparedStatementCreator(sql, paramSource), new SqlRowSetResultSetExtractor()); getPreparedStatementCreator(sql, paramSource), new SqlRowSetResultSetExtractor());
} }
public SqlRowSet queryForRowSet(String sql, Map<String, Object> paramMap) throws DataAccessException { public SqlRowSet queryForRowSet(String sql, Map<String, ?> paramMap) throws DataAccessException {
return queryForRowSet(sql, new MapSqlParameterSource(paramMap)); return queryForRowSet(sql, new MapSqlParameterSource(paramMap));
} }
@ -233,7 +233,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return getJdbcOperations().update(getPreparedStatementCreator(sql, paramSource)); return getJdbcOperations().update(getPreparedStatementCreator(sql, paramSource));
} }
public int update(String sql, Map<String, Object> paramMap) throws DataAccessException { public int update(String sql, Map<String, ?> paramMap) throws DataAccessException {
return update(sql, new MapSqlParameterSource(paramMap)); return update(sql, new MapSqlParameterSource(paramMap));
} }
@ -261,10 +261,10 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
return getJdbcOperations().update(pscf.newPreparedStatementCreator(params), generatedKeyHolder); return getJdbcOperations().update(pscf.newPreparedStatementCreator(params), generatedKeyHolder);
} }
public int[] batchUpdate(String sql, Map<String, Object>[] batchValues) { public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) {
SqlParameterSource[] batchArgs = new SqlParameterSource[batchValues.length]; SqlParameterSource[] batchArgs = new SqlParameterSource[batchValues.length];
int i = 0; int i = 0;
for (Map<String, Object> values : batchValues) { for (Map<String, ?> values : batchValues) {
batchArgs[i] = new MapSqlParameterSource(values); batchArgs[i] = new MapSqlParameterSource(values);
i++; i++;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -137,7 +137,7 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, Map<String, Object> args) { public <T> T executeFunction(Class<T> returnType, Map<String, ?> args) {
return (T) doExecute(args).get(getScalarOutParameterName()); return (T) doExecute(args).get(getScalarOutParameterName());
} }
@ -152,7 +152,7 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, Map<String, Object> args) { public <T> T executeObject(Class<T> returnType, Map<String, ?> args) {
return (T) doExecute(args).get(getScalarOutParameterName()); return (T) doExecute(args).get(getScalarOutParameterName());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -68,7 +68,7 @@ public interface SimpleJdbcCallOperations {
SimpleJdbcCallOperations withReturnValue(); SimpleJdbcCallOperations withReturnValue();
/** /**
* Specify one or more parameters if desired. These parameters will be supplemented with any * Specify one or more parameters if desired. These parameters will be supplemented with any
* parameter information retrieved from the database meta data. * parameter information retrieved from the database meta data.
* Note that only parameters declared as <code>SqlParameter</code> and <code>SqlInOutParameter</code> * Note that only parameters declared as <code>SqlParameter</code> and <code>SqlInOutParameter</code>
* will be used to provide input values. This is different from the <code>StoredProcedure</code> class * will be used to provide input values. This is different from the <code>StoredProcedure</code> class
@ -85,7 +85,7 @@ public interface SimpleJdbcCallOperations {
/** /**
* Used to specify when a ResultSet is returned by the stored procedure and you want it mapped * Used to specify when a ResultSet is returned by the stored procedure and you want it mapped
* by a RowMapper. The results will be returned using the parameter name specified. Multiple * by a RowMapper. The results will be returned using the parameter name specified. Multiple
* ResultSets must be declared in the correct order. If the database you are using uses ref cursors * ResultSets must be declared in the correct order. If the database you are using uses ref cursors
* then the name specified must match the name of the parameter declared for the procedure in the * then the name specified must match the name of the parameter declared for the procedure in the
* database. * database.
@ -114,7 +114,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return * @param returnType the type of the value to return
* @param args Map containing the parameter values to be used in the call. * @param args Map containing the parameter values to be used in the call.
*/ */
<T> T executeFunction(Class<T> returnType, Map<String, Object> args); <T> T executeFunction(Class<T> returnType, Map<String, ?> args);
/** /**
* Execute the stored function and return the results obtained as an Object of the specified return type. * Execute the stored function and return the results obtained as an Object of the specified return type.
@ -140,7 +140,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return * @param returnType the type of the value to return
* @param args Map containing the parameter values to be used in the call. * @param args Map containing the parameter values to be used in the call.
*/ */
<T> T executeObject(Class<T> returnType, Map<String, Object> args); <T> T executeObject(Class<T> returnType, Map<String, ?> args);
/** /**
* Execute the stored procedure and return the single out parameter as an Object of the specified return type. * Execute the stored procedure and return the single out parameter as an Object of the specified return type.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public interface SimpleJdbcOperations {
* @param sql the SQL query to run. * @param sql the SQL query to run.
* @param args the map containing the arguments for the query * @param args the map containing the arguments for the query
*/ */
int queryForInt(String sql, Map<String, Object> args) throws DataAccessException; int queryForInt(String sql, Map<String, ?> args) throws DataAccessException;
/** /**
* Query for an <code>int</code> passing in a SQL query * Query for an <code>int</code> passing in a SQL query
@ -90,7 +90,7 @@ public interface SimpleJdbcOperations {
* @param sql the SQL query to run. * @param sql the SQL query to run.
* @param args the map containing the arguments for the query * @param args the map containing the arguments for the query
*/ */
long queryForLong(String sql, Map<String, Object> args) throws DataAccessException; long queryForLong(String sql, Map<String, ?> args) throws DataAccessException;
/** /**
* Query for an <code>long</code> passing in a SQL query * Query for an <code>long</code> passing in a SQL query
@ -121,7 +121,7 @@ public interface SimpleJdbcOperations {
* @see JdbcOperations#queryForObject(String, Class) * @see JdbcOperations#queryForObject(String, Class)
* @see JdbcOperations#queryForObject(String, Object[], Class) * @see JdbcOperations#queryForObject(String, Object[], Class)
*/ */
<T> T queryForObject(String sql, Class<T> requiredType, Map<String, Object> args) <T> T queryForObject(String sql, Class<T> requiredType, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -160,7 +160,7 @@ public interface SimpleJdbcOperations {
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper) * @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper) * @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
*/ */
<T> T queryForObject(String sql, RowMapper<T> rm, Map<String, Object> args) <T> T queryForObject(String sql, RowMapper<T> rm, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -177,7 +177,7 @@ public interface SimpleJdbcOperations {
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now. * instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/ */
@Deprecated @Deprecated
<T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args) <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -251,7 +251,7 @@ public interface SimpleJdbcOperations {
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper) * @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper) * @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
*/ */
<T> List<T> query(String sql, RowMapper<T> rm, Map<String, Object> args) <T> List<T> query(String sql, RowMapper<T> rm, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -268,7 +268,7 @@ public interface SimpleJdbcOperations {
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now. * instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/ */
@Deprecated @Deprecated
<T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args) <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -342,7 +342,7 @@ public interface SimpleJdbcOperations {
* @see JdbcOperations#queryForMap(String) * @see JdbcOperations#queryForMap(String)
* @see JdbcOperations#queryForMap(String, Object[]) * @see JdbcOperations#queryForMap(String, Object[])
*/ */
Map<String, Object> queryForMap(String sql, Map<String, Object> args) Map<String, Object> queryForMap(String sql, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -383,7 +383,7 @@ public interface SimpleJdbcOperations {
* @see JdbcOperations#queryForList(String) * @see JdbcOperations#queryForList(String)
* @see JdbcOperations#queryForList(String, Object[]) * @see JdbcOperations#queryForList(String, Object[])
*/ */
List<Map<String, Object>> queryForList(String sql, Map<String, Object> args) List<Map<String, Object>> queryForList(String sql, Map<String, ?> args)
throws DataAccessException; throws DataAccessException;
/** /**
@ -422,7 +422,7 @@ public interface SimpleJdbcOperations {
* @return the numbers of rows affected by the update * @return the numbers of rows affected by the update
* @see NamedParameterJdbcOperations#update(String, Map) * @see NamedParameterJdbcOperations#update(String, Map)
*/ */
int update(String sql, Map<String, Object> args) throws DataAccessException; int update(String sql, Map<String, ?> args) throws DataAccessException;
/** /**
* Execute the supplied SQL statement with supplied arguments. * Execute the supplied SQL statement with supplied arguments.
@ -453,7 +453,7 @@ public interface SimpleJdbcOperations {
* @param batchValues the array of Maps containing the batch of arguments for the query * @param batchValues the array of Maps containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch * @return an array containing the numbers of rows affected by each update in the batch
*/ */
public int[] batchUpdate(String sql, Map<String, Object>[] batchValues); public int[] batchUpdate(String sql, Map<String, ?>[] batchValues);
/** /**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments. * Execute a batch using the supplied SQL statement with the batch of supplied arguments.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -100,7 +100,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
} }
public int queryForInt(String sql, Map<String, Object> args) throws DataAccessException { public int queryForInt(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForInt(sql, args); return getNamedParameterJdbcOperations().queryForInt(sql, args);
} }
@ -114,7 +114,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
getJdbcOperations().queryForInt(sql, getArguments(args))); getJdbcOperations().queryForInt(sql, getArguments(args)));
} }
public long queryForLong(String sql, Map<String, Object> args) throws DataAccessException { public long queryForLong(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForLong(sql, args); return getNamedParameterJdbcOperations().queryForLong(sql, args);
} }
@ -128,7 +128,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
getJdbcOperations().queryForLong(sql, getArguments(args))); getJdbcOperations().queryForLong(sql, getArguments(args)));
} }
public <T> T queryForObject(String sql, Class<T> requiredType, Map<String, Object> args) throws DataAccessException { public <T> T queryForObject(String sql, Class<T> requiredType, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType); return getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
} }
@ -143,12 +143,12 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
getJdbcOperations().queryForObject(sql, getArguments(args), requiredType)); getJdbcOperations().queryForObject(sql, getArguments(args), requiredType));
} }
public <T> T queryForObject(String sql, RowMapper<T> rm, Map<String, Object> args) throws DataAccessException { public <T> T queryForObject(String sql, RowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForObject(sql, args, rm); return getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
} }
@Deprecated @Deprecated
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args) throws DataAccessException { public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return queryForObject(sql, (RowMapper<T>) rm, args); return queryForObject(sql, (RowMapper<T>) rm, args);
} }
@ -174,12 +174,12 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
return queryForObject(sql, (RowMapper<T>) rm, args); return queryForObject(sql, (RowMapper<T>) rm, args);
} }
public <T> List<T> query(String sql, RowMapper<T> rm, Map<String, Object> args) throws DataAccessException { public <T> List<T> query(String sql, RowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().query(sql, args, rm); return getNamedParameterJdbcOperations().query(sql, args, rm);
} }
@Deprecated @Deprecated
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args) throws DataAccessException { public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return query(sql, (RowMapper<T>) rm, args); return query(sql, (RowMapper<T>) rm, args);
} }
@ -205,7 +205,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
return query(sql, (RowMapper<T>) rm, args); return query(sql, (RowMapper<T>) rm, args);
} }
public Map<String, Object> queryForMap(String sql, Map<String, Object> args) throws DataAccessException { public Map<String, Object> queryForMap(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForMap(sql, args); return getNamedParameterJdbcOperations().queryForMap(sql, args);
} }
@ -220,7 +220,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
getJdbcOperations().queryForMap(sql, getArguments(args))); getJdbcOperations().queryForMap(sql, getArguments(args)));
} }
public List<Map<String, Object>> queryForList(String sql, Map<String, Object> args) throws DataAccessException { public List<Map<String, Object>> queryForList(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForList(sql, args); return getNamedParameterJdbcOperations().queryForList(sql, args);
} }
@ -235,7 +235,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
getJdbcOperations().queryForList(sql, getArguments(args))); getJdbcOperations().queryForList(sql, getArguments(args)));
} }
public int update(String sql, Map<String, Object> args) throws DataAccessException { public int update(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().update(sql, args); return getNamedParameterJdbcOperations().update(sql, args);
} }
@ -257,7 +257,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, getJdbcOperations()); return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, getJdbcOperations());
} }
public int[] batchUpdate(String sql, Map<String, Object>[] batchValues) { public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) {
return getNamedParameterJdbcOperations().batchUpdate(sql, batchValues); return getNamedParameterJdbcOperations().batchUpdate(sql, batchValues);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,17 +29,16 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.logging.LogFactory;
import org.easymock.MockControl; import org.easymock.MockControl;
import org.easymock.internal.ArrayMatcher; import org.easymock.internal.ArrayMatcher;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.BatchUpdateTestHelper;
import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.BatchUpdateTestHelper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource;
@ -102,7 +101,7 @@ public class SimpleJdbcTemplateTests extends TestCase {
MockControl mc = MockControl.createControl(NamedParameterJdbcOperations.class); MockControl mc = MockControl.createControl(NamedParameterJdbcOperations.class);
NamedParameterJdbcOperations npjo = (NamedParameterJdbcOperations) mc.getMock(); NamedParameterJdbcOperations npjo = (NamedParameterJdbcOperations) mc.getMock();
Map args = new HashMap(2); Map<String, Object> args = new HashMap<String, Object>(2);
args.put("id", arg1); args.put("id", arg1);
args.put("xy", arg2); args.put("xy", arg2);
npjo.queryForInt(sql, args); npjo.queryForInt(sql, args);
@ -173,26 +172,6 @@ public class SimpleJdbcTemplateTests extends TestCase {
mc.verify(); mc.verify();
} }
public void testQueryForLongWithMap() {
String sql = "SELECT COUNT(0) FROM BAR WHERE ID=? AND XY=?";
long expectedResult = 666;
double arg1 = 24.7;
String arg2 = "foo";
Object arg3 = new Object();
MockControl mc = MockControl.createControl(JdbcOperations.class);
JdbcOperations jo = (JdbcOperations) mc.getMock();
jo.queryForLong(sql, new Object[]{arg1, arg2, arg3});
mc.setDefaultMatcher(new ArrayMatcher());
mc.setReturnValue(expectedResult);
mc.replay();
SimpleJdbcTemplate jth = new SimpleJdbcTemplate(jo);
long result = jth.queryForLong(sql, arg1, arg2, arg3);
assertEquals(expectedResult, result);
mc.verify();
}
public void testQueryForObjectWithoutArgs() throws Exception { public void testQueryForObjectWithoutArgs() throws Exception {
String sql = "SELECT SYSDATE FROM DUAL"; String sql = "SELECT SYSDATE FROM DUAL";
Date expectedResult = new Date(); Date expectedResult = new Date();