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:org.inbio.modeling.core.dao.impl.SystemUserDAOImpl.java

@Override
public SystemUser findByUsername(final String username) {

    String sqlStatement = null;/*w  w  w .  jav a 2s.  com*/
    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:com.eu.evaluation.server.dao.eva.history.SimpleStatisticsDAO.java

/**
 * ????/*  ww  w.j  a va2s  .c  o  m*/
 * @param evaulateVersionID
 * @param position
 * @param entityEnum
 * @return 
 */
public List<SimpleStatistics> find(String evaulateVersionID, String position, EntityEnum entityEnum) {
    String jpql = "select t from SimpleStatistics t where t.evaluateVersion.id = :evid and t.position = :position and t.instanceType = :instanceType";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("evid", evaulateVersionID);
    params.addValue("position", position);
    params.addValue("instanceType", entityEnum.getInstanceType());
    return this.query(jpql, params);
}

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

@Override
public void updateParameter(String parameterName, String value) {
    String createStatement = null;
    MapSqlParameterSource args = null;/*from w  ww  .j a  va2 s .  c  om*/

    createStatement = "UPDATE " + this.table + " " + " SET value = :value " + " WHERE name = :parameter_name";

    args = new MapSqlParameterSource();
    args.addValue("parameter_name", parameterName);
    args.addValue("value", value);

    getSimpleJdbcTemplate().update(createStatement, args);
}

From source file:com.griddynamics.spring.batch.football.internal.JdbcGameDao.java

public void write(List<? extends Game> games) {

    for (Game game : games) {

        SqlParameterSource values = new MapSqlParameterSource().addValue("player_id", game.getId())
                .addValue("year_no", game.getYear()).addValue("team", game.getTeam())
                .addValue("week", game.getWeek()).addValue("opponent", game.getOpponent())
                .addValue("completes", game.getCompletes()).addValue("attempts", game.getAttempts())
                .addValue("passing_yards", game.getPassingYards()).addValue("passing_td", game.getPassingTd())
                .addValue("interceptions", game.getInterceptions()).addValue("rushes", game.getRushes())
                .addValue("rush_yards", game.getRushYards()).addValue("receptions", game.getReceptions())
                .addValue("receptions_yards", game.getReceptionYards()).addValue("total_td", game.getTotalTd());
        this.insertGame.execute(values);

    }/* w  w  w  .  j  a va 2 s.c om*/

}

From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestCaseStepImpl.java

@Override
public void saveTestCaseSteps(List<TestCaseStep> steps, int primaryKeyOfTestCase) {
    for (TestCaseStep step : steps) {
        logger.info("============== save STEP \"" + step.getName() + "\" ==============");
        MapSqlParameterSource stepParameters = new MapSqlParameterSource();
        stepParameters.addValue("sahi_cases_id", primaryKeyOfTestCase);
        stepParameters.addValue("result", step.getState().getErrorCode());
        stepParameters.addValue("result_desc", step.getState());
        stepParameters.addValue("name", step.getName());
        stepParameters.addValue("start", step.getStartDateAsUnixTimestamp());
        stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp());
        stepParameters.addValue("warning", step.getWarningTime());
        stepParameters.addValue("duration", step.getDuration());

        logger.info("write the following values to 'sahi_steps': " + stepParameters.getValues()
                + "\n now execute ....");

        //generate the sql-statement
        SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_steps")
                .usingGeneratedKeyColumns("id");

        //execute the sql-statement and save the primary key
        int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue();
        logger.info("test case step '" + step.getName() + "' has been written to 'sahi_steps' with  primaryKey="
                + dbPrimaryKey);/*w w  w.  java 2s  .  c  o m*/
        step.setDbPrimaryKey(dbPrimaryKey);
    }
}

From source file:com.mec.DAO.Passport.UserDAO.java

public Usuario getUser(String nombre, String clave) {
    Usuario u = null;//from   w ww. j a v a  2s. com
    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(ds).withCatalogName("dbo")
            .withProcedureName("paValidarUsuario").withoutProcedureColumnMetaDataAccess()
            .declareParameters(new SqlParameter("NombreUsuario", Types.VARCHAR))
            .declareParameters(new SqlParameter("Clave", Types.VARCHAR))
            .declareParameters(new SqlOutParameter("UserId", Types.INTEGER))
            .declareParameters(new SqlOutParameter("ErrText", Types.VARCHAR));
    SqlParameterSource in = new MapSqlParameterSource().addValue("NombreUsuario", nombre).addValue("Clave",
            clave);
    Map<String, Object> r = jdbcCall.execute(in);
    Integer userId = null;
    String errText = "";
    for (Map.Entry<String, Object> entry : r.entrySet()) {
        String key = entry.getKey();
        if (key.equals("UserId")) {
            userId = (Integer) entry.getValue();
        } else if (key.equals("ErrText")) {
            errText = (String) entry.getValue();
        }
    }
    if (userId != null && errText.equals("Ok")) {
        List<GrantedAuthority> roles = getUserRoles(userId);
        u = new Usuario(userId, roles);
    }
    return u;
}

