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.lefff.LefffDaoImpl.java
public void saveAttribute(AttributeInternal attribute) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("attribute_code", attribute.getCode()); paramSource.addValue("attribute_value", attribute.getValue()); paramSource.addValue("attribute_morph", attribute.isMorphological()); if (attribute.isNew()) { String sql = "SELECT nextval('seq_attribute_id')"; LOG.info(sql);/* ww w.j ava2 s . c o m*/ int attributeId = jt.queryForInt(sql, paramSource); paramSource.addValue("attribute_id", attributeId); sql = "INSERT INTO lef_attribute (attribute_id, attribute_code, attribute_value, attribute_morph)" + " VALUES (:attribute_id, :attribute_code, :attribute_value, :attribute_morph)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); attribute.setId(attributeId); } else { String sql = "UPDATE lef_attribute" + " SET attribute_code = :attribute_code" + ", attribute_value = :attribute_value" + ", attribute_morph = :attribute_morph" + " WHERE attribute_id = :attribute_id"; paramSource.addValue("attribute_id", attribute.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.lefff.LefffDaoImpl.java
@Override public void saveLemma(LemmaInternal lemma) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("lemma_text", lemma.getText()); paramSource.addValue("lemma_index", lemma.getIndex()); paramSource.addValue("lemma_complement", lemma.getComplement()); if (lemma.isNew()) { String sql = "SELECT nextval('seq_lemma_id')"; LOG.info(sql);// www .ja va2s. c om int lemmaId = jt.queryForInt(sql, paramSource); paramSource.addValue("lemma_id", lemmaId); sql = "INSERT INTO lef_lemma (lemma_id, lemma_text, lemma_index, lemma_complement)" + " VALUES (:lemma_id, :lemma_text, :lemma_index, :lemma_complement)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); lemma.setId(lemmaId); } else { String sql = "UPDATE lef_lemma" + " SET lemma_text = :lemma_text" + ", lemma_index = :lemma_index" + ", lemma_complement = :lemma_complement" + " WHERE lemma_id = :lemma_id"; paramSource.addValue("lemma_id", lemma.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java
int getFileId(String fileName) { int fileId = 0; Integer fileIdObj = filenameMap.get(fileName); if (fileIdObj == null) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT file_id FROM file WHERE file_name=:file_name"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("file_name", fileName); LOG.trace(sql);//from w w w . j ava 2 s. c o m LogParameters(paramSource); try { fileId = jt.queryForInt(sql, paramSource); } catch (EmptyResultDataAccessException ex) { // do nothing } if (fileId == 0) { sql = "SELECT nextval('seq_file_id')"; LOG.trace(sql); fileId = jt.queryForInt(sql, paramSource); paramSource.addValue("file_id", fileId); sql = "INSERT INTO file (file_id, file_name)" + " VALUES (:file_id, :file_name)"; LOG.trace(sql); LogParameters(paramSource); jt.update(sql, paramSource); } filenameMap.put(fileName, fileId); } else { fileId = fileIdObj.intValue(); } return fileId; }
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 2 s . c o 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:com.joliciel.lefff.LefffDaoImpl.java
@Override public void saveEntry(LefffEntryInternal entry) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("entry_word_id", entry.getWordId()); paramSource.addValue("entry_lemma_id", entry.getLemmaId()); paramSource.addValue("entry_predicate_id", entry.getPredicateId() == 0 ? null : entry.getPredicateId()); paramSource.addValue("entry_morph_id", entry.getMorphologyId() == 0 ? null : entry.getMorphologyId()); paramSource.addValue("entry_lexical_weight", entry.getLexicalWeight()); paramSource.addValue("entry_category_id", entry.getCategoryId()); if (entry.isNew()) { String sql = "SELECT nextval('seq_entry_id')"; LOG.info(sql);/* w w w. ja v a2 s.c om*/ int entryId = jt.queryForInt(sql, paramSource); paramSource.addValue("entry_id", entryId); sql = "INSERT INTO lef_entry (entry_id, entry_word_id, entry_lemma_id, entry_predicate_id, entry_morph_id, entry_lexical_weight, entry_category_id)" + " VALUES (:entry_id, :entry_word_id, :entry_lemma_id, :entry_predicate_id, :entry_morph_id, :entry_lexical_weight, :entry_category_id)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); entry.setId(entryId); } else { String sql = "UPDATE lef_entry" + " SET entry_word_id = :entry_word_id" + ", entry_lemma_id = :entry_lemma_id" + ", entry_predicate_id = :entry_predicate_id" + ", entry_morph_id = :entry_morph_id" + ", entry_lexical_weight = :entry_lexical_weight" + ", entry_category_id = :entry_category_id" + " WHERE entry_id = :entry_id"; paramSource.addValue("entry_id", entry.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java
public void saveTerm(PostGresTerm term) { if (term.isDirty()) { int textId = this.getTextId(term.getText()); term.setTextId(textId);/* w w w . jav a 2 s . c om*/ NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("term_text_id", term.getTextId()); paramSource.addValue("term_frequency", term.getFrequency()); paramSource.addValue("term_project_id", this.getCurrentProjectId()); paramSource.addValue("term_marked", term.isMarked()); paramSource.addValue("term_expansion_count", term.getExpansionCount()); paramSource.addValue("term_head_count", term.getHeadCount()); if (term.isNew()) { String sql = "SELECT nextval('seq_term_id')"; LOG.trace(sql); int termId = jt.queryForInt(sql, paramSource); paramSource.addValue("term_id", termId); sql = "INSERT INTO term (term_id, term_text_id, term_project_id, term_frequency, term_marked, term_expansion_count, term_head_count)" + " VALUES (:term_id, :term_text_id, :term_project_id, :term_frequency, :term_marked, :term_expansion_count, :term_head_count)"; LOG.trace(sql); LogParameters(paramSource); jt.update(sql, paramSource); term.setId(termId); } else { String sql = "UPDATE term" + " SET term_text_id = :term_text_id" + ", term_frequency = :term_frequency" + ", term_project_id = :term_project_id" + ", term_marked = :term_marked" + ", term_expansion_count = :term_expansion_count" + ", term_head_count = :term_head_count" + " WHERE term_id = :term_id"; paramSource.addValue("term_id", term.getId()); LOG.trace(sql); LogParameters(paramSource); jt.update(sql, paramSource); } term.setDirty(false); } }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaDropDao.java
/** * For the given list of new drops, find those that the hash already exist * and update the drop entry with the existing id and remove the hash from * the new drop index./*from w w w .j a v a2 s . c o m*/ * * @param newDropIndex * @param drops */ private void updateNewDropIndex(Map<String, List<Integer>> newDropIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, droplet_hash FROM droplets WHERE droplet_hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newDropIndex.keySet()); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Update id for the drops that were found for (Map<String, Object> result : results) { String hash = (String) result.get("droplet_hash"); Long id = ((Number) result.get("id")).longValue(); List<Integer> indexes = newDropIndex.get(hash); for (Integer index : indexes) { drops.get(index).setId(id); } // Hash is not for a new drop so remove it newDropIndex.remove(hash); } }
From source file:com.joliciel.lefff.LefffDaoImpl.java
public void deleteLemma(int lemmaId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); String sql = "DELETE FROM lef_lemma WHERE lemma_id = :lemma_id"; paramSource.addValue("lemma_id", lemmaId); LOG.info(sql);//from w ww.j a v a2 s.c om LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); }
From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java
@Override public List<Term> getTerms(int frequencyThreshold, String searchText, boolean marked, boolean markedExpansions) { MONITOR.startTask("getTerms"); try {//from w w w . j av 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_project_id = :term_project_id"; if (marked && markedExpansions) { sql += " AND term_marked = :term_marked"; if (searchText.length() > 0) sql += " AND text_text LIKE :term_text"; } else { if (frequencyThreshold > 0) sql += " AND term_frequency >= :term_frequency"; if (searchText.length() > 0) sql += " AND text_text LIKE :term_text"; if (marked) sql += " AND term_marked = :term_marked"; } sql += " ORDER BY term_frequency DESC, text_text"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); if (frequencyThreshold > 0) paramSource.addValue("term_frequency", frequencyThreshold); if (searchText.length() > 0) paramSource.addValue("term_text", searchText + "%"); if (marked) 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()); if (marked && markedExpansions) { this.addParents(terms); List<Term> termsWithFrequency = new ArrayList<Term>(); for (Term term : terms) { int maxAncestorFrequency = this.getMaxAncestorFrequency(term); if (maxAncestorFrequency >= frequencyThreshold) termsWithFrequency.add(term); } terms = termsWithFrequency; } return terms; } finally { MONITOR.endTask("getTerms"); } }
From source file:com.joliciel.lefff.LefffDaoImpl.java
public void deleteCategory(int categoryId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); String sql = "DELETE FROM lef_category WHERE category_id = :category_id"; paramSource.addValue("category_id", categoryId); LOG.info(sql);// w ww.j a v a 2s . c om LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); }