org.springframework.jdbc.core.namedparam.ParsedSql#org.springframework.jdbc.core.namedparam.NamedParameterUtils源码实例Demo

下面列出了org.springframework.jdbc.core.namedparam.ParsedSql#org.springframework.jdbc.core.namedparam.NamedParameterUtils 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemini   文件: TransactionImpl.java
private PreparedStatement getPreparedStatement(String sql, @Nullable Map<String, ?> parameters, boolean returnKeys) throws SQLException {
    SqlParameterSource paramSource = new MapSqlParameterSource(parameters);
    ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
    PreparedStatementCreatorFactory psCreatorFactory = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
    psCreatorFactory.setReturnGeneratedKeys(returnKeys);
    PreparedStatementCreator psCreator = psCreatorFactory.newPreparedStatementCreator(params);
    PreparedStatement preparedStatement = psCreator.createPreparedStatement(connection);
    logger.debug(preparedStatement.unwrap(PreparedStatement.class).toString());
    return preparedStatement;
}
 
源代码2 项目: spring-analysis-note   文件: SqlOperation.java
/**
 * Obtain a parsed representation of this operation's SQL statement.
 * <p>Typically used for named parameter parsing.
 */
protected ParsedSql getParsedSql() {
	synchronized (this.parsedSqlMonitor) {
		if (this.cachedSql == null) {
			this.cachedSql = NamedParameterUtils.parseSqlStatement(resolveSql());
		}
		return this.cachedSql;
	}
}
 
源代码3 项目: spring-analysis-note   文件: SqlUpdate.java
/**
 * Generic method to execute the update given named parameters.
 * All other update methods invoke this method.
 * @param paramMap a Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params));
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码4 项目: spring-analysis-note   文件: SqlUpdate.java
/**
 * Method to execute the update given arguments and
 * retrieve the generated keys using a KeyHolder.
 * @param paramMap a Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @param generatedKeyHolder the KeyHolder that will hold the generated keys
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码5 项目: java-technology-stack   文件: SqlOperation.java
/**
 * Obtain a parsed representation of this operation's SQL statement.
 * <p>Typically used for named parameter parsing.
 */
protected ParsedSql getParsedSql() {
	synchronized (this.parsedSqlMonitor) {
		if (this.cachedSql == null) {
			this.cachedSql = NamedParameterUtils.parseSqlStatement(resolveSql());
		}
		return this.cachedSql;
	}
}
 
源代码6 项目: java-technology-stack   文件: SqlUpdate.java
/**
 * Generic method to execute the update given named parameters.
 * All other update methods invoke this method.
 * @param paramMap a Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params));
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码7 项目: java-technology-stack   文件: SqlUpdate.java
/**
 * Method to execute the update given arguments and
 * retrieve the generated keys using a KeyHolder.
 * @param paramMap a Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @param generatedKeyHolder the KeyHolder that will hold the generated keys
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码8 项目: lams   文件: SqlOperation.java
/**
 * Obtain a parsed representation of this operation's SQL statement.
 * <p>Typically used for named parameter parsing.
 */
protected ParsedSql getParsedSql() {
	synchronized (this.parsedSqlMonitor) {
		if (this.cachedSql == null) {
			this.cachedSql = NamedParameterUtils.parseSqlStatement(getSql());
		}
		return this.cachedSql;
	}
}
 
源代码9 项目: lams   文件: SqlUpdate.java
/**
 * Generic method to execute the update given named parameters.
 * All other update methods invoke this method.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params));
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码10 项目: lams   文件: SqlUpdate.java
/**
 * Method to execute the update given arguments and
 * retrieve the generated keys using a KeyHolder.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @param generatedKeyHolder KeyHolder that will hold the generated keys
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码11 项目: ureport   文件: DatasourceServletAction.java
protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource) {
	ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(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);
}
 
源代码12 项目: spring4-understanding   文件: SqlOperation.java
/**
 * Obtain a parsed representation of this operation's SQL statement.
 * <p>Typically used for named parameter parsing.
 */
protected ParsedSql getParsedSql() {
	synchronized (this.parsedSqlMonitor) {
		if (this.cachedSql == null) {
			this.cachedSql = NamedParameterUtils.parseSqlStatement(getSql());
		}
		return this.cachedSql;
	}
}
 
源代码13 项目: spring4-understanding   文件: SqlUpdate.java
/**
 * Generic method to execute the update given named parameters.
 * All other update methods invoke this method.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params));
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码14 项目: spring4-understanding   文件: SqlUpdate.java
/**
 * Method to execute the update given arguments and
 * retrieve the generated keys using a KeyHolder.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @param generatedKeyHolder KeyHolder that will hold the generated keys
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码15 项目: SimpleFlatMapper   文件: MappingSqlQuery.java
public List<T> executeByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
    validateNamedParameters(paramMap);
    ParsedSql parsedSql = getParsedSql();
    MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
    return query(newPreparedStatementCreator(sqlToUse, params));
}
 
源代码16 项目: effectivejava   文件: SqlOperation.java
/**
 * Obtain a parsed representation of this operation's SQL statement.
 * <p>Typically used for named parameter parsing.
 */
