Remove deprecated SimpleJdbcTemplate and supporting classes

Issue: SPR-11895
This commit is contained in:
Juergen Hoeller
2014-12-30 14:59:38 +01:00
parent f8a483f2d4
commit d6b16ffee3
8 changed files with 0 additions and 1475 deletions

View File

@@ -1,71 +0,0 @@
/*
* Copyright 2002-2012 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.simple;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
/**
* {@link ParameterizedRowMapper} implementation that converts a row into a new instance
* of the specified mapped target class. The mapped target class must be a top-level class
* and it must have a default or no-arg constructor.
*
* <p>Uses Java 5 covariant return types to override the return type of the {@link #mapRow}
* method to be the type parameter {@code T}.
*
* <p>Column values are mapped based on matching the column name as obtained from result set
* metadata to public setters for the corresponding properties. The names are matched either
* directly or by transforming a name separating the parts with underscores to the same name
* using "camel" case.
*
* <p>Mapping is provided for fields in the target class for many common types, e.g.:
* String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long,
* float, Float, double, Double, BigDecimal, {@code java.util.Date}, etc.
*
* <p>The mapper can be configured to use the primitives default value when mapping null values
* by setting the '{@link #setPrimitivesDefaultedForNullValue primitivesDefaultedForNullValue}'
* flag to 'true'.
*
* <p>To facilitate mapping between columns and fields that don't have matching names,
* try using column aliases in the SQL statement like "select fname as first_name from customer".
*
* <p>Please note that this class is designed to provide convenience rather than high performance.
* For best performance, consider using a custom {@link org.springframework.jdbc.core.RowMapper}
* implementation.
*
* @author Thomas Risberg
* @author Juergen Hoeller
* @since 2.5
* @see ParameterizedRowMapper
* @deprecated along with {@link SimpleJdbcTemplate}, in favor of the regular
* {@link org.springframework.jdbc.core.BeanPropertyRowMapper}
*/
@Deprecated
public class ParameterizedBeanPropertyRowMapper<T> extends BeanPropertyRowMapper<T>
implements ParameterizedRowMapper<T> {
/**
* Static factory method to create a new ParameterizedBeanPropertyRowMapper
* (with the mapped class specified only once).
* @param mappedClass the class that each row should be mapped to
*/
public static <T> ParameterizedBeanPropertyRowMapper<T> newInstance(Class<T> mappedClass) {
ParameterizedBeanPropertyRowMapper<T> newInstance = new ParameterizedBeanPropertyRowMapper<T>();
newInstance.setMappedClass(mappedClass);
return newInstance;
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2002-2008 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.simple;
import org.springframework.jdbc.core.RowMapper;
/**
* Extension of the {@link org.springframework.jdbc.core.RowMapper} interface,
* adding type parameterization. As of Spring 3.0, this is equivalent to
* using the RowMapper interface directly.
*
* @author Rob Harrop
* @author Juergen Hoeller
* @since 2.0
* @see org.springframework.jdbc.core.simple.SimpleJdbcOperations
* @deprecated along with {@link SimpleJdbcTemplate}, in favor of the regular
* {@link RowMapper}
*/
@Deprecated
public interface ParameterizedRowMapper<T> extends RowMapper<T> {
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2002-2012 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.simple;
import org.springframework.jdbc.core.SingleColumnRowMapper;
/**
* {@link ParameterizedRowMapper} implementation that converts a single column
* into a single result value per row. Expects to operate on a
* {@code java.sql.ResultSet} that just contains a single column.
*
* <p>The type of the result value for each row can be specified. The value
* for the single column will be extracted from the {@code ResultSet}
* and converted into the specified target type.
*
* <p>Uses Java 5 covariant return types to override the return type of the
* {@link #mapRow} method to be the type parameter {@code T}.
*
* @author Juergen Hoeller
* @since 2.5.2
* @deprecated along with {@link SimpleJdbcTemplate}, in favor of the regular
* {@link org.springframework.jdbc.core.SingleColumnRowMapper}
*/
@Deprecated
public class ParameterizedSingleColumnRowMapper<T> extends SingleColumnRowMapper<T>
implements ParameterizedRowMapper<T> {
/**
* Static factory method to create a new ParameterizedSingleColumnRowMapper
* (with the required type specified only once).
* @param requiredType the type that each result object is expected to match
*/
public static <T> ParameterizedSingleColumnRowMapper<T> newInstance(Class<T> requiredType) {
ParameterizedSingleColumnRowMapper<T> newInstance = new ParameterizedSingleColumnRowMapper<T>();
newInstance.setRequiredType(requiredType);
return newInstance;
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2002-2012 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.simple;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
/**
* Extension of {@link org.springframework.jdbc.core.support.JdbcDaoSupport}
* that exposes a {@link #getSimpleJdbcTemplate() SimpleJdbcTemplate} as well.
* Only usable on Java 5 and above.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 2.0
* @see SimpleJdbcTemplate
* @deprecated since Spring 3.1 in favor of {@link org.springframework.jdbc.core.support.JdbcDaoSupport} and
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport}. The JdbcTemplate and
* NamedParameterJdbcTemplate now provide all the functionality of the SimpleJdbcTemplate.
*/
@Deprecated
public class SimpleJdbcDaoSupport extends JdbcDaoSupport {
private SimpleJdbcTemplate simpleJdbcTemplate;
/**
* Create a SimpleJdbcTemplate based on the configured JdbcTemplate.
*/
@Override
protected void initTemplateConfig() {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(getJdbcTemplate());
}
/**
* Return a SimpleJdbcTemplate wrapping the configured JdbcTemplate.
*/
public SimpleJdbcTemplate getSimpleJdbcTemplate() {
return this.simpleJdbcTemplate;
}
}

View File

@@ -1,491 +0,0 @@
/*
* Copyright 2002-2012 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.simple;
import java.util.List;
import java.util.Map;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
/**
* JDBC operations interface usable on Java 5 and above, exposing a
* set of common JDBC operations, whose interface is simplified
* through the use of varargs and autoboxing.
*
* @author Rod Johnson
* @author Rob Harrop
* @author Thomas Risberg
* @since 2.0
* @see org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
* @see SimpleJdbcTemplate
* @see org.springframework.jdbc.core.JdbcOperations
* @deprecated since Spring 3.1 in favor of {@link org.springframework.jdbc.core.JdbcOperations} and
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations}. The JdbcTemplate and
* NamedParameterJdbcTemplate now provide all the functionality of the SimpleJdbcTemplate.
*/
@Deprecated
public interface SimpleJdbcOperations {
/**
* Expose the classic Spring JdbcTemplate to allow invocation of less
* commonly used methods.
*/
JdbcOperations getJdbcOperations();
/**
* Expose the Spring NamedParameterJdbcTemplate to allow invocation of less
* commonly used methods.
*/
NamedParameterJdbcOperations getNamedParameterJdbcOperations();
/**
* Query for an {@code int} passing in a SQL query
* using the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* and a map containing the arguments.
* @param sql the SQL query to run.
* @param args the map containing the arguments for the query
*/
int queryForInt(String sql, Map<String, ?> args) throws DataAccessException;
/**
* Query for an {@code int} passing in a SQL query
* using the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* and a {@code SqlParameterSource} containing the arguments.
* @param sql the SQL query to run.
* @param args the {@code SqlParameterSource} containing the arguments for the query.
*/
int queryForInt(String sql, SqlParameterSource args) throws DataAccessException;
/**
* Query for an {@code int} passing in a SQL query
* using the standard '?' placeholders for parameters
* and a variable number of arguments.
* @param sql the SQL query to run.
* @param args the variable number of arguments for the query
*/
int queryForInt(String sql, Object... args) throws DataAccessException;
/**
* Query for an {@code long} passing in a SQL query
* using the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* and a map containing the arguments.
* @param sql the SQL query to run.
* @param args the map containing the arguments for the query
*/
long queryForLong(String sql, Map<String, ?> args) throws DataAccessException;
/**
* Query for an {@code long} passing in a SQL query
* using the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* and a {@code SqlParameterSource} containing the arguments.
* @param sql the SQL query to run.
* @param args the {@code SqlParameterSource} containing the arguments for the query
*/
long queryForLong(String sql, SqlParameterSource args) throws DataAccessException;
/**
* Query for an {@code long} passing in a SQL query
* using the standard '?' placeholders for parameters
* and a variable number of arguments.
* @param sql the SQL query to run.
* @param args the variable number of arguments for the query
*/
long queryForLong(String sql, Object... args) throws DataAccessException;
/**
* Query for an object of type {@code T} identified by the supplied @{@link Class}.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param requiredType the required type of the return value
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForObject(String, Class)
* @see JdbcOperations#queryForObject(String, Object[], Class)
*/
<T> T queryForObject(String sql, Class<T> requiredType, Map<String, ?> args)
throws DataAccessException;
/**
* Query for an object of type {@code T} identified by the supplied @{@link Class}.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param requiredType the required type of the return value
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForObject(String, Class)
* @see JdbcOperations#queryForObject(String, Object[], Class)
*/
<T> T queryForObject(String sql, Class<T> requiredType, SqlParameterSource args)
throws DataAccessException;
/**
* Query for an object of type {@code T} identified by the supplied @{@link Class}.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param requiredType the required type of the return value
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForObject(String, Class)
* @see JdbcOperations#queryForObject(String, Object[], Class)
*/
<T> T queryForObject(String sql, Class<T> requiredType, Object... args)
throws DataAccessException;
/**
* Query for an object of type {@code T} using the supplied
* {@link RowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link RowMapper} to use for result mapping
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForObject(String, 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, ?> args)
throws DataAccessException;
/**
* Query for an object of type {@code T} using the supplied
* {@link ParameterizedRowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
* @deprecated as of Spring 3.0: Use the method using the newly genericized RowMapper interface
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/
@Deprecated
<T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args)
throws DataAccessException;
/**
* Query for an object of type {@code T} using the supplied
* {@link RowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link RowMapper} to use for result mapping
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
*/
<T> T queryForObject(String sql, RowMapper<T> rm, SqlParameterSource args)
throws DataAccessException;
/**
* Query for an object of type {@code T} using the supplied
* {@link ParameterizedRowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
* @deprecated as of Spring 3.0: Use the method using the newly genericized RowMapper interface
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/
@Deprecated
<T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
throws DataAccessException;
/**
* Query for an object of type {@code T} using the supplied
* {@link RowMapper} to the query results to the object.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param rm the @{@link RowMapper} to use for result mapping
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
*/
<T> T queryForObject(String sql, RowMapper<T> rm, Object... args)
throws DataAccessException;
/**
* Query for an object of type {@code T} using the supplied
* {@link ParameterizedRowMapper} to the query results to the object.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
* @deprecated as of Spring 3.0: Use the method using the newly genericized RowMapper interface
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/
@Deprecated
<T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Object... args)
throws DataAccessException;
/**
* Query for a {@link List} of {@code Objects} of type {@code T} using
* the supplied {@link RowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link RowMapper} to use for result mapping
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForObject(String, 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, ?> args)
throws DataAccessException;
/**
* Query for a {@link List} of {@code Objects} of type {@code T} using
* the supplied {@link ParameterizedRowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
* @deprecated as of Spring 3.0: Use the method using the newly genericized RowMapper interface
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/
@Deprecated
<T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args)
throws DataAccessException;
/**
* Query for a {@link List} of {@code Objects} of type {@code T} using
* the supplied {@link RowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link RowMapper} to use for result mapping
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
*/
<T> List<T> query(String sql, RowMapper<T> rm, SqlParameterSource args)
throws DataAccessException;
/**
* Query for a {@link List} of {@code Objects} of type {@code T} using
* the supplied {@link ParameterizedRowMapper} to the query results to the object.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
* @deprecated as of Spring 3.0: Use the method using the newly genericized RowMapper interface
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/
@Deprecated
<T> List<T> query(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
throws DataAccessException;
/**
* Query for a {@link List} of {@code Objects} of type {@code T} using
* the supplied {@link RowMapper} to the query results to the object.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param rm the @{@link RowMapper} to use for result mapping
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
*/
<T> List<T> query(String sql, RowMapper<T> rm, Object... args)
throws DataAccessException;
/**
* Query for a {@link List} of {@code Objects} of type {@code T} using
* the supplied {@link ParameterizedRowMapper} to the query results to the object.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForObject(String, org.springframework.jdbc.core.RowMapper)
* @see JdbcOperations#queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
* @deprecated as of Spring 3.0: Use the method using the newly genericized RowMapper interface
* instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now.
*/
@Deprecated
<T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Object... args)
throws DataAccessException;
/**
* Execute the supplied query with the supplied arguments.
* <p>The query is expected to be a single row query; the result row will be
* mapped to a Map<String, Object> (one entry for each column, using the column name as the key).
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForMap(String)
* @see JdbcOperations#queryForMap(String, Object[])
*/
Map<String, Object> queryForMap(String sql, Map<String, ?> args)
throws DataAccessException;
/**
* Execute the supplied query with the supplied arguments.
* <p>The query is expected to be a single row query; the result row will be
* mapped to a Map<String, Object> (one entry for each column, using the column name as the key).
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForMap(String)
* @see JdbcOperations#queryForMap(String, Object[])
*/
Map<String, Object> queryForMap(String sql, SqlParameterSource args)
throws DataAccessException;
/**
* Execute the supplied query with the (optional) supplied arguments.
* <p>The query is expected to be a single row query; the result row will be
* mapped to a Map<String, Object> (one entry for each column, using the column name as the key).
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForMap(String)
* @see JdbcOperations#queryForMap(String, Object[])
*/
Map<String, Object> queryForMap(String sql, Object... args)
throws DataAccessException;
/**
* Execute the supplied query with the supplied arguments.
* <p>Each element in the returned {@link List} is constructed as a {@link Map}
* as described in {@link #queryForMap}
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param args the map containing the arguments for the query
* @see JdbcOperations#queryForList(String)
* @see JdbcOperations#queryForList(String, Object[])
*/
List<Map<String, Object>> queryForList(String sql, Map<String, ?> args)
throws DataAccessException;
/**
* Execute the supplied query with the supplied arguments.
* <p>Each element in the returned {@link List} is constructed as a {@link Map}
* as described in {@link #queryForMap}
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL query to run
* @param args the {@code SqlParameterSource} containing the arguments for the query
* @see JdbcOperations#queryForList(String)
* @see JdbcOperations#queryForList(String, Object[])
*/
List<Map<String, Object>> queryForList(String sql, SqlParameterSource args)
throws DataAccessException;
/**
* Execute the supplied query with the (optional) supplied arguments.
* <p>Each element in the returned {@link List} is constructed as a {@link Map}
* as described in {@link #queryForMap}
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL query to run
* @param args the variable number of arguments for the query
* @see JdbcOperations#queryForList(String)
* @see JdbcOperations#queryForList(String, Object[])
*/
List<Map<String, Object>> queryForList(String sql, Object... args)
throws DataAccessException;
/**
* Execute the supplied SQL statement with (optional) supplied arguments.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL statement to execute
* @param args the map containing the arguments for the query
* @return the numbers of rows affected by the update
* @see NamedParameterJdbcOperations#update(String, Map)
*/
int update(String sql, Map<String, ?> args) throws DataAccessException;
/**
* Execute the supplied SQL statement with supplied arguments.
* Uses sql with the named parameter support provided by the
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
* @param sql the SQL statement to execute
* @param args the {@code SqlParameterSource} containing the arguments for the statement
* @return the numbers of rows affected by the update
* @see NamedParameterJdbcOperations#update(String, SqlParameterSource)
*/
int update(String sql, SqlParameterSource args) throws DataAccessException;
/**
* Execute the supplied SQL statement with supplied arguments.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL statement to execute
* @param args the variable number of arguments for the query
* @return the numbers of rows affected by the update
* @see JdbcOperations#update(String)
* @see JdbcOperations#update(String, Object[])
*/
int update(String sql, Object... args) throws DataAccessException;
/**
* Executes a batch using the supplied SQL statement with the batch of supplied arguments.
* Uses sql with the named parameter support.
* @param sql the SQL statement to execute
* @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
*/
public int[] batchUpdate(String sql, Map<String, ?>[] batchValues);
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
* Uses sql with the named parameter support.
* @param sql the SQL statement to execute
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs);
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL statement to execute
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, List<Object[]> batchArgs);
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
* Uses sql with the standard '?' placeholders for parameters
* @param sql the SQL statement to execute.
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @param argTypes SQL types of the arguments
* (constants from {@code java.sql.Types})
* @return an array containing the numbers of rows affected by each update in the batch
*/
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes);
}

View File

@@ -1,323 +0,0 @@
/*
* Copyright 2002-2014 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.simple;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BatchUpdateUtils;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.util.ObjectUtils;
/**
* Java-5-based convenience wrapper for the classic Spring
* {@link org.springframework.jdbc.core.JdbcTemplate},
* taking advantage of varargs and autoboxing, and exposing only the most
* commonly required operations in order to simplify JdbcTemplate usage.
*
* <p>Use the {@link #getJdbcOperations()} method (or a straight JdbcTemplate)
* if you need to invoke less commonly used template methods. This includes
* any methods specifying SQL types, methods using less commonly used callbacks
* such as RowCallbackHandler, updates with PreparedStatementSetters rather than
* argument arrays, and stored procedures as well as batch operations.
*
* <p><b>NOTE: An instance of this class is thread-safe once configured.</b>
*
* @author Rod Johnson
* @author Rob Harrop
* @author Juergen Hoeller
* @author Thomas Risberg
* @since 2.0
* @see ParameterizedRowMapper
* @see SimpleJdbcDaoSupport
* @see org.springframework.jdbc.core.JdbcTemplate
* @deprecated since Spring 3.1 in favor of {@link org.springframework.jdbc.core.JdbcTemplate} and
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}. The JdbcTemplate and
* NamedParameterJdbcTemplate now provide all the functionality of the SimpleJdbcTemplate.
*/
@Deprecated
public class SimpleJdbcTemplate implements SimpleJdbcOperations {
/** The NamedParameterJdbcTemplate that we are wrapping */
private final NamedParameterJdbcOperations namedParameterJdbcOperations;
/**
* Create a new SimpleJdbcTemplate for the given DataSource.
* <p>Creates a classic Spring JdbcTemplate and wraps it.
* @param dataSource the JDBC DataSource to access
*/
public SimpleJdbcTemplate(DataSource dataSource) {
this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
}
/**
* Create a new SimpleJdbcTemplate for the given classic Spring JdbcTemplate.
* @param classicJdbcTemplate the classic Spring JdbcTemplate to wrap
*/
public SimpleJdbcTemplate(JdbcOperations classicJdbcTemplate) {
this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(classicJdbcTemplate);
}
/**
* Create a new SimpleJdbcTemplate for the given Spring NamedParameterJdbcTemplate.
* @param namedParameterJdbcTemplate the Spring NamedParameterJdbcTemplate to wrap
*/
public SimpleJdbcTemplate(NamedParameterJdbcOperations namedParameterJdbcTemplate) {
this.namedParameterJdbcOperations = namedParameterJdbcTemplate;
}
/**
* Expose the classic Spring JdbcTemplate to allow invocation of
* less commonly used methods.
*/
@Override
public JdbcOperations getJdbcOperations() {
return this.namedParameterJdbcOperations.getJdbcOperations();
}
/**
* Expose the Spring NamedParameterJdbcTemplate to allow invocation of
* less commonly used methods.
*/
@Override
public NamedParameterJdbcOperations getNamedParameterJdbcOperations() {
return this.namedParameterJdbcOperations;
}
@Override
public int queryForInt(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForInt(sql, args);
}
@Override
public int queryForInt(String sql, SqlParameterSource args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForInt(sql, args);
}
@Override
public int queryForInt(String sql, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForInt(sql) :
getJdbcOperations().queryForInt(sql, getArguments(args)));
}
@Override
public long queryForLong(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForLong(sql, args);
}
@Override
public long queryForLong(String sql, SqlParameterSource args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForLong(sql, args);
}
@Override
public long queryForLong(String sql, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForLong(sql) :
getJdbcOperations().queryForLong(sql, getArguments(args)));
}
@Override
public <T> T queryForObject(String sql, Class<T> requiredType, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
}
@Override
public <T> T queryForObject(String sql, Class<T> requiredType, SqlParameterSource args)
throws DataAccessException {
return getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
}
@Override
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForObject(sql, requiredType) :
getJdbcOperations().queryForObject(sql, getArguments(args), requiredType));
}
@Override
public <T> T queryForObject(String sql, RowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
}
@Override
@Deprecated
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return queryForObject(sql, (RowMapper<T>) rm, args);
}
@Override
public <T> T queryForObject(String sql, RowMapper<T> rm, SqlParameterSource args)
throws DataAccessException {
return getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
}
@Override
@Deprecated
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
throws DataAccessException {
return queryForObject(sql, (RowMapper<T>) rm, args);
}
@Override
public <T> T queryForObject(String sql, RowMapper<T> rm, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForObject(sql, rm):
getJdbcOperations().queryForObject(sql, getArguments(args), rm));
}
@Override
@Deprecated
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException {
return queryForObject(sql, (RowMapper<T>) rm, args);
}
@Override
public <T> List<T> query(String sql, RowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().query(sql, args, rm);
}
@Override
@Deprecated
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, ?> args) throws DataAccessException {
return query(sql, (RowMapper<T>) rm, args);
}
@Override
public <T> List<T> query(String sql, RowMapper<T> rm, SqlParameterSource args)
throws DataAccessException {
return getNamedParameterJdbcOperations().query(sql, args, rm);
}
@Override
@Deprecated
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
throws DataAccessException {
return query(sql, (RowMapper<T>) rm, args);
}
@Override
public <T> List<T> query(String sql, RowMapper<T> rm, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().query(sql, rm) :
getJdbcOperations().query(sql, getArguments(args), rm));
}
@Override
@Deprecated
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException {
return query(sql, (RowMapper<T>) rm, args);
}
@Override
public Map<String, Object> queryForMap(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForMap(sql, args);
}
@Override
public Map<String, Object> queryForMap(String sql, SqlParameterSource args)
throws DataAccessException {
return getNamedParameterJdbcOperations().queryForMap(sql, args);
}
@Override
public Map<String, Object> queryForMap(String sql, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForMap(sql) :
getJdbcOperations().queryForMap(sql, getArguments(args)));
}
@Override
public List<Map<String, Object>> queryForList(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().queryForList(sql, args);
}
@Override
public List<Map<String, Object>> queryForList(String sql, SqlParameterSource args)
throws DataAccessException {
return getNamedParameterJdbcOperations().queryForList(sql, args);
}
@Override
public List<Map<String, Object>> queryForList(String sql, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForList(sql) :
getJdbcOperations().queryForList(sql, getArguments(args)));
}
@Override
public int update(String sql, Map<String, ?> args) throws DataAccessException {
return getNamedParameterJdbcOperations().update(sql, args);
}
@Override
public int update(String sql, SqlParameterSource args) throws DataAccessException {
return getNamedParameterJdbcOperations().update(sql, args);
}
@Override
public int update(String sql, Object ... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().update(sql) :
getJdbcOperations().update(sql, getArguments(args)));
}
@Override
public int[] batchUpdate(String sql, List<Object[]> batchArgs) {
return batchUpdate(sql, batchArgs, new int[0]);
}
@Override
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) {
return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, getJdbcOperations());
}
@Override
public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) {
return getNamedParameterJdbcOperations().batchUpdate(sql, batchValues);
}
@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
return getNamedParameterJdbcOperations().batchUpdate(sql, batchArgs);
}
/*
* Considers an Object array passed into a varargs parameter as
* collection of arguments rather than as single argument.
*/
private Object[] getArguments(Object[] varArgs) {
if (varArgs.length == 1 && varArgs[0] instanceof Object[]) {
return (Object[]) varArgs[0];
}
else {
return varArgs;
}
}
}