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:com.joliciel.frenchTreebank.TreebankDaoImpl.java

@SuppressWarnings("unchecked")
public List<Integer> findCompoundWordIds(int minId, int maxId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT word_id FROM ftb_word, ftb_phrase_unit" + " WHERE word_id >= :min_id"
            + " AND word_id <= :max_id" + " AND word_id = punit_word_id" + " AND punit_compound = true"
            + " AND punit_id not in" + " (select psubunit_punit_id from ftb_phrase_subunit"
            + " group by psubunit_punit_id" + " having count(*)=1)" + " GROUP BY word_id" + " ORDER BY word_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("min_id", minId);
    paramSource.addValue("max_id", maxId);

    LOG.info(sql);/*from w  w  w .  j  av  a 2 s . c om*/
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> wordIds = jt.queryForList(sql, paramSource, Integer.class);

    return wordIds;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

@Override
public TextItem loadTextItem(int textItemId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_TEXT_ITEM + " FROM ftb_text WHERE text_id=:text_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("text_id", textItemId);

    LOG.info(sql);/*from  ww w  . j  a v  a  2s  .co  m*/
    TreebankDaoImpl.LogParameters(paramSource);
    TextItem textItem = null;
    try {
        textItem = (TextItem) jt.queryForObject(sql, paramSource, new TextItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return textItem;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

@Override
public TextItem loadTextItem(String externalId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_TEXT_ITEM + " FROM ftb_text WHERE text_external_id=:text_external_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("text_external_id", externalId);

    LOG.info(sql);//ww  w  .j a v a2  s  .  co m
    TreebankDaoImpl.LogParameters(paramSource);
    TextItem textItem = null;
    try {
        textItem = (TextItem) jt.queryForObject(sql, paramSource, new TextItemMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return textItem;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public SubCategory loadSubCategory(Category category, String subCategoryCode) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SUB_CATEGORY
            + " FROM ftb_sub_category WHERE subcat_cat_id = :subcat_cat_id AND subcat_code=:subcat_code";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("subcat_cat_id", category.getId());
    paramSource.addValue("subcat_code", subCategoryCode);

    LOG.info(sql);/*  ww w .j av  a 2 s . co m*/
    TreebankDaoImpl.LogParameters(paramSource);
    SubCategory subCategory = null;
    try {
        subCategory = (SubCategory) jt.queryForObject(sql, paramSource, new SubCategoryMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return subCategory;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public void saveTreebankFile(TreebankFileInternal treebankFile) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("file_name", treebankFile.getFileName());

    if (treebankFile.isNew()) {
        String sql = "SELECT nextval('ftb_file_file_id_seq')";
        LOG.info(sql);//from www  .j  a  va 2 s. c  o  m
        int fileId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("file_id", fileId);

        sql = "INSERT INTO ftb_file (file_id, file_name) " + "VALUES (:file_id, :file_name)";

        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);

        treebankFile.setId(fileId);
    }
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

@SuppressWarnings("unchecked")
public List<Integer> findCompoundPhraseUnitIds(int minId, int maxId, boolean includeSingleSubunitCompounds) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT punit_id FROM ftb_phrase_unit" + " WHERE punit_id >= :min_id"
            + " AND punit_id <= :max_id" + " AND punit_compound = true";
    if (!includeSingleSubunitCompounds) {
        sql += " AND punit_id not in" + " (select psubunit_punit_id from ftb_phrase_subunit"
                + " group by psubunit_punit_id" + " having count(*)=1)";
    }/*ww  w  . jav a 2s.c  o m*/
    sql += " ORDER BY punit_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("min_id", minId);
    paramSource.addValue("max_id", maxId);

    LOG.info(sql);
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> phraseUnitIds = jt.queryForList(sql, paramSource, Integer.class);

    return phraseUnitIds;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public Sentence loadSentence(int sentenceId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SENTENCE + ", " + SELECT_PHRASE + " FROM ftb_phrase p, ftb_sentence s"
            + " WHERE sentence_id=:sentence_id AND phrase_id=sentence_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("sentence_id", sentenceId);

    LOG.info(sql);//from   w w  w .  ja  va  2s . c  om
    TreebankDaoImpl.LogParameters(paramSource);
    Sentence sentence = null;
    SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource);

    if (rowSet.next()) {
        PhraseMapper phraseMapper = new PhraseMapper(this.treebankServiceInternal);
        PhraseInternal phrase = (PhraseInternal) phraseMapper.mapRow(rowSet);
        SentenceMapper sentenceMapper = new SentenceMapper(this.treebankServiceInternal, phrase);
        sentence = sentenceMapper.mapRow(rowSet);
    }

    return sentence;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public List<Sentence> findSentences(TreebankFile treebankFile) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SENTENCE + ", " + SELECT_PHRASE + " FROM ftb_sentence"
            + " INNER JOIN ftb_phrase ON phrase_id=sentence_id" + " WHERE sentence_file_id=:sentence_file_id"
            + " ORDER BY sentence_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("sentence_file_id", treebankFile.getId());

    LOG.info(sql);//from   w w w . j a v a  2  s .  c  o m
    TreebankDaoImpl.LogParameters(paramSource);

    List<Sentence> sentences = new ArrayList<Sentence>();
    SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource);

    while (rowSet.next()) {
        PhraseMapper phraseMapper = new PhraseMapper(this.treebankServiceInternal);
        PhraseInternal phrase = (PhraseInternal) phraseMapper.mapRow(rowSet);
        SentenceMapper sentenceMapper = new SentenceMapper(this.treebankServiceInternal, phrase);
        Sentence sentence = sentenceMapper.mapRow(rowSet);
        sentences.add(sentence);
    }
    return sentences;
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public void savePhrase(PhraseInternal phrase) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("phrase_ptype_id", phrase.getPhraseTypeId() == 0 ? null : phrase.getPhraseTypeId());
    paramSource.addValue("phrase_parent_id", phrase.getParent() == null ? null : phrase.getParent().getId());
    paramSource.addValue("phrase_function_id", phrase.getFunctionId() == 0 ? null : phrase.getFunctionId());
    paramSource.addValue("phrase_position", phrase.getPositionInPhrase());
    paramSource.addValue("phrase_depth", phrase.getDepth());

    if (phrase.isNew()) {
        String sql = "SELECT nextval('ftb_phrase_phrase_id_seq')";
        LOG.info(sql);//from www .  j a  va  2  s.c om
        int phraseId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("phrase_id", phraseId);

        sql = "INSERT INTO ftb_phrase (phrase_id, phrase_ptype_id, phrase_parent_id, phrase_function_id, phrase_position, phrase_depth) "
                + "VALUES (:phrase_id, :phrase_ptype_id, :phrase_parent_id, :phrase_function_id, :phrase_position, :phrase_depth)";

        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);

        phrase.setId(phraseId);
    }
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public void saveSentence(SentenceInternal sentence) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("sentence_number", sentence.getSentenceNumber());
    paramSource.addValue("sentence_file_id", sentence.getFileId() == 0 ? null : sentence.getFileId());
    paramSource.addValue("sentence_text_id", sentence.getTextItemId() == 0 ? null : sentence.getTextItemId());
    paramSource.addValue("sentence_id", sentence.getId());
    paramSource.addValue("sentence_text", sentence.getText());

    if (sentence.isNew()) {
        String sql = "INSERT INTO ftb_sentence (sentence_id, sentence_number, sentence_file_id, sentence_text_id, sentence_text) "
                + "VALUES (:sentence_id, :sentence_number, :sentence_file_id, :sentence_text_id, :sentence_text)";

        LOG.info(sql);//from   w w  w .  j  a  v a2  s .com
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    } else {
        String sql = "UPDATE ftb_sentence" + " SET sentence_number = :sentence_number"
                + ", sentence_file_id = :sentence_file_id" + ", sentence_text_id = :sentence_text_id"
                + ", sentence_text = :sentence_text" + " WHERE sentence_id = :sentence_id";

        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}