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

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

Introduction

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

Prototype

public MapSqlParameterSource addValue(String paramName, @Nullable Object value) 

Source Link

Document

Add a parameter to this parameter source.

Usage

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

private MapSqlParameterSource getInitialDataParameters() {
    MapSqlParameterSource tcParameters = getGuidParameter();
    tcParameters.addValue("id", testSuite.getDbPrimaryKey());
    tcParameters.addValue("suiteID", testSuite.getId());
    if (testSuite.getState() != null) {
        tcParameters.addValue("result", testSuite.getState().getErrorCode());
        tcParameters.addValue("result_desc", testSuite.getState().toString());
    }//from  ww w .  j  ava 2  s  . c  om
    tcParameters.addValue("name", testSuite.getName());
    tcParameters.addValue("browser", testSuite.getBrowserInfo());
    tcParameters.addValue("host", testSuite.getHost());
    tcParameters.addValue("start", testSuite.getStartDateAsUnixTimestamp());
    return tcParameters;
}

From source file:com.eu.evaluation.server.service.impl.eva.UniqueEvaluate.java

public boolean evaluate(String evaluateItemHistoryID, AccessSystem accessSystem, String instanceClass,
        int instanceType, String instanceID) throws Exception {
    String debugInfo = "{0}  = {1} ,  = {2} ,  = {3} , ID = {4}";
    EvaluateItemHistory ev = evaluateItemHistoryDAO.get(evaluateItemHistoryID);//
    logger.debug(MessageFormat.format(debugInfo, new Object[] { "", accessSystem.getName(),
            ev.getObjectDictionary().getDisplayname(), ev.getFieldDictionary().getDisplayname(), instanceID }));

    Object entity = defaultDAO.findEvaluateData(instanceClass, instanceID, ev.getEvaluateVersion().getId(),
            accessSystem);//??
    if (entity == null) {
        notPassMessage = "{0}  {1} ? {2} ? {3} , ID {4}  {5}";
        notPassMessage = MessageFormat.format(notPassMessage,
                new Object[] { ev.getObjectDictionary().getDisplayname(),
                        ev.getFieldDictionary().getDisplayname(), accessSystem.getName(),
                        ev.getEvaluateVersion().getName(), instanceID,
                        ev.getObjectDictionary().getDisplayname() });
        return false;
    }/*ww  w  .  j a  va 2  s  .  c om*/

    //???
    String field = ev.getFieldDictionary().getPropertyName();
    Object fieldValue = BeanUtils.getProperty(entity, field);

    //sql??
    String jpql = "select count(*) from {0} t where t.{1} = :value and t.evaluateVersion.id = :evID and t.position = :position";
    jpql = MessageFormat.format(jpql, new Object[] { instanceClass, field });

    MapSqlParameterSource params = new MapSqlParameterSource("value", fieldValue);
    params.addValue("evID", ev.getEvaluateVersion().getId());
    params.addValue("position", accessSystem.getCode());

    long count = defaultDAO.executeCount(jpql, params);

    if (count > 1) {//1?
        notPassMessage = getErrorMsg(ev, entity, accessSystem);
    }

    logger.debug(MessageFormat.format(debugInfo, new Object[] { "?", accessSystem.getName(),
            ev.getObjectDictionary().getDisplayname(), ev.getFieldDictionary().getDisplayname(), instanceID }));
    return count <= 1;
}

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

@Override
public void deleteTargetDataByPrimaryKeys(TableSetting tableSetting, List<String> primaryKeys) {
    String sql = "DELETE FROM " + tableSetting.getTargetTable() + " WHERE " + tableSetting.getTargetPK()
            + " in (:ids)";
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(targetJdbcTemplate);
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", primaryKeys);
    namedParameterJdbcTemplate.update(sql, parameters);
}

From source file:com.xinferin.dao.DAOLicenceImpl.java

