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.inbio.modeling.core.dao.impl.LayerDAOImpl.java

@Override
public Layer findByName(String name) {
    String sqlStatement = null;//from   w ww.  j  av a 2 s .  c  o m
    MapSqlParameterSource args = null;
    Layer layer = null;

    sqlStatement = "SELECT * FROM " + this.table + " " + " WHERE name = :name limit 1 ";

    args = new MapSqlParameterSource();
    args.addValue("name", name);

    layer = getSimpleJdbcTemplate().queryForObject(sqlStatement, new LayerRowMapper(), args);

    return layer;
}

From source file:org.inbio.modeling.core.dao.impl.SystemUserDAOImpl.java

@Override
public SystemUser findByUsername(final String username) {

    String sqlStatement = null;//from   w ww.  jav a 2s  . co m
    MapSqlParameterSource args = null;
    SystemUser systemUser = null;

    try {
        sqlStatement = "Select * from " + this.table + " where username = :username";

        args = new MapSqlParameterSource();
        args.addValue("username", username);

        systemUser = getSimpleJdbcTemplate().queryForObject(sqlStatement, new SystemUserRowMapper(), args);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return systemUser;
}

From source file:org.inbio.modeling.core.dao.impl.LayerDAOImpl.java

@Override
public List<Layer> findAllSpeciesLayers() {
    String sqlStatement = null;//from w ww. j  a  v  a2 s .c  o  m
    MapSqlParameterSource args = null;
    List<Layer> layers = null;

    sqlStatement = "SELECT * FROM " + this.table + " " + " WHERE is_species_map = :isSpecies";

    args = new MapSqlParameterSource();
    args.addValue("isSpecies", true);

    layers = getSimpleJdbcTemplate().query(sqlStatement, new LayerRowMapper(), args);

    return layers;
}

From source file:org.inbio.ait.dao.sys.impl.SystemUserDAOImpl.java

@Override
public void updateUser(SystemUser user) {
    String sqlStatement = null;/*from  ww w .  j a  va 2 s .co m*/
    MapSqlParameterSource args = null;

    try {
        sqlStatement = "UPDATE ait.users " + "SET fullname = :fullname " + ", password = :password "
                + ", enabled = :enabled " + ", roles = :roles " + " WHERE username = :username ";

        args = new MapSqlParameterSource();
        args.addValue("username", user.getUsername());
        args.addValue("fullname", user.getFullname());
        args.addValue("password", user.getPassword());
        args.addValue("enabled", user.isEnabled());
        args.addValue("roles", user.getRoles());

        getSimpleJdbcTemplate().update(sqlStatement, args);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.gst.portfolio.search.service.SearchReadPlatformServiceImpl.java

@Override
public Collection<SearchData> retriveMatchingData(final SearchConditions searchConditions) {
    final AppUser currentUser = this.context.authenticatedUser();
    final String hierarchy = currentUser.getOffice().getHierarchy();

    final SearchMapper rm = new SearchMapper();

    final MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("hierarchy", hierarchy + "%");
    if (searchConditions.getExactMatch()) {
        params.addValue("search", searchConditions.getSearchQuery());
    } else {//  w  w  w . j  a v a2  s .c  o  m
        params.addValue("search", "%" + searchConditions.getSearchQuery() + "%");
    }
    return this.namedParameterjdbcTemplate.query(rm.searchSchema(searchConditions), params, rm);
}

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

/**
 * For the given list of new drops, find those that the media hash already
 * exists in the db and update the drop entry with the existing id. Also
 * remove the hash from the new media index for those that already exist.
 * /*from  w  ww  . java2 s  . c o m*/
 * @param newMediaIndex
 * @param drops
 */
private void updateNewMediaIndex(Map<String, List<int[]>> newMediaIndex, List<Drop> drops) {
    // First find and update existing drops with their ids.
    String sql = "SELECT id, hash FROM media WHERE hash IN (:hashes)";

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("hashes", newMediaIndex.keySet());

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

    // Update id for the drops that were found
    for (Map<String, Object> result : results) {
        String hash = (String) result.get("hash");
        Long id = ((Number) result.get("id")).longValue();

        List<int[]> indexes = newMediaIndex.get(hash);
        for (int[] index : indexes) {
            drops.get(index[0]).getMedia().get(index[1]).setId(id);
        }

        // Hash is not for a new drop so remove it
        newMediaIndex.remove(hash);
    }
}

From source file:com.epam.catgenome.dao.vcf.VcfFileDao.java

/**
 * Saves sample metadata to the database.
 *
 * @param samples   {@code List&lt;Sample&gt;} samples to save
 * @param vcfFileId {@code long} file ID to save samples for
 *//*from   ww  w .  j  a v a 2s .  co  m*/
@Transactional(propagation = Propagation.MANDATORY)
public void createSamples(List<VcfSample> samples, long vcfFileId) {
    List<Long> sampleIds = daoHelper.createIds(vcfSampleSequenceName, samples.size());
    for (int i = 0; i < samples.size(); i++) {
        samples.get(i).setId(sampleIds.get(i));
    }

    final List<MapSqlParameterSource> params = new ArrayList<>();
    for (VcfSample sample : samples) {

        MapSqlParameterSource param = new MapSqlParameterSource();
        param.addValue(SampleParameters.VCF_SAMPLE_ID.name(), sample.getId());
        param.addValue(SampleParameters.VCF_ID.name(), vcfFileId);
        param.addValue(SampleParameters.SAMPLE_NAME.name(), sample.getName());
        param.addValue(SampleParameters.ORDER_INDEX.name(), sample.getIndex());
        params.add(param);
    }

    getNamedParameterJdbcTemplate().batchUpdate(createSamplesForFileQuery,
            params.toArray(new MapSqlParameterSource[params.size()]));
}

From source file:com.ushahidi.swiftriver.core.api.service.DropIndexService.java

/**
 * Sets the <code>riverIds</code> property for each {@link Drop}
 * in <code>drops</code>/*ww w. j  a v  a  2 s . c o  m*/
 * 
 * @param drops
 */
private void populateRiverIds(List<Drop> drops) {
    // Store the drop index
    Map<Long, Integer> dropIndex = new HashMap<Long, Integer>();
    List<Long> dropIds = new ArrayList<Long>();
    int index = 0;
    for (Drop drop : drops) {
        dropIds.add(drop.getId());
        dropIndex.put(drop.getId(), index);
        index++;
    }

    String sql = "SELECT `droplet_id`, `river_id` " + "FROM `rivers_droplets` WHERE `droplet_id` IN (:dropIds)";

    MapSqlParameterSource paramMap = new MapSqlParameterSource();
    paramMap.addValue("dropIds", dropIds);

    for (Map<String, Object> row : namedJdbcTemplate.queryForList(sql, paramMap)) {
        Long dropId = ((Number) row.get("droplet_id")).longValue();
        Long riverId = ((Number) row.get("river_id")).longValue();

        Drop drop = drops.get(dropIndex.get(dropId));
        if (drop.getRiverIds() == null) {
            drop.setRiverIds(new ArrayList<Long>());
        }
        drop.getRiverIds().add(riverId);
    }

}

From source file:com.ushahidi.swiftriver.core.api.service.DropIndexService.java

/**
 * Sets the <code>bucketIds</code> property for each {@link Drop}
 * in <code>drops</code>//from  ww  w  .  j a  v  a 2s . c o  m
 * @param drops
 */
private void populateBucketIds(List<Drop> drops) {
    // Store the drop index
    Map<Long, Integer> dropIndex = new HashMap<Long, Integer>();
    List<Long> dropIds = new ArrayList<Long>();
    int index = 0;
    for (Drop drop : drops) {
        dropIds.add(drop.getId());
        dropIndex.put(drop.getId(), index);
        index++;
    }

    String sql = "SELECT `droplet_id`, `bucket_id` "
            + "FROM `buckets_droplets` WHERE `droplet_id` IN (:dropIds)";

    MapSqlParameterSource paramMap = new MapSqlParameterSource();
    paramMap.addValue("dropIds", dropIds);

    for (Map<String, Object> row : namedJdbcTemplate.queryForList(sql, paramMap)) {
        Long dropId = ((Number) row.get("droplet_id")).longValue();
        Long bucketId = ((Number) row.get("bucket_id")).longValue();

        Drop drop = drops.get(dropIndex.get(dropId));
        if (drop.getBucketIds() == null) {
            drop.setBucketIds(new ArrayList<Long>());
        }
        drop.getBucketIds().add(bucketId);
    }
}

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

@Override
protected int getCachedExperimentTaskId(String annotatorName, String datasetName, String experimentType,
        String matching) {/*from ww  w  . ja v a2  s. co  m*/
    MapSqlParameterSource params = createTaskParameters(annotatorName, datasetName, experimentType, matching);
    java.util.Date today = new java.util.Date();
    params.addValue("lastChanged", new java.sql.Timestamp(today.getTime() - this.resultDurability));
    params.addValue("errorState", ErrorTypes.HIGHEST_ERROR_CODE);
    List<Integer> result = this.template.query(GET_CACHED_TASK, params, new IntegerRowMapper());
    if (result.size() > 0) {
        return result.get(0);
    } else {
        return EXPERIMENT_TASK_NOT_CACHED;
    }
}