added convenience execute method that takes vararg of objects in the order of the parameters plus the corresponding executeFunction/executeObject methods (SPR-4739)
This commit is contained in:
@@ -540,6 +540,18 @@ public class CallMetaDataContext {
|
||||
return matchedParameters;
|
||||
}
|
||||
|
||||
public Map<String,?> matchInParameterValuesWithCallParameters(Object[] parameterValues) {
|
||||
Map<String, Object> matchedParameters = new HashMap<String, Object>(parameterValues.length);
|
||||
int i = 0;
|
||||
for (SqlParameter parameter : this.callParameters) {
|
||||
if (parameter.isInputValueProvided()) {
|
||||
String parameterName = parameter.getName();
|
||||
matchedParameters.put(parameterName, parameterValues[i++]);
|
||||
}
|
||||
}
|
||||
return matchedParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the call string based on configuration and metadata information.
|
||||
* @return the call string to be used
|
||||
|
||||
@@ -341,6 +341,17 @@ public abstract class AbstractJdbcCall {
|
||||
return executeCallInternal(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that provides execution of the call using the passed in array of parameters
|
||||
* @param args array of parameter values; order must match the order declared for the stored procedure
|
||||
* @return Map of out parameters
|
||||
*/
|
||||
protected Map<String, Object> doExecute(Object[] args) {
|
||||
checkCompiled();
|
||||
Map<String, ?> params = matchInParameterValuesWithCallParameters(args);
|
||||
return executeCallInternal(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that provides execution of the call using the passed in Map of parameters
|
||||
* @param args Map of parameter name and values
|
||||
@@ -385,6 +396,16 @@ public abstract class AbstractJdbcCall {
|
||||
return this.callMetaDataContext.matchInParameterValuesWithCallParameters(parameterSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the provided in parameter values with registered parameters and
|
||||
* parameters defined via metadata processing.
|
||||
* @param args the parameter values provided as an array
|
||||
* @return Map with parameter names and values
|
||||
*/
|
||||
private Map<String,?> matchInParameterValuesWithCallParameters(Object[] args) {
|
||||
return this.callMetaDataContext.matchInParameterValuesWithCallParameters(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the provided in parameter values with registered parameters and
|
||||
* parameters defined via metadata processing.
|
||||
|
||||
@@ -131,6 +131,10 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T executeFunction(Class<T> returnType, Object... args) {
|
||||
return (T) doExecute(args).get(getScalarOutParameterName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T executeFunction(Class<T> returnType, Map<String, Object> args) {
|
||||
@@ -142,6 +146,11 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
|
||||
return (T) doExecute(args).get(getScalarOutParameterName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T executeObject(Class<T> returnType, Object... args) {
|
||||
return (T) doExecute(args).get(getScalarOutParameterName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T executeObject(Class<T> returnType, Map<String, Object> args) {
|
||||
return (T) doExecute(args).get(getScalarOutParameterName());
|
||||
@@ -152,8 +161,8 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
|
||||
return (T) doExecute(args).get(getScalarOutParameterName());
|
||||
}
|
||||
|
||||
public Map<String, Object> execute() {
|
||||
return doExecute(new HashMap<String, Object>());
|
||||
public Map<String, Object> execute(Object... args) {
|
||||
return doExecute(args);
|
||||
}
|
||||
|
||||
public Map<String, Object> execute(Map<String, Object> args) {
|
||||
|
||||
@@ -101,6 +101,14 @@ public interface SimpleJdbcCallOperations {
|
||||
SimpleJdbcCallOperations withoutProcedureColumnMetaDataAccess();
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
<T> T executeFunction(Class<T> returnType, Object... args);
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -115,6 +123,16 @@ public interface SimpleJdbcCallOperations {
|
||||
*/
|
||||
<T> T executeFunction(Class<T> returnType, SqlParameterSource args);
|
||||
|
||||
/**
|
||||
* Execute the stored procedure and return the single out parameter as an Object of the specified return type.
|
||||
* In the case where there are multiple out parameters, the first one is returned and additional out parameters
|
||||
* are ignored.
|
||||
* @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.
|
||||
*/
|
||||
<T> T executeObject(Class<T> returnType, Object... args);
|
||||
|
||||
/**
|
||||
* Execute the stored procedure and return the single out parameter as an Object of the specified return type.
|
||||
* In the case where there are multiple out parameters, the first one is returned and additional out parameters
|
||||
@@ -134,10 +152,12 @@ public interface SimpleJdbcCallOperations {
|
||||
<T> T executeObject(Class<T> returnType, SqlParameterSource args);
|
||||
|
||||
/**
|
||||
* Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations..
|
||||
* Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.
|
||||
* @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.
|
||||
* @return map of output params.
|
||||
*/
|
||||
Map<String, Object> execute();
|
||||
Map<String, Object> execute(Object... args);
|
||||
|
||||
/**
|
||||
* Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations..
|
||||
|
||||
Reference in New Issue
Block a user