SimpleJdbcCall's "returningResultSet" accepts any plain RowMapper now (SPR-6963)
This commit is contained in:
parent
f588ab05fa
commit
ccb312a974
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
|
|
@ -24,7 +24,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
|
@ -34,8 +33,8 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
|||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SqlOutParameter;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.SqlReturnResultSet;
|
||||
import org.springframework.jdbc.core.SqlParameterValue;
|
||||
import org.springframework.jdbc.core.SqlReturnResultSet;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
|
|
@ -540,7 +539,7 @@ public class CallMetaDataContext {
|
|||
return matchedParameters;
|
||||
}
|
||||
|
||||
public Map<String,?> matchInParameterValuesWithCallParameters(Object[] parameterValues) {
|
||||
public Map<String, ?> matchInParameterValuesWithCallParameters(Object[] parameterValues) {
|
||||
Map<String, Object> matchedParameters = new HashMap<String, Object>(parameterValues.length);
|
||||
int i = 0;
|
||||
for (SqlParameter parameter : this.callParameters) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
|
|
@ -30,6 +30,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
|||
import org.springframework.jdbc.core.CallableStatementCreator;
|
||||
import org.springframework.jdbc.core.CallableStatementCreatorFactory;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.metadata.CallMetaDataContext;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
|
|
@ -55,7 +56,7 @@ public abstract class AbstractJdbcCall {
|
|||
private final List<SqlParameter> declaredParameters = new ArrayList<SqlParameter>();
|
||||
|
||||
/** List of RefCursor/ResultSet RowMapper objects */
|
||||
private final Map<String, ParameterizedRowMapper> declaredRowMappers = new LinkedHashMap<String, ParameterizedRowMapper>();
|
||||
private final Map<String, RowMapper> declaredRowMappers = new LinkedHashMap<String, RowMapper>();
|
||||
|
||||
/**
|
||||
* Has this operation been compiled? Compilation means at
|
||||
|
|
@ -203,7 +204,8 @@ public abstract class AbstractJdbcCall {
|
|||
*/
|
||||
public void addDeclaredParameter(SqlParameter parameter) {
|
||||
if (!StringUtils.hasText(parameter.getName())) {
|
||||
throw new InvalidDataAccessApiUsageException("You must specify a parameter name when declaring parameters for \"" + getProcedureName() + "\"");
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"You must specify a parameter name when declaring parameters for \"" + getProcedureName() + "\"");
|
||||
}
|
||||
this.declaredParameters.add(parameter);
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
@ -212,17 +214,26 @@ public abstract class AbstractJdbcCall {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a {@link org.springframework.jdbc.core.RowMapper} for the specified parameter or column
|
||||
* Add a {@link org.springframework.jdbc.core.RowMapper} for the specified parameter or column.
|
||||
* @param parameterName name of parameter or column
|
||||
* @param rowMapper the RowMapper implementation to use
|
||||
*/
|
||||
public void addDeclaredRowMapper(String parameterName, ParameterizedRowMapper rowMapper) {
|
||||
public void addDeclaredRowMapper(String parameterName, RowMapper rowMapper) {
|
||||
this.declaredRowMappers.put(parameterName, rowMapper);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Added row mapper for [" + getProcedureName() + "]: " + parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link org.springframework.jdbc.core.RowMapper} for the specified parameter or column.
|
||||
* @deprecated in favor of {@link #addDeclaredRowMapper(String, org.springframework.jdbc.core.RowMapper)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void addDeclaredRowMapper(String parameterName, ParameterizedRowMapper rowMapper) {
|
||||
addDeclaredRowMapper(parameterName, (RowMapper) rowMapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the call string that should be used based on parameters and meta data
|
||||
*/
|
||||
|
|
@ -279,7 +290,7 @@ public abstract class AbstractJdbcCall {
|
|||
this.callMetaDataContext.initializeMetaData(getJdbcTemplate().getDataSource());
|
||||
|
||||
// iterate over the declared RowMappers and register the corresponding SqlParameter
|
||||
for (Map.Entry<String, ParameterizedRowMapper> entry : this.declaredRowMappers.entrySet()) {
|
||||
for (Map.Entry<String, RowMapper> entry : this.declaredRowMappers.entrySet()) {
|
||||
SqlParameter resultSetParameter =
|
||||
this.callMetaDataContext.createReturnResultSetParameter(entry.getKey(), entry.getValue());
|
||||
this.declaredParameters.add(resultSetParameter);
|
||||
|
|
@ -402,7 +413,7 @@ public abstract class AbstractJdbcCall {
|
|||
* @param args the parameter values provided as an array
|
||||
* @return Map with parameter names and values
|
||||
*/
|
||||
private Map<String,?> matchInParameterValuesWithCallParameters(Object[] args) {
|
||||
private Map<String, ?> matchInParameterValuesWithCallParameters(Object[] args) {
|
||||
return this.callMetaDataContext.matchInParameterValuesWithCallParameters(args);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
|
|
@ -17,13 +17,12 @@
|
|||
package org.springframework.jdbc.core.simple;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
|
||||
|
|
@ -121,6 +120,15 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
|
|||
return this;
|
||||
}
|
||||
|
||||
public SimpleJdbcCall returningResultSet(String parameterName, RowMapper rowMapper) {
|
||||
addDeclaredRowMapper(parameterName, rowMapper);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #returningResultSet(String, org.springframework.jdbc.core.RowMapper)}
|
||||
*/
|
||||
@Deprecated
|
||||
public SimpleJdbcCall returningResultSet(String parameterName, ParameterizedRowMapper rowMapper) {
|
||||
addDeclaredRowMapper(parameterName, rowMapper);
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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,6 +18,7 @@ package org.springframework.jdbc.core.simple;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
|
||||
|
|
@ -74,7 +75,6 @@ public interface SimpleJdbcCallOperations {
|
|||
* will be used to provide input values. This is different from the <code>StoredProcedure</code> class
|
||||
* which for backwards compatibility reasons allows input values to be provided for parameters declared
|
||||
* as <code>SqlOutParameter</code>.
|
||||
*
|
||||
* @param sqlParameters the parameters to use
|
||||
* @return the instance of this SimpleJdbcCall
|
||||
*/
|
||||
|
|
@ -85,13 +85,24 @@ public interface SimpleJdbcCallOperations {
|
|||
|
||||
/**
|
||||
* Used to specify when a ResultSet is returned by the stored procedure and you want it mapped
|
||||
* by a RowMapper. The results will be returned using the parameter name specified. Multiple
|
||||
* by a RowMapper. The results will be returned using the parameter name specified. Multiple
|
||||
* ResultSets must be declared in the correct order. If the database you are using uses ref cursors
|
||||
* then the name specified must match the name of the parameter declared for the procedure in the
|
||||
* database.
|
||||
* @param parameterName the name of the returned results and/or the name of the ref cursor parameter
|
||||
* @param rowMapper the RowMapper implementation that will map the data returned for each row
|
||||
* */
|
||||
SimpleJdbcCallOperations returningResultSet(String parameterName, RowMapper rowMapper);
|
||||
|
||||
/**
|
||||
* Used to specify when a ResultSet is returned by the stored procedure and you want it mapped
|
||||
* by a RowMapper. The results will be returned using the parameter name specified. Multiple
|
||||
* ResultSets must be declared in the correct order. If the database you are using uses ref cursors
|
||||
* then the name specified must match the name of the parameter declared for the procedure in the
|
||||
* database.
|
||||
* @deprecated in favor of {@link #returningResultSet(String, org.springframework.jdbc.core.RowMapper)}
|
||||
*/
|
||||
@Deprecated
|
||||
SimpleJdbcCallOperations returningResultSet(String parameterName, ParameterizedRowMapper rowMapper);
|
||||
|
||||
/**
|
||||
|
|
@ -104,8 +115,9 @@ public interface SimpleJdbcCallOperations {
|
|||
/**
|
||||
* Execute the stored function and return the results obtained as an Object of the specified return type.
|
||||
* @param returnType the type of the value to return
|
||||
* @param args optional array containing the in parameter values to be used in the call. Parameter values must
|
||||
* be provided in the same order as the parameters are defined for the stored procedure.
|
||||
* @param args optional array containing the in parameter values to be used in the call.
|
||||
* Parameter values must be provided in the same order as the parameters are defined
|
||||
* for the stored procedure.
|
||||
*/
|
||||
<T> T executeFunction(Class<T> returnType, Object... args);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue