Java 类org.springframework.jdbc.core.namedparam.NamedParameterUtils 实例源码

项目:spring-data-jdbc    文件:JdbcByNameRepositoryQuery.java   
private void processMethodParameters(List<ParameterProperties> parameterProperties) {
    ParsedSql parsedSQL = NamedParameterUtils.parseSqlStatement(query);
    try {
        parametersNames = (List<String>) getParametersMethod.invoke(parsedSQL);

        for (int i = 0; i < parametersNames.size(); i++) {
            ParameterProperties properties = parameterProperties.get(i);
            QueryParameterProcessor processor = QueryParameterProcessorFactory
                    .getQueryParameterProcessor(properties);
            parameterMethodsList.add(processor);
        }

    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
项目: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;
    }
}
项目: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;
}
项目: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;
}
项目: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);
}
项目: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;
    }
}
项目: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;
}
项目: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;
}
项目:osmp    文件:BaseTemplate.java   
protected PreparedStatementCreator getPreparedStatementCreator(String sql, Map<String,Object> paramMap) {
    MapSqlParameterSource paramSource =  new MapSqlParameterSource(paramMap);
    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);
    pscf.setReturnGeneratedKeys(true);
    return pscf.newPreparedStatementCreator(params);
}
项目:Camel    文件:ElsqlProducer.java   
protected void processStreamList(Exchange exchange, String sql, SqlParameterSource param) throws Exception {
    // spring JDBC to parse the SQL and build the prepared statement creator
    // this is what NamedJdbcTemplate does internally
    ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, param);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, param, null);
    List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, param);
    PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
    PreparedStatementCreator statementCreator = pscf.newPreparedStatementCreator(params);

    processStreamList(exchange, statementCreator, sqlToUse);
}
项目:gomall.la    文件:BaseJdbcDaoImpl.java   
public <T> int updateNamed(String namedSql, T bean) {
    String sql = NamedParameterUtils.parseSqlStatementIntoString(namedSql);
    ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(namedSql);
    BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(bean);
    List<SqlParameter> params = NamedParameterUtils.buildSqlParameterList(parsedSql, source);
    Object[] args = NamedParameterUtils.buildValueArray(parsedSql, source, params);
    return jdbcTemplate.update(sql, args);

}
项目:gomall.la    文件:BaseJdbcDaoImpl.java   
public <T> int[] updateNamed(String namedSql, List<T> beans) {
    String sql = NamedParameterUtils.parseSqlStatementIntoString(namedSql);
    ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(namedSql);
    List<Object[]> batchArgs = new ArrayList<Object[]>();
    for (T bean : beans) {
        BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(bean);
        List<SqlParameter> params = NamedParameterUtils.buildSqlParameterList(parsedSql, source);
        Object[] args = NamedParameterUtils.buildValueArray(parsedSql, source, params);
        batchArgs.add(args);
    }
    return jdbcTemplate.batchUpdate(sql, batchArgs);
}
项目:gomall.la    文件:BaseJdbcDaoImpl.java   
public int[] updateNamedMap(String namedSql, List<Map<String, Object>> paramMaps) {
    String sql = NamedParameterUtils.parseSqlStatementIntoString(namedSql);
    List<Object[]> batchArgs = new ArrayList<Object[]>();
    for (Map<String, Object> paramMap : paramMaps) {
        Object[] args = NamedParameterUtils.buildValueArray(namedSql, paramMap);
        batchArgs.add(args);
    }
    return jdbcTemplate.batchUpdate(sql, batchArgs);
}
项目: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));
}
项目:class-guard    文件: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;
    }
}
项目:class-guard    文件: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;
}
项目:class-guard    文件: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;
}
项目:jlubricant    文件:NamedJdbcCursorItemReader.java   
/**
 * Obtain a parsed representation of the given SQL statement.
 * <p>The default implementation uses an LRU cache with an upper limit
 * of 256 entries.
 * @param sql the original SQL
 * @return a representation of the parsed SQL statement
 */
protected ExposedParsedSql getParsedSql(String sql) {
    if (getCacheLimit() <= 0) {
        return new ExposedParsedSql( NamedParameterUtils.parseSqlStatement(sql) );
    }
    synchronized (this.parsedSqlCache) {
        ExposedParsedSql parsedSql = this.parsedSqlCache.get(sql);
        if (parsedSql == null) {
            parsedSql = new ExposedParsedSql( NamedParameterUtils.parseSqlStatement(sql) );
            this.parsedSqlCache.put(sql, parsedSql);
        }
        return parsedSql;
    }
}
项目:gomall.la    文件:BaseJdbcDaoImpl.java   
public int updateNamedMap(String namedSql, Map<String, Object> paramMap) {
    String sql = NamedParameterUtils.parseSqlStatementIntoString(namedSql);
    Object[] args = NamedParameterUtils.buildValueArray(namedSql, paramMap);
    return jdbcTemplate.update(sql, args);
}
项目:jlubricant    文件:NamedJdbcCursorItemReader.java   
@Override
    protected void openCursor(Connection con) {

        //MyParsedSqlDel parsedSql = getParsedSql(sql);

        //String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql.getDelegate(), paramSource);

        //String theSql = sqlToUse;


        try {
//          if (isUseSharedExtendedConnection()) {
//              preparedStatement = con.prepareStatement(theSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
//                      ResultSet.HOLD_CURSORS_OVER_COMMIT);
//          }
//          else {
//              preparedStatement = con.prepareStatement(theSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
//          }
//          applyStatementSettings(preparedStatement);
//          if (this.preparedStatementSetter != null) {
//              
//              
//              preparedStatementSetter.setValues(preparedStatement);
//              
//              
//              
//              
//              
//          }
//          this.rs = preparedStatement.executeQuery();

            ParsedSql parsedSql1 = this.getParsedSql(sql).getDelegate();
            String sqlToUse1 = NamedParameterUtils.substituteNamedParameters(parsedSql1, paramSource);
            Object[] params = NamedParameterUtils.buildValueArray(parsedSql1, paramSource, null);
            List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql1, paramSource);
            PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse1, declaredParameters);
            pscf.setResultSetType( ResultSet.TYPE_FORWARD_ONLY );
            pscf.setUpdatableResults(false);
            PreparedStatementCreator preparedStatementCreator = pscf.newPreparedStatementCreator(params);

            //con.prepareStatement(theSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

            preparedStatement = preparedStatementCreator.createPreparedStatement(con);
            this.rs = preparedStatement.executeQuery();

            handleWarnings(preparedStatement);
        }
        catch (SQLException se) {
            close();
            throw getExceptionTranslator().translate("Executing query", getSql(), se);
        }

    }
项目: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);
}
项目: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);
}
项目:class-guard    文件: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);
}