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);
}
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);
}
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();
}
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);
}
Aggregations