/** * Delegate method that executes the call using the passed-in array of parameters. * @param args array of parameter values. The order of values must match the order * declared for the stored procedure. * @return a Map of out parameters */ protected Map<String, Object> doExecute(Object... args) { checkCompiled(); Map<String, ?> params = matchInParameterValuesWithCallParameters(args); return executeCallInternal(params); }
/** * Check whether this operation has been compiled already; * lazily compile it if not already compiled. * <p>Automatically called by {@code doExecute}. */ protected void checkCompiled() { if (!isCompiled()) { logger.debug("JdbcCall call not compiled before execution - invoking compile"); compile(); } }
/** * Compile this JdbcCall using provided parameters and meta-data plus other settings. * <p>This finalizes the configuration for this object and subsequent attempts to compile are * ignored. This will be implicitly called the first time an un-compiled call is executed. * @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't * been correctly initialized, for example if no DataSource has been provided */ public final synchronized void compile() throws InvalidDataAccessApiUsageException { if (!isCompiled()) { if (getProcedureName() == null) { throw new InvalidDataAccessApiUsageException("Procedure or Function name is required"); } try { this.jdbcTemplate.afterPropertiesSet(); } catch (IllegalArgumentException ex) { throw new InvalidDataAccessApiUsageException(ex.getMessage()); } compileInternal(); this.compiled = true; if (logger.isDebugEnabled()) { logger.debug("SqlCall for " + (isFunction() ? "function" : "procedure") + " [" + getProcedureName() + "] compiled"); } } }
/** * Delegate method to perform the actual call processing. */ private Map<String, Object> executeCallInternal(Map<String, ?> args) { CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(args); if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for call " + getCallString() + " with " + args); int i = 1; for (SqlParameter param : getCallParameters()) { logger.debug(i + ": " + param.getName() + ", SQL type "+ param.getSqlType() + ", type name " + param.getTypeName() + ", parameter class [" + param.getClass().getName() + "]"); i++; } } return getJdbcTemplate().call(csc, getCallParameters()); }
/** * Method to perform the actual compilation. Subclasses can override this template method to perform * their own compilation. Invoked after this base class's compilation is complete. */ protected void compileInternal() { this.callMetaDataContext.initializeMetaData(getJdbcTemplate().getDataSource()); // iterate over the declared RowMappers and register the corresponding SqlParameter for (Map.Entry<String, RowMapper> entry : this.declaredRowMappers.entrySet()) { SqlParameter resultSetParameter = this.callMetaDataContext.createReturnResultSetParameter(entry.getKey(), entry.getValue()); this.declaredParameters.add(resultSetParameter); } this.callMetaDataContext.processParameters(this.declaredParameters); this.callString = this.callMetaDataContext.createCallString(); if (logger.isDebugEnabled()) { logger.debug("Compiled stored procedure. Call string is [" + this.callString + "]"); } this.callableStatementFactory = new CallableStatementCreatorFactory(getCallString(), this.callMetaDataContext.getCallParameters()); this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor()); onCompileInternal(); }
/** * Delegate method to perform the actual compilation. * <p>Subclasses can override this template method to perform their own compilation. * Invoked after this base class's compilation is complete. */ protected void compileInternal() { DataSource dataSource = getJdbcTemplate().getDataSource(); Assert.state(dataSource != null, "No DataSource set"); this.callMetaDataContext.initializeMetaData(dataSource); // Iterate over the declared RowMappers and register the corresponding SqlParameter this.declaredRowMappers.forEach((key, value) -> { this.declaredParameters.add(this.callMetaDataContext.createReturnResultSetParameter(key, value)); }); this.callMetaDataContext.processParameters(this.declaredParameters); this.callString = this.callMetaDataContext.createCallString(); if (logger.isDebugEnabled()) { logger.debug("Compiled stored procedure. Call string is [" + this.callString + "]"); } this.callableStatementFactory = new CallableStatementCreatorFactory( this.callString, this.callMetaDataContext.getCallParameters()); onCompileInternal(); }
/** * 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, RowMapper<?> rowMapper) { this.declaredRowMappers.put(parameterName, rowMapper); if (logger.isDebugEnabled()) { logger.debug("Added row mapper for [" + getProcedureName() + "]: " + parameterName); } }
/** * Delegate method to perform the actual call processing. */ private Map<String, Object> executeCallInternal(Map<String, ?> args) { CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(args); if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for call " + getCallString() + " with " + args); int i = 1; for (SqlParameter param : getCallParameters()) { logger.debug(i + ": " + param.getName() + ", SQL type "+ param.getSqlType() + ", type name " + param.getTypeName() + ", parameter class [" + param.getClass().getName() + "]"); i++; } } return getJdbcTemplate().call(csc, getCallParameters()); }
/** * Delegate method to perform the actual compilation. * <p>Subclasses can override this template method to perform their own compilation. * Invoked after this base class's compilation is complete. */ protected void compileInternal() { DataSource dataSource = getJdbcTemplate().getDataSource(); Assert.state(dataSource != null, "No DataSource set"); this.callMetaDataContext.initializeMetaData(dataSource); // Iterate over the declared RowMappers and register the corresponding SqlParameter this.declaredRowMappers.forEach((key, value) -> { this.declaredParameters.add(this.callMetaDataContext.createReturnResultSetParameter(key, value)); }); this.callMetaDataContext.processParameters(this.declaredParameters); this.callString = this.callMetaDataContext.createCallString(); if (logger.isDebugEnabled()) { logger.debug("Compiled stored procedure. Call string is [" + this.callString + "]"); } this.callableStatementFactory = new CallableStatementCreatorFactory( this.callString, this.callMetaDataContext.getCallParameters()); onCompileInternal(); }
/** * Add a declared parameter to the list of parameters for the call. * <p>Only parameters declared as {@code SqlParameter} and {@code SqlInOutParameter} will * be used to provide input values. This is different from the {@code StoredProcedure} * class which - for backwards compatibility reasons - allows input values to be provided * for parameters declared as {@code SqlOutParameter}. * @param parameter the {@link SqlParameter} to add */ public void addDeclaredParameter(SqlParameter parameter) { Assert.notNull(parameter, "The supplied parameter must not be null"); if (!StringUtils.hasText(parameter.getName())) { throw new InvalidDataAccessApiUsageException( "You must specify a parameter name when declaring parameters for \"" + getProcedureName() + "\""); } this.declaredParameters.add(parameter); if (logger.isDebugEnabled()) { logger.debug("Added declared parameter for [" + getProcedureName() + "]: " + parameter.getName()); } }
/** * Delegate method that executes the call using the passed-in {@link SqlParameterSource}. * @param parameterSource parameter names and values to be used in call * @return a Map of out parameters */ protected Map<String, Object> doExecute(SqlParameterSource parameterSource) { checkCompiled(); Map<String, Object> params = matchInParameterValuesWithCallParameters(parameterSource); return executeCallInternal(params); }
/** * Method to perform the actual call processing */ private Map<String, Object> executeCallInternal(Map<String, ?> params) { CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(params); if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for call " + getCallString() + " with: " + params); int i = 1; for (SqlParameter p : getCallParameters()) { logger.debug(i++ + ": " + p.getName() + " SQL Type "+ p.getSqlType() + " Type Name " + p.getTypeName() + " " + p.getClass().getName()); } } return getJdbcTemplate().call(csc, getCallParameters()); }
/** * Compile this JdbcCall using provided parameters and meta data plus other settings. This * finalizes the configuration for this object and subsequent attempts to compile are ignored. * This will be implicitly called the first time an un-compiled call is executed. * @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't * been correctly initialized, for example if no DataSource has been provided */ public synchronized final void compile() throws InvalidDataAccessApiUsageException { if (!isCompiled()) { if (getProcedureName() == null) { throw new InvalidDataAccessApiUsageException("Procedure or Function name is required"); } try { this.jdbcTemplate.afterPropertiesSet(); } catch (IllegalArgumentException ex) { throw new InvalidDataAccessApiUsageException(ex.getMessage()); } compileInternal(); this.compiled = true; if (logger.isDebugEnabled()) { logger.debug("SqlCall for " + (isFunction() ? "function" : "procedure") + " [" + getProcedureName() + "] compiled"); } } }
/** * Check whether this operation has been compiled already; * lazily compile it if not already compiled. * <p>Automatically called by {@code doExecute}. */ protected void checkCompiled() { if (!isCompiled()) { logger.debug("JdbcCall call not compiled before execution - invoking compile"); compile(); } }
/** * 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, RowMapper rowMapper) { this.declaredRowMappers.put(parameterName, rowMapper); if (logger.isDebugEnabled()) { logger.debug("Added row mapper for [" + getProcedureName() + "]: " + parameterName); } }
/** * Delegate method that executes the call using the passed-in Map of parameters. * @param args a Map of parameter name and values * @return a Map of out parameters */ protected Map<String, Object> doExecute(Map<String, ?> args) { checkCompiled(); Map<String, ?> params = matchInParameterValuesWithCallParameters(args); return executeCallInternal(params); }
/** * Compile this JdbcCall using provided parameters and meta-data plus other settings. * <p>This finalizes the configuration for this object and subsequent attempts to compile are * ignored. This will be implicitly called the first time an un-compiled call is executed. * @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't * been correctly initialized, for example if no DataSource has been provided */ public final synchronized void compile() throws InvalidDataAccessApiUsageException { if (!isCompiled()) { if (getProcedureName() == null) { throw new InvalidDataAccessApiUsageException("Procedure or Function name is required"); } try { this.jdbcTemplate.afterPropertiesSet(); } catch (IllegalArgumentException ex) { throw new InvalidDataAccessApiUsageException(ex.getMessage()); } compileInternal(); this.compiled = true; if (logger.isDebugEnabled()) { logger.debug("SqlCall for " + (isFunction() ? "function" : "procedure") + " [" + getProcedureName() + "] compiled"); } } }
/** * Check whether this operation has been compiled already; * lazily compile it if not already compiled. * <p>Automatically called by {@code doExecute}. */ protected void checkCompiled() { if (!isCompiled()) { logger.debug("JdbcCall call not compiled before execution - invoking compile"); compile(); } }
/** * 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, RowMapper<?> rowMapper) { this.declaredRowMappers.put(parameterName, rowMapper); if (logger.isDebugEnabled()) { logger.debug("Added row mapper for [" + getProcedureName() + "]: " + parameterName); } }
/** * 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); }