Search in sources :

Example 1 with CallableStatementCreatorFactory

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

the class AbstractJdbcCall method compileInternal.

/**
	 * 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() {
    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());
    onCompileInternal();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) CallableStatementCreatorFactory(org.springframework.jdbc.core.CallableStatementCreatorFactory) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) RowMapper(org.springframework.jdbc.core.RowMapper)

Example 2 with CallableStatementCreatorFactory

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

the class SqlCall method compileInternal.

/**
	 * Overridden method to configure the CallableStatementCreatorFactory
	 * based on our declared parameters.
	 * @see RdbmsOperation#compileInternal()
	 */
@Override
protected final void compileInternal() {
    if (isSqlReadyForUse()) {
        this.callString = getSql();
    } else {
        List<SqlParameter> parameters = getDeclaredParameters();
        int parameterCount = 0;
        if (isFunction()) {
            this.callString = "{? = call " + getSql() + "(";
            parameterCount = -1;
        } else {
            this.callString = "{call " + getSql() + "(";
        }
        for (SqlParameter parameter : parameters) {
            if (!(parameter.isResultsParameter())) {
                if (parameterCount > 0) {
                    this.callString += ", ";
                }
                if (parameterCount >= 0) {
                    this.callString += "?";
                }
                parameterCount++;
            }
        }
        this.callString += ")}";
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Compiled stored procedure. Call string is [" + getCallString() + "]");
    }
    this.callableStatementFactory = new CallableStatementCreatorFactory(getCallString(), getDeclaredParameters());
    this.callableStatementFactory.setResultSetType(getResultSetType());
    this.callableStatementFactory.setUpdatableResults(isUpdatableResults());
    onCompileInternal();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) CallableStatementCreatorFactory(org.springframework.jdbc.core.CallableStatementCreatorFactory)

Aggregations

CallableStatementCreatorFactory (org.springframework.jdbc.core.CallableStatementCreatorFactory)2 SqlParameter (org.springframework.jdbc.core.SqlParameter)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RowMapper (org.springframework.jdbc.core.RowMapper)1