@Override
public String checkRevoke(int licenceId) {
    String sql = "SELECT can_revoke FROM xlicenser.licence WHERE id = :id";

    MapSqlParameterSource args = new MapSqlParameterSource();
    args = new MapSqlParameterSource();
    args.addValue("id", licenceId);
    int can_revoke = jdbcTemplate.queryForObject(sql, args, Integer.class);

    if (can_revoke == 1) {
        return "REVOKE";
    } else {/*from  www . jav  a  2  s  . c  o  m*/
        return "OK";
    }
}

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

@Override
public List<Map<String, Object>> findSourceByPrimaryKeys(TableSetting tableSetting, List<String> primaryKeys) {

    String sql = "SELECT " + SettingUtils.getSourceFields(tableSetting) + " FROM "
            + tableSetting.getSourceTable();
    sql += " WHERE " + tableSetting.getSourcePK() + " in (:ids) ";

    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(sourceJdbcTemplate);
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", primaryKeys);
    return namedParameterJdbcTemplate.queryForList(sql, parameters);

}

From source file:airport.database.services.statistics.StatisticsDaoImpl.java

@Override
public void incAmountSecondsOnline(User user, int amountSeconds) {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("amountSeconds", amountSeconds);
    parameterSource.addValue("id", user.getId());

    jdbcTemplate.update(SQL_QUERY_INC_SECONDS_ONLINE, parameterSource);
}

From source file:com.eu.evaluation.server.dao.eva.history.EvaluateVersionDAO.java

public List<EvaluateVersion> find(EvaluateVersion ev, Calendar startDate, Calendar endDate) {
    String jpql = "select t from EvaluateVersion t where 1=1";
    MapSqlParameterSource params = new MapSqlParameterSource();
    if (!StringUtils.isBlank(ev.getId())) {
        jpql += " and t.id = :id";
        params.addValue("id", ev.getId());
    }//from w  ww. ja  v a 2s  .c om

    if (!StringUtils.isBlank(ev.getName())) {
        jpql += " and t.name like :name";
        params.addValue("name", "'" + ev.getName() + "'");
    }

    if (startDate != null) {
        jpql += " and t.createDate >= :startDate";
        params.addValue("startDate", startDate);
    }

    if (endDate != null) {
        jpql += " and t.createDate <= :endDate";
        params.addValue("endDate", endDate);
    }

    return this.query(jpql, params);
}

From source file:dao.LineageDAO.java

