Example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate

List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate.

Prototype

public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate) 

Source Link

Document

Create a new NamedParameterJdbcTemplate for the given classic Spring org.springframework.jdbc.core.JdbcTemplate .

Usage

From source file:com.joliciel.lefff.LefffDaoImpl.java

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

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

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

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

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

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

public SubCategory loadSubCategory(int subCategoryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_SUB_CATEGORY + " FROM ftb_sub_category WHERE subcat_id = :subcat_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("subcat_id", subCategoryId);

    LOG.info(sql);/*from   ww w.  j  a  va  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 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);//from  w ww  .j  av a  2s.c  o  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.lefff.LefffDaoImpl.java

@Override
public LefffEntry loadEntry(int entryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_ENTRY + " FROM lef_entry WHERE entry_id=:entry_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("entry_id", entryId);

    LOG.info(sql);//  w w  w.  j a  v a  2 s .c  o  m
    LefffDaoImpl.LogParameters(paramSource);
    LefffEntry entry = null;
    try {
        entry = (LefffEntry) jt.queryForObject(sql, paramSource, new EntryMapper(this.lefffServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return entry;
}

From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java

@Override
public void deleteContiguousShapeInternal(ShapeInternal shape) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("shape_id", shape.getId());

    String sql = "DELETE FROM ocr_shape WHERE shape_id = :shape_id";
    LOG.debug(sql);/*from w  w w. j av a2  s .c  om*/
    logParameters(paramSource);
    jt.update(sql, paramSource);
}

From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java

