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.lefff.LefffDaoImpl.java

public Attribute loadAttribute(int attributeId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute WHERE attribute_id=:attribute_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("attribute_id", attributeId);

    LOG.info(sql);/*from w  ww  .  j a va  2  s. c  o  m*/
    LefffDaoImpl.LogParameters(paramSource);
    Attribute attribute = null;
    try {
        attribute = (Attribute) jt.queryForObject(sql, paramSource,
                new AttributeMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return attribute;
}

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

@Override
public int getGameId(String gameRefId, String pass) {
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("gamereqid", gameRefId);
    namedParameters.addValue("gamepassword", pass);

    int temp = 0;
    try {/*from ww  w  . j a v  a2s . c  o m*/
        temp = this.namedParameterJdbcTemplate.queryForInt(SQL_GETGAMEREF, namedParameters);
    } catch (Exception e) {
        e.printStackTrace();
        temp = 0;
    } finally {
        //status=(boolean) temp;
        return temp;

    }
}

From source file:tds.assessment.repositories.impl.AssessmentWindowQueryRepositoryIntegrationTests.java

@Test
public void shouldFindMultipleAssessmentWindowsForMultipleIds() {
    final String assessmentId1 = "SBAC-Mathematics-3";
    final String assessmentId2 = "SBAC-Mathematics-11";

    String clientTestModeInsertSQL = "INSERT INTO configs.client_testmode (clientname,testid,mode,algorithm,formtideselectable,issegmented,maxopps,requirertsform,requirertsformwindow,requirertsformifexists,sessiontype,testkey,_key) "
            + "VALUES ('SBAC_PT','SBAC-Mathematics-3','online','virtual',0,1,50,0,0,1,0,'(SBAC_PT)SBAC-Mathematics-3-Spring-2013-2015',UNHEX('0431F6515F2D11E6B2C80243FCF25EAB')),"
            + "('SBAC_PT','SBAC-Mathematics-11','online','virtual',0,1,50,0,0,1,0,'(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015',UNHEX('0431F6515F2D11E6B2C80243FCF25EAC'));";

    String clientTestWindowInsertSQL = "INSERT INTO configs.client_testwindow (clientname,testid,window,numopps,startdate,enddate,origin,source,windowid,_key,sessiontype,sortorder)"
            + "VALUES ('SBAC_PT','SBAC-Mathematics-3',1,3, NULL ,NULL,NULL,NULL,'ANNUAL',UNHEX('043A37525F2D11E6B2C80243FCF25EAB'),-1,1), "
            + "('SBAC_PT','SBAC-Mathematics-11',1,3, NULL ,NULL,NULL,NULL,'ANNUAL',UNHEX('043A37525F2D11E6B2C80243FCF25EAC'),-1,1);";

    jdbcTemplate.update(clientTestModeInsertSQL, new MapSqlParameterSource());
    jdbcTemplate.update(clientTestWindowInsertSQL, new MapSqlParameterSource());

    List<AssessmentWindow> assessmentWindows = repository.findAssessmentWindowsForAssessmentIds("SBAC_PT",
            assessmentId1, assessmentId2);
    assertThat(assessmentWindows).hasSize(2);

    AssessmentWindow window1 = null;//from w w w. j a va  2  s.c o  m
    AssessmentWindow window2 = null;

    for (AssessmentWindow w : assessmentWindows) {
        if (w.getAssessmentKey().equals("(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015")) {
            window1 = w;
        } else if (w.getAssessmentKey().equals("(SBAC_PT)SBAC-Mathematics-3-Spring-2013-2015")) {
            window2 = w;
        }
    }

    assertThat(window1.getAssessmentKey()).isEqualTo("(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015");
    assertThat(window1.getFormKey()).isNull();
    assertThat(window1.getMode()).isEqualTo("online");
    assertThat(window1.getWindowId()).isEqualTo("ANNUAL");
    assertThat(window1.getModeMaxAttempts()).isEqualTo(50);
    assertThat(window1.getWindowSessionType()).isEqualTo(-1);
    assertThat(window1.getModeSessionType()).isEqualTo(0);
    assertThat(window2).isNotNull();
}

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

public int deleteContestant(String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));
    return update(deleteByCode, params);
}

From source file:org.terasoluna.gfw.functionaltest.app.DBLogProvider.java

public long countContainsMessageAndLevelsAndLogger(String message, String level, String loggerName) {

    StringBuilder sql = new StringBuilder();
    sql.append(/*  w  ww .ja v  a 2s . com*/
            "SELECT COUNT(e.*) FROM logging_event e WHERE e.formatted_message REGEXP :message AND e.level_string = :level");

    if (StringUtils.hasText(loggerName)) {
        sql.append(" AND e.logger_name = :loggerName");
    }

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("message", message);
    params.addValue("level", level);
    params.addValue("loggerName", loggerName);

    Long count = jdbcOperations.queryForObject(sql.toString(), params, Long.class);
    return count;
}

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

@Override
public List<JochrePage> findJochrePages(JochreDocument jochreDocument) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PAGE + " FROM ocr_page WHERE page_doc_id=:page_doc_id"
            + " ORDER BY page_index";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("page_doc_id", jochreDocument.getId());

    LOG.info(sql);/*  w w w  .j  a v  a 2s.  c o  m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<JochrePage> jochrePages = jt.query(sql, paramSource,
            new JochrePageMapper(this.getDocumentServiceInternal()));

    return jochrePages;
}

From source file:com.example.securelogin.selenium.loginform.SecureLoggingTest.java

private void isLogged(long start, long end, String username, String message) {
    NamedParameterJdbcOperations jdbcOperations = dbLogAssertOperations.getJdbcOperations();

    StringBuilder sql = new StringBuilder();
    StringBuilder where = new StringBuilder();
    sql.append("SELECT COUNT(e.*) FROM logging_event e");
    where.append(" WHERE e.formatted_message REGEXP :message");
    where.append(" AND e.timestmp BETWEEN :start AND :end");
    sql.append(" JOIN logging_event_property ep ON ep.event_id = e.event_id");
    if (username != null) {
        where.append(" AND ep.mapped_key = 'USER' AND ep.mapped_value = :username");
    }//from   w  w w. j av a2 s . co m
    sql.append(where);

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("start", start);
    params.addValue("end", end);
    params.addValue("username", username);
    params.addValue("message", message);
    Long count = jdbcOperations.queryForObject(sql.toString(), params, Long.class);
    assertThat(count, is(not(0L)));
}

From source file:ru.org.linux.user.UserTagDao.java

/**
 *    ? ./*  ww  w  . j a  v  a  2s .c om*/
 *
 * @param tagId   
 */
public void deleteTags(int tagId) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("tag_id", tagId);
    jdbcTemplate.update("DELETE FROM user_tags WHERE tag_id=:tag_id", parameters);
}

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

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

    try {
        sqlStatement = "UPDATE " + this.table + " SET fullname = :fullname" + ", password = :passwd"
                + ", enabled = :enabled" + ", roles = :roles" + " WHERE username = :username ";

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

        getSimpleJdbcTemplate().update(sqlStatement, args);

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

From source file:org.smart.migrate.dao.impl.DefaultImportDao.java

@Override
public void deleteTargetDataByPrimaryKeys(TableSetting tableSetting, List<String> primaryKeys) {
    String sql = "DELETE FROM " + tableSetting.getTargetTable() + " WHERE " + tableSetting.getTargetPK()
            + " in (:ids)";
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(targetJdbcTemplate);
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", primaryKeys);
    namedParameterJdbcTemplate.update(sql, parameters);
}