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

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

Introduction

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

Prototype

public MapSqlParameterSource() 

Source Link

Document

Create an empty MapSqlParameterSource, with values to be added via addValue .

Usage

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public List<JochreDocument> findDocuments() {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_DOCUMENT + " FROM ocr_document ORDER BY doc_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    LOG.info(sql);//from w w  w .  java  2  s  .  co m
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<JochreDocument> documents = jt.query(sql, paramSource,
            new JochreDocumentMapper(this.getDocumentServiceInternal()));

    return documents;
}

From source file:com.exploringspatial.dao.impl.ConflictDaoImpl.java

private MapSqlParameterSource buildMapSqlParameterSource(Conflict instance) {
    final DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    final MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource();
    mapSqlParameterSource.addValue("gwno", instance.getGwno());
    mapSqlParameterSource.addValue("event_id_cnty", instance.getEventIdCountry());
    mapSqlParameterSource.addValue("eventId", instance.getEventPk());
    mapSqlParameterSource.addValue("eventDate", df.format(instance.getEventDate()));
    mapSqlParameterSource.addValue("year", instance.getYear());
    mapSqlParameterSource.addValue("timePrecision", instance.getTimePrecision());
    mapSqlParameterSource.addValue("eventType", instance.getEventType());
    mapSqlParameterSource.addValue("actor1", instance.getActor1());
    mapSqlParameterSource.addValue("allyActor1", instance.getAllyActor1());
    mapSqlParameterSource.addValue("inter1", instance.getInter1());
    mapSqlParameterSource.addValue("actor2", instance.getActor2());
    mapSqlParameterSource.addValue("allyActor2", instance.getAllyActor2());
    mapSqlParameterSource.addValue("inter2", instance.getInter2());
    mapSqlParameterSource.addValue("interaction", instance.getInteraction());
    mapSqlParameterSource.addValue("country", instance.getCountry());
    mapSqlParameterSource.addValue("admin1", instance.getAdmin1());
    mapSqlParameterSource.addValue("admin2", instance.getAdmin2());
    mapSqlParameterSource.addValue("admin3", instance.getAdmin3());
    mapSqlParameterSource.addValue("location", instance.getLocation());
    mapSqlParameterSource.addValue("latitude", instance.getLatitude());
    mapSqlParameterSource.addValue("longitude", instance.getLongitude());
    mapSqlParameterSource.addValue("geoPrecision", instance.getGwno());
    mapSqlParameterSource.addValue("source", instance.getSource());
    mapSqlParameterSource.addValue("notes", instance.getNotes());
    mapSqlParameterSource.addValue("fatalities", instance.getFatalities());
    return mapSqlParameterSource;
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaRiverDao.java

public List<Drop> getDrops(Long riverId, DropFilter filter, int page, int dropCount, Account queryingAccount) {

    String sql = "SELECT droplets.id, rivers_droplets.id AS tracking_id, ";
    sql += "droplet_title, droplet_content, droplets.channel, ";
    sql += "identities.id AS identity_id, identity_name, identity_avatar, ";
    sql += "rivers_droplets.droplet_date_pub, droplet_orig_id, ";
    sql += "user_scores.score AS user_score, links.id as original_url_id, ";
    sql += "links.url AS original_url, comment_count, river_droplets_read.rivers_droplets_id AS drop_read ";
    sql += "FROM rivers_droplets ";
    sql += "INNER JOIN droplets ON (rivers_droplets.droplet_id = droplets.id) ";
    sql += "INNER JOIN identities ON (droplets.identity_id = identities.id) ";

    if (filter.getChannelIds() != null && !filter.getChannelIds().isEmpty()) {
        sql += "INNER JOIN river_channels ON (rivers_droplets.river_channel_id = river_channels.id) ";
    }//from   www  .j  a v  a2s. c  o m

    sql += "LEFT JOIN droplet_scores AS user_scores ON (user_scores.droplet_id = droplets.id AND user_scores.user_id = :userId) ";
    sql += "LEFT JOIN links ON (links.id = droplets.original_url) ";
    sql += "LEFT JOIN river_droplets_read ON (river_droplets_read.rivers_droplets_id = rivers_droplets.id AND river_droplets_read.account_id = :accountId) ";
    sql += "WHERE rivers_droplets.droplet_date_pub > '1970-01-01 00:00:00' ";
    sql += "AND rivers_droplets.river_id = :riverId ";

    if (filter.getSinceId() != null) {
        sql += "AND rivers_droplets.id > :since_id ";
    }

    if (filter.getMaxId() != null) {
        sql += "AND rivers_droplets.id <= :max_id ";
    }

    if (filter.getChannels() != null && !filter.getChannels().isEmpty()) {
        sql += "AND `droplets`.`channel` IN (:channels) ";
    }

    if (filter.getChannelIds() != null && !filter.getChannelIds().isEmpty()) {
        sql += "AND rivers_droplets.river_channel_id IN (:channel_ids) ";
    }

    if (filter.getRead() != null) {
        if (filter.getRead()) {
            sql += "AND river_droplets_read.rivers_droplets_id IS NOT NULL ";
        } else {
            sql += "AND river_droplets_read.rivers_droplets_id IS NULL ";
        }
    }

    if (filter.getPhotos() != null && filter.getPhotos()) {
        sql += "AND `droplets`.`droplet_image` > 0 ";
    }

    if (filter.getDateFrom() != null) {
        sql += "AND rivers_droplets.droplet_date_pub >= :date_from ";
    }

    if (filter.getDateTo() != null) {
        sql += "AND rivers_droplets.droplet_date_pub <= :date_to ";
    }

    if (filter.getDropIds() != null && !filter.getDropIds().isEmpty()) {
        sql += "AND `droplets`.`id` IN (:dropIds) ";
    }

    boolean newer = filter.getSinceId() != null;

    if (newer) {
        sql += "ORDER BY rivers_droplets.droplet_date_pub ASC ";
    } else {
        sql += "ORDER BY rivers_droplets.droplet_date_pub DESC ";
    }

    sql += "LIMIT " + dropCount + " OFFSET " + dropCount * (page - 1);

    // Set the query parameters
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("userId", queryingAccount.getOwner().getId());
    params.addValue("accountId", queryingAccount.getId());
    params.addValue("riverId", riverId);

    if (filter.getSinceId() != null) {
        params.addValue("since_id", filter.getSinceId());
    }

    if (filter.getMaxId() != null) {
        params.addValue("max_id", filter.getMaxId());
    }

    if (filter.getChannels() != null && !filter.getChannels().isEmpty()) {
        params.addValue("channels", filter.getChannels());
    }

    if (filter.getChannelIds() != null && !filter.getChannelIds().isEmpty()) {
        params.addValue("channel_ids", filter.getChannelIds());
    }

    if (filter.getDateFrom() != null) {
        params.addValue("date_from", filter.getDateFrom());
    }

    if (filter.getDateTo() != null) {
        params.addValue("date_to", filter.getDateTo());
    }

    if (filter.getDropIds() != null && !filter.getDropIds().isEmpty()) {
        params.addValue("dropIds", filter.getDropIds());
    }

    List<Map<String, Object>> results = this.jdbcTemplate.queryForList(sql, params);

    return formatDrops(results, queryingAccount);
}

From source file:com.epam.catgenome.dao.BiologicalDataItemDao.java

/**
 * Finds files with a specified file name, checks name for strict, case sensitive equality
 * @param name search query/*  ww  w  . j a  v a2s .  c om*/
 * @return {@code List} of files with a matching name
 */
@Transactional(propagation = Propagation.MANDATORY)
public List<BiologicalDataItem> loadFilesByNameStrict(final String name) {
    final MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(BiologicalDataItemParameters.NAME.name(), name);
    return getNamedParameterJdbcTemplate().query(loadBiologicalDataItemsByNameStrictQuery, params,
            getRowMapper());
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public void deleteCategory(int categoryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    String sql = "DELETE FROM ftb_category WHERE cat_id = :cat_id";
    paramSource.addValue("cat_id", categoryId);
    LOG.info(sql);/*from  ww  w.  j  a va 2  s. c om*/
    TreebankDaoImpl.LogParameters(paramSource);
    jt.update(sql, paramSource);
}

From source file:com.epam.catgenome.dao.reference.ReferenceGenomeDao.java

@Transactional(propagation = Propagation.MANDATORY)
public void updateReferenceGeneFileId(long referenceId, Long geneFileId) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(GenomeParameters.REFERENCE_GENOME_ID.name(), referenceId);
    params.addValue(GenomeParameters.GENE_ITEM_ID.name(), geneFileId);

    getNamedParameterJdbcTemplate().update(updateReferenceGeneFileIdQuery, params);
}

From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java

public int saveConversation(int requestId, int responseId) throws DataAccessException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(REQUESTID, requestId, Types.INTEGER);
    params.addValue(RESPONSEID, responseId, Types.INTEGER);

    KeyHolder key = new GeneratedKeyHolder();
    getNamedParameterJdbcTemplate().update(INSERT_CONVERSATION, params, key);
    return key.getKey().intValue();
}

