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.talismane.terminology.postgres.PostGresTerminologyBase.java

public Term loadTerm(int termId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
            + " WHERE term_id=:term_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("term_id", termId);

    LOG.trace(sql);/*www  . j  av  a2 s  .  c om*/
    LogParameters(paramSource);
    Term term = null;
    try {
        term = (Term) jt.queryForObject(sql, paramSource, new TermMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return term;
}

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

public Term loadTerm(String termText) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());

    String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
            + " WHERE text_text=:term_text" + " AND term_project_id=:term_project_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("term_text", termText);
    paramSource.addValue("term_project_id", this.getCurrentProjectId());

    LOG.trace(sql);/*ww w  . j  a va  2s  .  c o  m*/
    LogParameters(paramSource);
    Term term = null;
    try {
        term = (Term) jt.queryForObject(sql, paramSource, new TermMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return term;
}

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

void saveExpansions(Term term) {
    PostGresTerm iTerm = (PostGresTerm) term;
    for (Term expansion : iTerm.getExpansionSet().getItemsAdded()) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "INSERT INTO term_expansions (termexp_term_id, termexp_expansion_id)"
                + " VALUES (:termexp_term_id, :termexp_expansion_id)";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("termexp_term_id", iTerm.getId());
        paramSource.addValue("termexp_expansion_id", ((PostGresTerm) expansion).getId());

        LOG.trace(sql);//  ww w.  ja v  a2  s .  c  om
        LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
    iTerm.getExpansionSet().cleanSlate();
}

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

void saveHeads(Term term) {
    PostGresTerm iTerm = (PostGresTerm) term;
    for (Term head : iTerm.getHeadSet().getItemsAdded()) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "INSERT INTO term_heads (termhead_term_id, termhead_head_id)"
                + " VALUES (:termhead_term_id, :termhead_head_id)";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("termhead_head_id", ((PostGresTerm) head).getId());
        paramSource.addValue("termhead_term_id", iTerm.getId());

        LOG.trace(sql);/*from ww  w  .jav a2  s  .co  m*/
        LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
    iTerm.getHeadSet().cleanSlate();
}

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

String getFileName(int fileId) {
    String fileName = fileIdMap.get(fileId);
    if (fileName == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT file_name FROM file WHERE file_id=:file_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("file_id", fileId);

        LOG.trace(sql);/*from w ww .j av a  2s. com*/
        LogParameters(paramSource);

        fileName = (String) jt.queryForObject(sql, paramSource, String.class);

        fileIdMap.put(fileId, fileName);
    }
    return fileName;
}

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

@Override
public List<Context> getContexts(Term term) {
    MONITOR.startTask("getContexts");
    try {//from  ww  w.  j av a  2s  . co m
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_CONTEXT + " FROM context" + " WHERE context_term_id = :context_term_id"
                + " ORDER BY context_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("context_term_id", ((PostGresTerm) term).getId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Context> contexts = jt.query(sql, paramSource, new ContextMapper());

        return contexts;
    } finally {
        MONITOR.endTask("getContexts");
    }
}

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  w w w .j  a  v  a2  s . c o m*/
    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.lefff.LefffDaoImpl.java

public Attribute loadAttribute(int attributeId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute WHERE attribute_id=:attribute_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("attribute_id", attributeId);

    LOG.info(sql);/*from  w w  w  . j  a  v a  2s. co m*/
    LefffDaoImpl.LogParameters(paramSource);
    Attribute attribute = null;
    try {
        attribute = (Attribute) jt.queryForObject(sql, paramSource,
                new AttributeMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return attribute;
}

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

@SuppressWarnings("unchecked")
@Override//from www.  j a  va2s  .  c o  m
public List<Attribute> findAttributes(LefffEntryInternal entry) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute, lef_entry_attribute"
            + " WHERE attribute_id = entatt_attribute_id AND entatt_entry_id = :entry_id"
            + " ORDER BY attribute_code, attribute_value";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("entry_id", entry.getId());

    LOG.info(sql);
    LefffDaoImpl.LogParameters(paramSource);
    List<Attribute> attributes = jt.query(sql, paramSource,
            new AttributeMapper(this.getLefffServiceInternal()));

    return attributes;
}

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

public Category loadCategory(int categoryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_CATEGORY + " FROM lef_category WHERE category_id=:category_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("category_id", categoryId);

    LOG.info(sql);/*from w w w. ja  va2s  .c  om*/
    LefffDaoImpl.LogParameters(paramSource);
    Category category = null;
    try {
        category = (Category) jt.queryForObject(sql, paramSource,
                new CategoryMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return category;
}