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.jochre.graphics.GraphicsDaoJdbc.java

@Override
public void saveParagraph(Paragraph paragraph) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    ParagraphInternal iParagraph = (ParagraphInternal) paragraph;

    paramSource.addValue("paragraph_image_id", paragraph.getImageId());
    paramSource.addValue("paragraph_index", paragraph.getIndex());
    String sql = null;//from  w  w  w .j  a v  a 2s. co m

    if (paragraph.isNew()) {
        sql = "SELECT nextval('ocr_paragraph_id_seq')";
        LOG.debug(sql);
        int paragraphId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("paragraph_id", paragraphId);

        sql = "INSERT INTO ocr_paragraph (paragraph_id, paragraph_image_id, paragraph_index) "
                + "VALUES (:paragraph_id, :paragraph_image_id, :paragraph_index)";

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

        iParagraph.setId(paragraphId);
    } else {
        paramSource.addValue("paragraph_id", paragraph.getId());

        sql = "UPDATE ocr_paragraph" + " SET paragraph_image_id = :paragraph_image_id"
                + ", paragraph_index = :paragraph_index" + " WHERE paragraph_id = :paragraph_id";

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

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

public TreebankFile loadTreebankFile(String fileName) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_TREEBANK_FILE + " FROM ftb_file WHERE file_name=:file_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("file_name", fileName);

    LOG.info(sql);// w w w.j a  v  a 2s  . co  m
    TreebankDaoImpl.LogParameters(paramSource);
    TreebankFile treebankFile = null;
    try {
        treebankFile = (TreebankFile) jt.queryForObject(sql, paramSource,
                new TreebankFileMapper(treebankServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return treebankFile;
}

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

@Override
public List<TreebankFile> findTreebankFiles() {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_TREEBANK_FILE + " FROM ftb_file" + " ORDER BY file_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    LOG.info(sql);/*  w w w.  j  av  a  2  s .  c om*/
    TreebankDaoImpl.LogParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<TreebankFile> files = jt.query(sql, paramSource, new TreebankFileMapper(treebankServiceInternal));

    return files;
}

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

@Override
public int getShapeCount(JochreImage jochreImage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT count(*) FROM ocr_shape" + " INNER JOIN ocr_group ON shape_group_id = group_id"
            + " INNER JOIN ocr_row ON group_row_id = row_id"
            + " INNER JOIN ocr_paragraph ON row_paragraph_id = paragraph_id"
            + " INNER JOIN ocr_image ON paragraph_image_id = image_id" + " WHERE image_id = :image_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_id", jochreImage.getId());

    LOG.debug(sql);//  w ww  .  java2 s.c o  m
    logParameters(paramSource);
    int count = jt.queryForInt(sql, paramSource);
    return count;
}

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

public TreebankFile loadTreebankFile(int fileId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_TREEBANK_FILE + " FROM ftb_file WHERE file_id=:file_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("file_id", fileId);

    LOG.info(sql);/*from  ww  w.j ava2s. c  o m*/
    TreebankDaoImpl.LogParameters(paramSource);
    TreebankFile treebankFile = null;
    try {
        treebankFile = (TreebankFile) jt.queryForObject(sql, paramSource,
                new TreebankFileMapper(treebankServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return treebankFile;
}

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

@Override
public List<Integer> findShapeIds(String letter) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT shape_id FROM ocr_shape" + " INNER JOIN ocr_group ON shape_group_id = group_id"
            + " INNER JOIN ocr_row ON group_row_id = row_id"
            + " INNER JOIN ocr_paragraph ON row_paragraph_id = paragraph_id"
            + " INNER JOIN ocr_image ON paragraph_image_id = image_id"
            + " WHERE image_imgstatus_id = :image_imgstatus_id" + " AND shape_letter = :shape_letter"
            + " ORDER BY shape_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_imgstatus_id", ImageStatus.TRAINING_VALIDATED.getId());
    paramSource.addValue("shape_letter", letter);

    LOG.debug(sql);/* w  ww  . ja v a 2  s.c  o  m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<Integer> shapeIds = jt.queryForList(sql, paramSource, Integer.class);
    return shapeIds;
}

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);//from   w  w w  .j ava2  s . c o  m
        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 w  w w.j a  v a 2 s. c o  m*/
        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 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);/*from   www. j a  v a  2s.com*/
        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 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);//from www. j av  a2 s  . 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);
    }
}