@Override
public void saveJochreImage(JochreImage image) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    JochreImageInternal iImage = (JochreImageInternal) image;

    paramSource.addValue("image_name", image.getName());
    paramSource.addValue("image_width", image.getWidth());
    paramSource.addValue("image_height", image.getHeight());
    paramSource.addValue("image_black_threshold", image.getBlackThreshold());
    paramSource.addValue("image_sep_threshold", image.getSeparationThreshold());
    paramSource.addValue("image_black_limit", image.getBlackLimit());
    paramSource.addValue("image_white_limit", image.getWhiteLimit());
    paramSource.addValue("image_white_gap_fill_factor", image.getWhiteGapFillFactor());
    paramSource.addValue("image_page_id", image.getPageId());
    paramSource.addValue("image_index", image.getIndex());
    paramSource.addValue("image_imgstatus_id", image.getImageStatus().getId());
    paramSource.addValue("image_owner_id", image.getOwnerId());

    String sql = null;/*from www .j av  a 2  s.  c  o m*/

    if (image.isNew()) {
        sql = "SELECT nextval('ocr_image_id_seq')";
        LOG.debug(sql);
        int imageId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("image_id", imageId);

        sql = "INSERT INTO ocr_image (image_id, image_name, image_width, image_height, image_black_threshold,"
                + " image_page_id, image_index, image_sep_threshold, image_black_limit, image_white_limit,"
                + " image_white_gap_fill_factor, image_imgstatus_id, image_owner_id) "
                + "VALUES (:image_id, :image_name, :image_width, :image_height, :image_black_threshold,"
                + " :image_page_id, :image_index, :image_sep_threshold, :image_black_limit, :image_white_limit,"
                + " :image_white_gap_fill_factor, :image_imgstatus_id, :image_owner_id)";

        LOG.debug(sql);
        logParameters(paramSource);
        jt.update(sql, paramSource);

        iImage.setId(imageId);
    } else {
        paramSource.addValue("image_id", image.getId());

        sql = "UPDATE ocr_image" + " SET image_name = :image_name" + ", image_width = :image_width"
                + ", image_height = :image_height" + ", image_black_threshold = :image_black_threshold"
                + ", image_sep_threshold = :image_sep_threshold" + ", image_black_limit = :image_black_limit"
                + ", image_white_limit = :image_white_limit"
                + ", image_white_gap_fill_factor = :image_white_gap_fill_factor"
                + ", image_page_id = :image_page_id" + ", image_index = :image_index"
                + ", image_imgstatus_id = :image_imgstatus_id" + ", image_owner_id = :image_owner_id"
                + " WHERE image_id = :image_id";

        LOG.debug(sql);
        logParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

From source file:com.joliciel.lefff.LefffDaoImpl.java

@Override
public void saveEntry(LefffEntryInternal entry) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("entry_word_id", entry.getWordId());
    paramSource.addValue("entry_lemma_id", entry.getLemmaId());
    paramSource.addValue("entry_predicate_id", entry.getPredicateId() == 0 ? null : entry.getPredicateId());
    paramSource.addValue("entry_morph_id", entry.getMorphologyId() == 0 ? null : entry.getMorphologyId());
    paramSource.addValue("entry_lexical_weight", entry.getLexicalWeight());
    paramSource.addValue("entry_category_id", entry.getCategoryId());
    if (entry.isNew()) {
        String sql = "SELECT nextval('seq_entry_id')";
        LOG.info(sql);//from  w  w w  .  j  a v  a2s.  c o m
        int entryId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("entry_id", entryId);

        sql = "INSERT INTO lef_entry (entry_id, entry_word_id, entry_lemma_id, entry_predicate_id, entry_morph_id, entry_lexical_weight, entry_category_id)"
                + " VALUES (:entry_id, :entry_word_id, :entry_lemma_id, :entry_predicate_id, :entry_morph_id, :entry_lexical_weight, :entry_category_id)";

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

        entry.setId(entryId);
    } else {
        String sql = "UPDATE lef_entry" + " SET entry_word_id = :entry_word_id"
                + ", entry_lemma_id = :entry_lemma_id" + ", entry_predicate_id = :entry_predicate_id"
                + ", entry_morph_id = :entry_morph_id" + ", entry_lexical_weight = :entry_lexical_weight"
                + ", entry_category_id = :entry_category_id" + " WHERE entry_id = :entry_id";

        paramSource.addValue("entry_id", entry.getId());
        LOG.info(sql);
        LefffDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

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

public Word loadWord(String text, String originalText) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    if (text == null)
        text = "";
    String sql = "SELECT " + SELECT_WORD + " FROM ftb_word" + " WHERE word_text=:word_text"
            + " AND word_original_text=:word_original_text";
    paramSource.addValue("word_text", text);
    paramSource.addValue("word_original_text", originalText);

    LOG.info(sql);/*w w  w. j  a  v  a  2  s.c om*/
    TreebankDaoImpl.LogParameters(paramSource);
    Word word = null;
    try {
        word = (Word) jt.queryForObject(sql, paramSource, new WordMapper(this.treebankServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return word;
}

From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java

int getCurrentProjectId() {
    if (projectId == 0) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT project_id FROM project WHERE project_code=:project_code";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("project_code", this.projectCode);

        LOG.trace(sql);/*from w  w  w  .  jav a2  s. c  om*/
        LogParameters(paramSource);
        try {
            projectId = jt.queryForInt(sql, paramSource);
        } catch (EmptyResultDataAccessException ex) {
            // do nothing
        }

        if (projectId == 0) {
            sql = "SELECT nextval('seq_project_id')";
            LOG.trace(sql);
            projectId = jt.queryForInt(sql, paramSource);
            paramSource.addValue("project_id", projectId);

            sql = "INSERT INTO project (project_id, project_code)" + " VALUES (:project_id, :project_code)";

            LOG.trace(sql);
            LogParameters(paramSource);
            jt.update(sql, paramSource);
        }
    }
    return projectId;
}

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

public Word loadWord(int wordId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_WORD + " FROM ftb_word WHERE word_id=:word_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("word_id", wordId);

    LOG.info(sql);//from   ww  w.j a v a  2s . c o m
    TreebankDaoImpl.LogParameters(paramSource);
    Word word = null;
    try {
        word = (Word) jt.queryForObject(sql, paramSource, new WordMapper(this.treebankServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return word;
}