List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate update
@Override public int update(String sql, Map<String, ?> paramMap) throws DataAccessException
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 w w .j a v a 2s .com 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 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);/*www . j a v a 2s . 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.jochre.security.SecurityDaoJdbc.java
@Override public void saveUserInternal(UserInternal user) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("user_username", user.getUsername()); paramSource.addValue("user_password", user.getPassword()); paramSource.addValue("user_first_name", user.getFirstName()); paramSource.addValue("user_last_name", user.getLastName()); paramSource.addValue("user_role", user.getRole().getId()); paramSource.addValue("user_failed_logins", user.getFailedLoginCount()); paramSource.addValue("user_logins", user.getLoginCount()); String sql = null;//from ww w. j a v a2s .co m if (user.isNew()) { sql = "SELECT nextval('ocr_user_id_seq')"; LOG.info(sql); int userId = jt.queryForInt(sql, paramSource); paramSource.addValue("user_id", userId); sql = "INSERT INTO ocr_user (user_id, user_username, user_password" + ", user_first_name, user_last_name, user_role, user_failed_logins, user_logins) " + "VALUES (:user_id, :user_username, :user_password" + ", :user_first_name, :user_last_name, :user_role, :user_failed_logins, :user_logins)"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); user.setId(userId); } else { paramSource.addValue("user_id", user.getId()); sql = "UPDATE ocr_user" + " SET user_username = :user_username" + ", user_password = :user_password" + ", user_first_name = :user_first_name" + ", user_last_name = :user_last_name" + ", user_role = :user_role" + ", user_failed_logins = :user_failed_logins" + ", user_logins = :user_logins" + " WHERE user_id = :user_id"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public void deleteJochreImage(JochreImage image) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("image_id", image.getId()); String sql = null;/*ww w. ja va2 s .co m*/ sql = "delete from ocr_split where split_shape_id in (" + " select shape_id from ocr_shape" + " inner join ocr_group on shape_group_id = group_id" + " inner join ocr_row on group_row_id = row_id" + " inner join ocr_paragraph on row_paragraph_id = paragraph_id" + " WHERE paragraph_image_id = :image_id)"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); sql = "delete from ocr_shape where shape_group_id in (" + " select group_id from ocr_group" + " inner join ocr_row on group_row_id = row_id" + " inner join ocr_paragraph on row_paragraph_id = paragraph_id" + " WHERE paragraph_image_id = :image_id)"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); sql = "delete from ocr_group where group_row_id in (" + " select row_id from ocr_row" + " inner join ocr_paragraph on row_paragraph_id = paragraph_id" + " WHERE paragraph_image_id = :image_id)"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); sql = "delete from ocr_row where row_paragraph_id in (" + " select paragraph_id from ocr_paragraph" + " WHERE paragraph_image_id = :image_id)"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); sql = "delete from ocr_paragraph" + " where paragraph_image_id = :image_id"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); sql = "delete from ocr_image" + " WHERE image_id = :image_id"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); }
From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java
@Override public void saveAuthor(Author author) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); AuthorInternal iAuthor = (AuthorInternal) author; paramSource.addValue("author_first_name", author.getFirstName()); paramSource.addValue("author_last_name", author.getLastName()); paramSource.addValue("author_first_name_local", author.getFirstNameLocal()); paramSource.addValue("author_last_name_local", author.getLastNameLocal()); String sql = null;/*w w w . j ava 2 s. com*/ if (author.isNew()) { sql = "SELECT nextval('ocr_author_id_seq')"; LOG.info(sql); int authorId = jt.queryForInt(sql, paramSource); paramSource.addValue("author_id", authorId); sql = "INSERT INTO ocr_author (author_id, author_first_name, author_last_name" + ", author_first_name_local, author_last_name_local) " + "VALUES (:author_id, :author_first_name, :author_last_name" + ", :author_first_name_local, :author_last_name_local)"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); iAuthor.setId(authorId); } else { paramSource.addValue("author_id", author.getId()); sql = "UPDATE ocr_author" + " SET author_first_name = :author_first_name" + ", author_last_name = :author_last_name" + ", author_first_name_local = :author_first_name_local" + ", author_last_name_local = :author_last_name_local" + " WHERE author_id = :author_id"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public void saveOriginalImage(JochreImage jochreImage) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("image_id", jochreImage.getId()); ByteArrayOutputStream os = new ByteArrayOutputStream(); try {/*ww w. j a v a 2 s. c om*/ ImageIO.write(jochreImage.getOriginalImage(), "png", os); os.flush(); paramSource.addValue("image_image", os.toByteArray()); os.close(); } catch (IOException e) { throw new RuntimeException(e); } String sql = "UPDATE ocr_image SET image_image = :image_image" + " WHERE image_id = :image_id"; LOG.debug(sql); 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);/*from w ww. ja v a 2 s. co m*/ 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 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);//from w ww.j av a 2 s .c o m 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
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);/*from www .j ava 2s. 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.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 a va 2 s . co 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; }