Search in sources :

Example 1 with PreparedStatementCreatorFactory

use of org.springframework.jdbc.core.PreparedStatementCreatorFactory in project camel by apache.

the class ElsqlProducer method processStreamList.

protected void processStreamList(final Exchange exchange, final String sql, final SqlParameterSource param) throws Exception {
    // spring JDBC to parse the SQL and build the prepared statement creator
    // this is what NamedJdbcTemplate does internally
    final ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
    final String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, param);
    final Object[] params = NamedParameterUtils.buildValueArray(parsedSql, param, null);
    final List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, param);
    final PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
    final PreparedStatementCreator statementCreator = pscf.newPreparedStatementCreator(params);
    processStreamList(exchange, statementCreator, sqlToUse);
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) PreparedStatementCreator(org.springframework.jdbc.core.PreparedStatementCreator) ParsedSql(org.springframework.jdbc.core.namedparam.ParsedSql) PreparedStatementCreatorFactory(org.springframework.jdbc.core.PreparedStatementCreatorFactory)

Example 2 with PreparedStatementCreatorFactory

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

the class NamedParameterJdbcTemplate method getPreparedStatementCreator.

/**
	 * Build a PreparedStatementCreator based on the given SQL and named parameters.
	 * <p>Note: Not used for the {@code update} variant with generated key handling.
	 * @param sql SQL to execute
	 * @param paramSource container of arguments to bind
	 * @return the corresponding PreparedStatementCreator
	 */
protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource) {
    ParsedSql parsedSql = getParsedSql(sql);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
    List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, paramSource);
    PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
    return pscf.newPreparedStatementCreator(params);
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) PreparedStatementCreatorFactory(org.springframework.jdbc.core.PreparedStatementCreatorFactory)

Example 3 with PreparedStatementCreatorFactory

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

the class SqlOperation method compileInternal.

/**
	 * Overridden method to configure the PreparedStatementCreatorFactory
	 * based on our declared parameters.
	 */
@Override
protected final void compileInternal() {
    this.preparedStatementFactory = new PreparedStatementCreatorFactory(getSql(), getDeclaredParameters());
    this.preparedStatementFactory.setResultSetType(getResultSetType());
    this.preparedStatementFactory.setUpdatableResults(isUpdatableResults());
    this.preparedStatementFactory.setReturnGeneratedKeys(isReturnGeneratedKeys());
    if (getGeneratedKeysColumnNames() != null) {
        this.preparedStatementFactory.setGeneratedKeysColumnNames(getGeneratedKeysColumnNames());
    }
    onCompileInternal();
}
Also used : PreparedStatementCreatorFactory(org.springframework.jdbc.core.PreparedStatementCreatorFactory)

Example 4 with PreparedStatementCreatorFactory

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

the class NamedParameterJdbcTemplate method update.

@Override
public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames) throws DataAccessException {
    ParsedSql parsedSql = getParsedSql(sql);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
    List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, paramSource);
    PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
    if (keyColumnNames != null) {
        pscf.setGeneratedKeysColumnNames(keyColumnNames);
    } else {
        pscf.setReturnGeneratedKeys(true);
    }
    return getJdbcOperations().update(pscf.newPreparedStatementCreator(params), generatedKeyHolder);
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) PreparedStatementCreatorFactory(org.springframework.jdbc.core.PreparedStatementCreatorFactory)

Aggregations

PreparedStatementCreatorFactory (org.springframework.jdbc.core.PreparedStatementCreatorFactory)4 SqlParameter (org.springframework.jdbc.core.SqlParameter)3 PreparedStatementCreator (org.springframework.jdbc.core.PreparedStatementCreator)1 ParsedSql (org.springframework.jdbc.core.namedparam.ParsedSql)1