public static void getNodes(LineagePathInfo pathInfo, int level, int upLevel, int downLevel,
        LineageNode currentNode, List<LineageNode> allSourceNodes, List<LineageNode> allTargetNodes,
        Map<Long, List<LineageNode>> addedSourceNodes, Map<Long, List<LineageNode>> addedTargetNodes,
        Map<Long, LineageNode> addedJobNodes, int lookBackTime) {
    if (upLevel < 1 && downLevel < 1) {
        return;//from ww  w  .j  a v  a  2 s . c o m
    }
    if (currentNode != null) {
        if (StringUtils.isBlank(currentNode.source_target_type)) {
            Logger.error("Source target type is not available");
            Logger.error(currentNode.abstracted_path);
            return;
        } else if (currentNode.source_target_type.equalsIgnoreCase("target") && downLevel <= 0) {
            Logger.warn(
                    "Dataset " + currentNode.abstracted_path + " downLevel = " + Integer.toString(downLevel));
            return;
        } else if (currentNode.source_target_type.equalsIgnoreCase("source") && upLevel <= 0) {
            Logger.warn("Dataset " + currentNode.abstracted_path + " upLevel = " + Integer.toString(upLevel));
            return;
        }
    }
    List<String> nameList = getLiasDatasetNames(pathInfo.filePath);
    List<Map<String, Object>> rows = null;
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("names", nameList);
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
            getJdbcTemplate().getDataSource());
    parameters.addValue("days", lookBackTime);

    if (currentNode != null) {
        if (currentNode.source_target_type.equalsIgnoreCase("source")) {
            rows = namedParameterJdbcTemplate.queryForList(GET_UP_LEVEL_JOB, parameters);
        } else {
            parameters.addValue("type", currentNode.source_target_type);
            rows = namedParameterJdbcTemplate.queryForList(GET_JOB_WITH_SOURCE, parameters);
        }

    } else {
        rows = namedParameterJdbcTemplate.queryForList(GET_JOB, parameters);
    }

    if (rows != null) {
        for (Map row : rows) {
            LineageNode node = new LineageNode();
            Object jobExecIdObject = row.get("job_exec_id");
            if (jobExecIdObject == null) {
                continue;
            }
            Long jobExecId = ((BigInteger) jobExecIdObject).longValue();
            if (addedJobNodes.get(jobExecId) != null) {
                continue;
            }
            node._sort_list = new ArrayList<String>();
            node.node_type = "script";
            node.job_type = (String) row.get("job_type");
            node.cluster = (String) row.get("cluster");
            node.job_name = (String) row.get("job_name");
            node.job_path = (String) row.get("flow_path") + "/" + node.job_name;
            node.exec_id = jobExecId;
            node.operation = (String) row.get("operation");
            node.source_target_type = (String) row.get("source_target_type");
            node.level = level;
            node._sort_list.add("cluster");
            node._sort_list.add("job_path");
            node._sort_list.add("job_name");
            node._sort_list.add("job_type");
            node._sort_list.add("job_start_time");
            node._sort_list.add("job_end_time");
            node._sort_list.add("exec_id");
            addedJobNodes.put(jobExecId, node);
            List<LineageNode> sourceNodeList = new ArrayList<LineageNode>();
            List<LineageNode> targetNodeList = new ArrayList<LineageNode>();
            int applicationID = (int) row.get("app_id");
            Long jobId = ((BigInteger) row.get("job_exec_id")).longValue();
            List<Map<String, Object>> relatedDataRows = null;

            if (node.source_target_type.equalsIgnoreCase("source")
                    && node.operation.equalsIgnoreCase("JDBC Read")) {
                MapSqlParameterSource lassenParams = new MapSqlParameterSource();
                lassenParams.addValue("names", nameList);
                lassenParams.addValue("appid", applicationID);
                lassenParams.addValue("execid", jobId);
                relatedDataRows = namedParameterJdbcTemplate.queryForList(GET_DATA_FILTER_OUT_LASSEN,
                        lassenParams);
            } else {
                relatedDataRows = getJdbcTemplate().queryForList(GET_DATA, applicationID, jobId);
            }

            if (relatedDataRows != null) {
                for (Map relatedDataRow : relatedDataRows) {
                    String abstractedObjectName = (String) relatedDataRow.get("abstracted_object_name");
                    if (abstractedObjectName.startsWith("/tmp/")) {
                        continue;
                    }
                    String relatedSourceType = (String) relatedDataRow.get("source_target_type");
                    LineageNode relatedNode = new LineageNode();
                    relatedNode._sort_list = new ArrayList<String>();
                    relatedNode.node_type = "data";
                    relatedNode.level = level;
                    relatedNode.source_target_type = relatedSourceType;
                    relatedNode.abstracted_path = (String) relatedDataRow.get("abstracted_object_name");
                    relatedNode.storage_type = ((String) relatedDataRow.get("storage_type")).toLowerCase();
                    relatedNode.job_start_unix_time = (Long) relatedDataRow.get("job_start_unixtime");
                    relatedNode.job_end_unix_time = (Long) relatedDataRow.get("job_finished_unixtime");

                    relatedNode.job_start_time = DateFormat.format(relatedDataRow.get("start_time").toString());
                    relatedNode.job_end_time = DateFormat.format(relatedDataRow.get("end_time").toString());

                    node.job_start_unix_time = relatedNode.job_start_unix_time;
                    node.job_end_unix_time = relatedNode.job_end_unix_time;
                    node.job_start_time = relatedNode.job_start_time;
                    node.job_end_time = relatedNode.job_end_time;
                    relatedNode.operation = (String) relatedDataRow.get("operation");
                    LineagePathInfo info = new LineagePathInfo();
                    info.filePath = relatedNode.abstracted_path;
                    info.storageType = relatedNode.storage_type;
                    relatedNode.urn = utils.Lineage.convertToURN(info);
                    relatedNode._sort_list.add("abstracted_path");
                    relatedNode._sort_list.add("storage_type");
                    relatedNode._sort_list.add("urn");
                    if (relatedSourceType.equalsIgnoreCase("source")) {
                        if (node.source_target_type.equalsIgnoreCase("target")
                                || utils.Lineage.isInList(nameList, relatedNode.abstracted_path)) {
                            sourceNodeList.add(relatedNode);
                            allSourceNodes.add(relatedNode);
                        }
                    } else if (relatedSourceType.equalsIgnoreCase("target")) {
                        if (node.source_target_type.equalsIgnoreCase("source")
                                || utils.Lineage.isInList(nameList, relatedNode.abstracted_path)) {
                            targetNodeList.add(relatedNode);
                            allTargetNodes.add(relatedNode);
                        }
                    }
                }
                if (sourceNodeList.size() > 0) {
                    addedSourceNodes.put(jobExecId, sourceNodeList);
                }
                if (targetNodeList.size() > 0) {
                    addedTargetNodes.put(jobExecId, targetNodeList);
                }
            }
        }
    }
    if ((allSourceNodes != null) && (allSourceNodes.size() > 0) && (upLevel > 1)) {
        List<LineageNode> currentSourceNodes = new ArrayList<LineageNode>();
        currentSourceNodes.addAll(allSourceNodes);
        for (LineageNode sourceNode : currentSourceNodes) {
            LineagePathInfo subPath = new LineagePathInfo();
            subPath.storageType = sourceNode.storage_type;
            subPath.filePath = sourceNode.abstracted_path;
            if (sourceNode.level == level) {
                getObjectAdjacentNode(subPath, level + 1, upLevel - 1, 0, sourceNode, allSourceNodes,
                        allTargetNodes, addedSourceNodes, addedTargetNodes, addedJobNodes, lookBackTime);
            }
        }
    }
    if ((allTargetNodes != null) && (allTargetNodes.size() > 0) && (downLevel > 1)) {
        List<LineageNode> currentTargetNodes = new ArrayList<LineageNode>();
        currentTargetNodes.addAll(allTargetNodes);
        for (LineageNode targetNode : currentTargetNodes) {
            LineagePathInfo subPath = new LineagePathInfo();
            subPath.storageType = targetNode.storage_type;
            subPath.filePath = targetNode.abstracted_path;
            if (targetNode.level == level) {
                getObjectAdjacentNode(subPath, level - 1, 0, downLevel - 1, targetNode, allSourceNodes,
                        allTargetNodes, addedSourceNodes, addedTargetNodes, addedJobNodes, lookBackTime);
            }
        }
    }

}

