Deprecated JdbcTemplate's queryForInt/Long operations in favor of queryForObject (following NamedParameterJdbcTemplate)

Issue: SPR-10257
This commit is contained in:
Juergen Hoeller 2013-02-09 17:06:30 +01:00
parent 3fa6723748
commit c1c27e7142
2 changed files with 26 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@ -133,7 +133,8 @@ public interface JdbcOperations {
* object via a RowMapper.
* <p>Uses a JDBC Statement, not a PreparedStatement. If you want to
* execute a static query with a PreparedStatement, use the overloaded
* {@code queryForObject} method with {@code null} as argument array.
* {@link #queryForObject(String, RowMapper, Object...)} method with
* {@code null} as argument array.
* @param sql SQL query to execute
* @param rowMapper object that will map one object per row
* @return the single mapped object
@ -148,7 +149,8 @@ public interface JdbcOperations {
* Execute a query for a result object, given static SQL.
* <p>Uses a JDBC Statement, not a PreparedStatement. If you want to
* execute a static query with a PreparedStatement, use the overloaded
* {@code queryForObject} method with {@code null} as argument array.
* {@link #queryForObject(String, Class, Object...)} method with
* {@code null} as argument array.
* <p>This method is useful for running static SQL with a known outcome.
* The query is expected to be a single row/single column query; the returned
* result will be directly mapped to the corresponding object type.
@ -166,7 +168,8 @@ public interface JdbcOperations {
* Execute a query for a result Map, given static SQL.
* <p>Uses a JDBC Statement, not a PreparedStatement. If you want to
* execute a static query with a PreparedStatement, use the overloaded
* {@code queryForMap} method with {@code null} as argument array.
* {@link #queryForMap(String, Object...)} method with {@code null}
* as argument array.
* <p>The query is expected to be a single row query; the result row will be
* mapped to a Map (one entry for each column, using the column name as the key).
* @param sql SQL query to execute
@ -194,7 +197,9 @@ public interface JdbcOperations {
* exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if there is any problem executing the query
* @see #queryForLong(String, Object[])
* @deprecated in favor of {@link #queryForObject(String, Class)}
*/
@Deprecated
long queryForLong(String sql) throws DataAccessException;
/**
@ -211,7 +216,9 @@ public interface JdbcOperations {
* exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if there is any problem executing the query
* @see #queryForInt(String, Object[])
* @deprecated in favor of {@link #queryForObject(String, Class)}
*/
@Deprecated
int queryForInt(String sql) throws DataAccessException;
/**
@ -712,7 +719,9 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @see #queryForLong(String)
* @see java.sql.Types
* @deprecated in favor of {@link #queryForObject(String, Object[], int[], Class)} )}
*/
@Deprecated
long queryForLong(String sql, Object[] args, int[] argTypes) throws DataAccessException;
/**
@ -730,7 +739,9 @@ public interface JdbcOperations {
* exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if the query fails
* @see #queryForLong(String)
* @deprecated in favor of {@link #queryForObject(String, Class, Object[])} )}
*/
@Deprecated
long queryForLong(String sql, Object... args) throws DataAccessException;
/**
@ -748,7 +759,9 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @see #queryForInt(String)
* @see java.sql.Types
* @deprecated in favor of {@link #queryForObject(String, Object[], int[], Class)} )}
*/
@Deprecated
int queryForInt(String sql, Object[] args, int[] argTypes) throws DataAccessException;
/**
@ -766,7 +779,9 @@ public interface JdbcOperations {
* exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if the query fails
* @see #queryForInt(String)
* @deprecated in favor of {@link #queryForObject(String, Class, Object[])} )}
*/
@Deprecated
int queryForInt(String sql, Object... args) throws DataAccessException;
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@ -477,11 +477,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return queryForObject(sql, getSingleColumnRowMapper(requiredType));
}
@Deprecated
public long queryForLong(String sql) throws DataAccessException {
Number number = queryForObject(sql, Long.class);
return (number != null ? number.longValue() : 0);
}
@Deprecated
public int queryForInt(String sql) throws DataAccessException {
Number number = queryForObject(sql, Integer.class);
return (number != null ? number.intValue() : 0);
@ -757,21 +759,25 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return queryForObject(sql, args, getColumnMapRowMapper());
}
@Deprecated
public long queryForLong(String sql, Object[] args, int[] argTypes) throws DataAccessException {
Number number = queryForObject(sql, args, argTypes, Long.class);
return (number != null ? number.longValue() : 0);
}
@Deprecated
public long queryForLong(String sql, Object... args) throws DataAccessException {
Number number = queryForObject(sql, args, Long.class);
return (number != null ? number.longValue() : 0);
}
@Deprecated
public int queryForInt(String sql, Object[] args, int[] argTypes) throws DataAccessException {
Number number = queryForObject(sql, args, argTypes, Integer.class);
return (number != null ? number.intValue() : 0);
}
@Deprecated
public int queryForInt(String sql, Object... args) throws DataAccessException {
Number number = queryForObject(sql, args, Integer.class);
return (number != null ? number.intValue() : 0);