protected ParsedSql getParsedSql() {
	synchronized (this.parsedSqlMonitor) {
		if (this.cachedSql == null) {
			this.cachedSql = NamedParameterUtils.parseSqlStatement(getSql());
		}
		return this.cachedSql;
	}
}
 
源代码17 项目: effectivejava   文件: SqlUpdate.java
/**
 * Generic method to execute the update given named parameters.
 * All other update methods invoke this method.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params));
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码18 项目: effectivejava   文件: SqlUpdate.java
/**
 * Method to execute the update given arguments and
 * retrieve the generated keys using a KeyHolder.
 * @param paramMap Map of parameter name to parameter object,
 * matching named parameters specified in the SQL statement
 * @param generatedKeyHolder KeyHolder that will hold the generated keys
 * @return the number of rows affected by the update
 */
public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
	checkRowsAffected(rowsAffected);
	return rowsAffected;
}
 
源代码19 项目: sqlhelper   文件: NamedParameterJdbcTemplate.java
/**
 * Build a {@link PreparedStatementCreator} based on the given SQL and named parameters.
 * <p>Note: Directly called from all {@code query} variants.
 * Not used for the {@code update} variant with generated key handling.
 *
 * @param sql         the SQL statement to execute
 * @param paramSource container of arguments to bind
 * @return the corresponding {@link PreparedStatementCreator}
 */
@Override
protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource) {
    ParsedSql parsedSql = getParsedSql(sql);
    PreparedStatementCreatorFactory pscf = getPreparedStatementCreatorFactory(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
    return pscf.newPreparedStatementCreator(params);
}
 
源代码20 项目: sqlhelper   文件: NamedParameterJdbcTemplate.java
/**
 * Build a {@link PreparedStatementCreatorFactory} based on the given SQL and named parameters.
 *
 * @param parsedSql   parsed representation of the given SQL statement
 * @param paramSource container of arguments to bind
 * @return the corresponding {@link PreparedStatementCreatorFactory}
 * @see #getParsedSql(String)
 * @since Spring 5.1.3
 */
protected PreparedStatementCreatorFactory getPreparedStatementCreatorFactory(
        ParsedSql parsedSql, SqlParameterSource paramSource) {
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, paramSource);
    return new NamedParameterPreparedStatementCreatorFactory(sqlToUse, declaredParameters);
}
 
源代码21 项目: spring-analysis-note   文件: SqlQuery.java
/**
 * Central execution method. All named parameter execution goes through this method.
 * @param paramMap parameters associated with the name specified while declaring
 * the SqlParameters. Primitive parameters must be represented by their Object wrapper
 * type. The ordering of parameters is not significant since they are supplied in a
 * SqlParameterMap which is an implementation of the Map interface.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public List<T> executeByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	RowMapper<T> rowMapper = newRowMapper(params, context);
	return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
}
 
源代码22 项目: java-technology-stack   文件: SqlQuery.java
/**
 * Central execution method. All named parameter execution goes through this method.
 * @param paramMap parameters associated with the name specified while declaring
 * the SqlParameters. Primitive parameters must be represented by their Object wrapper
 * type. The ordering of parameters is not significant since they are supplied in a
 * SqlParameterMap which is an implementation of the Map interface.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public List<T> executeByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	RowMapper<T> rowMapper = newRowMapper(params, context);
	return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
}
 
源代码23 项目: lams   文件: SqlQuery.java
/**
 * Central execution method. All named parameter execution goes through this method.
 * @param paramMap parameters associated with the name specified while declaring
 * the SqlParameters. Primitive parameters must be represented by their Object wrapper
 * type. The ordering of parameters is not significant since they are supplied in a
 * SqlParameterMap which is an implementation of the Map interface.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public List<T> executeByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	RowMapper<T> rowMapper = newRowMapper(params, context);
		return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
}
 
源代码24 项目: spring4-understanding   文件: SqlQuery.java
/**
 * Central execution method. All named parameter execution goes through this method.
 * @param paramMap parameters associated with the name specified while declaring
 * the SqlParameters. Primitive parameters must be represented by their Object wrapper
 * type. The ordering of parameters is not significant since they are supplied in a
 * SqlParameterMap which is an implementation of the Map interface.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public List<T> executeByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	RowMapper<T> rowMapper = newRowMapper(params, context);
		return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
}
 
源代码25 项目: effectivejava   文件: SqlQuery.java
/**
 * Central execution method. All named parameter execution goes through this method.
 * @param paramMap parameters associated with the name specified while declaring
 * the SqlParameters. Primitive parameters must be represented by their Object wrapper
 * type. The ordering of parameters is not significant since they are supplied in a
 * SqlParameterMap which is an implementation of the Map interface.
 * @param context contextual information passed to the {@code mapRow}
 * callback method. The JDBC operation itself doesn't rely on this parameter,
 * but it can be useful for creating the objects of the result list.
 * @return a List of objects, one per row of the ResultSet. Normally all these
 * will be of the same class, although it is possible to use different types.
 */
public List<T> executeByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException {
	validateNamedParameters(paramMap);
	ParsedSql parsedSql = getParsedSql();
	MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
	String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
	Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
	RowMapper<T> rowMapper = newRowMapper(params, context);
		return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
}