You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there are methods that take in "Object[]" for the execution of operations in most of the jdbc.object classes, such as:
SqlUpdate.update(Object[])
MappingSqlQuery.execute(Object[])
It would be very beneficial to have a similar method in StoredProcedure as "execute(Object[])".
I understand that there is a distinction in terms of update or query, and stored procedures in that stored procs can have a mixture of input and output params. However, this can be handled quite easily by using the already existing metadata provided to construct the StoredProcedure.
Below is a sample implementation:
/**
* Avoids having to use a Map, hence to duplicate the keys of the map, which are the parameter names already
* provided while registering the parameters to the {@link StoredProcedure}.
*
* @param values
* the values for the <b>input</b> parameters defined on this stored procedure, in the order of
* registration. It is legal for map entries to be null, and this will produce the correct behavior using
* a NULL argument to the stored procedure.
* @return map of output params, keyed by name as in parameter declarations. Output parameters will appear here,
* with their values after the stored procedure has been called.
*/
public Map execute(Object[] values) {
if (values == null) {
return execute(Collections.EMPTY_MAP);
} else {
List<SqlParameter> params = this.getDeclaredParameters();
List<SqlParameter> inputParams = new ArrayList<SqlParameter>();
// filter the input params
for (SqlParameter sqlParameter : params) {
if (sqlParameter.isInputValueProvided()) {
inputParams.add(sqlParameter);
}
}
// Make sure exactly correct number of arguments are provided
if (inputParams.size() != values.length) {
throw new IllegalArgumentException("There are " + inputParams.size() + " input arguments, but "
+ values.length + " values are provided");
}
// Create a map, and call existing execute method
Map<String, Object> valuesToReturn = new HashMap<String, Object>();
for (int i = 0; i < inputParams.size(); i++) {
valuesToReturn.put(inputParams.get(i).getName(), values[i]);
}
return execute(valuesToReturn);
}
}
The use-case for this is: this avoids having to duplicate the input parameter names twice:
once during the registration of the input parameter with name to StoredProcedure
second, when we construct the Map for values to pass values to StoredProcedure.execute(Map) method
Celal Ziftci opened SPR-5696 and commented
Currently there are methods that take in "Object[]" for the execution of operations in most of the jdbc.object classes, such as:
It would be very beneficial to have a similar method in StoredProcedure as "execute(Object[])".
I understand that there is a distinction in terms of update or query, and stored procedures in that stored procs can have a mixture of input and output params. However, this can be handled quite easily by using the already existing metadata provided to construct the StoredProcedure.
Below is a sample implementation:
The use-case for this is: this avoids having to duplicate the input parameter names twice:
Affects: 3.0 M1
Referenced from: commits 7c05312
The text was updated successfully, but these errors were encountered: