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

public Morphology loadMorphology(int morphologyId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_MORPHOLOGY + " FROM ftb_morph WHERE morph_id=:morph_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("morph_id", morphologyId);

    LOG.info(sql);//from  ww  w.j  av  a 2  s  . c  o  m
    TreebankDaoImpl.LogParameters(paramSource);
    Morphology morphology = null;
    try {
        morphology = (Morphology) jt.queryForObject(sql, paramSource, new MorphologyMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return morphology;
}

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

public Morphology loadMorphology(String morphologyCode) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_MORPHOLOGY + " FROM ftb_morph WHERE morph_code=:morph_code";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("morph_code", morphologyCode);

    LOG.info(sql);// ww w .j  a  va2s  . com
    TreebankDaoImpl.LogParameters(paramSource);
    Morphology morphology = null;
    try {
        morphology = (Morphology) jt.queryForObject(sql, paramSource, new MorphologyMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return morphology;
}

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

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

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

    LOG.info(sql);/*from w w w.j  a v  a2 s.com*/
    LefffDaoImpl.LogParameters(paramSource);
    Word word = null;
    try {
        word = (Word) jt.queryForObject(sql, paramSource, new WordMapper(this.lefffServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return word;
}

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

@Override
public void saveShape(Shape shape) {
    // note: update will not update the pixels (not strictly required).
    try {/*ww  w  . j  a  v  a2s.c  o  m*/
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        ShapeInternal iShape = (ShapeInternal) shape;

        paramSource.addValue("shape_top", shape.getTop());
        paramSource.addValue("shape_left", shape.getLeft());
        paramSource.addValue("shape_bottom", shape.getBottom());
        paramSource.addValue("shape_right", shape.getRight());
        paramSource.addValue("shape_cap_line", shape.getCapLine());
        paramSource.addValue("shape_mean_line", shape.getMeanLine());
        paramSource.addValue("shape_base_line", shape.getBaseLine());
        paramSource.addValue("shape_letter", shape.getLetter());
        paramSource.addValue("shape_original_guess", shape.getOriginalGuess());
        paramSource.addValue("shape_group_id", shape.getGroupId());
        paramSource.addValue("shape_index", shape.getIndex());
        String sql = null;

        if (shape.isNew()) {
            sql = "SELECT nextval('ocr_shape_id_seq')";
            LOG.debug(sql);
            int shapeId = jt.queryForInt(sql, paramSource);
            paramSource.addValue("shape_id", shapeId);

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ImageIO.write(shape.getImage(), "png", os);
            os.flush();
            paramSource.addValue("shape_pixels", os.toByteArray());
            os.close();

            sql = "INSERT INTO ocr_shape (shape_id, shape_top, shape_left, shape_bottom, shape_right"
                    + ", shape_cap_line, shape_mean_line, shape_base_line, shape_pixels, shape_letter, shape_group_id"
                    + ", shape_index, shape_original_guess) "
                    + "VALUES (:shape_id, :shape_top, :shape_left, :shape_bottom, :shape_right"
                    + ", :shape_cap_line, :shape_mean_line, :shape_base_line, :shape_pixels, :shape_letter, :shape_group_id"
                    + ", :shape_index, :shape_original_guess)";

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

            iShape.setId(shapeId);
        } else {
            paramSource.addValue("shape_id", shape.getId());

            sql = "UPDATE ocr_shape" + " SET shape_top = :shape_top" + ", shape_left = :shape_left"
                    + ", shape_bottom = :shape_bottom" + ", shape_right = :shape_right"
                    + ", shape_cap_line = :shape_cap_line" + ", shape_mean_line = :shape_mean_line"
                    + ", shape_base_line = :shape_base_line" + ", shape_letter = :shape_letter"
                    + ", shape_group_id = :shape_group_id" + ", shape_index = :shape_index "
                    + ", shape_original_guess = :shape_original_guess " + " WHERE shape_id = :shape_id";

            LOG.debug(sql);
            logParameters(paramSource);
            jt.update(sql, paramSource);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

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

public PhraseType loadPhraseType(String phraseTypeCode) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PHRASE_TYPE + " FROM ftb_phrase_type WHERE ptype_code=:ptype_code";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("ptype_code", phraseTypeCode);

    LOG.info(sql);/*from w w  w. ja  va  2s. c  o  m*/
    TreebankDaoImpl.LogParameters(paramSource);
    PhraseType phraseType = null;
    try {
        phraseType = (PhraseType) jt.queryForObject(sql, paramSource, new PhraseTypeMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return phraseType;
}

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

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

    LOG.info(sql);//from ww w.ja  va2  s . c om
    LefffDaoImpl.LogParameters(paramSource);
    Word word = null;
    try {
        word = (Word) jt.queryForObject(sql, paramSource, new WordMapper(this.lefffServiceInternal));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return word;
}

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

public Context loadContext(int contextId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_CONTEXT + " FROM context WHERE context_id=:context_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("context_id", contextId);

    LOG.trace(sql);/*from   www  .  j  ava2  s  .c om*/
    LogParameters(paramSource);
    Context context = null;
    try {
        context = (Context) jt.queryForObject(sql, paramSource, new ContextMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return context;
}

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

public PhraseType loadPhraseType(int phraseTypeId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PHRASE_TYPE + " FROM ftb_phrase_type WHERE ptype_id=:ptype_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("ptype_id", phraseTypeId);

    LOG.info(sql);//from w w w  .ja v a2  s .co m
    TreebankDaoImpl.LogParameters(paramSource);
    PhraseType phraseType = null;
    try {
        phraseType = (PhraseType) jt.queryForObject(sql, paramSource, new PhraseTypeMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return phraseType;
}

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

public void saveContext(PostGresContext context) {
    if (context.isDirty()) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("context_start_row", context.getLineNumber());
        paramSource.addValue("context_start_column", context.getColumnNumber());
        paramSource.addValue("context_text", context.getTextSegment());
        paramSource.addValue("context_term_id", ((PostGresTerm) context.getTerm()).getId());
        paramSource.addValue("context_file_id", this.getFileId(context.getFileName()));

        // context_id, context_start_row, context_start_column, context_text, context_file_id, context_term_id
        if (context.isNew()) {
            String sql = "SELECT nextval('seq_context_id')";
            LOG.trace(sql);//from w  ww  . jav  a  2s . co m
            int contextId = jt.queryForInt(sql, paramSource);
            paramSource.addValue("context_id", contextId);

            sql = "INSERT INTO context (context_id, context_start_row, context_start_column, context_text, context_file_id, context_term_id)"
                    + " VALUES (:context_id, :context_start_row, :context_start_column, :context_text, :context_file_id, :context_term_id)";

            LOG.trace(sql);
            LogParameters(paramSource);
            jt.update(sql, paramSource);
            context.setId(contextId);
        } else {
            String sql = "UPDATE context" + " SET context_start_row = :context_start_row"
                    + ", context_start_column = :context_start_column" + ", context_text = :context_text"
                    + ", context_file_id = :context_file_id" + ", context_term_id = :context_term_id"
                    + " WHERE context_id = :context_id";

            paramSource.addValue("context_id", context.getId());
            LOG.trace(sql);
            LogParameters(paramSource);
            jt.update(sql, paramSource);
        }
        context.setDirty(false);
    }
}

From source file:info.raack.appliancelabeler.data.JDBCDatabase.java

public List<SecondData> getEnergyMeasurementsForMonitor(EnergyMonitor energyMonitor, Date start, Date end,
        int ticks) {
    EnergyMeasurementQueryItems items = getEnergyMeasurementQueryItems(energyMonitor, start, end, ticks);

    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(jdbcTemplate);

    return template.query(items.sql, items.parameters, secondDataRowMapper);
}