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.lefff.LefffDaoImpl.java

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

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

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

public Predicate loadPredicate(int predicateId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PREDICATE + " FROM lef_predicate WHERE predicate_id=:predicate_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("predicate_id", predicateId);

    LOG.info(sql);//from  ww  w  .  j  a v a 2 s.c  o  m
    LefffDaoImpl.LogParameters(paramSource);
    Predicate predicate = null;
    try {
        predicate = (Predicate) jt.queryForObject(sql, paramSource,
                new PredicateMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return predicate;
}

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

public Predicate loadPredicate(String predicateText) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PREDICATE + " FROM lef_predicate WHERE predicate_text=:predicate_text";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("predicate_text", predicateText);

    LOG.info(sql);//  ww w  .j  av  a  2 s .c om
    LefffDaoImpl.LogParameters(paramSource);
    Predicate predicate = null;
    try {
        predicate = (Predicate) jt.queryForObject(sql, paramSource,
                new PredicateMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return predicate;
}

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

@Override
public Lemma loadLemma(int lemmaId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_LEMMA + " FROM lef_lemma WHERE lemma_id=:lemma_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("lemma_id", lemmaId);

    LOG.info(sql);/*www  .  j  a va  2  s . c  o m*/
    LefffDaoImpl.LogParameters(paramSource);
    Lemma lemma = null;
    try {
        lemma = (Lemma) jt.queryForObject(sql, paramSource, new LemmaMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return lemma;
}

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);/*from ww  w. jav a2  s  .c  om*/
    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.talismane.terminology.postgres.PostGresTerminologyBase.java

@Override
public List<Term> getTermsByFrequency(final int frequencyThreshold) {
    MONITOR.startTask("getTermsByFrequency");
    try {//ww w. ja v a2  s  .co m
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " WHERE term_frequency >= :term_frequency" + " AND term_project_id = :term_project_id"
                + " ORDER BY term_frequency DESC, text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_frequency", frequencyThreshold);
        paramSource.addValue("term_project_id", this.getCurrentProjectId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        return terms;
    } finally {
        MONITOR.endTask("getTermsByFrequency");
    }
}

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

@Override
public List<Term> getTermsByText(final String searchText) {
    MONITOR.startTask("getTermsByText");
    try {//w  w w  .j ava2s.  com
        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 LIKE :term_text" + " AND term_project_id = :term_project_id"
                + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_text", searchText + "%");
        paramSource.addValue("term_project_id", this.getCurrentProjectId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        return terms;

    } finally {
        MONITOR.endTask("getTermsByText");
    }
}

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

@Override
public List<Term> getMarkedTerms() {
    MONITOR.startTask("getMarkedTerms");
    try {/* w ww .  j a  v  a 2  s  .  c om*/
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " WHERE term_marked = :term_marked" + " AND term_project_id = :term_project_id"
                + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_marked", true);
        paramSource.addValue("term_project_id", this.getCurrentProjectId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        return terms;

    } finally {
        MONITOR.endTask("getMarkedTerms");
    }
}

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

@Override
public Set<Term> getParents(final Term term) {
    MONITOR.startTask("getParents");
    try {/*from ww  w . j  a va 2  s  .  c  om*/
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " INNER JOIN term_expansions ON term_id = termexp_term_id"
                + " WHERE termexp_expansion_id = :term_id" + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_id", ((PostGresTerm) term).getId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        Set<Term> termSet = new TreeSet<Term>(new TermFrequencyComparator());
        termSet.addAll(terms);
        return termSet;
    } finally {
        MONITOR.endTask("getHeads");
    }
}

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

@Override
public Set<Term> getExpansions(Term term) {
    MONITOR.startTask("getExpansions");
    try {//  w  ww.  jav a2  s.c  o  m
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " INNER JOIN term_expansions ON term_id = termexp_expansion_id"
                + " WHERE termexp_term_id = :term_id" + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_id", ((PostGresTerm) term).getId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        Set<Term> termSet = new TreeSet<Term>(new TermFrequencyComparator());
        termSet.addAll(terms);
        return termSet;
    } finally {
        MONITOR.endTask("getExpansions");
    }
}