Example usage for org.springframework.jdbc.core.namedparam MapSqlParameterSource getValue

List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource getValue

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam MapSqlParameterSource getValue.

Prototype

@Override
    @Nullable
    public Object getValue(String paramName) 

Source Link

Usage

From source file:com.eu.evaluation.server.dao.AbstractDAO.java

private Query initQueryParams(Query query, MapSqlParameterSource params) {
    if (params != null) {
        for (String paramsName : params.getValues().keySet()) {
            query.setParameter(paramsName, params.getValue(paramsName));
        }// w w w  . j a v  a2  s  . com
    }
    return query;
}

From source file:com.qualogy.qafe.business.resource.rdb.query.QueryToStringCreator.java

/**
 *
 * @param sql/*from   w ww.j a  v a 2s . c om*/
 * @param statement
 * @param namedParameters
 * @param inputMapping
 * @return
 */
// CHECKSTYLE.OFF: CyclomaticComplexity
private static String enrichSQLWithInParams(String sql, SQLQuery statement,
        MapSqlParameterSource namedParameters, String[] inputMapping) {
    if ((inputMapping != null) && (inputMapping.length > 0)) {
        if (statement instanceof Insert) {
            sql += " (";
            for (int i = 0; i < inputMapping.length; i++) {
                if (i > 0) {
                    sql += ", ";
                }
                sql += inputMapping[i];
            }
            sql += ") values (";
            for (int i = 0; i < inputMapping.length; i++) {
                if (i > 0) {
                    sql += ", ";
                }
                sql += (":" + inputMapping[i]);
            }
            sql += ")";
        } else if (statement instanceof Delete || statement instanceof Select || statement instanceof Update) {
            boolean first = true;
            if (sql.indexOf("where") < 0) {
                sql += " where ";
            } else {
                first = false;
            }

            // Added the extra where clause. Only for Delete and Update
            boolean whereAtrributeExist = false;
            if (statement instanceof Update) {
                if (((Update) statement).getWhere() != null) {
                    sql += ((Update) statement).getWhere();
                    whereAtrributeExist = true;
                }
            } else if (statement instanceof Delete) {
                if (((Delete) statement).getWhere() != null) {
                    sql += ((Delete) statement).getWhere();
                    whereAtrributeExist = true;
                }
            }

            if (!whereAtrributeExist) {
                for (int i = 0; i < inputMapping.length; i++) {
                    if (namedParameters != null) {
                        String columnName = getColumnName(namedParameters, inputMapping[i]);
                        if (StringUtils.isNotBlank(columnName)
                                && namedParameters.getValue(columnName) instanceof String) {
                            String userFilledValue = (String) namedParameters.getValue(columnName);
                            String userOperator = getUserFirstUsedOperator(userFilledValue);

                            if (StringUtils.isNotBlank(userFilledValue)) {
                                if (StringUtils.isNotBlank(userOperator)) {
                                    boolean isReverseCondition = false;
                                    sql += generateConditionForUserFilledValue(isReverseCondition, userOperator,
                                            userFilledValue, columnName, namedParameters);
                                } else {
                                    sql += generateEquality(columnName, columnName);
                                }
                            }
                        } else {
                            sql += generateEquality(inputMapping[i], inputMapping[i]);
                        }
                    } else {
                        sql += generateEquality(inputMapping[i], inputMapping[i]);
                    }
                }
            }
        } else {
            throw new IllegalArgumentException(
                    "cannot enrich [" + statement.getKeyword() + "], unsupported action");
        }
    }
    sql = finalClean(sql);
    return sql;
}