Search in sources :

Example 66 with SqlParameter

use of org.springframework.jdbc.core.SqlParameter in project spring-framework by spring-projects.

the class StoredProcedure method execute.

/**
	 * Execute the stored procedure with the provided parameter values. This is
	 * a convenience method where the order of the passed in parameter values
	 * must match the order that the parameters where declared in.
	 * @param inParams variable number of input parameters. Output parameters should
	 * not be included in this map.
	 * It is legal for values to be {@code 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<String, Object> execute(Object... inParams) {
    Map<String, Object> paramsToUse = new HashMap<>();
    validateParameters(inParams);
    int i = 0;
    for (SqlParameter sqlParameter : getDeclaredParameters()) {
        if (sqlParameter.isInputValueProvided()) {
            if (i < inParams.length) {
                paramsToUse.put(sqlParameter.getName(), inParams[i++]);
            }
        }
    }
    return getJdbcTemplate().call(newCallableStatementCreator(paramsToUse), getDeclaredParameters());
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) HashMap(java.util.HashMap)

Aggregations

SqlParameter (org.springframework.jdbc.core.SqlParameter)66 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)23 Test (org.junit.Test)22 ResultSet (java.sql.ResultSet)15 DataSource (javax.sql.DataSource)15 HashMap (java.util.HashMap)12 Customer (org.springframework.jdbc.Customer)12 SqlOutParameter (org.springframework.jdbc.core.SqlOutParameter)6 LinkedHashMap (java.util.LinkedHashMap)5 ArrayList (java.util.ArrayList)4 InvalidDataAccessApiUsageException (org.springframework.dao.InvalidDataAccessApiUsageException)4 File (com.github.hakko.musiccabinet.domain.model.library.File)3 PreparedStatementCreatorFactory (org.springframework.jdbc.core.PreparedStatementCreatorFactory)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 Track (com.github.hakko.musiccabinet.domain.model.music.Track)2 PreparedStatement (java.sql.PreparedStatement)2 Map (java.util.Map)2 CallableStatementCreatorFactory (org.springframework.jdbc.core.CallableStatementCreatorFactory)2 SqlParameterValue (org.springframework.jdbc.core.SqlParameterValue)2 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)2