List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate
public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@SuppressWarnings("unchecked") public List<Integer> findSentenceIds(int minId, int maxId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT sentence_id FROM ftb_sentence" + " WHERE sentence_id >= :min_id" + " AND sentence_id <= :max_id" + " ORDER BY sentence_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("min_id", minId); paramSource.addValue("max_id", maxId); LOG.info(sql);//w w w . j ava2s. c om TreebankDaoImpl.LogParameters(paramSource); List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class); return sentenceIds; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public List<Integer> findSentenceIds(TreebankFile treebankFile) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT sentence_id" + " FROM ftb_sentence" + " WHERE sentence_file_id=:sentence_file_id" + " ORDER BY sentence_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("sentence_file_id", treebankFile.getId()); LOG.info(sql);//from w ww . j a v a 2 s .c o m TreebankDaoImpl.LogParameters(paramSource); @SuppressWarnings("unchecked") List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class); return sentenceIds; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@SuppressWarnings("unchecked") @Override// w w w . jav a 2 s . c o m public List<Integer> findSentenceIds(TreebankSubSet treebankSubSet, int numIds, int startId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); String sql = "SELECT sentence_id FROM ftb_sentence" + " WHERE sentence_id >= :min_id"; paramSource.addValue("min_id", startId); String andWord = " AND "; for (String whereClause : this.getWhereClausesForSubSet(treebankSubSet, paramSource)) { sql += andWord + whereClause; } sql += " ORDER BY sentence_id"; if (numIds > 0) { sql += " LIMIT :maxResults"; paramSource.addValue("maxResults", numIds); } LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class); return sentenceIds; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public Set<String> findUnknownWords(TreebankSubSet knownSet, TreebankSubSet unknownSet) { Set<String> unknownWords = new TreeSet<String>(); NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); String sql = "SELECT word_text" + " FROM ftb_phrase_unit pu1" + " INNER JOIN ftb_phrase_child pc1 ON pu1.punit_phrase_id = pc1.pchild_child_id" + " INNER JOIN ftb_sentence s1 ON s1.sentence_id = pc1.pchild_phrase_id" + " INNER JOIN ftb_word ON pu1.punit_word_id = word_id" + " WHERE NOT EXISTS" + " (SELECT pu2.punit_word_id FROM ftb_phrase_unit pu2" + " INNER JOIN ftb_phrase_child pc2 ON pu2.punit_phrase_id = pc2.pchild_child_id" + " INNER JOIN ftb_sentence s2 ON s2.sentence_id = pc2.pchild_phrase_id" + " WHERE pu2.punit_word_id = pu1.punit_word_id"; for (String whereClause : this.getWhereClausesForSubSet(knownSet, paramSource, "known_")) { sql += " AND " + whereClause; }// ww w .ja v a 2s. c o m sql += ")"; for (String whereClause : this.getWhereClausesForSubSet(unknownSet, paramSource, "unknown_")) { sql += " AND " + whereClause; } sql += " GROUP BY word_text"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); @SuppressWarnings("unchecked") List<String> unknownWordList = jt.queryForList(sql, paramSource, String.class); unknownWords.addAll(unknownWordList); return unknownWords; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@SuppressWarnings("unchecked") public List<Integer> findWordIds(int minId, int maxId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT word_id FROM ftb_word" + " WHERE word_id >= :min_id" + " AND word_id <= :max_id" + " ORDER BY word_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("min_id", minId); paramSource.addValue("max_id", maxId); LOG.info(sql);/*w w w . j a v a 2s. com*/ TreebankDaoImpl.LogParameters(paramSource); List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class); return sentenceIds; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@SuppressWarnings("unchecked") public List<Integer> findCompoundWordIds(int minId, int maxId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT word_id FROM ftb_word, ftb_phrase_unit" + " WHERE word_id >= :min_id" + " AND word_id <= :max_id" + " AND word_id = punit_word_id" + " AND punit_compound = true" + " AND punit_id not in" + " (select psubunit_punit_id from ftb_phrase_subunit" + " group by psubunit_punit_id" + " having count(*)=1)" + " GROUP BY word_id" + " ORDER BY word_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("min_id", minId); paramSource.addValue("max_id", maxId); LOG.info(sql);//from ww w. jav a2 s .c o m TreebankDaoImpl.LogParameters(paramSource); List<Integer> wordIds = jt.queryForList(sql, paramSource, Integer.class); return wordIds; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@SuppressWarnings("unchecked") public List<Integer> findCompoundPhraseUnitIds(int minId, int maxId, boolean includeSingleSubunitCompounds) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT punit_id FROM ftb_phrase_unit" + " WHERE punit_id >= :min_id" + " AND punit_id <= :max_id" + " AND punit_compound = true"; if (!includeSingleSubunitCompounds) { sql += " AND punit_id not in" + " (select psubunit_punit_id from ftb_phrase_subunit" + " group by psubunit_punit_id" + " having count(*)=1)"; }//from w w w . j ava 2 s . co m sql += " ORDER BY punit_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("min_id", minId); paramSource.addValue("max_id", maxId); LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); List<Integer> phraseUnitIds = jt.queryForList(sql, paramSource, Integer.class); return phraseUnitIds; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@Override public TextItem loadTextItem(int textItemId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_TEXT_ITEM + " FROM ftb_text WHERE text_id=:text_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("text_id", textItemId); LOG.info(sql);//from w ww. java 2 s .c o m TreebankDaoImpl.LogParameters(paramSource); TextItem textItem = null; try { textItem = (TextItem) jt.queryForObject(sql, paramSource, new TextItemMapper()); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return textItem; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@Override public TextItem loadTextItem(String externalId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_TEXT_ITEM + " FROM ftb_text WHERE text_external_id=:text_external_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("text_external_id", externalId); LOG.info(sql);/*ww w. j a v a 2 s. c o m*/ TreebankDaoImpl.LogParameters(paramSource); TextItem textItem = null; try { textItem = (TextItem) jt.queryForObject(sql, paramSource, new TextItemMapper()); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return textItem; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
@Override public void saveTextItem(TextItemInternal textItem) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("text_file_id", textItem.getFileId()); paramSource.addValue("text_external_id", textItem.getExternalId()); if (textItem.isNew()) { String sql = "SELECT nextval('ftb_text_text_id_seq')"; LOG.info(sql);// ww w .j ava2s . c o m int textItemId = jt.queryForInt(sql, paramSource); paramSource.addValue("text_id", textItemId); sql = "INSERT INTO ftb_text (text_id, text_file_id, text_external_id) VALUES (:text_id, :text_file_id, :text_external_id)"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); textItem.setId(textItemId); } else { String sql = "UPDATE ftb_text" + " SET text_file_id = :text_file_id" + ", text_external_id = :text_external_id" + " WHERE text_id = :text_id"; paramSource.addValue("text_id", textItem.getId()); LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }