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

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

Introduction

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

Prototype

public MapSqlParameterSource addValues(@Nullable Map<String, ?> values) 

Source Link

Document

Add a Map of parameters to this parameter source.

Usage

From source file:fr.acxio.tools.agia.item.database.MapSqlParameterSourceProvider.java

@Override
public SqlParameterSource createSqlParameterSource(Map<String, Object> sItem) {
    MapSqlParameterSource aMapSqlParameterSource = new MapSqlParameterSource();
    aMapSqlParameterSource.addValues(sItem);
    return aMapSqlParameterSource;
}

From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestSuiteImpl.java

private MapSqlParameterSource getCompleteParameters() {
    MapSqlParameterSource tcParameters = getInitialDataParameters();
    tcParameters.addValues(getGuidParameter().getValues());
    tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp());
    tcParameters.addValue("warning", testSuite.getWarningTime());
    tcParameters.addValue("critical", testSuite.getCriticalTime());
    tcParameters.addValue("duration", testSuite.getDuration());
    //try to save the screenshot
    try {//from ww w  .jav  a  2 s  .co m
        if (testSuite.getScreenShotPath() != null) {
            final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath());
            final int length = (int) testSuite.getScreenShotPath().toFile().length();
            tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    tcParameters.addValue("msg", testSuite.getExceptionMessages());
    return tcParameters;
}

From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java

private MapSqlParameterSource getCompleteParameters() {
    MapSqlParameterSource tcParameters = getInitialDataParameters();
    tcParameters.addValues(getGuidParameter().getValues());
    tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp());
    int warningTime = testSuite.getWarningTime();
    tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
    int criticalTime = testSuite.getCriticalTime();
    tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null);
    tcParameters.addValue("duration", testSuite.getDuration());
    //try to save the screenshot
    try {/*w ww . j  a  v a 2s .  c o m*/
        if (testSuite.getScreenShotPath() != null) {
            final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath());
            final int length = (int) testSuite.getScreenShotPath().toFile().length();
            tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    tcParameters.addValue("msg", testSuite.getExceptionMessages());
    return tcParameters;
}

From source file:org.smart.migrate.dao.impl.DefaultImportDao.java

@Override
public void saveTargetData(TableSetting tableSetting, List<Map<String, Object>> targetDataList) {

    String sql = "INSERT INTO " + tableSetting.getTargetTable() + " ("
            + SettingUtils.getTargetFields(tableSetting) + ")";
    sql += " VALUES (" + SettingUtils.getTargetPreparedFields(tableSetting) + ")";

    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(targetJdbcTemplate);
    List<MapSqlParameterSource> parameterSources = new ArrayList<MapSqlParameterSource>();
    for (Map<String, Object> targetData : targetDataList) {
        MapSqlParameterSource psource = new MapSqlParameterSource();
        psource.addValues(targetData);
        parameterSources.add(psource);/* w  ww. j a va 2 s  .c  o  m*/
    }

    namedParameterJdbcTemplate.batchUpdate(sql, parameterSources.toArray(new MapSqlParameterSource[0]));
}

From source file:com.qualogy.qafe.business.integration.rdb.SQLQueryDAO.java

private Object execute(RDBDatasource ds, SQLQuery stmt, Map<String, AdaptedToService> paramsIn,
        Set outputMapping, Filters filters, DataIdentifier dataId) {
    Long oldChecksum = null;/*from  w ww. j  a  v  a  2  s  .c o  m*/
    if (isConcurrentModificationEnabled()) {
        oldChecksum = ConflictDetectionUtil.removeChecksum(paramsIn);
    }

    String[] inputKeys = null;
    Map<String, Object> paramIns = new HashMap<String, Object>();
    if (paramsIn != null) {
        paramIns = narrow(paramsIn);
        inputKeys = (String[]) paramIns.keySet().toArray(new String[paramIns.size()]);
    }
    MapSqlParameterSource namedParameters = new MapSqlParameterSource(paramIns);
    Object result = null;
    isCountOnly = DataStore.findValue(dataId, DataStore.KEY_WORD_COUNT) != null;
    String sql = QueryToStringCreator.toString(stmt, namedParameters, inputKeys, outputMapping);
    Map values = namedParameters.getValues();
    if ((values != null) && (values.size() > 0)) {
        Map replacementMap = new HashMap<String, Object>();
        for (String key : inputKeys) {
            if (values.containsKey(key.toUpperCase())) {
                replacementMap.put(key, values.get(key.toUpperCase()));
            }
            if (values.containsKey(key.toLowerCase())) {
                replacementMap.put(key, values.get(key.toLowerCase()));
            }
        }
        namedParameters.addValues(replacementMap);
    }
    logger.info("Executing SQL: " + sql);
    SimpleJdbcTemplate template = new SimpleJdbcTemplate(ds.getDataSource());
    try {
        Connection conn = ds.getDataSource().getConnection();
        dialect = getDatabaseDialect(conn);
        DataSourceUtils.releaseConnection(conn, ds.getDataSource());
    } catch (SQLException e) {
        ExceptionHelper.printStackTrace(e);
    }
    if (stmt instanceof Select) {
        result = handleSelect(sql, namedParameters, (Select) stmt, template, filters);
        if (!isCountOnly && isConcurrentModificationEnabled()) {
            ConflictDetectionUtil.addChecksums((List<Map<String, Object>>) result, sql);
        }
    } else if (stmt instanceof Insert) {
        result = handleInsert(sql, namedParameters, (Insert) stmt, template);
        if (isConcurrentModificationEnabled()) {
            DataStore.store(dataId, DataStore.KEY_SERVICE_MODIFY);
        }
    } else if (stmt instanceof SQLOnly) {
        result = handleQueryTag(sql, namedParameters, template);
    } else {
        if (isConcurrentModificationEnabled()) {
            ConflictDetectionUtil.validateChecksum(template, sql, namedParameters.getValues(), oldChecksum);
        }
        template.update(sql, namedParameters);
        if (isConcurrentModificationEnabled()) {
            DataStore.store(dataId, DataStore.KEY_SERVICE_MODIFY);
        }
    }
    return result;
}