List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource addValue
public MapSqlParameterSource addValue(String paramName, @Nullable Object value)
From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java
@Override public Set<Term> getHeads(Term term) { MONITOR.startTask("getHeads"); try {/*from w ww .j a v 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_heads ON term_id = termhead_head_id" + " WHERE termhead_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("getHeads"); } }
From source file:com.joliciel.lefff.LefffDaoImpl.java
public Attribute loadAttribute(String attributeCode, String attributeValue) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute" + " WHERE attribute_code=:attribute_code" + " AND attribute_value=:attribute_value"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("attribute_code", attributeCode); paramSource.addValue("attribute_value", attributeValue); LOG.info(sql);/*from ww w.j a v a2 s .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
@Override public Lemma loadLemma(String text, int index, String complement) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_LEMMA + " FROM lef_lemma" + " WHERE lemma_text=:lemma_text" + " AND lemma_index=:lemma_index" + " AND lemma_complement=:lemma_complement"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("lemma_text", text); paramSource.addValue("lemma_index", index); paramSource.addValue("lemma_complement", complement); LOG.info(sql);//from w w w. 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.talismane.terminology.postgres.PostGresTerminologyBase.java
int getTextId(String text) { int textId = 0; NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT text_id FROM text WHERE text_text=:text_text"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("text_text", text); LOG.trace(sql);/* w w w .ja v a2s . c om*/ LogParameters(paramSource); try { textId = jt.queryForInt(sql, paramSource); } catch (EmptyResultDataAccessException ex) { // do nothing } if (textId == 0) { sql = "SELECT nextval('seq_text_id')"; LOG.trace(sql); textId = jt.queryForInt(sql, paramSource); paramSource.addValue("text_id", textId); sql = "INSERT INTO text (text_id, text_text)" + " VALUES (:text_id, :text_text)"; LOG.trace(sql); LogParameters(paramSource); jt.update(sql, paramSource); } return textId; }
From source file:com.joliciel.lefff.LefffDaoImpl.java
@Override public void saveAttributes(LefffEntryInternal entry) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("entatt_entry_id", entry.getId()); String sql = "DELETE FROM lef_entry_attribute WHERE entatt_entry_id = :entatt_entry_id"; LOG.info(sql);//w ww . j a v a 2 s. c o m LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); for (Attribute attribute : entry.getAttributes()) { paramSource = new MapSqlParameterSource(); paramSource.addValue("entatt_entry_id", entry.getId()); paramSource.addValue("entatt_attribute_id", attribute.getId()); sql = "INSERT INTO lef_entry_attribute (entatt_entry_id, entatt_attribute_id)" + " VALUES (:entatt_entry_id, :entatt_attribute_id)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
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 ww w .j a va 2 s .co m 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.lefff.LefffDaoImpl.java
public void savePredicate(PredicateInternal predicate) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("predicate_text", predicate.getText()); if (predicate.isNew()) { String sql = "SELECT nextval('seq_predicate_id')"; LOG.info(sql);/*from w ww .j a v a2 s . c om*/ int predicateId = jt.queryForInt(sql, paramSource); paramSource.addValue("predicate_id", predicateId); sql = "INSERT INTO lef_predicate (predicate_id, predicate_text) VALUES (:predicate_id, :predicate_text)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); predicate.setId(predicateId); } else { String sql = "UPDATE lef_predicate" + " SET predicate_text = :predicate_text" + " WHERE predicate_id = :predicate_id"; paramSource.addValue("predicate_id", predicate.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
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 w w . j ava 2 s . c om 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.lefff.LefffDaoImpl.java
public void saveCategory(CategoryInternal category) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("category_code", category.getCode()); paramSource.addValue("category_description", category.getDescription()); if (category.isNew()) { String sql = "SELECT nextval('seq_category_id')"; LOG.info(sql);//w w w .ja va 2 s. c o m int categoryId = jt.queryForInt(sql, paramSource); paramSource.addValue("category_id", categoryId); sql = "INSERT INTO lef_category (category_id, category_code, category_description) VALUES (:category_id, :category_code, :category_description)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); category.setId(categoryId); } else { String sql = "UPDATE lef_category" + " SET category_code = :category_code" + ", category_description = :category_description" + " WHERE category_id = :category_id"; paramSource.addValue("category_id", category.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java
void addParents(List<Term> childTerms) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_TERM + ", term_expansion_id FROM term" + " INNER JOIN text ON term_text_id=text_id" + " INNER JOIN term_expansions ON term_id = termexp_term_id" + " WHERE term_project_id = :term_project_id" + " AND termexp_expansion_id IN (:child_terms)"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("term_project_id", this.getCurrentProjectId()); List<Integer> termIds = new ArrayList<Integer>(); Map<Integer, PostGresTerm> childTermMap = new HashMap<Integer, PostGresTerm>(); for (Term childTerm : childTerms) { PostGresTerm termInternal = (PostGresTerm) childTerm; if (termInternal.getParentsInternal() == null) { termIds.add(termInternal.getId()); termInternal.setParentsInternal(new TreeSet<Term>()); childTermMap.put(termInternal.getId(), termInternal); }//from www . j a v a 2s .c o m } paramSource.addValue("child_terms", termIds); LOG.trace(sql); LogParameters(paramSource); SqlRowSet rs = jt.queryForRowSet(sql, paramSource); TermMapper termMapper = new TermMapper(); List<Term> parentTerms = new ArrayList<Term>(); while (rs.next()) { Term term = termMapper.mapRow(rs); parentTerms.add(term); int childId = rs.getInt("termexp_expansion_id"); PostGresTerm childTerm = childTermMap.get(childId); childTerm.getParentsInternal().add(term); } if (parentTerms.size() > 0) { this.addParents(parentTerms); } }