From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java

@Override
public void setExperimentTaskResult(int experimentTaskId, ExperimentTaskResult result) {
    // Note that we have to set the state first if we want to override the
    // automatic timestamp with the one from the
    // result object
    setExperimentState(experimentTaskId, result.state);

    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("id", experimentTaskId);
    parameters.addValue("microF1", result.getMicroF1Measure());
    parameters.addValue("microPrecision", result.getMicroPrecision());
    parameters.addValue("microRecall", result.getMicroRecall());
    parameters.addValue("macroF1", result.getMacroF1Measure());
    parameters.addValue("macroPrecision", result.getMacroPrecision());
    parameters.addValue("macroRecall", result.getMacroRecall());
    parameters.addValue("errorCount", result.getErrorCount());
    parameters.addValue("lastChanged", new java.sql.Timestamp(result.timestamp));

    this.template.update(SET_EXPERIMENT_TASK_RESULT, parameters);
}

From source file:org.mulima.internal.freedb.FreeDbJdbcDaoImpl.java

/**
 * Adds CDDB ids for the disc id./*www.j  a  va  2  s  .  c o m*/
 * @param discId the disc id
 * @param disc the disc with the cddb ids
 */
private void addCddbIds(int discId, Disc disc) {
    logger.trace("Entering addCddbIds");
    final String sql = "INSERT INTO `cddb_ids` VALUES(null, :disc_id, :cddb_id)";
    List<String> cddbIds = disc.getAll(GenericTag.CDDB_ID);
    MapSqlParameterSource[] parms = new MapSqlParameterSource[cddbIds.size()];

    for (int i = 0; i < cddbIds.size(); i++) {
        parms[i] = new MapSqlParameterSource();
        parms[i].addValue("disc_id", discId);
        parms[i].addValue("cddb_id", cddbIds.get(i));
    }
    this.getNamedParameterJdbcTemplate().batchUpdate(sql, parms);
    logger.trace("Exiting addCddbIds");
}

From source file:net.algem.security.UserDaoImpl.java

@Override
public boolean isMemberOnYear(String login, String start, String end) {
    try {//from   w  ww .  jav  a2 s  . com
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue("login", login);
        params.addValue("start", new java.sql.Date(GemConstants.DATE_FORMAT.parse(start).getTime()));
        params.addValue("end", new java.sql.Date(GemConstants.DATE_FORMAT.parse(end).getTime()));
        params.addValue("accounts", getMemberShipAccounts());
        //      String debug = login +","+start+","+end+","+getMemberShipAccounts();
        //      LOGGER.log(Level.INFO, debug);
        String query = "SELECT e.paye FROM echeancier2 e JOIN " + TABLE + " l ON (e.adherent = l.idper)"
                + " WHERE l.login = :login AND e.echeance BETWEEN :start AND :end AND e.compte IN(:accounts)";
        List<Boolean> result = namedJdbcTemplate.query(query, params, new RowMapper<Boolean>() {

            @Override
            public Boolean mapRow(ResultSet rs, int i) throws SQLException {
                return rs.getBoolean(1);
            }
        });
        for (Boolean b : result) {
            if (b) {
                return true;
            }
        }
        return false;
    } catch (ParseException | DataAccessException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        return false;
    }

}