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(String paramName, @Nullable Object value) 

Source Link

Document

Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.

Usage

From source file:io.lavagna.service.ProjectService.java

private void createDefaultColumnDefinitions(int projectId) {
    List<SqlParameterSource> params = new ArrayList<>(ColumnDefinition.values().length);
    for (ColumnDefinition definition : ColumnDefinition.values()) {
        SqlParameterSource param = new MapSqlParameterSource("value", definition.toString())
                .addValue("color", definition.getDefaultColor()).addValue("projectId", projectId);
        params.add(param);/*from w ww  .  j  a va 2  s.  co m*/
    }
    jdbc.batchUpdate(queries.createColumnDefinition(), params.toArray(new SqlParameterSource[params.size()]));
}

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

/**
 * Generates and returns the next value for a sequence with the given name.
 *
 * @param sequenceName {@code String} specifies full-qualified name of sequence which
 *                     next value should be returned by a call
 * @return {@code Long}//w ww  .  j a va  2  s.c o  m
 * @throws IllegalArgumentException will be thrown if the provided <tt>sequenceName</tt>
 *                                  id <tt>null</tt> or empty string
 */
@Transactional(propagation = Propagation.MANDATORY)
public Long createId(final String sequenceName) {
    Assert.isTrue(StringUtils.isNotBlank(sequenceName));
    return getNamedParameterJdbcTemplate().queryForObject(createIdQuery,
            new MapSqlParameterSource(HelperParameters.SEQUENCE_NAME.name(), sequenceName), Long.class);
}

From source file:airport.database.dispatcher.airplane.FlightDaoImpl.java

@Override
public String getFlightState(String flightNumber) {
    MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource("flightNumber", flightNumber);

    String resultStateFlight = jdbcTemplate.queryForObject(SQL_QUERY_SELECT_FLIGHT_STATE, mapSqlParameterSource,
            String.class);

    if (LOG.isInfoEnabled()) {
        LOG.info("get flight state. FlightNumber : " + flightNumber + ". Result : " + resultStateFlight);
    }/* w w w .  ja v  a  2s. co m*/

    return resultStateFlight;
}

From source file:com.eu.evaluation.server.dao.DefaultDAO.java

/**
 * ???position//from   www.j  a v a 2s.  c o m
 * @param entityEnum
 * @param position
 * @return 
 */
public int deleteData(Class<?> orgDataClass, String position) {
    String jpql = "delete from {0} t where t.position = :position";
    jpql = MessageFormat.format(jpql, orgDataClass.getName());
    MapSqlParameterSource params = new MapSqlParameterSource("position", position);
    return this.createQuery(jpql, params).executeUpdate();
}

From source file:com.example.dfa.demo.service.DfaDemoServiceImpl.java

@Override
public DfaWorkflowDetailDTO getWorkflowDetail(Long dfaWorkflowId) {
    SqlParameterSource inParam = new MapSqlParameterSource("dfaWorkflowId", dfaWorkflowId);
    Map<String, Object> out = getWorkflowsSpaCall.execute(inParam);
    Collection<DfaWorkflowsDTO> workflows = (Collection) out.get("workflows");
    out = getSelectedEventsAndStatesSpaCall.execute(inParam);
    Collection<SelectedEventsDTO> events = (Collection) out.get("events");
    Collection<WorkflowStatesDTO> states = (Collection) out.get("states");

    return new DfaWorkflowDetailDTO(dfaWorkflowId, workflows, events, states);
}

From source file:com.neeti.neg.dao.impl.RegisterUserDaoImpl.java

@Override
public RegisterUser getRegisterUserByUserName(String username) {
    SqlParameterSource namedParameters = new MapSqlParameterSource("groupname", username);
    RegisterUser registerUser = (RegisterUser) this.namedParameterJdbcTemplate
            .queryForObject(SQL_GETUSER_BYUSERNAME, namedParameters, new RegisterUserRowMapper());
    return registerUser;
}

From source file:alfio.manager.UploadedResourceManager.java

public void outputResource(String name, OutputStream out) {
    SqlParameterSource param = new MapSqlParameterSource("name", name);
    jdbc.query(uploadedResourceRepository.fileContentTemplate(name), param, rs -> {
        try (InputStream is = rs.getBinaryStream("content")) {
            StreamUtils.copy(is, out);//from   www .j av a 2s  .  c o m
        } catch (IOException e) {
            throw new IllegalStateException("Error while copying data", e);
        }
    });
}

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

@Override
public int update(final CodeDefinition instance) {
    final String sql = "UPDATE CODE_DEFINITION SET CODE_CATEGORY_PK = :codeCategoryPk, CODE = :code, DEFINITION = :definition WHERE CODE_DEFINITION_PK = :codeDefinitionPk";
    final MapSqlParameterSource params = new MapSqlParameterSource("codeCategoryPk",
            instance.getCodeCategoryPk()).addValue("code", instance.getCode())
                    .addValue("definition", instance.getDefinition())
                    .addValue("codeDefinitionPk", instance.getCodeDefinitionPk());

    return jdbcTemplate.update(sql, params);
}

From source file:org.openlmis.performancetesting.dao.FacilityDAO.java

public GeographicZone getDistrictZone(int offset) {
    String sql = "SELECT id FROM geographic_zones WHERE levelId = 3 LIMIT 1 OFFSET :offset";

    SqlParameterSource namedParameters = new MapSqlParameterSource("offset", offset);

    long id = template.queryForLong(sql, namedParameters);
    GeographicZone zone = new GeographicZone();
    zone.setId(id);// www .ja v a 2 s.  c  o m
    return zone;

}