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

public void saveCategory(CategoryInternal category) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("cat_code", category.getCode());
    paramSource.addValue("cat_description", category.getDescription());
    if (category.isNew()) {
        String sql = "SELECT nextval('ftb_category_cat_id_seq')";
        LOG.info(sql);/*from   ww  w.  ja v  a 2 s .  co m*/
        int categoryId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("cat_id", categoryId);

        sql = "INSERT INTO ftb_category (cat_id, cat_code, cat_description) VALUES (:cat_id, :cat_code, :cat_description)";

        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
        category.setId(categoryId);
    } else {
        String sql = "UPDATE ftb_category" + " SET cat_code = :cat_code"
                + ", cat_description = :cat_description" + " WHERE cat_id = :cat_id";

        paramSource.addValue("cat_id", category.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

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

public void savePhraseType(PhraseTypeInternal phraseType) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("ptype_code", phraseType.getCode());
    paramSource.addValue("ptype_description", phraseType.getDescription());
    if (phraseType.isNew()) {
        String sql = "SELECT nextval('ftb_phrase_type_ptype_id_seq')";
        LOG.info(sql);//  ww w .  j a va 2  s  .c  o m
        int phraseTypeId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("ptype_id", phraseTypeId);

        sql = "INSERT INTO ftb_phrase_type (ptype_id, ptype_code, ptype_description) VALUES (:ptype_id, :ptype_code, :ptype_description)";

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

        phraseType.setId(phraseTypeId);
    } else {
        String sql = "UPDATE ftb_phrase_type" + " SET ptype_code = :ptype_code"
                + ", ptype_description = :ptype_description" + " WHERE ptype_id = :ptype_id";

        paramSource.addValue("ptype_id", phraseType.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

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

public void saveWord(WordInternal word) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("word_text", word.getText());
    paramSource.addValue("word_original_text", word.getOriginalText());
    if (word.isNew()) {
        String sql = "SELECT nextval('ftb_word_word_id_seq')";
        LOG.info(sql);//from  w  w  w  .  j a v  a2  s .  co  m
        int wordId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("word_id", wordId);

        sql = "INSERT INTO ftb_word (word_id, word_text, word_original_text) VALUES (:word_id, :word_text, :word_original_text)";

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

        word.setId(wordId);
    } else {
        String sql = "UPDATE ftb_word" + " SET word_text = :word_text"
                + ", word_original_text = :word_original_text" + " WHERE word_id = :word_id";

        paramSource.addValue("word_id", word.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

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

@Override
public void saveTextItem(TextItemInternal textItem) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("text_file_id", textItem.getFileId());
    paramSource.addValue("text_external_id", textItem.getExternalId());
    if (textItem.isNew()) {
        String sql = "SELECT nextval('ftb_text_text_id_seq')";
        LOG.info(sql);//from  w  w  w . ja v a 2s. com
        int textItemId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("text_id", textItemId);

        sql = "INSERT INTO ftb_text (text_id, text_file_id, text_external_id) VALUES (:text_id, :text_file_id, :text_external_id)";

        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
        textItem.setId(textItemId);
    } else {
        String sql = "UPDATE ftb_text" + " SET text_file_id = :text_file_id"
                + ", text_external_id = :text_external_id" + " WHERE text_id = :text_id";

        paramSource.addValue("text_id", textItem.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

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

public void saveFunction(FunctionInternal function) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("function_code", function.getCode());
    paramSource.addValue("function_description", function.getDescription());
    if (function.isNew()) {
        String sql = "SELECT nextval('ftb_function_function_id_seq')";
        LOG.info(sql);//w w w  .  j a v  a2  s .c om
        int functionId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("function_id", functionId);

        sql = "INSERT INTO ftb_function (function_id, function_code, function_description) VALUES (:function_id, :function_code, :function_description)";

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

        function.setId(functionId);
    } else {
        String sql = "UPDATE ftb_function" + " SET function_code = :function_code"
                + ", function_description = :function_description" + " WHERE function_id = :function_id";

        paramSource.addValue("function_id", function.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }

}

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

public void saveMorphology(MorphologyInternal morphology) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("morph_code", morphology.getCode());
    paramSource.addValue("morph_description", morphology.getDescription());
    if (morphology.isNew()) {
        String sql = "SELECT nextval('ftb_morph_morph_id_seq')";
        LOG.info(sql);//from   www  .  ja  va  2 s  .c om
        int morphologyId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("morph_id", morphologyId);

        sql = "INSERT INTO ftb_morph (morph_id, morph_code, morph_description) VALUES (:morph_id, :morph_code, :morph_description)";

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

        morphology.setId(morphologyId);
    } else {
        String sql = "UPDATE ftb_morph" + " SET morph_code = :morph_code"
                + ", morph_description = :morph_description" + " WHERE morph_id = :morph_id";

        paramSource.addValue("morph_id", morphology.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }

}

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

public void saveSubCategory(SubCategoryInternal subCategory) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("subcat_code", subCategory.getCode());
    paramSource.addValue("subcat_cat_id", subCategory.getCategoryId());
    paramSource.addValue("subcat_description", subCategory.getDescription());
    if (subCategory.isNew()) {
        String sql = "SELECT nextval('ftb_sub_category_subcat_id_seq')";
        LOG.info(sql);/* w  w  w .  ja  va  2s. c  o  m*/
        int subCategoryId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("subcat_id", subCategoryId);

        sql = "INSERT INTO ftb_sub_category (subcat_id, subcat_code, subcat_cat_id, subcat_description) VALUES (:subcat_id, :subcat_code, :subcat_cat_id, :subcat_description)";

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

        subCategory.setId(subCategoryId);
    } else {
        String sql = "UPDATE ftb_sub_subCategory" + " SET subcat_code = :subcat_code"
                + ", subcat_cat_id = :subcat_cat_id" + ", subcat_description = :subcat_description"
                + " WHERE subcat_id = :subcat_id";

        paramSource.addValue("subcat_id", subCategory.getId());
        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

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

@Override
public void findAllWordsAndLemmas(Phrase phrase, List<? extends PhraseUnit> phraseUnits) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT punit_id, w.word_id as w_word_id, w.word_text as w_word_text, w.word_original_text as w_word_original_text"
            + ", l.word_id as l_word_id, l.word_text as l_word_text, l.word_original_text as l_word_original_text"
            + " FROM ftb_phrase_unit pu"
            + " INNER JOIN ftb_phrase_child pc ON punit_phrase_id = pchild_child_id AND pchild_phrase_id = :pchild_phrase_id"
            + " INNER JOIN ftb_word w ON punit_word_id = w.word_id"
            + " INNER JOIN ftb_word l ON punit_lemma_id = l.word_id" + " ORDER BY punit_position";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("pchild_phrase_id", phrase.getId());

    LOG.info(sql);/*from w ww .j  a v a2  s  . c  o m*/
    TreebankDaoImpl.LogParameters(paramSource);
    SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource);
    WordMapper wordMapper = new WordMapper("w", this.treebankServiceInternal);
    WordMapper lemmaMapper = new WordMapper("l", this.treebankServiceInternal);
    while (rowSet.next()) {
        int phraseUnitId = rowSet.getInt("punit_id");
        Word word = wordMapper.mapRow(rowSet);
        Word lemma = lemmaMapper.mapRow(rowSet);
        for (PhraseUnit phraseUnit : phraseUnits) {
            if (phraseUnit.getId() == phraseUnitId) {
                PhraseUnitInternal iPhraseUnit = (PhraseUnitInternal) phraseUnit;
                iPhraseUnit.setWord(word);
                iPhraseUnit.setLemma(lemma);
                break;
            }
        }
    }
}

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

public List<PhraseUnitInternal> findPhraseUnits(Phrase phrase) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PHRASE_UNIT + "," + SELECT_PHRASE_SUBUNIT + " FROM ftb_phrase_unit pu"
            + " LEFT JOIN ftb_phrase_subunit psu ON pu.punit_id = psu.psubunit_punit_id"
            + " WHERE punit_phrase_id = :phrase_id" + " ORDER BY punit_position, psubunit_position";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("phrase_id", phrase.getId());

    LOG.info(sql);/*from w  ww  . ja  v  a 2  s  . co m*/
    TreebankDaoImpl.LogParameters(paramSource);
    SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource);
    PhraseUnitMapper phraseUnitMapper = new PhraseUnitMapper(this.treebankServiceInternal);
    PhraseSubUnitMapper phraseSubUnitMapper = new PhraseSubUnitMapper(this.treebankServiceInternal);

    List<PhraseUnitInternal> phraseUnits = new ArrayList<PhraseUnitInternal>();
    int currentPunitId = 0;
    PhraseUnitInternal currentPhraseUnit = null;
    while (rowSet.next()) {
        int phraseUnitId = rowSet.getInt("punit_id");
        if (phraseUnitId != currentPunitId) {
            currentPhraseUnit = phraseUnitMapper.mapRow(rowSet);
            currentPhraseUnit.setSubunitsInternal(new ArrayList<PhraseSubunit>());
            phraseUnits.add(currentPhraseUnit);
            currentPunitId = phraseUnitId;
        }

        int phraseSubunitId = rowSet.getInt("psubunit_id");
        if (phraseSubunitId != 0) {
            PhraseSubunit psubunit = phraseSubUnitMapper.mapRow(rowSet);
            currentPhraseUnit.getSubunitsInternal().add(psubunit);
        }
    }
    return phraseUnits;
}

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

public List<PhraseUnit> findAllPhraseUnits(Phrase phrase) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PHRASE_UNIT + "," + SELECT_PHRASE_SUBUNIT + " FROM ftb_phrase_unit pu"
            + " LEFT JOIN ftb_phrase_subunit psu ON pu.punit_id = psu.psubunit_punit_id"
            + " INNER JOIN ftb_phrase_child pc ON punit_phrase_id = pchild_child_id AND pchild_phrase_id = :pchild_phrase_id"
            + " ORDER BY punit_position, psubunit_position";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("pchild_phrase_id", phrase.getId());

    LOG.info(sql);//from  www. java  2 s . c o  m
    TreebankDaoImpl.LogParameters(paramSource);
    SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource);
    PhraseUnitMapper phraseUnitMapper = new PhraseUnitMapper(this.treebankServiceInternal);
    PhraseSubUnitMapper phraseSubUnitMapper = new PhraseSubUnitMapper(this.treebankServiceInternal);

    List<PhraseUnit> phraseUnits = new ArrayList<PhraseUnit>();
    int currentPunitId = 0;
    PhraseUnitInternal currentPhraseUnit = null;
    while (rowSet.next()) {
        int phraseUnitId = rowSet.getInt("punit_id");
        if (phraseUnitId != currentPunitId) {
            currentPhraseUnit = phraseUnitMapper.mapRow(rowSet);
            currentPhraseUnit.setSubunitsInternal(new ArrayList<PhraseSubunit>());
            phraseUnits.add(currentPhraseUnit);
            currentPunitId = phraseUnitId;
        }

        int phraseSubunitId = rowSet.getInt("psubunit_id");
        if (phraseSubunitId != 0) {
            PhraseSubunit psubunit = phraseSubUnitMapper.mapRow(rowSet);
            currentPhraseUnit.getSubunitsInternal().add(psubunit);
        }
    }
    return phraseUnits;
}