Fixed extractOutputParameters to properly extract ResultSet in all cases

Issue: SPR-11076
This commit is contained in:
Juergen Hoeller 2013-12-11 12:28:54 +01:00
parent ccafccbec8
commit 3ff3805ed6
2 changed files with 36 additions and 31 deletions

View File

@ -35,7 +35,6 @@ import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
@ -1199,28 +1198,29 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @param resultSetParameters Parameter list of declared resultSet parameters for the stored procedure * @param resultSetParameters Parameter list of declared resultSet parameters for the stored procedure
* @return Map that contains returned results * @return Map that contains returned results
*/ */
@SuppressWarnings("rawtypes") protected Map<String, Object> extractReturnedResults(CallableStatement cs,
protected Map<String, Object> extractReturnedResults( List<SqlParameter> updateCountParameters, List<SqlParameter> resultSetParameters, int updateCount)
CallableStatement cs, List updateCountParameters, List resultSetParameters, int updateCount)
throws SQLException { throws SQLException {
Map<String, Object> returnedResults = new HashMap<String, Object>(); Map<String, Object> returnedResults = new HashMap<String, Object>();
int rsIndex = 0; int rsIndex = 0;
int updateIndex = 0; int updateIndex = 0;
boolean moreResults; boolean moreResults;
if (!skipResultsProcessing) { if (!this.skipResultsProcessing) {
do { do {
if (updateCount == -1) { if (updateCount == -1) {
if (resultSetParameters != null && resultSetParameters.size() > rsIndex) { if (resultSetParameters != null && resultSetParameters.size() > rsIndex) {
SqlReturnResultSet declaredRsParam = (SqlReturnResultSet)resultSetParameters.get(rsIndex); SqlReturnResultSet declaredRsParam = (SqlReturnResultSet) resultSetParameters.get(rsIndex);
returnedResults.putAll(processResultSet(cs.getResultSet(), declaredRsParam)); returnedResults.putAll(processResultSet(cs.getResultSet(), declaredRsParam));
rsIndex++; rsIndex++;
} }
else { else {
if (!skipUndeclaredResults) { if (!this.skipUndeclaredResults) {
String rsName = RETURN_RESULT_SET_PREFIX + (rsIndex + 1); String rsName = RETURN_RESULT_SET_PREFIX + (rsIndex + 1);
SqlReturnResultSet undeclaredRsParam = new SqlReturnResultSet(rsName, new ColumnMapRowMapper()); SqlReturnResultSet undeclaredRsParam = new SqlReturnResultSet(rsName, new ColumnMapRowMapper());
logger.info("Added default SqlReturnResultSet parameter named " + rsName); if (logger.isDebugEnabled()) {
logger.debug("Added default SqlReturnResultSet parameter named '" + rsName + "'");
}
returnedResults.putAll(processResultSet(cs.getResultSet(), undeclaredRsParam)); returnedResults.putAll(processResultSet(cs.getResultSet(), undeclaredRsParam));
rsIndex++; rsIndex++;
} }
@ -1228,16 +1228,18 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
} }
else { else {
if (updateCountParameters != null && updateCountParameters.size() > updateIndex) { if (updateCountParameters != null && updateCountParameters.size() > updateIndex) {
SqlReturnUpdateCount ucParam = (SqlReturnUpdateCount)updateCountParameters.get(updateIndex); SqlReturnUpdateCount ucParam = (SqlReturnUpdateCount) updateCountParameters.get(updateIndex);
String declaredUcName = ucParam.getName(); String declaredUcName = ucParam.getName();
returnedResults.put(declaredUcName, updateCount); returnedResults.put(declaredUcName, updateCount);
updateIndex++; updateIndex++;
} }
else { else {
if (!skipUndeclaredResults) { if (!this.skipUndeclaredResults) {
String undeclaredUcName = RETURN_UPDATE_COUNT_PREFIX + (updateIndex + 1); String undeclaredName = RETURN_UPDATE_COUNT_PREFIX + (updateIndex + 1);
logger.info("Added default SqlReturnUpdateCount parameter named " + undeclaredUcName); if (logger.isDebugEnabled()) {
returnedResults.put(undeclaredUcName, updateCount); logger.debug("Added default SqlReturnUpdateCount parameter named '" + undeclaredName + "'");
}
returnedResults.put(undeclaredName, updateCount);
updateIndex++; updateIndex++;
} }
} }
@ -1281,8 +1283,10 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
else { else {
String rsName = outParam.getName(); String rsName = outParam.getName();
SqlReturnResultSet rsParam = new SqlReturnResultSet(rsName, new ColumnMapRowMapper()); SqlReturnResultSet rsParam = new SqlReturnResultSet(rsName, new ColumnMapRowMapper());
returnedResults.putAll(processResultSet(cs.getResultSet(), rsParam)); returnedResults.putAll(processResultSet((ResultSet) out, rsParam));
logger.info("Added default SqlReturnResultSet parameter named " + rsName); if (logger.isDebugEnabled()) {
logger.debug("Added default SqlReturnResultSet parameter named '" + rsName + "'");
}
} }
} }
else { else {

View File

@ -24,7 +24,8 @@ import org.springframework.jdbc.core.SqlParameter;
/** /**
* Interface specifying the API to be implemented by a class providing call metadata. * Interface specifying the API to be implemented by a class providing call metadata.
* This is intended for internal use by Spring's *
* <p>This is intended for internal use by Spring's
* {@link org.springframework.jdbc.core.simple.SimpleJdbcCall}. * {@link org.springframework.jdbc.core.simple.SimpleJdbcCall}.
* *
* @author Thomas Risberg * @author Thomas Risberg
@ -74,15 +75,15 @@ public interface CallMetaDataProvider {
/** /**
* Provide any modification of the catalog name passed in to match the meta data currently used. * Provide any modification of the catalog name passed in to match the meta data currently used.
* The returned value will be used for meta data lookups. This could include altering the case used * The returned value will be used for meta data lookups. This could include altering the case
* or providing a base catalog if none is provided. * used or providing a base catalog if none is provided.
*/ */
String metaDataCatalogNameToUse(String catalogName) ; String metaDataCatalogNameToUse(String catalogName) ;
/** /**
* Provide any modification of the schema name passed in to match the meta data currently used. * Provide any modification of the schema name passed in to match the meta data currently used.
* The returned value will be used for meta data lookups. This could include altering the case used * The returned value will be used for meta data lookups. This could include altering the case
* or providing a base schema if none is provided. * used or providing a base schema if none is provided.
*/ */
String metaDataSchemaNameToUse(String schemaName) ; String metaDataSchemaNameToUse(String schemaName) ;
@ -94,8 +95,8 @@ public interface CallMetaDataProvider {
String parameterNameToUse(String parameterName); String parameterNameToUse(String parameterName);
/** /**
* Create a default out parameter based on the provided meta data. This is used when no * Create a default out parameter based on the provided meta data.
* explicit parameter declaration has been made. * This is used when no explicit parameter declaration has been made.
* @param parameterName the name of the parameter * @param parameterName the name of the parameter
* @param meta meta data used for this call * @param meta meta data used for this call
* @return the configured SqlOutParameter * @return the configured SqlOutParameter
@ -103,8 +104,8 @@ public interface CallMetaDataProvider {
SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta); SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta);
/** /**
* Create a default inout parameter based on the provided meta data. This is used when no * Create a default inout parameter based on the provided meta data.
* explicit parameter declaration has been made. * This is used when no explicit parameter declaration has been made.
* @param parameterName the name of the parameter * @param parameterName the name of the parameter
* @param meta meta data used for this call * @param meta meta data used for this call
* @return the configured SqlInOutParameter * @return the configured SqlInOutParameter
@ -112,8 +113,8 @@ public interface CallMetaDataProvider {
SqlParameter createDefaultInOutParameter(String parameterName, CallParameterMetaData meta); SqlParameter createDefaultInOutParameter(String parameterName, CallParameterMetaData meta);
/** /**
* Create a default in parameter based on the provided meta data. This is used when no * Create a default in parameter based on the provided meta data.
* explicit parameter declaration has been made. * This is used when no explicit parameter declaration has been made.
* @param parameterName the name of the parameter * @param parameterName the name of the parameter
* @param meta meta data used for this call * @param meta meta data used for this call
* @return the configured SqlParameter * @return the configured SqlParameter
@ -127,20 +128,20 @@ public interface CallMetaDataProvider {
String getUserName(); String getUserName();
/** /**
* Does this database support returning resultsets that should be retrieved with the JDBC call * Does this database support returning ResultSets that should be retrieved with the JDBC call.
* {@link java.sql.Statement#getResultSet()} * {@link java.sql.Statement#getResultSet()}
*/ */
boolean isReturnResultSetSupported(); boolean isReturnResultSetSupported();
/** /**
* Does this database support returning resultsets as ref cursors to be retrieved with * Does this database support returning ResultSets as ref cursors to be retrieved with
* {@link java.sql.CallableStatement#getObject(int)} for the specified column. * {@link java.sql.CallableStatement#getObject(int)} for the specified column.
*/ */
boolean isRefCursorSupported(); boolean isRefCursorSupported();
/** /**
* Get the {@link java.sql.Types} type for columns that return resultsets as ref cursors if this feature * Get the {@link java.sql.Types} type for columns that return ResultSets as ref cursors
* is supported. * if this feature is supported.
*/ */
int getRefCursorSqlType(); int getRefCursorSqlType();