From source file:com.eu.evaluation.server.dao.dictionary.ObjectDictionaryDAO.java

public ObjectDictionary findByDisplayName(String displayName) {
    String jpql = "select t from ObjectDictionary t where t.displayname = :displayname and t.valid = :valid";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("displayname", displayName);
    params.addValue("valid", true);
    List<ObjectDictionary> result = this.query(jpql, params);
    if (result.isEmpty()) {
        return null;
    } else if (result.size() == 1) {
        return result.get(0);
    } else {//from   w  w  w.ja va 2s  .c o  m
        throw new RuntimeException("?? " + displayName
                + " valid1??");
    }
}

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

@Override
public void saveTestCaseSteps(SortedSet<TestCaseStep> steps, int primaryKeyOfTestCase) {
    for (TestCaseStep step : steps) {
        LOGGER.info("============== save STEP \"" + step.getName() + "\" ==============");
        MapSqlParameterSource stepParameters = new MapSqlParameterSource();
        stepParameters.addValue("sakuli_cases_id", primaryKeyOfTestCase);
        stepParameters.addValue("result", step.getState().getErrorCode());
        stepParameters.addValue("result_desc", step.getState());
        stepParameters.addValue("name", step.getName());
        stepParameters.addValue("start", step.getStartDateAsUnixTimestamp());
        stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp());
        int warningTime = step.getWarningTime();
        stepParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
        stepParameters.addValue("duration", step.getDuration());

        LOGGER.debug("write the following values to 'sakuli_steps': " + stepParameters.getValues()
                + "\n now execute ....");

        //generate the sql-statement
        SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_steps")
                .usingGeneratedKeyColumns("id");

        //execute the sql-statement and save the primary key
        int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue();
        LOGGER.info("test case step '" + step.getName()
                + "' has been written to 'sakuli_steps' with  primaryKey=" + dbPrimaryKey);
        step.setDbPrimaryKey(dbPrimaryKey);
    }/*from  w  ww .j a  va2 s.c om*/
}

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

@Override
public void create(Layer newLayer) {

    String createStatement = null;
    MapSqlParameterSource args = null;//from   w  ww . java2s .c  om

    createStatement = "INSERT INTO " + this.table + "( display_name, "
            + "\"name\", description, uri, \"year\", last_update, is_species_map, source, visualization_scale, data_scale, generation_procedure)"
            + "VALUES (:display_name, :name, :description, :uri, :year, :last_update, :is_species_map, :source, :viz_scale, :data_scale, :generation_procedure);";

    args = new MapSqlParameterSource();
    args.addValue("name", newLayer.getName());
    args.addValue("display_name", newLayer.getDisplayName());
    args.addValue("uri", newLayer.getUri());
    args.addValue("source", newLayer.getSource());
    args.addValue("year", newLayer.getYear());
    args.addValue("viz_scale", newLayer.getVizScale());
    args.addValue("data_scale", newLayer.getDataScale());
    args.addValue("generation_procedure", newLayer.getGenerationProcedure());
    args.addValue("last_update", Calendar.getInstance().getTime());
    args.addValue("description", newLayer.getDescription());
    args.addValue("is_species_map", newLayer.isSpeciesMap());

    getSimpleJdbcTemplate().update(createStatement, args);
}

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

/**
 * ??SimpleStatistics/*from  w  w w.j a  va 2 s  .c o m*/
 * @param ev
 * @param system
 * @return 
 */
public List<SimpleStatistics> countToSimpleStatistics(EvaluateVersion ev, AccessSystem system) {
    String jpql = "select new SimpleStatistics(t.evaluateTypeEnum , t.instanceType , t.instanceClass , count(t.instanceType)) "
            + "from UnPassedEvaluatedData t " + "where t.evaluateVersion.id = :evid and t.position = :position "
            + "group by t.evaluateTypeEnum , t.instanceType , t.instanceClass";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("evid", ev.getId());
    params.addValue("position", system.getCode());
    return this.createQuery(jpql, params).getResultList();
}