Java 5 code style
This commit is contained in:
@@ -61,22 +61,22 @@ import org.springframework.util.Assert;
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5
|
||||
*/
|
||||
public class BeanPropertyRowMapper implements RowMapper {
|
||||
public class BeanPropertyRowMapper<T> implements RowMapper<T> {
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
/** The class we are mapping to */
|
||||
private Class mappedClass;
|
||||
private Class<T> mappedClass;
|
||||
|
||||
/** Whether we're strictly validating */
|
||||
private boolean checkFullyPopulated = false;
|
||||
|
||||
/** Map of the fields we provide mapping for */
|
||||
private Map mappedFields;
|
||||
private Map<String, PropertyDescriptor> mappedFields;
|
||||
|
||||
/** Set of bean properties we provide mapping for */
|
||||
private Set mappedProperties;
|
||||
private Set<String> mappedProperties;
|
||||
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
* in the target bean.
|
||||
* @param mappedClass the class that each row should be mapped to
|
||||
*/
|
||||
public BeanPropertyRowMapper(Class mappedClass) {
|
||||
public BeanPropertyRowMapper(Class<T> mappedClass) {
|
||||
initialize(mappedClass);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
* @param checkFullyPopulated whether we're strictly validating that
|
||||
* all bean properties have been mapped from corresponding database fields
|
||||
*/
|
||||
public BeanPropertyRowMapper(Class mappedClass, boolean checkFullyPopulated) {
|
||||
public BeanPropertyRowMapper(Class<T> mappedClass, boolean checkFullyPopulated) {
|
||||
initialize(mappedClass);
|
||||
this.checkFullyPopulated = checkFullyPopulated;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
/**
|
||||
* Set the class that each row should be mapped to.
|
||||
*/
|
||||
public void setMappedClass(Class mappedClass) {
|
||||
public void setMappedClass(Class<T> mappedClass) {
|
||||
if (this.mappedClass == null) {
|
||||
initialize(mappedClass);
|
||||
}
|
||||
@@ -127,13 +127,12 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
* Initialize the mapping metadata for the given class.
|
||||
* @param mappedClass the mapped class.
|
||||
*/
|
||||
protected void initialize(Class mappedClass) {
|
||||
protected void initialize(Class<T> mappedClass) {
|
||||
this.mappedClass = mappedClass;
|
||||
this.mappedFields = new HashMap();
|
||||
this.mappedProperties = new HashSet();
|
||||
this.mappedFields = new HashMap<String, PropertyDescriptor>();
|
||||
this.mappedProperties = new HashSet<String>();
|
||||
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
|
||||
for (int i = 0; i < pds.length; i++) {
|
||||
PropertyDescriptor pd = pds[i];
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
if (pd.getWriteMethod() != null) {
|
||||
this.mappedFields.put(pd.getName().toLowerCase(), pd);
|
||||
String underscoredName = underscoreName(pd.getName());
|
||||
@@ -152,7 +151,7 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
* @return the converted name
|
||||
*/
|
||||
private String underscoreName(String name) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (name != null && name.length() > 0) {
|
||||
result.append(name.substring(0, 1).toLowerCase());
|
||||
for (int i = 1; i < name.length(); i++) {
|
||||
@@ -172,7 +171,7 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
/**
|
||||
* Get the class that we are mapping to.
|
||||
*/
|
||||
public final Class getMappedClass() {
|
||||
public final Class<T> getMappedClass() {
|
||||
return this.mappedClass;
|
||||
}
|
||||
|
||||
@@ -200,19 +199,19 @@ public class BeanPropertyRowMapper implements RowMapper {
|
||||
* <p>Utilizes public setters and result set metadata.
|
||||
* @see java.sql.ResultSetMetaData
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
|
||||
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
|
||||
Assert.state(this.mappedClass != null, "Mapped class was not specified");
|
||||
Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
|
||||
T mappedObject = BeanUtils.instantiate(this.mappedClass);
|
||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
|
||||
initBeanWrapper(bw);
|
||||
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
Set populatedProperties = (isCheckFullyPopulated() ? new HashSet() : null);
|
||||
Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);
|
||||
|
||||
for (int index = 1; index <= columnCount; index++) {
|
||||
String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
|
||||
PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column);
|
||||
PropertyDescriptor pd = this.mappedFields.get(column);
|
||||
if (pd != null) {
|
||||
try {
|
||||
Object value = getColumnValue(rs, index, pd);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -40,7 +40,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @see JdbcTemplate#execute(String, CallableStatementCallback)
|
||||
* @see JdbcTemplate#execute(CallableStatementCreator, CallableStatementCallback)
|
||||
*/
|
||||
public interface CallableStatementCallback {
|
||||
public interface CallableStatementCallback<T> {
|
||||
|
||||
/**
|
||||
* Gets called by <code>JdbcTemplate.execute</code> with an active JDBC
|
||||
@@ -72,6 +72,6 @@ public interface CallableStatementCallback {
|
||||
* into a DataAccessException by a SQLExceptionTranslator
|
||||
* @throws DataAccessException in case of custom exceptions
|
||||
*/
|
||||
Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException;
|
||||
T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CallableStatementCreatorFactory {
|
||||
private final String callString;
|
||||
|
||||
/** List of SqlParameter objects. May not be <code>null</code>. */
|
||||
private final List declaredParameters;
|
||||
private final List<SqlParameter> declaredParameters;
|
||||
|
||||
private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CallableStatementCreatorFactory {
|
||||
*/
|
||||
public CallableStatementCreatorFactory(String callString) {
|
||||
this.callString = callString;
|
||||
this.declaredParameters = new LinkedList();
|
||||
this.declaredParameters = new LinkedList<SqlParameter>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ public class CallableStatementCreatorFactory {
|
||||
* @param callString the SQL call string
|
||||
* @param declaredParameters list of {@link SqlParameter} objects
|
||||
*/
|
||||
public CallableStatementCreatorFactory(String callString, List declaredParameters) {
|
||||
public CallableStatementCreatorFactory(String callString, List<SqlParameter> declaredParameters) {
|
||||
this.callString = callString;
|
||||
this.declaredParameters = declaredParameters;
|
||||
}
|
||||
@@ -112,8 +112,8 @@ public class CallableStatementCreatorFactory {
|
||||
* Return a new CallableStatementCreator instance given this parameters.
|
||||
* @param params list of parameters (may be <code>null</code>)
|
||||
*/
|
||||
public CallableStatementCreator newCallableStatementCreator(Map params) {
|
||||
return new CallableStatementCreatorImpl(params != null ? params : new HashMap());
|
||||
public CallableStatementCreator newCallableStatementCreator(Map<String, ?> params) {
|
||||
return new CallableStatementCreatorImpl(params != null ? params : new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class CallableStatementCreatorFactory {
|
||||
|
||||
private ParameterMapper inParameterMapper;
|
||||
|
||||
private Map inParameters;
|
||||
private Map<String, ?> inParameters;
|
||||
|
||||
/**
|
||||
* Create a new CallableStatementCreatorImpl.
|
||||
@@ -146,7 +146,7 @@ public class CallableStatementCreatorFactory {
|
||||
* Create a new CallableStatementCreatorImpl.
|
||||
* @param inParams list of SqlParameter objects
|
||||
*/
|
||||
public CallableStatementCreatorImpl(Map inParams) {
|
||||
public CallableStatementCreatorImpl(Map<String, ?> inParams) {
|
||||
this.inParameters = inParams;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,7 @@ public class CallableStatementCreatorFactory {
|
||||
}
|
||||
|
||||
int sqlColIndx = 1;
|
||||
for (int i = 0; i < declaredParameters.size(); i++) {
|
||||
SqlParameter declaredParam = (SqlParameter) declaredParameters.get(i);
|
||||
for (SqlParameter declaredParam : declaredParameters) {
|
||||
if (!declaredParam.isResultsParameter()) {
|
||||
// So, it's a call parameter - part of the call string.
|
||||
// Get the value - it may still be null.
|
||||
@@ -193,7 +192,7 @@ public class CallableStatementCreatorFactory {
|
||||
}
|
||||
else {
|
||||
if (declaredParam.getScale() != null) {
|
||||
cs.registerOutParameter(sqlColIndx, declaredParam.getSqlType(), declaredParam.getScale().intValue());
|
||||
cs.registerOutParameter(sqlColIndx, declaredParam.getSqlType(), declaredParam.getScale());
|
||||
}
|
||||
else {
|
||||
cs.registerOutParameter(sqlColIndx, declaredParam.getSqlType());
|
||||
@@ -231,9 +230,10 @@ public class CallableStatementCreatorFactory {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer("CallableStatementCreatorFactory.CallableStatementCreatorImpl: sql=[");
|
||||
buf.append(callString).append("]; parameters=").append(this.inParameters);
|
||||
return buf.toString();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("CallableStatementCreatorFactory.CallableStatementCreatorImpl: sql=[");
|
||||
sb.append(callString).append("]; parameters=").append(this.inParameters);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ import org.springframework.jdbc.support.JdbcUtils;
|
||||
* @see JdbcTemplate#queryForList(String)
|
||||
* @see JdbcTemplate#queryForMap(String)
|
||||
*/
|
||||
public class ColumnMapRowMapper implements RowMapper {
|
||||
public class ColumnMapRowMapper implements RowMapper<Map<String, Object>> {
|
||||
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
Map mapOfColValues = createColumnMap(columnCount);
|
||||
Map<String, Object> mapOfColValues = createColumnMap(columnCount);
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
String key = getColumnKey(JdbcUtils.lookupColumnName(rsmd, i));
|
||||
Object obj = getColumnValue(rs, i);
|
||||
@@ -68,8 +68,9 @@ public class ColumnMapRowMapper implements RowMapper {
|
||||
* @return the new Map instance
|
||||
* @see org.springframework.core.CollectionFactory#createLinkedCaseInsensitiveMapIfPossible
|
||||
*/
|
||||
protected Map createColumnMap(int columnCount) {
|
||||
return CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(columnCount);
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Object> createColumnMap(int columnCount) {
|
||||
return (Map<String, Object>) CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(columnCount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -37,7 +37,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @see JdbcTemplate#query
|
||||
* @see JdbcTemplate#update
|
||||
*/
|
||||
public interface ConnectionCallback {
|
||||
public interface ConnectionCallback<T> {
|
||||
|
||||
/**
|
||||
* Gets called by <code>JdbcTemplate.execute</code> with an active JDBC
|
||||
@@ -64,6 +64,6 @@ public interface ConnectionCallback {
|
||||
* @see JdbcTemplate#queryForObject(String, Class)
|
||||
* @see JdbcTemplate#queryForRowSet(String)
|
||||
*/
|
||||
Object doInConnection(Connection con) throws SQLException, DataAccessException;
|
||||
T doInConnection(Connection con) throws SQLException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -58,7 +58,7 @@ public interface JdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(ConnectionCallback action) throws DataAccessException;
|
||||
<T> T execute(ConnectionCallback<T> action) throws DataAccessException;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -77,7 +77,7 @@ public interface JdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(StatementCallback action) throws DataAccessException;
|
||||
<T> T execute(StatementCallback<T> action) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Issue a single SQL execute, typically a DDL statement.
|
||||
@@ -98,7 +98,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query
|
||||
* @see #query(String, Object[], ResultSetExtractor)
|
||||
*/
|
||||
Object query(String sql, ResultSetExtractor rse) throws DataAccessException;
|
||||
<T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query given static SQL, reading the ResultSet on a per-row
|
||||
@@ -125,7 +125,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query
|
||||
* @see #query(String, Object[], RowMapper)
|
||||
*/
|
||||
List query(String sql, RowMapper rowMapper) throws DataAccessException;
|
||||
<T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query given static SQL, mapping a single result row to a Java
|
||||
@@ -141,7 +141,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query
|
||||
* @see #queryForObject(String, Object[], RowMapper)
|
||||
*/
|
||||
Object queryForObject(String sql, RowMapper rowMapper) throws DataAccessException;
|
||||
<T> T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a result object, given static SQL.
|
||||
@@ -159,7 +159,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query
|
||||
* @see #queryForObject(String, Object[], Class)
|
||||
*/
|
||||
Object queryForObject(String sql, Class requiredType) throws DataAccessException;
|
||||
<T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a result Map, given static SQL.
|
||||
@@ -177,7 +177,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForMap(String, Object[])
|
||||
* @see ColumnMapRowMapper
|
||||
*/
|
||||
Map queryForMap(String sql) throws DataAccessException;
|
||||
Map<String, Object> queryForMap(String sql) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query that results in a long value, given static SQL.
|
||||
@@ -228,7 +228,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForList(String, Object[], Class)
|
||||
* @see SingleColumnRowMapper
|
||||
*/
|
||||
List queryForList(String sql, Class elementType) throws DataAccessException;
|
||||
<T> List<T> queryForList(String sql, Class<T> elementType) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a result list, given static SQL.
|
||||
@@ -244,7 +244,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query
|
||||
* @see #queryForList(String, Object[])
|
||||
*/
|
||||
List queryForList(String sql) throws DataAccessException;
|
||||
List<Map<String, Object>> queryForList(String sql) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a SqlRowSet, given static SQL.
|
||||
@@ -303,7 +303,7 @@ public interface JdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(PreparedStatementCreator psc, PreparedStatementCallback action)
|
||||
<T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -319,7 +319,7 @@ public interface JdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(String sql, PreparedStatementCallback action) throws DataAccessException;
|
||||
<T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the ResultSet with a
|
||||
@@ -332,7 +332,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem
|
||||
* @see PreparedStatementCreatorFactory
|
||||
*/
|
||||
Object query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException;
|
||||
<T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the ResultSet with a
|
||||
@@ -346,7 +346,7 @@ public interface JdbcOperations {
|
||||
* @return an arbitrary result object, as returned by the ResultSetExtractor
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object query(String sql, PreparedStatementSetter pss, ResultSetExtractor rse)
|
||||
<T> T query(String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -362,7 +362,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if the query fails
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
Object query(String sql, Object[] args, int[] argTypes, ResultSetExtractor rse)
|
||||
<T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -378,7 +378,7 @@ public interface JdbcOperations {
|
||||
* @return an arbitrary result object, as returned by the ResultSetExtractor
|
||||
* @throws DataAccessException if the query fails
|
||||
*/
|
||||
Object query(String sql, Object[] args, ResultSetExtractor rse) throws DataAccessException;
|
||||
<T> T query(String sql, Object[] args, ResultSetExtractor<T> rse) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the ResultSet on a per-row
|
||||
@@ -448,7 +448,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if there is any problem
|
||||
* @see PreparedStatementCreatorFactory
|
||||
*/
|
||||
List query(PreparedStatementCreator psc, RowMapper rowMapper) throws DataAccessException;
|
||||
<T> List<T> query(PreparedStatementCreator psc, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -463,7 +463,7 @@ public interface JdbcOperations {
|
||||
* @return the result List, containing mapped objects
|
||||
* @throws DataAccessException if the query fails
|
||||
*/
|
||||
List query(String sql, PreparedStatementSetter pss, RowMapper rowMapper)
|
||||
<T> List<T> query(String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -479,7 +479,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if the query fails
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
List query(String sql, Object[] args, int[] argTypes, RowMapper rowMapper)
|
||||
<T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -495,7 +495,7 @@ public interface JdbcOperations {
|
||||
* @return the result List, containing mapped objects
|
||||
* @throws DataAccessException if the query fails
|
||||
*/
|
||||
List query(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException;
|
||||
<T> List<T> query(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a list
|
||||
@@ -512,7 +512,7 @@ public interface JdbcOperations {
|
||||
* return exactly one row
|
||||
* @throws DataAccessException if the query fails
|
||||
*/
|
||||
Object queryForObject(String sql, Object[] args, int[] argTypes, RowMapper rowMapper)
|
||||
<T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -530,7 +530,7 @@ public interface JdbcOperations {
|
||||
* return exactly one row
|
||||
* @throws DataAccessException if the query fails
|
||||
*/
|
||||
Object queryForObject(String sql, Object[] args, RowMapper rowMapper)
|
||||
<T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -550,7 +550,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForObject(String, Class)
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
Object queryForObject(String sql, Object[] args, int[] argTypes, Class requiredType)
|
||||
<T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -570,7 +570,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if the query fails
|
||||
* @see #queryForObject(String, Class)
|
||||
*/
|
||||
Object queryForObject(String sql, Object[] args, Class requiredType) throws DataAccessException;
|
||||
<T> T queryForObject(String sql, Object[] args, Class<T> requiredType) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -590,7 +590,7 @@ public interface JdbcOperations {
|
||||
* @see ColumnMapRowMapper
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
Map queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException;
|
||||
Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -613,7 +613,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForMap(String)
|
||||
* @see ColumnMapRowMapper
|
||||
*/
|
||||
Map queryForMap(String sql, Object[] args) throws DataAccessException;
|
||||
Map<String, Object> queryForMap(String sql, Object[] args) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -703,7 +703,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForList(String, Class)
|
||||
* @see SingleColumnRowMapper
|
||||
*/
|
||||
List queryForList(String sql, Object[] args, int[] argTypes, Class elementType)
|
||||
<T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elementType)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -723,7 +723,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForList(String, Class)
|
||||
* @see SingleColumnRowMapper
|
||||
*/
|
||||
List queryForList(String sql, Object[] args, Class elementType) throws DataAccessException;
|
||||
<T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -741,7 +741,7 @@ public interface JdbcOperations {
|
||||
* @see #queryForList(String)
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
List queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException;
|
||||
List<Map<String, Object>> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -759,7 +759,7 @@ public interface JdbcOperations {
|
||||
* @throws DataAccessException if the query fails
|
||||
* @see #queryForList(String)
|
||||
*/
|
||||
List queryForList(String sql, Object[] args) throws DataAccessException;
|
||||
List<Map<String, Object>> queryForList(String sql, Object[] args) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -905,7 +905,7 @@ public interface JdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(CallableStatementCreator csc, CallableStatementCallback action)
|
||||
<T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -921,7 +921,7 @@ public interface JdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(String callString, CallableStatementCallback action) throws DataAccessException;
|
||||
<T> T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a SQL call using a CallableStatementCreator to provide SQL and any
|
||||
@@ -931,6 +931,7 @@ public interface JdbcOperations {
|
||||
* @return Map of extracted out parameters
|
||||
* @throws DataAccessException if there is any problem issuing the update
|
||||
*/
|
||||
Map call(CallableStatementCreator csc, List declaredParameters) throws DataAccessException;
|
||||
Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters)
|
||||
throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.core.CollectionFactory;
|
||||
@@ -325,7 +324,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
// Methods dealing with a plain java.sql.Connection
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public Object execute(ConnectionCallback action) throws DataAccessException {
|
||||
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
|
||||
Assert.notNull(action, "Callback object must not be null");
|
||||
|
||||
Connection con = DataSourceUtils.getConnection(getDataSource());
|
||||
@@ -376,7 +375,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
// Methods dealing with static SQL (java.sql.Statement)
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public Object execute(StatementCallback action) throws DataAccessException {
|
||||
public <T> T execute(StatementCallback<T> action) throws DataAccessException {
|
||||
Assert.notNull(action, "Callback object must not be null");
|
||||
|
||||
Connection con = DataSourceUtils.getConnection(getDataSource());
|
||||
@@ -393,7 +392,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (this.nativeJdbcExtractor != null) {
|
||||
stmtToUse = this.nativeJdbcExtractor.getNativeStatement(stmt);
|
||||
}
|
||||
Object result = action.doInStatement(stmtToUse);
|
||||
T result = action.doInStatement(stmtToUse);
|
||||
handleWarnings(stmt);
|
||||
return result;
|
||||
}
|
||||
@@ -416,8 +415,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing SQL statement [" + sql + "]");
|
||||
}
|
||||
|
||||
class ExecuteStatementCallback implements StatementCallback, SqlProvider {
|
||||
class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
|
||||
public Object doInStatement(Statement stmt) throws SQLException {
|
||||
stmt.execute(sql);
|
||||
return null;
|
||||
@@ -429,15 +427,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
execute(new ExecuteStatementCallback());
|
||||
}
|
||||
|
||||
public Object query(final String sql, final ResultSetExtractor rse) throws DataAccessException {
|
||||
public <T> T query(final String sql, final ResultSetExtractor<T> rse) throws DataAccessException {
|
||||
Assert.notNull(sql, "SQL must not be null");
|
||||
Assert.notNull(rse, "ResultSetExtractor must not be null");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing SQL query [" + sql + "]");
|
||||
}
|
||||
|
||||
class QueryStatementCallback implements StatementCallback, SqlProvider {
|
||||
public Object doInStatement(Statement stmt) throws SQLException {
|
||||
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
|
||||
public T doInStatement(Statement stmt) throws SQLException {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = stmt.executeQuery(sql);
|
||||
@@ -462,43 +459,43 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
query(sql, new RowCallbackHandlerResultSetExtractor(rch));
|
||||
}
|
||||
|
||||
public List query(String sql, RowMapper rowMapper) throws DataAccessException {
|
||||
return (List) query(sql, new RowMapperResultSetExtractor(rowMapper));
|
||||
public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(sql, new RowMapperResultSetExtractor<T>(rowMapper));
|
||||
}
|
||||
|
||||
public Map queryForMap(String sql) throws DataAccessException {
|
||||
return (Map) queryForObject(sql, getColumnMapRowMapper());
|
||||
public Map<String, Object> queryForMap(String sql) throws DataAccessException {
|
||||
return queryForObject(sql, getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, RowMapper rowMapper) throws DataAccessException {
|
||||
List results = query(sql, rowMapper);
|
||||
public <T> T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
List<T> results = query(sql, rowMapper);
|
||||
return DataAccessUtils.requiredSingleResult(results);
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Class requiredType) throws DataAccessException {
|
||||
public <T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException {
|
||||
return queryForObject(sql, getSingleColumnRowMapper(requiredType));
|
||||
}
|
||||
|
||||
public long queryForLong(String sql) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, Long.class);
|
||||
Number number = queryForObject(sql, Long.class);
|
||||
return (number != null ? number.longValue() : 0);
|
||||
}
|
||||
|
||||
public int queryForInt(String sql) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, Integer.class);
|
||||
Number number = queryForObject(sql, Integer.class);
|
||||
return (number != null ? number.intValue() : 0);
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Class elementType) throws DataAccessException {
|
||||
public <T> List<T> queryForList(String sql, Class<T> elementType) throws DataAccessException {
|
||||
return query(sql, getSingleColumnRowMapper(elementType));
|
||||
}
|
||||
|
||||
public List queryForList(String sql) throws DataAccessException {
|
||||
public List<Map<String, Object>> queryForList(String sql) throws DataAccessException {
|
||||
return query(sql, getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public SqlRowSet queryForRowSet(String sql) throws DataAccessException {
|
||||
return (SqlRowSet) query(sql, new SqlRowSetResultSetExtractor());
|
||||
return query(sql, new SqlRowSetResultSetExtractor());
|
||||
}
|
||||
|
||||
public int update(final String sql) throws DataAccessException {
|
||||
@@ -506,20 +503,19 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing SQL update [" + sql + "]");
|
||||
}
|
||||
|
||||
class UpdateStatementCallback implements StatementCallback, SqlProvider {
|
||||
public Object doInStatement(Statement stmt) throws SQLException {
|
||||
class UpdateStatementCallback implements StatementCallback<Integer>, SqlProvider {
|
||||
public Integer doInStatement(Statement stmt) throws SQLException {
|
||||
int rows = stmt.executeUpdate(sql);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SQL update affected " + rows + " rows");
|
||||
}
|
||||
return new Integer(rows);
|
||||
return rows;
|
||||
}
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
return ((Integer) execute(new UpdateStatementCallback())).intValue();
|
||||
return execute(new UpdateStatementCallback());
|
||||
}
|
||||
|
||||
public int[] batchUpdate(final String[] sql) throws DataAccessException {
|
||||
@@ -527,15 +523,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing SQL batch update of " + sql.length + " statements");
|
||||
}
|
||||
|
||||
class BatchUpdateStatementCallback implements StatementCallback, SqlProvider {
|
||||
class BatchUpdateStatementCallback implements StatementCallback<int[]>, SqlProvider {
|
||||
private String currSql;
|
||||
public Object doInStatement(Statement stmt) throws SQLException, DataAccessException {
|
||||
public int[] doInStatement(Statement stmt) throws SQLException, DataAccessException {
|
||||
int[] rowsAffected = new int[sql.length];
|
||||
if (JdbcUtils.supportsBatchUpdates(stmt.getConnection())) {
|
||||
for (int i = 0; i < sql.length; i++) {
|
||||
this.currSql = sql[i];
|
||||
stmt.addBatch(sql[i]);
|
||||
for (String sqlStmt : sql) {
|
||||
this.currSql = sqlStmt;
|
||||
stmt.addBatch(sqlStmt);
|
||||
}
|
||||
rowsAffected = stmt.executeBatch();
|
||||
}
|
||||
@@ -553,10 +548,10 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
return rowsAffected;
|
||||
}
|
||||
public String getSql() {
|
||||
return currSql;
|
||||
return this.currSql;
|
||||
}
|
||||
}
|
||||
return (int[]) execute(new BatchUpdateStatementCallback());
|
||||
return execute(new BatchUpdateStatementCallback());
|
||||
}
|
||||
|
||||
|
||||
@@ -564,7 +559,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
// Methods dealing with prepared statements
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public Object execute(PreparedStatementCreator psc, PreparedStatementCallback action)
|
||||
public <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException {
|
||||
|
||||
Assert.notNull(psc, "PreparedStatementCreator must not be null");
|
||||
@@ -588,7 +583,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (this.nativeJdbcExtractor != null) {
|
||||
psToUse = this.nativeJdbcExtractor.getNativePreparedStatement(ps);
|
||||
}
|
||||
Object result = action.doInPreparedStatement(psToUse);
|
||||
T result = action.doInPreparedStatement(psToUse);
|
||||
handleWarnings(ps);
|
||||
return result;
|
||||
}
|
||||
@@ -615,7 +610,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
}
|
||||
}
|
||||
|
||||
public Object execute(String sql, PreparedStatementCallback action) throws DataAccessException {
|
||||
public <T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException {
|
||||
return execute(new SimplePreparedStatementCreator(sql), action);
|
||||
}
|
||||
|
||||
@@ -631,15 +626,15 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @return an arbitrary result object, as returned by the ResultSetExtractor
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
public Object query(
|
||||
PreparedStatementCreator psc, final PreparedStatementSetter pss, final ResultSetExtractor rse)
|
||||
public <T> T query(
|
||||
PreparedStatementCreator psc, final PreparedStatementSetter pss, final ResultSetExtractor<T> rse)
|
||||
throws DataAccessException {
|
||||
|
||||
Assert.notNull(rse, "ResultSetExtractor must not be null");
|
||||
logger.debug("Executing prepared SQL query");
|
||||
|
||||
return execute(psc, new PreparedStatementCallback() {
|
||||
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
return execute(psc, new PreparedStatementCallback<T>() {
|
||||
public T doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
if (pss != null) {
|
||||
@@ -662,19 +657,19 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
});
|
||||
}
|
||||
|
||||
public Object query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException {
|
||||
public <T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException {
|
||||
return query(psc, null, rse);
|
||||
}
|
||||
|
||||
public Object query(String sql, PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException {
|
||||
public <T> T query(String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException {
|
||||
return query(new SimplePreparedStatementCreator(sql), pss, rse);
|
||||
}
|
||||
|
||||
public Object query(String sql, Object[] args, int[] argTypes, ResultSetExtractor rse) throws DataAccessException {
|
||||
public <T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException {
|
||||
return query(sql, new ArgTypePreparedStatementSetter(args, argTypes), rse);
|
||||
}
|
||||
|
||||
public Object query(String sql, Object[] args, ResultSetExtractor rse) throws DataAccessException {
|
||||
public <T> T query(String sql, Object[] args, ResultSetExtractor<T> rse) throws DataAccessException {
|
||||
return query(sql, new ArgPreparedStatementSetter(args), rse);
|
||||
}
|
||||
|
||||
@@ -694,103 +689,102 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
query(sql, new ArgPreparedStatementSetter(args), rch);
|
||||
}
|
||||
|
||||
public List query(PreparedStatementCreator psc, RowMapper rowMapper) throws DataAccessException {
|
||||
return (List) query(psc, new RowMapperResultSetExtractor(rowMapper));
|
||||
public <T> List<T> query(PreparedStatementCreator psc, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(psc, new RowMapperResultSetExtractor<T>(rowMapper));
|
||||
}
|
||||
|
||||
public List query(String sql, PreparedStatementSetter pss, RowMapper rowMapper) throws DataAccessException {
|
||||
return (List) query(sql, pss, new RowMapperResultSetExtractor(rowMapper));
|
||||
public <T> List<T> query(String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(sql, pss, new RowMapperResultSetExtractor<T>(rowMapper));
|
||||
}
|
||||
|
||||
public List query(String sql, Object[] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException {
|
||||
return (List) query(sql, args, argTypes, new RowMapperResultSetExtractor(rowMapper));
|
||||
public <T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(sql, args, argTypes, new RowMapperResultSetExtractor<T>(rowMapper));
|
||||
}
|
||||
|
||||
public List query(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException {
|
||||
return (List) query(sql, args, new RowMapperResultSetExtractor(rowMapper));
|
||||
public <T> List<T> query(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(sql, args, new RowMapperResultSetExtractor<T>(rowMapper));
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Object[] args, int[] argTypes, RowMapper rowMapper)
|
||||
public <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper)
|
||||
throws DataAccessException {
|
||||
|
||||
List results = (List) query(sql, args, argTypes, new RowMapperResultSetExtractor(rowMapper, 1));
|
||||
List<T> results = query(sql, args, argTypes, new RowMapperResultSetExtractor<T>(rowMapper, 1));
|
||||
return DataAccessUtils.requiredSingleResult(results);
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException {
|
||||
List results = (List) query(sql, args, new RowMapperResultSetExtractor(rowMapper, 1));
|
||||
public <T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
List<T> results = query(sql, args, new RowMapperResultSetExtractor<T>(rowMapper, 1));
|
||||
return DataAccessUtils.requiredSingleResult(results);
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Object[] args, int[] argTypes, Class requiredType)
|
||||
public <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType)
|
||||
throws DataAccessException {
|
||||
|
||||
return queryForObject(sql, args, argTypes, getSingleColumnRowMapper(requiredType));
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Object[] args, Class requiredType) throws DataAccessException {
|
||||
public <T> T queryForObject(String sql, Object[] args, Class<T> requiredType) throws DataAccessException {
|
||||
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
|
||||
}
|
||||
|
||||
public Map queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
return (Map) queryForObject(sql, args, argTypes, getColumnMapRowMapper());
|
||||
public Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
return queryForObject(sql, args, argTypes, getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public Map queryForMap(String sql, Object[] args) throws DataAccessException {
|
||||
return (Map) queryForObject(sql, args, getColumnMapRowMapper());
|
||||
public Map<String, Object> queryForMap(String sql, Object[] args) throws DataAccessException {
|
||||
return queryForObject(sql, args, getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public long queryForLong(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, args, argTypes, Long.class);
|
||||
Number number = queryForObject(sql, args, argTypes, Long.class);
|
||||
return (number != null ? number.longValue() : 0);
|
||||
}
|
||||
|
||||
public long queryForLong(String sql, Object[] args) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, args, Long.class);
|
||||
Number number = queryForObject(sql, args, Long.class);
|
||||
return (number != null ? number.longValue() : 0);
|
||||
}
|
||||
|
||||
public int queryForInt(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, args, argTypes, Integer.class);
|
||||
Number number = queryForObject(sql, args, argTypes, Integer.class);
|
||||
return (number != null ? number.intValue() : 0);
|
||||
}
|
||||
|
||||
public int queryForInt(String sql, Object[] args) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, args, Integer.class);
|
||||
Number number = queryForObject(sql, args, Integer.class);
|
||||
return (number != null ? number.intValue() : 0);
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Object[] args, int[] argTypes, Class elementType) throws DataAccessException {
|
||||
public <T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elementType) throws DataAccessException {
|
||||
return query(sql, args, argTypes, getSingleColumnRowMapper(elementType));
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Object[] args, Class elementType) throws DataAccessException {
|
||||
public <T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) throws DataAccessException {
|
||||
return query(sql, args, getSingleColumnRowMapper(elementType));
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
public List<Map<String, Object>> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
return query(sql, args, argTypes, getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Object[] args) throws DataAccessException {
|
||||
public List<Map<String, Object>> queryForList(String sql, Object[] args) throws DataAccessException {
|
||||
return query(sql, args, getColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
return (SqlRowSet) query(sql, args, argTypes, new SqlRowSetResultSetExtractor());
|
||||
return query(sql, args, argTypes, new SqlRowSetResultSetExtractor());
|
||||
}
|
||||
|
||||
public SqlRowSet queryForRowSet(String sql, Object[] args) throws DataAccessException {
|
||||
return (SqlRowSet) query(sql, args, new SqlRowSetResultSetExtractor());
|
||||
return query(sql, args, new SqlRowSetResultSetExtractor());
|
||||
}
|
||||
|
||||
protected int update(final PreparedStatementCreator psc, final PreparedStatementSetter pss)
|
||||
throws DataAccessException {
|
||||
|
||||
logger.debug("Executing prepared SQL update");
|
||||
|
||||
Integer result = (Integer) execute(psc, new PreparedStatementCallback() {
|
||||
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
return execute(psc, new PreparedStatementCallback<Integer>() {
|
||||
public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
try {
|
||||
if (pss != null) {
|
||||
pss.setValues(ps);
|
||||
@@ -799,7 +793,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SQL update affected " + rows + " rows");
|
||||
}
|
||||
return new Integer(rows);
|
||||
return rows;
|
||||
}
|
||||
finally {
|
||||
if (pss instanceof ParameterDisposer) {
|
||||
@@ -808,7 +802,6 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
}
|
||||
}
|
||||
});
|
||||
return result.intValue();
|
||||
}
|
||||
|
||||
public int update(PreparedStatementCreator psc) throws DataAccessException {
|
||||
@@ -821,17 +814,17 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
Assert.notNull(generatedKeyHolder, "KeyHolder must not be null");
|
||||
logger.debug("Executing SQL update and returning generated keys");
|
||||
|
||||
Integer result = (Integer) execute(psc, new PreparedStatementCallback() {
|
||||
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
return execute(psc, new PreparedStatementCallback<Integer>() {
|
||||
public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
int rows = ps.executeUpdate();
|
||||
List generatedKeys = generatedKeyHolder.getKeyList();
|
||||
List<Map<String, Object>> generatedKeys = generatedKeyHolder.getKeyList();
|
||||
generatedKeys.clear();
|
||||
ResultSet keys = ps.getGeneratedKeys();
|
||||
if (keys != null) {
|
||||
try {
|
||||
RowMapper rowMapper = getColumnMapRowMapper();
|
||||
RowMapperResultSetExtractor rse = new RowMapperResultSetExtractor(rowMapper, 1);
|
||||
generatedKeys.addAll((List) rse.extractData(keys));
|
||||
RowMapperResultSetExtractor<Map<String, Object>> rse =
|
||||
new RowMapperResultSetExtractor<Map<String, Object>>(getColumnMapRowMapper(), 1);
|
||||
generatedKeys.addAll(rse.extractData(keys));
|
||||
}
|
||||
finally {
|
||||
JdbcUtils.closeResultSet(keys);
|
||||
@@ -840,10 +833,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SQL update affected " + rows + " rows and returned " + generatedKeys.size() + " keys");
|
||||
}
|
||||
return new Integer(rows);
|
||||
return rows;
|
||||
}
|
||||
});
|
||||
return result.intValue();
|
||||
}
|
||||
|
||||
public int update(String sql, PreparedStatementSetter pss) throws DataAccessException {
|
||||
@@ -863,8 +855,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
logger.debug("Executing SQL batch update [" + sql + "]");
|
||||
}
|
||||
|
||||
return (int[]) execute(sql, new PreparedStatementCallback() {
|
||||
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
return execute(sql, new PreparedStatementCallback<int[]>() {
|
||||
public int[] doInPreparedStatement(PreparedStatement ps) throws SQLException {
|
||||
try {
|
||||
int batchSize = pss.getBatchSize();
|
||||
InterruptibleBatchPreparedStatementSetter ipss =
|
||||
@@ -881,17 +873,17 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
return ps.executeBatch();
|
||||
}
|
||||
else {
|
||||
List rowsAffected = new ArrayList();
|
||||
List<Integer> rowsAffected = new ArrayList<Integer>();
|
||||
for (int i = 0; i < batchSize; i++) {
|
||||
pss.setValues(ps, i);
|
||||
if (ipss != null && ipss.isBatchExhausted(i)) {
|
||||
break;
|
||||
}
|
||||
rowsAffected.add(new Integer(ps.executeUpdate()));
|
||||
rowsAffected.add(ps.executeUpdate());
|
||||
}
|
||||
int[] rowsAffectedArray = new int[rowsAffected.size()];
|
||||
for (int i = 0; i < rowsAffectedArray.length; i++) {
|
||||
rowsAffectedArray[i] = ((Integer) rowsAffected.get(i)).intValue();
|
||||
rowsAffectedArray[i] = rowsAffected.get(i);
|
||||
}
|
||||
return rowsAffectedArray;
|
||||
}
|
||||
@@ -910,7 +902,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
// Methods dealing with callable statements
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public Object execute(CallableStatementCreator csc, CallableStatementCallback action)
|
||||
public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
|
||||
throws DataAccessException {
|
||||
|
||||
Assert.notNull(csc, "CallableStatementCreator must not be null");
|
||||
@@ -933,7 +925,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (this.nativeJdbcExtractor != null) {
|
||||
csToUse = this.nativeJdbcExtractor.getNativeCallableStatement(cs);
|
||||
}
|
||||
Object result = action.doInCallableStatement(csToUse);
|
||||
T result = action.doInCallableStatement(csToUse);
|
||||
handleWarnings(cs);
|
||||
return result;
|
||||
}
|
||||
@@ -960,16 +952,17 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
}
|
||||
}
|
||||
|
||||
public Object execute(String callString, CallableStatementCallback action) throws DataAccessException {
|
||||
public <T> T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException {
|
||||
return execute(new SimpleCallableStatementCreator(callString), action);
|
||||
}
|
||||
|
||||
public Map call(CallableStatementCreator csc, List declaredParameters) throws DataAccessException {
|
||||
final List updateCountParameters = new ArrayList();
|
||||
final List resultSetParameters = new ArrayList();
|
||||
final List callParameters = new ArrayList();
|
||||
for (int i = 0; i < declaredParameters.size(); i++) {
|
||||
SqlParameter parameter = (SqlParameter) declaredParameters.get(i);
|
||||
public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters)
|
||||
throws DataAccessException {
|
||||
|
||||
final List<SqlParameter> updateCountParameters = new ArrayList<SqlParameter>();
|
||||
final List<SqlParameter> resultSetParameters = new ArrayList<SqlParameter>();
|
||||
final List<SqlParameter> callParameters = new ArrayList<SqlParameter>();
|
||||
for (SqlParameter parameter : declaredParameters) {
|
||||
if (parameter.isResultsParameter()) {
|
||||
if (parameter instanceof SqlReturnResultSet) {
|
||||
resultSetParameters.add(parameter);
|
||||
@@ -982,15 +975,15 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
callParameters.add(parameter);
|
||||
}
|
||||
}
|
||||
return (Map) execute(csc, new CallableStatementCallback() {
|
||||
public Object doInCallableStatement(CallableStatement cs) throws SQLException {
|
||||
return execute(csc, new CallableStatementCallback<Map<String, Object>>() {
|
||||
public Map<String, Object> doInCallableStatement(CallableStatement cs) throws SQLException {
|
||||
boolean retVal = cs.execute();
|
||||
int updateCount = cs.getUpdateCount();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("CallableStatement.execute() returned '" + retVal + "'");
|
||||
logger.debug("CallableStatement.getUpdateCount() returned " + updateCount);
|
||||
}
|
||||
Map returnedResults = createResultsMap();
|
||||
Map<String, Object> returnedResults = createResultsMap();
|
||||
if (retVal || updateCount != -1) {
|
||||
returnedResults.putAll(extractReturnedResults(cs, updateCountParameters, resultSetParameters, updateCount));
|
||||
}
|
||||
@@ -1007,11 +1000,11 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @param resultSetParameters Parameter list of declared resturn resultSet parameters for the stored procedure
|
||||
* @return Map that contains returned results
|
||||
*/
|
||||
protected Map extractReturnedResults(
|
||||
protected Map<String, Object> extractReturnedResults(
|
||||
CallableStatement cs, List updateCountParameters, List resultSetParameters, int updateCount)
|
||||
throws SQLException {
|
||||
|
||||
Map returnedResults = new HashMap();
|
||||
Map<String, Object> returnedResults = new HashMap<String, Object>();
|
||||
int rsIndex = 0;
|
||||
int updateIndex = 0;
|
||||
boolean moreResults;
|
||||
@@ -1037,14 +1030,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
if (updateCountParameters != null && updateCountParameters.size() > updateIndex) {
|
||||
SqlReturnUpdateCount ucParam = (SqlReturnUpdateCount)updateCountParameters.get(updateIndex);
|
||||
String declaredUcName = ucParam.getName();
|
||||
returnedResults.put(declaredUcName, new Integer(updateCount));
|
||||
returnedResults.put(declaredUcName, updateCount);
|
||||
updateIndex++;
|
||||
}
|
||||
else {
|
||||
if (!skipUndeclaredResults) {
|
||||
String undeclaredUcName = RETURN_UPDATE_COUNT_PREFIX + (updateIndex + 1);
|
||||
logger.info("Added default SqlReturnUpdateCount parameter named " + undeclaredUcName);
|
||||
returnedResults.put(undeclaredUcName, new Integer(updateCount));
|
||||
returnedResults.put(undeclaredUcName, updateCount);
|
||||
updateIndex++;
|
||||
}
|
||||
}
|
||||
@@ -1066,11 +1059,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @param parameters parameter list for the stored procedure
|
||||
* @return Map that contains returned results
|
||||
*/
|
||||
protected Map extractOutputParameters(CallableStatement cs, List parameters) throws SQLException {
|
||||
Map returnedResults = new HashMap();
|
||||
protected Map<String, Object> extractOutputParameters(CallableStatement cs, List<SqlParameter> parameters)
|
||||
throws SQLException {
|
||||
|
||||
Map<String, Object> returnedResults = new HashMap<String, Object>();
|
||||
int sqlColIndex = 1;
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
SqlParameter param = (SqlParameter) parameters.get(i);
|
||||
for (SqlParameter param : parameters) {
|
||||
if (param instanceof SqlOutParameter) {
|
||||
SqlOutParameter outParam = (SqlOutParameter) param;
|
||||
if (outParam.isReturnTypeSupported()) {
|
||||
@@ -1109,11 +1103,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @param param the corresponding stored procedure parameter
|
||||
* @return Map that contains returned results
|
||||
*/
|
||||
protected Map processResultSet(ResultSet rs, ResultSetSupportingSqlParameter param) throws SQLException {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Object> processResultSet(ResultSet rs, ResultSetSupportingSqlParameter param) throws SQLException {
|
||||
if (rs == null) {
|
||||
return Collections.EMPTY_MAP;
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map returnedResults = new HashMap();
|
||||
Map<String, Object> returnedResults = new HashMap<String, Object>();
|
||||
try {
|
||||
ResultSet rsToUse = rs;
|
||||
if (this.nativeJdbcExtractor != null) {
|
||||
@@ -1150,7 +1145,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @return the RowMapper to use
|
||||
* @see ColumnMapRowMapper
|
||||
*/
|
||||
protected RowMapper getColumnMapRowMapper() {
|
||||
protected RowMapper<Map<String, Object>> getColumnMapRowMapper() {
|
||||
return new ColumnMapRowMapper();
|
||||
}
|
||||
|
||||
@@ -1160,8 +1155,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @return the RowMapper to use
|
||||
* @see SingleColumnRowMapper
|
||||
*/
|
||||
protected RowMapper getSingleColumnRowMapper(Class requiredType) {
|
||||
return new SingleColumnRowMapper(requiredType);
|
||||
protected <T> RowMapper<T> getSingleColumnRowMapper(Class<T> requiredType) {
|
||||
return new SingleColumnRowMapper<T>(requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1172,12 +1167,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* @see #setResultsMapCaseInsensitive
|
||||
* @see org.springframework.core.CollectionFactory#createLinkedCaseInsensitiveMapIfPossible
|
||||
*/
|
||||
protected Map createResultsMap() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Object> createResultsMap() {
|
||||
if (isResultsMapCaseInsensitive()) {
|
||||
return CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(10);
|
||||
return (Map<String, Object>) CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(16);
|
||||
}
|
||||
else {
|
||||
return new LinkedHashMap();
|
||||
return new LinkedHashMap<String, Object>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1280,7 +1276,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
}
|
||||
else if (method.getName().equals("hashCode")) {
|
||||
// Use hashCode of PersistenceManager proxy.
|
||||
return new Integer(System.identityHashCode(proxy));
|
||||
return System.identityHashCode(proxy);
|
||||
}
|
||||
else if (method.getName().equals("close")) {
|
||||
// Handle close method: suppress, not valid.
|
||||
@@ -1355,7 +1351,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
* <p>Uses a regular ResultSet, so we have to be careful when using it:
|
||||
* We don't use it for navigating since this could lead to unpredictable consequences.
|
||||
*/
|
||||
private static class RowCallbackHandlerResultSetExtractor implements ResultSetExtractor {
|
||||
private static class RowCallbackHandlerResultSetExtractor implements ResultSetExtractor<Object> {
|
||||
|
||||
private final RowCallbackHandler rch;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
@@ -42,6 +42,6 @@ public interface ParameterMapper {
|
||||
* parameter values (that is, there's no need to catch SQLException)
|
||||
* @return Map of input parameters, keyed by name (never <code>null</code>)
|
||||
*/
|
||||
Map createMap(Connection con) throws SQLException;
|
||||
Map<String, ?> createMap(Connection con) throws SQLException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -40,7 +40,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @see JdbcTemplate#execute(String, PreparedStatementCallback)
|
||||
* @see JdbcTemplate#execute(PreparedStatementCreator, PreparedStatementCallback)
|
||||
*/
|
||||
public interface PreparedStatementCallback {
|
||||
public interface PreparedStatementCallback<T> {
|
||||
|
||||
/**
|
||||
* Gets called by <code>JdbcTemplate.execute</code> with an active JDBC
|
||||
@@ -75,6 +75,6 @@ public interface PreparedStatementCallback {
|
||||
* @see JdbcTemplate#queryForObject(String, Object[], Class)
|
||||
* @see JdbcTemplate#queryForList(String, Object[])
|
||||
*/
|
||||
Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;
|
||||
T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -50,7 +49,7 @@ public class PreparedStatementCreatorFactory {
|
||||
private final String sql;
|
||||
|
||||
/** List of SqlParameter objects. May not be <code>null</code>. */
|
||||
private final List declaredParameters;
|
||||
private final List<SqlParameter> declaredParameters;
|
||||
|
||||
private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
|
||||
|
||||
@@ -69,7 +68,7 @@ public class PreparedStatementCreatorFactory {
|
||||
*/
|
||||
public PreparedStatementCreatorFactory(String sql) {
|
||||
this.sql = sql;
|
||||
this.declaredParameters = new LinkedList();
|
||||
this.declaredParameters = new LinkedList<SqlParameter>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +87,7 @@ public class PreparedStatementCreatorFactory {
|
||||
* @param declaredParameters list of {@link SqlParameter} objects
|
||||
* @see SqlParameter
|
||||
*/
|
||||
public PreparedStatementCreatorFactory(String sql, List declaredParameters) {
|
||||
public PreparedStatementCreatorFactory(String sql, List<SqlParameter> declaredParameters) {
|
||||
this.sql = sql;
|
||||
this.declaredParameters = declaredParameters;
|
||||
}
|
||||
@@ -148,7 +147,7 @@ public class PreparedStatementCreatorFactory {
|
||||
* @param params list of parameters (may be <code>null</code>)
|
||||
*/
|
||||
public PreparedStatementSetter newPreparedStatementSetter(List params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? params : Collections.EMPTY_LIST);
|
||||
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,15 +155,15 @@ public class PreparedStatementCreatorFactory {
|
||||
* @param params the parameter array (may be <code>null</code>)
|
||||
*/
|
||||
public PreparedStatementSetter newPreparedStatementSetter(Object[] params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.EMPTY_LIST);
|
||||
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new PreparedStatementCreator for the given parameters.
|
||||
* @param params list of parameters (may be <code>null</code>)
|
||||
*/
|
||||
public PreparedStatementCreator newPreparedStatementCreator(List params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? params : Collections.EMPTY_LIST);
|
||||
public PreparedStatementCreator newPreparedStatementCreator(List<?> params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +171,7 @@ public class PreparedStatementCreatorFactory {
|
||||
* @param params the parameter array (may be <code>null</code>)
|
||||
*/
|
||||
public PreparedStatementCreator newPreparedStatementCreator(Object[] params) {
|
||||
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.EMPTY_LIST);
|
||||
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +182,7 @@ public class PreparedStatementCreatorFactory {
|
||||
*/
|
||||
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object[] params) {
|
||||
return new PreparedStatementCreatorImpl(
|
||||
sqlToUse, params != null ? Arrays.asList(params) : Collections.EMPTY_LIST);
|
||||
sqlToUse, params != null ? Arrays.asList(params) : Collections.emptyList());
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +196,7 @@ public class PreparedStatementCreatorFactory {
|
||||
|
||||
private final List parameters;
|
||||
|
||||
public PreparedStatementCreatorImpl(List parameters) {
|
||||
public PreparedStatementCreatorImpl(List<?> parameters) {
|
||||
this(sql, parameters);
|
||||
}
|
||||
|
||||
@@ -207,11 +206,11 @@ public class PreparedStatementCreatorFactory {
|
||||
this.parameters = parameters;
|
||||
if (this.parameters.size() != declaredParameters.size()) {
|
||||
// account for named parameters being used multiple times
|
||||
Set names = new HashSet();
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
Object o = parameters.get(i);
|
||||
if (o instanceof SqlParameterValue) {
|
||||
names.add(((SqlParameterValue)o).getName());
|
||||
Object param = parameters.get(i);
|
||||
if (param instanceof SqlParameterValue) {
|
||||
names.add(((SqlParameterValue) param).getName());
|
||||
}
|
||||
else {
|
||||
names.add("Parameter #" + i);
|
||||
@@ -279,16 +278,14 @@ public class PreparedStatementCreatorFactory {
|
||||
" given only " + declaredParameters.size() + " parameters");
|
||||
|
||||
}
|
||||
declaredParameter = (SqlParameter) declaredParameters.get(i);
|
||||
declaredParameter = declaredParameters.get(i);
|
||||
}
|
||||
if (in instanceof Collection && declaredParameter.getSqlType() != Types.ARRAY) {
|
||||
Collection entries = (Collection) in;
|
||||
for (Iterator it = entries.iterator(); it.hasNext();) {
|
||||
Object entry = it.next();
|
||||
for (Object entry : entries) {
|
||||
if (entry instanceof Object[]) {
|
||||
Object[] valueArray = ((Object[])entry);
|
||||
for (int k = 0; k < valueArray.length; k++) {
|
||||
Object argValue = valueArray[k];
|
||||
for (Object argValue : valueArray) {
|
||||
StatementCreatorUtils.setParameterValue(psToUse, sqlColIndx++, declaredParameter, argValue);
|
||||
}
|
||||
}
|
||||
@@ -313,9 +310,10 @@ public class PreparedStatementCreatorFactory {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer("PreparedStatementCreatorFactory.PreparedStatementCreatorImpl: sql=[");
|
||||
buf.append(sql).append("]; parameters=").append(this.parameters);
|
||||
return buf.toString();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("PreparedStatementCreatorFactory.PreparedStatementCreatorImpl: sql=[");
|
||||
sb.append(sql).append("]; parameters=").append(this.parameters);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -46,7 +46,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @see RowMapper
|
||||
* @see org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor
|
||||
*/
|
||||
public interface ResultSetExtractor {
|
||||
public interface ResultSetExtractor<T> {
|
||||
|
||||
/**
|
||||
* Implementations must implement this method to process the entire ResultSet.
|
||||
@@ -58,6 +58,6 @@ public interface ResultSetExtractor {
|
||||
* values or navigating (that is, there's no need to catch SQLException)
|
||||
* @throws DataAccessException in case of custom exceptions
|
||||
*/
|
||||
Object extractData(ResultSet rs) throws SQLException, DataAccessException;
|
||||
T extractData(ResultSet rs) throws SQLException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ResultSetSupportingSqlParameter extends SqlParameter {
|
||||
* Return the ResultSetExtractor held by this parameter, if any.
|
||||
*/
|
||||
public ResultSetExtractor getResultSetExtractor() {
|
||||
return resultSetExtractor;
|
||||
return this.resultSetExtractor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ import java.sql.SQLException;
|
||||
* @see ResultSetExtractor
|
||||
* @see org.springframework.jdbc.object.MappingSqlQuery
|
||||
*/
|
||||
public interface RowMapper {
|
||||
public interface RowMapper<T> {
|
||||
|
||||
/**
|
||||
* Implementations must implement this method to map each row of data
|
||||
@@ -57,7 +57,7 @@ public interface RowMapper {
|
||||
* @throws SQLException if a SQLException is encountered getting
|
||||
* column values (that is, there's no need to catch SQLException)
|
||||
*/
|
||||
Object mapRow(ResultSet rs, int rowNum) throws SQLException;
|
||||
T mapRow(ResultSet rs, int rowNum) throws SQLException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
@@ -57,9 +57,9 @@ import org.springframework.util.Assert;
|
||||
* @see JdbcTemplate
|
||||
* @see org.springframework.jdbc.object.MappingSqlQuery
|
||||
*/
|
||||
public class RowMapperResultSetExtractor implements ResultSetExtractor {
|
||||
public class RowMapperResultSetExtractor<T> implements ResultSetExtractor<List<T>> {
|
||||
|
||||
private final RowMapper rowMapper;
|
||||
private final RowMapper<T> rowMapper;
|
||||
|
||||
private final int rowsExpected;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class RowMapperResultSetExtractor implements ResultSetExtractor {
|
||||
* Create a new RowMapperResultSetExtractor.
|
||||
* @param rowMapper the RowMapper which creates an object for each row
|
||||
*/
|
||||
public RowMapperResultSetExtractor(RowMapper rowMapper) {
|
||||
public RowMapperResultSetExtractor(RowMapper<T> rowMapper) {
|
||||
this(rowMapper, 0);
|
||||
}
|
||||
|
||||
@@ -78,15 +78,15 @@ public class RowMapperResultSetExtractor implements ResultSetExtractor {
|
||||
* @param rowsExpected the number of expected rows
|
||||
* (just used for optimized collection handling)
|
||||
*/
|
||||
public RowMapperResultSetExtractor(RowMapper rowMapper, int rowsExpected) {
|
||||
public RowMapperResultSetExtractor(RowMapper<T> rowMapper, int rowsExpected) {
|
||||
Assert.notNull(rowMapper, "RowMapper is required");
|
||||
this.rowMapper = rowMapper;
|
||||
this.rowsExpected = rowsExpected;
|
||||
}
|
||||
|
||||
|
||||
public Object extractData(ResultSet rs) throws SQLException {
|
||||
List results = (this.rowsExpected > 0 ? new ArrayList(this.rowsExpected) : new ArrayList());
|
||||
public List<T> extractData(ResultSet rs) throws SQLException {
|
||||
List<T> results = (this.rowsExpected > 0 ? new ArrayList<T>(this.rowsExpected) : new ArrayList<T>());
|
||||
int rowNum = 0;
|
||||
while (rs.next()) {
|
||||
results.add(this.rowMapper.mapRow(rs, rowNum++));
|
||||
|
||||
@@ -39,9 +39,9 @@ import org.springframework.util.NumberUtils;
|
||||
* @see JdbcTemplate#queryForList(String, Class)
|
||||
* @see JdbcTemplate#queryForObject(String, Class)
|
||||
*/
|
||||
public class SingleColumnRowMapper implements RowMapper {
|
||||
public class SingleColumnRowMapper<T> implements RowMapper<T> {
|
||||
|
||||
private Class requiredType;
|
||||
private Class<T> requiredType;
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ public class SingleColumnRowMapper implements RowMapper {
|
||||
* Create a new SingleColumnRowMapper.
|
||||
* @param requiredType the type that each result object is expected to match
|
||||
*/
|
||||
public SingleColumnRowMapper(Class requiredType) {
|
||||
public SingleColumnRowMapper(Class<T> requiredType) {
|
||||
this.requiredType = requiredType;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class SingleColumnRowMapper implements RowMapper {
|
||||
* <p>If not specified, the column value will be exposed as
|
||||
* returned by the JDBC driver.
|
||||
*/
|
||||
public void setRequiredType(Class requiredType) {
|
||||
public void setRequiredType(Class<T> requiredType) {
|
||||
this.requiredType = requiredType;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ public class SingleColumnRowMapper implements RowMapper {
|
||||
* @see #getColumnValue(java.sql.ResultSet, int, Class)
|
||||
* @see #convertValueToRequiredType(Object, Class)
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
// Validate column count.
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
int nrOfColumns = rsmd.getColumnCount();
|
||||
@@ -91,7 +92,7 @@ public class SingleColumnRowMapper implements RowMapper {
|
||||
if (result != null && this.requiredType != null && !this.requiredType.isInstance(result)) {
|
||||
// Extracted value does not match already: try to convert it.
|
||||
try {
|
||||
return convertValueToRequiredType(result, this.requiredType);
|
||||
return (T) convertValueToRequiredType(result, this.requiredType);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new TypeMismatchDataAccessException(
|
||||
@@ -99,7 +100,7 @@ public class SingleColumnRowMapper implements RowMapper {
|
||||
rsmd.getColumnTypeName(1) + "': " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return (T) result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -74,7 +74,7 @@ public class SqlParameter {
|
||||
*/
|
||||
public SqlParameter(int sqlType, int scale) {
|
||||
this.sqlType = sqlType;
|
||||
this.scale = new Integer(scale);
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public class SqlParameter {
|
||||
public SqlParameter(String name, int sqlType, int scale) {
|
||||
this.name = name;
|
||||
this.sqlType = sqlType;
|
||||
this.scale = new Integer(scale);
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,11 +177,11 @@ public class SqlParameter {
|
||||
* Convert a list of JDBC types, as defined in <code>java.sql.Types</code>,
|
||||
* to a List of SqlParameter objects as used in this package.
|
||||
*/
|
||||
public static List sqlTypesToAnonymousParameterList(int[] types) {
|
||||
List result = new LinkedList();
|
||||
public static List<SqlParameter> sqlTypesToAnonymousParameterList(int[] types) {
|
||||
List<SqlParameter> result = new LinkedList<SqlParameter>();
|
||||
if (types != null) {
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
result.add(new SqlParameter(types[i]));
|
||||
for (int type : types) {
|
||||
result.add(new SqlParameter(type));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.jdbc.core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.rowset.CachedRowSet;
|
||||
|
||||
import com.sun.rowset.CachedRowSetImpl;
|
||||
@@ -32,9 +31,7 @@ import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
*
|
||||
* <p>The default implementation uses a standard JDBC CachedRowSet underneath.
|
||||
* This means that JDBC RowSet support needs to be available at runtime:
|
||||
* by default, Sun's <code>com.sun.rowset.CachedRowSetImpl</code> class is
|
||||
* used, which is part of JDK 1.5+ and also available separately as part of
|
||||
* Sun's JDBC RowSet Implementations download (rowset.jar).
|
||||
* by default, Sun's <code>com.sun.rowset.CachedRowSetImpl</code> class.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.2
|
||||
@@ -43,9 +40,9 @@ import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
* @see JdbcTemplate#queryForRowSet(String)
|
||||
* @see javax.sql.rowset.CachedRowSet
|
||||
*/
|
||||
public class SqlRowSetResultSetExtractor implements ResultSetExtractor {
|
||||
public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet> {
|
||||
|
||||
public Object extractData(ResultSet rs) throws SQLException {
|
||||
public SqlRowSet extractData(ResultSet rs) throws SQLException {
|
||||
return createSqlRowSet(rs);
|
||||
}
|
||||
|
||||
@@ -71,9 +68,7 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor {
|
||||
* Create a new CachedRowSet instance, to be populated by
|
||||
* the <code>createSqlRowSet</code> implementation.
|
||||
* <p>The default implementation creates a new instance of
|
||||
* Sun's <code>com.sun.rowset.CachedRowSetImpl</code> class,
|
||||
* which is part of JDK 1.5+ and also available separately
|
||||
* as part of Sun's JDBC RowSet Implementations download.
|
||||
* Sun's <code>com.sun.rowset.CachedRowSetImpl</code> class.
|
||||
* @return a new CachedRowSet instance
|
||||
* @throws SQLException if thrown by JDBC methods
|
||||
* @see #createSqlRowSet
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -33,7 +33,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @since 16.03.2004
|
||||
* @see JdbcTemplate#execute(StatementCallback)
|
||||
*/
|
||||
public interface StatementCallback {
|
||||
public interface StatementCallback<T> {
|
||||
|
||||
/**
|
||||
* Gets called by <code>JdbcTemplate.execute</code> with an active JDBC
|
||||
@@ -68,6 +68,6 @@ public interface StatementCallback {
|
||||
* @see JdbcTemplate#queryForObject(String, Class)
|
||||
* @see JdbcTemplate#queryForRowSet(String)
|
||||
*/
|
||||
Object doInStatement(Statement stmt) throws SQLException, DataAccessException;
|
||||
T doInStatement(Statement stmt) throws SQLException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -61,32 +61,32 @@ public abstract class StatementCreatorUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(StatementCreatorUtils.class);
|
||||
|
||||
private static Map javaTypeToSqlTypeMap = new HashMap(32);
|
||||
private static Map<Class, Integer> javaTypeToSqlTypeMap = new HashMap<Class, Integer>(32);
|
||||
|
||||
static {
|
||||
/* JDBC 3.0 only - not compatible with e.g. MySQL at present
|
||||
javaTypeToSqlTypeMap.put(boolean.class, new Integer(Types.BOOLEAN));
|
||||
javaTypeToSqlTypeMap.put(Boolean.class, new Integer(Types.BOOLEAN));
|
||||
*/
|
||||
javaTypeToSqlTypeMap.put(byte.class, new Integer(Types.TINYINT));
|
||||
javaTypeToSqlTypeMap.put(Byte.class, new Integer(Types.TINYINT));
|
||||
javaTypeToSqlTypeMap.put(short.class, new Integer(Types.SMALLINT));
|
||||
javaTypeToSqlTypeMap.put(Short.class, new Integer(Types.SMALLINT));
|
||||
javaTypeToSqlTypeMap.put(int.class, new Integer(Types.INTEGER));
|
||||
javaTypeToSqlTypeMap.put(Integer.class, new Integer(Types.INTEGER));
|
||||
javaTypeToSqlTypeMap.put(long.class, new Integer(Types.BIGINT));
|
||||
javaTypeToSqlTypeMap.put(Long.class, new Integer(Types.BIGINT));
|
||||
javaTypeToSqlTypeMap.put(BigInteger.class, new Integer(Types.BIGINT));
|
||||
javaTypeToSqlTypeMap.put(float.class, new Integer(Types.FLOAT));
|
||||
javaTypeToSqlTypeMap.put(Float.class, new Integer(Types.FLOAT));
|
||||
javaTypeToSqlTypeMap.put(double.class, new Integer(Types.DOUBLE));
|
||||
javaTypeToSqlTypeMap.put(Double.class, new Integer(Types.DOUBLE));
|
||||
javaTypeToSqlTypeMap.put(BigDecimal.class, new Integer(Types.DECIMAL));
|
||||
javaTypeToSqlTypeMap.put(java.sql.Date.class, new Integer(Types.DATE));
|
||||
javaTypeToSqlTypeMap.put(java.sql.Time.class, new Integer(Types.TIME));
|
||||
javaTypeToSqlTypeMap.put(java.sql.Timestamp.class, new Integer(Types.TIMESTAMP));
|
||||
javaTypeToSqlTypeMap.put(Blob.class, new Integer(Types.BLOB));
|
||||
javaTypeToSqlTypeMap.put(Clob.class, new Integer(Types.CLOB));
|
||||
javaTypeToSqlTypeMap.put(byte.class, Types.TINYINT);
|
||||
javaTypeToSqlTypeMap.put(Byte.class, Types.TINYINT);
|
||||
javaTypeToSqlTypeMap.put(short.class, Types.SMALLINT);
|
||||
javaTypeToSqlTypeMap.put(Short.class, Types.SMALLINT);
|
||||
javaTypeToSqlTypeMap.put(int.class, Types.INTEGER);
|
||||
javaTypeToSqlTypeMap.put(Integer.class, Types.INTEGER);
|
||||
javaTypeToSqlTypeMap.put(long.class, Types.BIGINT);
|
||||
javaTypeToSqlTypeMap.put(Long.class, Types.BIGINT);
|
||||
javaTypeToSqlTypeMap.put(BigInteger.class, Types.BIGINT);
|
||||
javaTypeToSqlTypeMap.put(float.class, Types.FLOAT);
|
||||
javaTypeToSqlTypeMap.put(Float.class, Types.FLOAT);
|
||||
javaTypeToSqlTypeMap.put(double.class, Types.DOUBLE);
|
||||
javaTypeToSqlTypeMap.put(Double.class, Types.DOUBLE);
|
||||
javaTypeToSqlTypeMap.put(BigDecimal.class, Types.DECIMAL);
|
||||
javaTypeToSqlTypeMap.put(java.sql.Date.class, Types.DATE);
|
||||
javaTypeToSqlTypeMap.put(java.sql.Time.class, Types.TIME);
|
||||
javaTypeToSqlTypeMap.put(java.sql.Timestamp.class, Types.TIMESTAMP);
|
||||
javaTypeToSqlTypeMap.put(Blob.class, Types.BLOB);
|
||||
javaTypeToSqlTypeMap.put(Clob.class, Types.CLOB);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,9 +96,9 @@ public abstract class StatementCreatorUtils {
|
||||
* @return the corresponding SQL type, or <code>null</code> if none found
|
||||
*/
|
||||
public static int javaTypeToSqlParameterType(Class javaType) {
|
||||
Integer sqlType = (Integer) javaTypeToSqlTypeMap.get(javaType);
|
||||
Integer sqlType = javaTypeToSqlTypeMap.get(javaType);
|
||||
if (sqlType != null) {
|
||||
return sqlType.intValue();
|
||||
return sqlType;
|
||||
}
|
||||
if (Number.class.isAssignableFrom(javaType)) {
|
||||
return Types.NUMERIC;
|
||||
@@ -273,7 +273,7 @@ public abstract class StatementCreatorUtils {
|
||||
ps.setBigDecimal(paramIndex, (BigDecimal) inValue);
|
||||
}
|
||||
else if (scale != null) {
|
||||
ps.setObject(paramIndex, inValue, sqlType, scale.intValue());
|
||||
ps.setObject(paramIndex, inValue, sqlType, scale);
|
||||
}
|
||||
else {
|
||||
ps.setObject(paramIndex, inValue, sqlType);
|
||||
@@ -394,8 +394,7 @@ public abstract class StatementCreatorUtils {
|
||||
*/
|
||||
public static void cleanupParameters(Collection paramValues) {
|
||||
if (paramValues != null) {
|
||||
for (Iterator it = paramValues.iterator(); it.hasNext();) {
|
||||
Object inValue = it.next();
|
||||
for (Object inValue : paramValues) {
|
||||
if (inValue instanceof DisposableSqlTypeValue) {
|
||||
((DisposableSqlTypeValue) inValue).cleanup();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
||||
* Create a new MapSqlParameterSource based on a Map.
|
||||
* @param values a Map holding existing parameter values (can be <code>null</code>)
|
||||
*/
|
||||
public MapSqlParameterSource(Map<String, Object> values) {
|
||||
public MapSqlParameterSource(Map<String, ?> values) {
|
||||
addValues(values);
|
||||
}
|
||||
|
||||
@@ -128,9 +128,9 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
|
||||
* @return a reference to this parameter source,
|
||||
* so it's possible to chain several calls together
|
||||
*/
|
||||
public MapSqlParameterSource addValues(Map<String, Object> values) {
|
||||
public MapSqlParameterSource addValues(Map<String, ?> values) {
|
||||
if (values != null) {
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
for (Map.Entry<String, ?> entry : values.entrySet()) {
|
||||
this.values.put(entry.getKey(), entry.getValue());
|
||||
if (entry.getValue() instanceof SqlParameterValue) {
|
||||
SqlParameterValue value = (SqlParameterValue) entry.getValue();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -67,7 +67,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action)
|
||||
<T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return a result object returned by the action, or <code>null</code>
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
Object execute(String sql, Map paramMap, PreparedStatementCallback action)
|
||||
<T> T execute(String sql, Map<String, Object> paramMap, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return an arbitrary result object, as returned by the ResultSetExtractor
|
||||
* @throws DataAccessException if the query fails
|
||||
*/
|
||||
Object query(String sql, SqlParameterSource paramSource, ResultSetExtractor rse)
|
||||
<T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,8 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return an arbitrary result object, as returned by the ResultSetExtractor
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
*/
|
||||
Object query(String sql, Map paramMap, ResultSetExtractor rse) throws DataAccessException;
|
||||
<T> T query(String sql, Map<String, Object> paramMap, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a list of
|
||||
@@ -136,7 +137,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @param rch object that will extract results, one row at a time
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
*/
|
||||
void query(String sql, Map paramMap, RowCallbackHandler rch) throws DataAccessException;
|
||||
void query(String sql, Map<String, Object> paramMap, RowCallbackHandler rch) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a list
|
||||
@@ -148,7 +149,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return the result List, containing mapped objects
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
*/
|
||||
List query(String sql, SqlParameterSource paramSource, RowMapper rowMapper)
|
||||
<T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -162,7 +163,8 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return the result List, containing mapped objects
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
*/
|
||||
List query(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException;
|
||||
<T> List<T> query(String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a list
|
||||
@@ -177,7 +179,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* one column in that row
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
*/
|
||||
Object queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper)
|
||||
<T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -194,7 +196,8 @@ public interface NamedParameterJdbcOperations {
|
||||
* one column in that row
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
*/
|
||||
Object queryForObject(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException;
|
||||
<T> T queryForObject(String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -211,7 +214,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
|
||||
*/
|
||||
Object queryForObject(String sql, SqlParameterSource paramSource, Class requiredType)
|
||||
<T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -230,7 +233,8 @@ public interface NamedParameterJdbcOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
|
||||
*/
|
||||
Object queryForObject(String sql, Map paramMap, Class requiredType) throws DataAccessException;
|
||||
<T> T queryForObject(String sql, Map<String, Object> paramMap, Class<T> requiredType)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -247,7 +251,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
|
||||
* @see org.springframework.jdbc.core.ColumnMapRowMapper
|
||||
*/
|
||||
Map queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException;
|
||||
Map<String, Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -268,7 +272,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
|
||||
* @see org.springframework.jdbc.core.ColumnMapRowMapper
|
||||
*/
|
||||
Map queryForMap(String sql, Map paramMap) throws DataAccessException;
|
||||
Map<String, Object> queryForMap(String sql, Map<String, Object> paramMap) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -301,7 +305,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForLong(String)
|
||||
*/
|
||||
long queryForLong(String sql, Map paramMap) throws DataAccessException;
|
||||
long queryForLong(String sql, Map<String, Object> paramMap) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -332,7 +336,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForInt(String)
|
||||
*/
|
||||
int queryForInt(String sql, Map paramMap) throws DataAccessException;
|
||||
int queryForInt(String sql, Map<String, Object> paramMap) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -348,7 +352,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class)
|
||||
* @see org.springframework.jdbc.core.SingleColumnRowMapper
|
||||
*/
|
||||
List queryForList(String sql, SqlParameterSource paramSource, Class elementType)
|
||||
<T> List<T> queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -366,7 +370,8 @@ public interface NamedParameterJdbcOperations {
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String, Class)
|
||||
* @see org.springframework.jdbc.core.SingleColumnRowMapper
|
||||
*/
|
||||
List queryForList(String sql, Map paramMap, Class elementType) throws DataAccessException;
|
||||
<T> List<T> queryForList(String sql, Map<String, Object> paramMap, Class<T> elementType)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -381,7 +386,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String)
|
||||
*/
|
||||
List queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException;
|
||||
List<Map<String, Object>> queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -397,7 +402,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if the query fails
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate#queryForList(String)
|
||||
*/
|
||||
List queryForList(String sql, Map paramMap) throws DataAccessException;
|
||||
List<Map<String, Object>> queryForList(String sql, Map<String, Object> paramMap) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given SQL to create a prepared statement from SQL and a
|
||||
@@ -438,7 +443,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @see org.springframework.jdbc.core.SqlRowSetResultSetExtractor
|
||||
* @see javax.sql.rowset.CachedRowSet
|
||||
*/
|
||||
SqlRowSet queryForRowSet(String sql, Map paramMap) throws DataAccessException;
|
||||
SqlRowSet queryForRowSet(String sql, Map<String, Object> paramMap) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Issue an update via a prepared statement, binding the given arguments.
|
||||
@@ -457,7 +462,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @return the number of rows affected
|
||||
* @throws org.springframework.dao.DataAccessException if there is any problem issuing the update
|
||||
*/
|
||||
int update(String sql, Map paramMap) throws DataAccessException;
|
||||
int update(String sql, Map<String, Object> paramMap) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Issue an update via a prepared statement, binding the given arguments,
|
||||
@@ -485,8 +490,7 @@ public interface NamedParameterJdbcOperations {
|
||||
* @see MapSqlParameterSource
|
||||
* @see org.springframework.jdbc.support.GeneratedKeyHolder
|
||||
*/
|
||||
int update(
|
||||
String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)
|
||||
int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)
|
||||
throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -64,7 +64,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
||||
private final JdbcOperations classicJdbcTemplate;
|
||||
|
||||
/** Map of original SQL String to ParsedSql representation */
|
||||
private final Map parsedSqlCache = new HashMap();
|
||||
private final Map<String, ParsedSql> parsedSqlCache = new HashMap<String, ParsedSql>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -97,23 +97,27 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
||||
}
|
||||
|
||||
|
||||
public Object execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action)
|
||||
public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException {
|
||||
|
||||
return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action);
|
||||
}
|
||||
|
||||
public Object execute(String sql, Map paramMap, PreparedStatementCallback action) throws DataAccessException {
|
||||
public <T> T execute(String sql, Map<String, Object> paramMap, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException {
|
||||
|
||||
return execute(sql, new MapSqlParameterSource(paramMap), action);
|
||||
}
|
||||
|
||||
public Object query(String sql, SqlParameterSource paramSource, ResultSetExtractor rse)
|
||||
public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException {
|
||||
|
||||
return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse);
|
||||
}
|
||||
|
||||
public Object query(String sql, Map paramMap, ResultSetExtractor rse) throws DataAccessException {
|
||||
public <T> T query(String sql, Map<String, Object> paramMap, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException {
|
||||
|
||||
return query(sql, new MapSqlParameterSource(paramMap), rse);
|
||||
}
|
||||
|
||||
@@ -123,90 +127,105 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
||||
getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rch);
|
||||
}
|
||||
|
||||
public void query(String sql, Map paramMap, RowCallbackHandler rch) throws DataAccessException {
|
||||
public void query(String sql, Map<String, Object> paramMap, RowCallbackHandler rch)
|
||||
throws DataAccessException {
|
||||
|
||||
query(sql, new MapSqlParameterSource(paramMap), rch);
|
||||
}
|
||||
|
||||
public List query(String sql, SqlParameterSource paramSource, RowMapper rowMapper)
|
||||
public <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
|
||||
throws DataAccessException {
|
||||
|
||||
return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
|
||||
}
|
||||
|
||||
public List query(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException {
|
||||
public <T> List<T> query(String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper)
|
||||
throws DataAccessException {
|
||||
|
||||
return query(sql, new MapSqlParameterSource(paramMap), rowMapper);
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper)
|
||||
public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
|
||||
throws DataAccessException {
|
||||
|
||||
List results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
|
||||
List<T> results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
|
||||
return DataAccessUtils.requiredSingleResult(results);
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException {
|
||||
public <T> T queryForObject(String sql, Map<String, Object> paramMap, RowMapper<T>rowMapper)
|
||||
throws DataAccessException {
|
||||
|
||||
return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper);
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, SqlParameterSource paramSource, Class requiredType)
|
||||
public <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
|
||||
throws DataAccessException {
|
||||
|
||||
return queryForObject(sql, paramSource, new SingleColumnRowMapper(requiredType));
|
||||
return queryForObject(sql, paramSource, new SingleColumnRowMapper<T>(requiredType));
|
||||
}
|
||||
|
||||
public Object queryForObject(String sql, Map paramMap, Class requiredType) throws DataAccessException {
|
||||
return queryForObject(sql, paramMap, new SingleColumnRowMapper(requiredType));
|
||||
public <T> T queryForObject(String sql, Map<String, Object> paramMap, Class<T> requiredType)
|
||||
throws DataAccessException {
|
||||
|
||||
return queryForObject(sql, paramMap, new SingleColumnRowMapper<T>(requiredType));
|
||||
}
|
||||
|
||||
public Map queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
return (Map) queryForObject(sql, paramSource, new ColumnMapRowMapper());
|
||||
public Map<String, Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
return queryForObject(sql, paramSource, new ColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public Map queryForMap(String sql, Map paramMap) throws DataAccessException {
|
||||
return (Map) queryForObject(sql, paramMap, new ColumnMapRowMapper());
|
||||
public Map<String, Object> queryForMap(String sql, Map<String, Object> paramMap) throws DataAccessException {
|
||||
return queryForObject(sql, paramMap, new ColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public long queryForLong(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, paramSource, Number.class);
|
||||
Number number = queryForObject(sql, paramSource, Number.class);
|
||||
return (number != null ? number.longValue() : 0);
|
||||
}
|
||||
|
||||
public long queryForLong(String sql, Map paramMap) throws DataAccessException {
|
||||
public long queryForLong(String sql, Map<String, Object> paramMap) throws DataAccessException {
|
||||
return queryForLong(sql, new MapSqlParameterSource(paramMap));
|
||||
}
|
||||
|
||||
public int queryForInt(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
Number number = (Number) queryForObject(sql, paramSource, Number.class);
|
||||
Number number = queryForObject(sql, paramSource, Number.class);
|
||||
return (number != null ? number.intValue() : 0);
|
||||
}
|
||||
|
||||
public int queryForInt(String sql, Map paramMap) throws DataAccessException {
|
||||
public int queryForInt(String sql, Map<String, Object> paramMap) throws DataAccessException {
|
||||
return queryForInt(sql, new MapSqlParameterSource(paramMap));
|
||||
}
|
||||
|
||||
public List queryForList(String sql, SqlParameterSource paramSource, Class elementType)
|
||||
public <T> List<T> queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType)
|
||||
throws DataAccessException {
|
||||
return query(sql, paramSource, new SingleColumnRowMapper(elementType));
|
||||
|
||||
return query(sql, paramSource, new SingleColumnRowMapper<T>(elementType));
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Map paramMap, Class elementType) throws DataAccessException {
|
||||
public <T> List<T> queryForList(String sql, Map<String, Object> paramMap, Class<T> elementType)
|
||||
throws DataAccessException {
|
||||
|
||||
return queryForList(sql, new MapSqlParameterSource(paramMap), elementType);
|
||||
}
|
||||
|
||||
public List queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
public List<Map<String, Object>> queryForList(String sql, SqlParameterSource paramSource)
|
||||
throws DataAccessException {
|
||||
|
||||
return query(sql, paramSource, new ColumnMapRowMapper());
|
||||
}
|
||||
|
||||
public List queryForList(String sql, Map paramMap) throws DataAccessException {
|
||||
public List<Map<String, Object>> queryForList(String sql, Map<String, Object> paramMap)
|
||||
throws DataAccessException {
|
||||
|
||||
return queryForList(sql, new MapSqlParameterSource(paramMap));
|
||||
}
|
||||
|
||||
public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
return (SqlRowSet) getJdbcOperations().query(
|
||||
return getJdbcOperations().query(
|
||||
getPreparedStatementCreator(sql, paramSource), new SqlRowSetResultSetExtractor());
|
||||
}
|
||||
|
||||
public SqlRowSet queryForRowSet(String sql, Map paramMap) throws DataAccessException {
|
||||
public SqlRowSet queryForRowSet(String sql, Map<String, Object> paramMap) throws DataAccessException {
|
||||
return queryForRowSet(sql, new MapSqlParameterSource(paramMap));
|
||||
}
|
||||
|
||||
@@ -214,7 +233,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
||||
return getJdbcOperations().update(getPreparedStatementCreator(sql, paramSource));
|
||||
}
|
||||
|
||||
public int update(String sql, Map paramMap) throws DataAccessException {
|
||||
public int update(String sql, Map<String, Object> paramMap) throws DataAccessException {
|
||||
return update(sql, new MapSqlParameterSource(paramMap));
|
||||
}
|
||||
|
||||
@@ -266,7 +285,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
||||
*/
|
||||
protected ParsedSql getParsedSql(String sql) {
|
||||
synchronized (this.parsedSqlCache) {
|
||||
ParsedSql parsedSql = (ParsedSql) this.parsedSqlCache.get(sql);
|
||||
ParsedSql parsedSql = this.parsedSqlCache.get(sql);
|
||||
if (parsedSql == null) {
|
||||
parsedSql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
this.parsedSqlCache.put(sql, parsedSql);
|
||||
|
||||
@@ -191,7 +191,7 @@ public abstract class NamedParameterUtils {
|
||||
*/
|
||||
public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameterSource paramSource) {
|
||||
String originalSql = parsedSql.getOriginalSql();
|
||||
StringBuffer actualSql = new StringBuffer();
|
||||
StringBuilder actualSql = new StringBuilder();
|
||||
List paramNames = parsedSql.getParameterNames();
|
||||
int lastIndex = 0;
|
||||
for (int i = 0; i < paramNames.size(); i++) {
|
||||
@@ -379,7 +379,7 @@ public abstract class NamedParameterUtils {
|
||||
* @param paramMap the Map of parameters
|
||||
* @return the array of values
|
||||
*/
|
||||
public static Object[] buildValueArray(String sql, Map paramMap) {
|
||||
public static Object[] buildValueArray(String sql, Map<String, ?> paramMap) {
|
||||
ParsedSql parsedSql = parseSqlStatement(sql);
|
||||
return buildValueArray(parsedSql, new MapSqlParameterSource(paramMap), null);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.jdbc.core.simple;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
|
||||
/**
|
||||
@@ -49,25 +46,9 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
* @since 2.5
|
||||
* @see ParameterizedRowMapper
|
||||
*/
|
||||
public class ParameterizedBeanPropertyRowMapper<T> extends BeanPropertyRowMapper
|
||||
public class ParameterizedBeanPropertyRowMapper<T> extends BeanPropertyRowMapper<T>
|
||||
implements ParameterizedRowMapper<T> {
|
||||
|
||||
/**
|
||||
* Create a new ParameterizedBeanPropertyRowMapper.
|
||||
* <p>Generally prefer the {@link #newInstance(Class)} method instead,
|
||||
* which avoids the need for specifying the mapped type twice.
|
||||
* @see #setMappedClass
|
||||
*/
|
||||
public ParameterizedBeanPropertyRowMapper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
|
||||
return (T) super.mapRow(rs, rowNumber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static factory method to create a new ParameterizedBeanPropertyRowMapper
|
||||
* (with the mapped class specified only once).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,28 +16,18 @@
|
||||
|
||||
package org.springframework.jdbc.core.simple;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* Extension of the {@link org.springframework.jdbc.core.RowMapper} interface,
|
||||
* adding type parameterization. Uses Java 5 covariant return types to override
|
||||
* the return type of the {@link #mapRow} method to be the type parameter
|
||||
* <code>T</code>.
|
||||
* 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
|
||||
*/
|
||||
public interface ParameterizedRowMapper<T> extends RowMapper {
|
||||
|
||||
/**
|
||||
* Implementations should return the object representation of
|
||||
* the current row in the supplied {@link ResultSet}.
|
||||
* @see org.springframework.jdbc.core.RowMapper#mapRow
|
||||
*/
|
||||
T mapRow(ResultSet rs, int rowNum) throws SQLException;
|
||||
public interface ParameterizedRowMapper<T> extends RowMapper<T> {
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.jdbc.core.simple;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.core.SingleColumnRowMapper;
|
||||
|
||||
/**
|
||||
@@ -36,25 +33,9 @@ import org.springframework.jdbc.core.SingleColumnRowMapper;
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5.2
|
||||
*/
|
||||
public class ParameterizedSingleColumnRowMapper<T> extends SingleColumnRowMapper
|
||||
public class ParameterizedSingleColumnRowMapper<T> extends SingleColumnRowMapper<T>
|
||||
implements ParameterizedRowMapper<T> {
|
||||
|
||||
/**
|
||||
* Create a new ParameterizedSingleColumnRowMapper.
|
||||
* <p>Generally prefer the {@link #newInstance(Class)} method instead,
|
||||
* which avoids the need for specifying the mapped type twice.
|
||||
* @see #setRequiredType
|
||||
*/
|
||||
public ParameterizedSingleColumnRowMapper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
|
||||
return (T) super.mapRow(rs, rowNumber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static factory method to create a new ParameterizedSingleColumnRowMapper
|
||||
* (with the required type specified only once).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -58,9 +58,9 @@ public interface SimpleJdbcOperations {
|
||||
* {@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.
|
||||
* @param args the map containing the arguments for the query
|
||||
*/
|
||||
int queryForInt(String sql, Map args) throws DataAccessException;
|
||||
int queryForInt(String sql, Map<String, Object> args) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query for an <code>int</code> passing in a SQL query
|
||||
@@ -77,7 +77,7 @@ public interface SimpleJdbcOperations {
|
||||
* 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.
|
||||
* @param args the variable number of arguments for the query
|
||||
*/
|
||||
int queryForInt(String sql, Object... args) throws DataAccessException;
|
||||
|
||||
@@ -87,9 +87,9 @@ public interface SimpleJdbcOperations {
|
||||
* {@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.
|
||||
* @param args the map containing the arguments for the query
|
||||
*/
|
||||
long queryForLong(String sql, Map args) throws DataAccessException;
|
||||
long queryForLong(String sql, Map<String, Object> args) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query for an <code>long</code> passing in a SQL query
|
||||
@@ -97,7 +97,7 @@ public interface SimpleJdbcOperations {
|
||||
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
|
||||
* and a <code>SqlParameterSource</code> containing the arguments.
|
||||
* @param sql the SQL query to run.
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query.
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query
|
||||
*/
|
||||
long queryForLong(String sql, SqlParameterSource args) throws DataAccessException;
|
||||
|
||||
@@ -106,7 +106,7 @@ public interface SimpleJdbcOperations {
|
||||
* 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.
|
||||
* @param args the variable number of arguments for the query
|
||||
*/
|
||||
long queryForLong(String sql, Object... args) throws DataAccessException;
|
||||
|
||||
@@ -114,22 +114,22 @@ public interface SimpleJdbcOperations {
|
||||
* Query for an object of type <code>T</code> 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.
|
||||
* @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 args)
|
||||
<T> T queryForObject(String sql, Class<T> requiredType, Map<String, Object> args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query for an object of type <code>T</code> 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</code> containing the arguments for the query.
|
||||
* @param sql the SQL query to run
|
||||
* @param requiredType the required type of the return value
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query
|
||||
* @see JdbcOperations#queryForObject(String, Class)
|
||||
* @see JdbcOperations#queryForObject(String, Object[], Class)
|
||||
*/
|
||||
@@ -139,9 +139,9 @@ public interface SimpleJdbcOperations {
|
||||
/**
|
||||
* Query for an object of type <code>T</code> 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.
|
||||
* @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)
|
||||
*/
|
||||
@@ -153,13 +153,13 @@ public interface SimpleJdbcOperations {
|
||||
* {@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 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.
|
||||
* @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, ParameterizedRowMapper<T> rm, Map args)
|
||||
<T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -167,9 +167,9 @@ public interface SimpleJdbcOperations {
|
||||
* {@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 sql the SQL query to run
|
||||
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query.
|
||||
* @param args the <code>SqlParameterSource</code> 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)
|
||||
*/
|
||||
@@ -180,9 +180,9 @@ public interface SimpleJdbcOperations {
|
||||
* Query for an object of type <code>T</code> 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 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.
|
||||
* @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)
|
||||
*/
|
||||
@@ -194,13 +194,13 @@ public interface SimpleJdbcOperations {
|
||||
* 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 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.
|
||||
* @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, ParameterizedRowMapper<T> rm, Map args)
|
||||
<T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -208,9 +208,9 @@ public interface SimpleJdbcOperations {
|
||||
* 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 sql the SQL query to run
|
||||
* @param rm the @{@link ParameterizedRowMapper} to use for result mapping
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query.
|
||||
* @param args the <code>SqlParameterSource</code> 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)
|
||||
*/
|
||||
@@ -221,9 +221,9 @@ public interface SimpleJdbcOperations {
|
||||
* Query for a {@link List} of <code>Objects</code> of type <code>T</code> 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 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.
|
||||
* @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)
|
||||
*/
|
||||
@@ -233,25 +233,25 @@ public interface SimpleJdbcOperations {
|
||||
/**
|
||||
* 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 (one entry for each column, using the column name as the key).
|
||||
* 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.
|
||||
* @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 args)
|
||||
Map<String, Object> queryForMap(String sql, Map<String, 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 (one entry for each column, using the column name as the key).
|
||||
* 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</code> containing the arguments for the query.
|
||||
* @param sql the SQL query to run
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query
|
||||
* @see JdbcOperations#queryForMap(String)
|
||||
* @see JdbcOperations#queryForMap(String, Object[])
|
||||
*/
|
||||
@@ -261,10 +261,10 @@ public interface SimpleJdbcOperations {
|
||||
/**
|
||||
* 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 (one entry for each column, using the column name as the key).
|
||||
* 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.
|
||||
* @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[])
|
||||
*/
|
||||
@@ -277,12 +277,12 @@ public interface SimpleJdbcOperations {
|
||||
* 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.
|
||||
* @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 args)
|
||||
List<Map<String, Object>> queryForList(String sql, Map<String, Object> args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -291,8 +291,8 @@ public interface SimpleJdbcOperations {
|
||||
* 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</code> containing the arguments for the query.
|
||||
* @param sql the SQL query to run
|
||||
* @param args the <code>SqlParameterSource</code> containing the arguments for the query
|
||||
* @see JdbcOperations#queryForList(String)
|
||||
* @see JdbcOperations#queryForList(String, Object[])
|
||||
*/
|
||||
@@ -304,8 +304,8 @@ public interface SimpleJdbcOperations {
|
||||
* <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.
|
||||
* @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[])
|
||||
*/
|
||||
@@ -316,20 +316,20 @@ public interface SimpleJdbcOperations {
|
||||
* 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.
|
||||
* @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 args) throws DataAccessException;
|
||||
int update(String sql, Map<String, Object> 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</code> containing the arguments for the statement.
|
||||
* @return the numbers of rows affected by the update.
|
||||
* @param sql the SQL statement to execute
|
||||
* @param args the <code>SqlParameterSource</code> 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;
|
||||
@@ -337,9 +337,9 @@ public interface SimpleJdbcOperations {
|
||||
/**
|
||||
* 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.
|
||||
* @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[])
|
||||
*/
|
||||
@@ -348,27 +348,27 @@ public interface SimpleJdbcOperations {
|
||||
/**
|
||||
* 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.
|
||||
* @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[] batchValues);
|
||||
public int[] batchUpdate(String sql, Map<String, Object>[] 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.
|
||||
* @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.
|
||||
* @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);
|
||||
|
||||
@@ -376,10 +376,10 @@ public interface SimpleJdbcOperations {
|
||||
* 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 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</code>)
|
||||
* @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, List<Object[]> batchArgs, int[] argTypes);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -107,7 +107,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
}
|
||||
|
||||
|
||||
public int queryForInt(String sql, Map args) throws DataAccessException {
|
||||
public int queryForInt(String sql, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().queryForInt(sql, args);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
getJdbcOperations().queryForInt(sql, getArguments(args)));
|
||||
}
|
||||
|
||||
public long queryForLong(String sql, Map args) throws DataAccessException {
|
||||
public long queryForLong(String sql, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().queryForLong(sql, args);
|
||||
}
|
||||
|
||||
@@ -136,61 +136,61 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T queryForObject(String sql, Class<T> requiredType, Map args) throws DataAccessException {
|
||||
return (T) getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
|
||||
public <T> T queryForObject(String sql, Class<T> requiredType, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T queryForObject(String sql, Class<T> requiredType, SqlParameterSource args)
|
||||
throws DataAccessException {
|
||||
return (T) getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
|
||||
return getNamedParameterJdbcOperations().queryForObject(sql, args, requiredType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws DataAccessException {
|
||||
return (T) (ObjectUtils.isEmpty(args) ?
|
||||
return (ObjectUtils.isEmpty(args) ?
|
||||
getJdbcOperations().queryForObject(sql, requiredType) :
|
||||
getJdbcOperations().queryForObject(sql, getArguments(args), requiredType));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map args) throws DataAccessException {
|
||||
return (T) getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
|
||||
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
|
||||
throws DataAccessException {
|
||||
return (T) getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
|
||||
return getNamedParameterJdbcOperations().queryForObject(sql, args, rm);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException {
|
||||
return (T) (ObjectUtils.isEmpty(args) ?
|
||||
return (ObjectUtils.isEmpty(args) ?
|
||||
getJdbcOperations().queryForObject(sql, rm):
|
||||
getJdbcOperations().queryForObject(sql, getArguments(args), rm));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map args) throws DataAccessException {
|
||||
return (List<T>) getNamedParameterJdbcOperations().query(sql, args, rm);
|
||||
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().query(sql, args, rm);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, SqlParameterSource args)
|
||||
throws DataAccessException {
|
||||
return (List<T>) getNamedParameterJdbcOperations().query(sql, args, rm);
|
||||
return getNamedParameterJdbcOperations().query(sql, args, rm);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException {
|
||||
return (List<T>) (ObjectUtils.isEmpty(args) ?
|
||||
return (ObjectUtils.isEmpty(args) ?
|
||||
getJdbcOperations().query(sql, rm) :
|
||||
getJdbcOperations().query(sql, getArguments(args), rm));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> queryForMap(String sql, Map args) throws DataAccessException {
|
||||
public Map<String, Object> queryForMap(String sql, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().queryForMap(sql, args);
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Map<String, Object>> queryForList(String sql, Map args) throws DataAccessException {
|
||||
public List<Map<String, Object>> queryForList(String sql, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().queryForList(sql, args);
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
getJdbcOperations().queryForList(sql, getArguments(args)));
|
||||
}
|
||||
|
||||
public int update(String sql, Map args) throws DataAccessException {
|
||||
public int update(String sql, Map<String, Object> args) throws DataAccessException {
|
||||
return getNamedParameterJdbcOperations().update(sql, args);
|
||||
}
|
||||
|
||||
@@ -247,10 +247,10 @@ public class SimpleJdbcTemplate implements SimpleJdbcOperations {
|
||||
return doExecuteBatchUpdate(sql, batchArgs, argTypes);
|
||||
}
|
||||
|
||||
public int[] batchUpdate(String sql, Map[] batchValues) {
|
||||
public int[] batchUpdate(String sql, Map<String, Object>[] batchValues) {
|
||||
SqlParameterSource[] batchArgs = new SqlParameterSource[batchValues.length];
|
||||
int i = 0;
|
||||
for (Map values : batchValues) {
|
||||
for (Map<String, Object> values : batchValues) {
|
||||
batchArgs[i] = new MapSqlParameterSource(values);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
@@ -35,7 +35,7 @@ import org.springframework.jdbc.core.SqlTypeValue;
|
||||
* <pre class="code">proc.declareParameter(new SqlParameter("myarray", Types.ARRAY, "NUMBERS"));
|
||||
* ...
|
||||
*
|
||||
* Map in = new HashMap();
|
||||
* Map<String, Object> in = new HashMap<String, Object>();
|
||||
* in.put("myarray", new AbstractSqlTypeValue() {
|
||||
* public Object createTypeValue(Connection con, int sqlType, String typeName) throws SQLException {
|
||||
* oracle.sql.ArrayDescriptor desc = new oracle.sql.ArrayDescriptor(typeName, con);
|
||||
|
||||
@@ -188,12 +188,12 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
|
||||
}
|
||||
else if (method.getName().equals("toString")) {
|
||||
// Allow for differentiating between the proxy and the raw Connection.
|
||||
StringBuffer buf = new StringBuffer("Transaction-aware proxy for target Connection ");
|
||||
StringBuilder sb = new StringBuilder("Transaction-aware proxy for target Connection ");
|
||||
if (this.target != null) {
|
||||
buf.append("[").append(this.target.toString()).append("]");
|
||||
sb.append("[").append(this.target.toString()).append("]");
|
||||
}
|
||||
else {
|
||||
buf.append(" from DataSource [").append(this.targetDataSource).append("]");
|
||||
sb.append(" from DataSource [").append(this.targetDataSource).append("]");
|
||||
}
|
||||
}
|
||||
else if (method.getName().equals("close")) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.jdbc.datasource.lookup;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
@@ -37,7 +36,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MapDataSourceLookup implements DataSourceLookup {
|
||||
|
||||
private final Map dataSources = new HashMap(4);
|
||||
private final Map<String, DataSource> dataSources = new HashMap<String, DataSource>(4);
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,7 +50,7 @@ public class MapDataSourceLookup implements DataSourceLookup {
|
||||
* @param dataSources the {@link Map} of {@link DataSource DataSources}; the keys
|
||||
* are {@link String Strings}, the values are actual {@link DataSource} instances.
|
||||
*/
|
||||
public MapDataSourceLookup(Map dataSources) {
|
||||
public MapDataSourceLookup(Map<String, DataSource> dataSources) {
|
||||
setDataSources(dataSources);
|
||||
}
|
||||
|
||||
@@ -72,7 +71,7 @@ public class MapDataSourceLookup implements DataSourceLookup {
|
||||
* call effectively has no effect.
|
||||
* @param dataSources said {@link Map} of {@link DataSource DataSources}
|
||||
*/
|
||||
public void setDataSources(Map dataSources) {
|
||||
public void setDataSources(Map<String, DataSource> dataSources) {
|
||||
if (dataSources != null) {
|
||||
this.dataSources.putAll(dataSources);
|
||||
}
|
||||
@@ -83,7 +82,7 @@ public class MapDataSourceLookup implements DataSourceLookup {
|
||||
* <p>The returned {@link Map} is {@link Collections#unmodifiableMap(java.util.Map) unmodifiable}.
|
||||
* @return said {@link Map} of {@link DataSource DataSources} (never <code>null</code>)
|
||||
*/
|
||||
public Map getDataSources() {
|
||||
public Map<String, DataSource> getDataSources() {
|
||||
return Collections.unmodifiableMap(this.dataSources);
|
||||
}
|
||||
|
||||
@@ -101,17 +100,12 @@ public class MapDataSourceLookup implements DataSourceLookup {
|
||||
|
||||
public DataSource getDataSource(String dataSourceName) throws DataSourceLookupFailureException {
|
||||
Assert.notNull(dataSourceName, "DataSource name must not be null");
|
||||
Object value = this.dataSources.get(dataSourceName);
|
||||
if (value == null) {
|
||||
DataSource dataSource = this.dataSources.get(dataSourceName);
|
||||
if (dataSource == null) {
|
||||
throw new DataSourceLookupFailureException(
|
||||
"No DataSource with name '" + dataSourceName + "' registered");
|
||||
}
|
||||
if (!(value instanceof DataSource)) {
|
||||
throw new DataSourceLookupFailureException(
|
||||
"The object [" + value + "] with name '" + dataSourceName +
|
||||
"' in the DataSource map is not a [javax.sql.DataSource]");
|
||||
}
|
||||
return (DataSource) value;
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
@@ -38,21 +38,21 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
*/
|
||||
public class GeneratedKeyHolder implements KeyHolder {
|
||||
|
||||
private final List keyList;
|
||||
private final List<Map<String, Object>> keyList;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new GeneratedKeyHolder with a default list.
|
||||
*/
|
||||
public GeneratedKeyHolder() {
|
||||
this.keyList = new LinkedList();
|
||||
this.keyList = new LinkedList<Map<String, Object>>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GeneratedKeyHolder with a given list.
|
||||
* @param keyList a list to hold maps of keys
|
||||
*/
|
||||
public GeneratedKeyHolder(List keyList) {
|
||||
public GeneratedKeyHolder(List<Map<String, Object>> keyList) {
|
||||
this.keyList = keyList;
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ public class GeneratedKeyHolder implements KeyHolder {
|
||||
if (this.keyList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (this.keyList.size() > 1 || ((Map) this.keyList.get(0)).size() > 1) {
|
||||
if (this.keyList.size() > 1 || this.keyList.get(0).size() > 1) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"The getKey method should only be used when a single key is returned. " +
|
||||
"The current key entry contains multiple keys: " + this.keyList);
|
||||
}
|
||||
Iterator keyIter = ((Map) this.keyList.get(0)).values().iterator();
|
||||
Iterator<Object> keyIter = this.keyList.get(0).values().iterator();
|
||||
if (keyIter.hasNext()) {
|
||||
Object key = keyIter.next();
|
||||
if (!(key instanceof Number)) {
|
||||
@@ -83,7 +83,7 @@ public class GeneratedKeyHolder implements KeyHolder {
|
||||
}
|
||||
}
|
||||
|
||||
public Map getKeys() throws InvalidDataAccessApiUsageException {
|
||||
public Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException {
|
||||
if (this.keyList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -91,10 +91,10 @@ public class GeneratedKeyHolder implements KeyHolder {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"The getKeys method should only be used when keys for a single row are returned. " +
|
||||
"The current key list contains keys for multiple rows: " + this.keyList);
|
||||
return (Map) this.keyList.get(0);
|
||||
return this.keyList.get(0);
|
||||
}
|
||||
|
||||
public List getKeyList() {
|
||||
public List<Map<String, Object>> getKeyList() {
|
||||
return this.keyList;
|
||||
}
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ public abstract class JdbcUtils {
|
||||
* @return the name using "camel case"
|
||||
*/
|
||||
public static String convertUnderscoreNameToPropertyName(String name) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean nextIsUpper = false;
|
||||
if (name != null && name.length() > 0) {
|
||||
if (name.length() > 1 && name.substring(1,2).equals("_")) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -35,6 +35,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
* usual type for auto-generated keys.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.1
|
||||
* @see org.springframework.jdbc.core.JdbcTemplate
|
||||
* @see org.springframework.jdbc.object.SqlUpdate
|
||||
@@ -62,7 +63,7 @@ public interface KeyHolder {
|
||||
* @return the Map of generated keys
|
||||
* @throws InvalidDataAccessApiUsageException if keys for multiple rows are encountered
|
||||
*/
|
||||
Map getKeys() throws InvalidDataAccessApiUsageException;
|
||||
Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException;
|
||||
|
||||
/**
|
||||
* Return a reference to the List that contains the keys.
|
||||
@@ -71,6 +72,6 @@ public interface KeyHolder {
|
||||
* @return the List for the generated keys, with each entry being a Map
|
||||
* of column names and key values
|
||||
*/
|
||||
List getKeyList();
|
||||
List<Map<String, Object>> getKeyList();
|
||||
|
||||
}
|
||||
|
||||
@@ -129,12 +129,12 @@ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldM
|
||||
String s = Long.toString(getNextKey());
|
||||
int len = s.length();
|
||||
if (len < this.paddingLength) {
|
||||
StringBuffer buf = new StringBuffer(this.paddingLength);
|
||||
StringBuilder sb = new StringBuilder(this.paddingLength);
|
||||
for (int i = 0; i < this.paddingLength - len; i++) {
|
||||
buf.append('0');
|
||||
sb.append('0');
|
||||
}
|
||||
buf.append(s);
|
||||
s = buf.toString();
|
||||
sb.append(s);
|
||||
s = sb.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user