org.springframework.jdbc.core.CallableStatementCreatorFactory Java Examples

The following examples show how to use org.springframework.jdbc.core.CallableStatementCreatorFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractJdbcCall.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: AbstractJdbcCall.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: AbstractJdbcCall.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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());
	this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());

	onCompileInternal();
}
 
Example #4
Source File: AbstractJdbcCall.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
	this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());

	onCompileInternal();
}
 
Example #5
Source File: AbstractJdbcCall.java    From effectivejava with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #6
Source File: ProcedureJdbcTemplate.java    From opscenter with Apache License 2.0 5 votes vote down vote up
/**
 * 引自NamedParameterJdbcTemplate
 * @param sql
 * @param paramSource
 * @return PreparedStatementCreator
 */
private CallableStatementCreator getCallableStatementCreator(String sql, Map<String,Object> paramMap , String[] outParam) {
	SqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	ParsedSqlBean parsedSqlBean = getParsedSqlBean(sql);
	parsedSqlBean.setOutParam(outParam);
	String sqlToUse = ProcedureParameterUtils.substituteNamedParameters(parsedSqlBean, paramSource);
	List<SqlParameter> declaredParameters = ProcedureParameterUtils.buildSqlParameterList(parsedSqlBean, paramSource);
	CallableStatementCreatorFactory cscf = new CallableStatementCreatorFactory(sqlToUse, declaredParameters);
	return cscf.newCallableStatementCreator(paramMap);
}
 
Example #7
Source File: SqlCall.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
	this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());

	onCompileInternal();
}
 
Example #8
Source File: SqlCall.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
	this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());

	onCompileInternal();
}
 
Example #9
Source File: SqlCall.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
	this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());

	onCompileInternal();
}
 
Example #10
Source File: AbstractJdbcCall.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Get the {@link CallableStatementCreatorFactory} being used.
 */
protected CallableStatementCreatorFactory getCallableStatementFactory() {
	Assert.state(this.callableStatementFactory != null, "No CallableStatementCreatorFactory available");
	return this.callableStatementFactory;
}
 
Example #11
Source File: AbstractJdbcCall.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Get the {@link CallableStatementCreatorFactory} being used.
 */
protected CallableStatementCreatorFactory getCallableStatementFactory() {
	Assert.state(this.callableStatementFactory != null, "No CallableStatementCreatorFactory available");
	return this.callableStatementFactory;
}
 
Example #12
Source File: AbstractJdbcCall.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the {@link CallableStatementCreatorFactory} being used
 */
protected CallableStatementCreatorFactory getCallableStatementFactory() {
	return this.callableStatementFactory;
}
 
Example #13
Source File: AbstractJdbcCall.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Get the {@link CallableStatementCreatorFactory} being used
 */
protected CallableStatementCreatorFactory getCallableStatementFactory() {
	return this.callableStatementFactory;
}
 
Example #14
Source File: AbstractJdbcCall.java    From effectivejava with Apache License 2.0 4 votes vote down vote up
/**
 * Get the {@link CallableStatementCreatorFactory} being used
 */
protected CallableStatementCreatorFactory getCallableStatementFactory() {
	return this.callableStatementFactory;
}