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:airport.database.services.users.UsersDaoOnlineImpl.java

@Override
public void updateTimer(User user) {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("last_visit", new Timestamp(new Date().getTime()));
    parameterSource.addValue("id_session", user.getId());

    jdbcTemplate.update(SQL_QUERY_UPDATE_LAS_VISIT, parameterSource);

    if (LOG.isInfoEnabled()) {
        LOG.info("update time of user. User : " + user);
    }/* ww  w.  j a va 2  s  .co  m*/
}

From source file:org.voltdb.example.springjdbc.ContestantDao.java

public int insertContestant(String firstName, String lastName, String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("firstName", new SqlParameterValue(Types.VARCHAR, firstName));
    params.addValue("lastName", new SqlParameterValue(Types.VARCHAR, lastName));
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));

    return update(insertContestant, params);
}

From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java

@Override
public List<User> findUsers() {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_USER + " FROM ocr_user" + " ORDER BY user_last_name, user_first_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    LOG.info(sql);//from  w  w  w. ja v a  2s . c  o m
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<User> users = jt.query(sql, paramSource, new UserMapper(this.getSecurityServiceInternal()));
    return users;
}

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 {/*from w  w w.j ava2  s.c  o  m*/
        params.addValue("search", "%" + searchConditions.getSearchQuery() + "%");
    }
    return this.namedParameterjdbcTemplate.query(rm.searchSchema(searchConditions), params, rm);
}

From source file:fi.luontola.cqrshotel.framework.PsqlEventStore.java

@Override
public List<Event> getEventsForStream(UUID streamId, int sinceVersion) {
    return jdbcTemplate.query(
            "SELECT data, metadata " + "FROM event " + "WHERE stream_id = :stream_id "
                    + "  AND version > :since_version " + "ORDER BY version",
            new MapSqlParameterSource().addValue("stream_id", streamId).addValue("since_version", sinceVersion),
            this::eventMapping);
}

From source file:com.branded.holdings.qpc.repository.jdbc.JdbcTopicRepositoryImpl.java

/**
 * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Pet} instance.
 *//*from  w  ww.j  a  va  2  s.co m*/
private MapSqlParameterSource createTopicParameterSource(Topic topic) {
    return new MapSqlParameterSource().addValue("id", topic.getId()).addValue("weight", topic.getWeight())
            .addValue("description", topic.getdescription()).addValue("type_id", topic.getType().getId());
}

From source file:com.github.dbourdette.glass.log.execution.jdbc.JdbcJobExecutions.java

@Override
public Page<JobExecution> find(Query query) {
    String sql = "from " + getTableName();

    MapSqlParameterSource params = new MapSqlParameterSource();

    if (query.getResult() != null) {
        sql += " where result = :result";

        params.addValue("result", query.getResult().name());
    }/* w  ww .  j a v a  2s  .c  o m*/

    return getLogs(sql, params, query);
}

From source file:com.daugherty.e2c.persistence.data.jdbc.JdbcSupplierDao.java

@Override
public Supplier loadApproved(Long id, Locale locale) {
    LOGGER.debug("Looking up approved supplier with ID " + id);
    String sql = getSql("supplier/loadApproved.sql");
    SqlParameterSource parameterSource = new MapSqlParameterSource().addValue("partyId", id)
            .addValue(SqlQueryCriteria.LANGUAGE_PARAMETER_NAME, locale.getLanguage());
    Supplier supplier = null;//from ww w. j a  v  a 2 s  . c o  m
    try {
        supplier = jdbcTemplate.query(sql, parameterSource, new SupplierResultSetExtractor()).get(0);
    } catch (IndexOutOfBoundsException e) {
        throw new EmptyResultDataAccessException(1);
    }

    return supplier;
}

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

/**
 * {@inheritDoc}/*from   w ww  .  j a v a 2s.  co m*/
 */
@Override
@Transactional
public void addDisc(Disc disc) {
    logger.trace("Entering addDisc");
    final String sql = "INSERT INTO `discs` VALUES(null, :artist, :title, :year, :genre)";
    MapSqlParameterSource parms = new MapSqlParameterSource();
    parms.addValue("artist", disc.getFlat(GenericTag.ARTIST));
    parms.addValue("title", disc.getFlat(GenericTag.ALBUM));
    String year = disc.getFirst(GenericTag.DATE);
    if (year == null || "".equals(year) || year.length() > 4) {
        parms.addValue("year", null);
    } else {
        parms.addValue("year", year + "-01-01");
    }

    parms.addValue("genre", disc.getFlat(GenericTag.GENRE));

    KeyHolder keys = new GeneratedKeyHolder();
    this.getNamedParameterJdbcTemplate().update(sql, parms, keys);

    int newDiscId = keys.getKey().intValue();
    addCddbIds(newDiscId, disc);
    addTracks(newDiscId, disc.getTracks());
    logger.trace("Exiting addDisc");
}

From source file:com.google.enterprise.connector.sharepoint.dao.QueryProvider.java

/**
 * Creates a name-value map to that can be used to execute the query
 *
 * @param values//  w  w  w.  j av  a 2  s . c om
 * @return {@link MapSqlParameterSource}
 */
public SqlParameterSource createParameter(Object... values) {
    check(values);
    MapSqlParameterSource namedParam = new MapSqlParameterSource();
    int i = 0;
    for (String placeholder : parameters) {
        namedParam.addValue(placeholder, values[i++]);
    }
    return namedParam;
}