Browse Source

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

Issue: SPR-10257
pull/230/head
Juergen Hoeller 12 years ago
parent
commit
c1c27e7142
  1. 23
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
  2. 8
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

23
spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

@ -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"); * 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.
@ -133,7 +133,8 @@ public interface JdbcOperations {
* object via a RowMapper. * object via a RowMapper.
* <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to
* execute a static query with a PreparedStatement, use the overloaded * 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 sql SQL query to execute
* @param rowMapper object that will map one object per row * @param rowMapper object that will map one object per row
* @return the single mapped object * @return the single mapped object
@ -148,7 +149,8 @@ public interface JdbcOperations {
* Execute a query for a result object, given static SQL. * Execute a query for a result object, given static SQL.
* <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to
* execute a static query with a PreparedStatement, use the overloaded * 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. * <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 * The query is expected to be a single row/single column query; the returned
* result will be directly mapped to the corresponding object type. * 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. * Execute a query for a result Map, given static SQL.
* <p>Uses a JDBC Statement, not a PreparedStatement. If you want to * <p>Uses a JDBC Statement, not a PreparedStatement. If you want to
* execute a static query with a PreparedStatement, use the overloaded * 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 * <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). * mapped to a Map (one entry for each column, using the column name as the key).
* @param sql SQL query to execute * @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 * exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if there is any problem executing the query * @throws DataAccessException if there is any problem executing the query
* @see #queryForLong(String, Object[]) * @see #queryForLong(String, Object[])
* @deprecated in favor of {@link #queryForObject(String, Class)}
*/ */
@Deprecated
long queryForLong(String sql) throws DataAccessException; 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 * exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if there is any problem executing the query * @throws DataAccessException if there is any problem executing the query
* @see #queryForInt(String, Object[]) * @see #queryForInt(String, Object[])
* @deprecated in favor of {@link #queryForObject(String, Class)}
*/ */
@Deprecated
int queryForInt(String sql) throws DataAccessException; int queryForInt(String sql) throws DataAccessException;
/** /**
@ -712,7 +719,9 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForLong(String) * @see #queryForLong(String)
* @see java.sql.Types * @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; 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 * exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForLong(String) * @see #queryForLong(String)
* @deprecated in favor of {@link #queryForObject(String, Class, Object[])} )}
*/ */
@Deprecated
long queryForLong(String sql, Object... args) throws DataAccessException; long queryForLong(String sql, Object... args) throws DataAccessException;
/** /**
@ -748,7 +759,9 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForInt(String) * @see #queryForInt(String)
* @see java.sql.Types * @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; 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 * exactly one row, or does not return exactly one column in that row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForInt(String) * @see #queryForInt(String)
* @deprecated in favor of {@link #queryForObject(String, Class, Object[])} )}
*/ */
@Deprecated
int queryForInt(String sql, Object... args) throws DataAccessException; int queryForInt(String sql, Object... args) throws DataAccessException;
/** /**

8
spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

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

Loading…
Cancel
Save