From source file:ru.org.linux.user.UserTagDao.java

/**
 *    ? ./*  w  w w . j ava  2 s .c o m*/
 *
 * @param tagId   
 */
public void deleteTags(int tagId) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("tag_id", tagId);
    jdbcTemplate.update("DELETE FROM user_tags WHERE tag_id=:tag_id", parameters);
}

From source file:airport.database.services.chat.ChatDaoImpl.java

@Override
public void addMessage(User user, String text, Timestamp timestampMessage) {
    SqlParameterSource parameterUser = new MapSqlParameterSource(PARAMETER_SQL_QUERY_LOGIN, user.getLogin());

    int numberUser = jdbcTemplate.queryForObject(SQL_QUERY_SEEK_USER, parameterUser, Integer.class);

    MapSqlParameterSource parameterMessage = new MapSqlParameterSource();
    parameterMessage.addValue(PARAMETER_SQL_QUERY_USER_ID, numberUser);
    parameterMessage.addValue(PARAMETER_SQL_QUERY_TEXT, text);
    parameterMessage.addValue(PARAMETER_SQL_QUERY_DATE, timestampMessage);

    jdbcTemplate.update(SQL_QUERY_ADD_MESSAGE, parameterMessage);

    if (LOG.isInfoEnabled()) {
        LOG.info(// w w  w  .j  a  v  a2 s  .c  o m
                "add message. User : " + user + ". Text : " + text + ". Time : " + timestampMessage.toString());
    }
}