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.frenchTreebank.TreebankDaoImpl.java
public void savePhrase(PhraseInternal phrase) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("phrase_ptype_id", phrase.getPhraseTypeId() == 0 ? null : phrase.getPhraseTypeId()); paramSource.addValue("phrase_parent_id", phrase.getParent() == null ? null : phrase.getParent().getId()); paramSource.addValue("phrase_function_id", phrase.getFunctionId() == 0 ? null : phrase.getFunctionId()); paramSource.addValue("phrase_position", phrase.getPositionInPhrase()); paramSource.addValue("phrase_depth", phrase.getDepth()); if (phrase.isNew()) { String sql = "SELECT nextval('ftb_phrase_phrase_id_seq')"; LOG.info(sql);/*from w w w .j a va 2 s. c om*/ int phraseId = jt.queryForInt(sql, paramSource); paramSource.addValue("phrase_id", phraseId); sql = "INSERT INTO ftb_phrase (phrase_id, phrase_ptype_id, phrase_parent_id, phrase_function_id, phrase_position, phrase_depth) " + "VALUES (:phrase_id, :phrase_ptype_id, :phrase_parent_id, :phrase_function_id, :phrase_position, :phrase_depth)"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); phrase.setId(phraseId); } }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public void saveJochreImage(JochreImage image) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); JochreImageInternal iImage = (JochreImageInternal) image; paramSource.addValue("image_name", image.getName()); paramSource.addValue("image_width", image.getWidth()); paramSource.addValue("image_height", image.getHeight()); paramSource.addValue("image_black_threshold", image.getBlackThreshold()); paramSource.addValue("image_sep_threshold", image.getSeparationThreshold()); paramSource.addValue("image_black_limit", image.getBlackLimit()); paramSource.addValue("image_white_limit", image.getWhiteLimit()); paramSource.addValue("image_white_gap_fill_factor", image.getWhiteGapFillFactor()); paramSource.addValue("image_page_id", image.getPageId()); paramSource.addValue("image_index", image.getIndex()); paramSource.addValue("image_imgstatus_id", image.getImageStatus().getId()); paramSource.addValue("image_owner_id", image.getOwnerId()); String sql = null;/* ww w.j a v a 2 s . com*/ if (image.isNew()) { sql = "SELECT nextval('ocr_image_id_seq')"; LOG.debug(sql); int imageId = jt.queryForInt(sql, paramSource); paramSource.addValue("image_id", imageId); sql = "INSERT INTO ocr_image (image_id, image_name, image_width, image_height, image_black_threshold," + " image_page_id, image_index, image_sep_threshold, image_black_limit, image_white_limit," + " image_white_gap_fill_factor, image_imgstatus_id, image_owner_id) " + "VALUES (:image_id, :image_name, :image_width, :image_height, :image_black_threshold," + " :image_page_id, :image_index, :image_sep_threshold, :image_black_limit, :image_white_limit," + " :image_white_gap_fill_factor, :image_imgstatus_id, :image_owner_id)"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); iImage.setId(imageId); } else { paramSource.addValue("image_id", image.getId()); sql = "UPDATE ocr_image" + " SET image_name = :image_name" + ", image_width = :image_width" + ", image_height = :image_height" + ", image_black_threshold = :image_black_threshold" + ", image_sep_threshold = :image_sep_threshold" + ", image_black_limit = :image_black_limit" + ", image_white_limit = :image_white_limit" + ", image_white_gap_fill_factor = :image_white_gap_fill_factor" + ", image_page_id = :image_page_id" + ", image_index = :image_index" + ", image_imgstatus_id = :image_imgstatus_id" + ", image_owner_id = :image_owner_id" + " WHERE image_id = :image_id"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public void saveShape(Shape shape) { // note: update will not update the pixels (not strictly required). try {/*from w ww .j ava 2s .c o m*/ NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); ShapeInternal iShape = (ShapeInternal) shape; paramSource.addValue("shape_top", shape.getTop()); paramSource.addValue("shape_left", shape.getLeft()); paramSource.addValue("shape_bottom", shape.getBottom()); paramSource.addValue("shape_right", shape.getRight()); paramSource.addValue("shape_cap_line", shape.getCapLine()); paramSource.addValue("shape_mean_line", shape.getMeanLine()); paramSource.addValue("shape_base_line", shape.getBaseLine()); paramSource.addValue("shape_letter", shape.getLetter()); paramSource.addValue("shape_original_guess", shape.getOriginalGuess()); paramSource.addValue("shape_group_id", shape.getGroupId()); paramSource.addValue("shape_index", shape.getIndex()); String sql = null; if (shape.isNew()) { sql = "SELECT nextval('ocr_shape_id_seq')"; LOG.debug(sql); int shapeId = jt.queryForInt(sql, paramSource); paramSource.addValue("shape_id", shapeId); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(shape.getImage(), "png", os); os.flush(); paramSource.addValue("shape_pixels", os.toByteArray()); os.close(); sql = "INSERT INTO ocr_shape (shape_id, shape_top, shape_left, shape_bottom, shape_right" + ", shape_cap_line, shape_mean_line, shape_base_line, shape_pixels, shape_letter, shape_group_id" + ", shape_index, shape_original_guess) " + "VALUES (:shape_id, :shape_top, :shape_left, :shape_bottom, :shape_right" + ", :shape_cap_line, :shape_mean_line, :shape_base_line, :shape_pixels, :shape_letter, :shape_group_id" + ", :shape_index, :shape_original_guess)"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); iShape.setId(shapeId); } else { paramSource.addValue("shape_id", shape.getId()); sql = "UPDATE ocr_shape" + " SET shape_top = :shape_top" + ", shape_left = :shape_left" + ", shape_bottom = :shape_bottom" + ", shape_right = :shape_right" + ", shape_cap_line = :shape_cap_line" + ", shape_mean_line = :shape_mean_line" + ", shape_base_line = :shape_base_line" + ", shape_letter = :shape_letter" + ", shape_group_id = :shape_group_id" + ", shape_index = :shape_index " + ", shape_original_guess = :shape_original_guess " + " WHERE shape_id = :shape_id"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public void savePhraseSubunit(PhraseSubunitInternal phraseSubunit) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("psubunit_punit_id", phraseSubunit.getPhraseUnit() == null ? null : phraseSubunit.getPhraseUnit().getId()); paramSource.addValue("psubunit_word_id", phraseSubunit.getWordId() == 0 ? null : phraseSubunit.getWordId()); paramSource.addValue("psubunit_position", phraseSubunit.getPosition()); paramSource.addValue("psubunit_cat_id", phraseSubunit.getCategoryId() == 0 ? null : phraseSubunit.getCategoryId()); paramSource.addValue("psubunit_subcat_id", phraseSubunit.getSubCategoryId() == 0 ? null : phraseSubunit.getSubCategoryId()); paramSource.addValue("psubunit_morph_id", phraseSubunit.getMorphologyId() == 0 ? null : phraseSubunit.getMorphologyId()); if (phraseSubunit.isNew()) { String sql = "SELECT nextval('ftb_phrase_subunit_psubunit_id_seq')"; LOG.info(sql);//from w w w. j av a 2 s .co m int phraseSubunitId = jt.queryForInt(sql, paramSource); paramSource.addValue("psubunit_id", phraseSubunitId); sql = "INSERT INTO ftb_phrase_subunit (psubunit_id, psubunit_punit_id, psubunit_word_id, psubunit_position" + ", psubunit_cat_id, psubunit_subcat_id, psubunit_morph_id) " + "VALUES (:psubunit_id, :psubunit_punit_id, :psubunit_word_id, :psubunit_position" + ", :psubunit_cat_id, :psubunit_subcat_id, :psubunit_morph_id)"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); phraseSubunit.setId(phraseSubunitId); } else { paramSource.addValue("psubunit_id", phraseSubunit.getId()); String sql = "UPDATE ftb_phrase_subunit" + " SET psubunit_punit_id=:psubunit_punit_id" + ", psubunit_word_id=:psubunit_word_id" + ", psubunit_position=:psubunit_position" + ", psubunit_cat_id=:psubunit_cat_id" + ", psubunit_subcat_id=:psubunit_subcat_id" + ", psubunit_morph_id=:psubunit_morph_id " + " WHERE psubunit_id = :psubunit_id"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public void savePhraseUnit(PhraseUnitInternal phraseUnit) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("punit_word_id", phraseUnit.getWordId() == 0 ? null : phraseUnit.getWordId()); paramSource.addValue("punit_phrase_id", phraseUnit.getPhraseId() == 0 ? null : phraseUnit.getPhraseId()); paramSource.addValue("punit_position", phraseUnit.getPositionInSentence()); paramSource.addValue("punit_lemma_id", phraseUnit.getLemmaId() == 0 ? null : phraseUnit.getLemmaId()); paramSource.addValue("punit_cat_id", phraseUnit.getCategoryId() == 0 ? null : phraseUnit.getCategoryId()); paramSource.addValue("punit_subcat_id", phraseUnit.getSubCategoryId() == 0 ? null : phraseUnit.getSubCategoryId()); paramSource.addValue("punit_morph_id", phraseUnit.getMorphologyId() == 0 ? null : phraseUnit.getMorphologyId()); paramSource.addValue("punit_compound", phraseUnit.isCompound()); paramSource.addValue("punit_pos_in_phrase", phraseUnit.getPositionInPhrase()); paramSource.addValue("punit_compound_next", phraseUnit.getNextCompoundPartId() == 0 ? null : phraseUnit.getNextCompoundPartId()); paramSource.addValue("punit_guessed_postag_id", phraseUnit.getGuessedPosTagId() == 0 ? null : phraseUnit.getGuessedPosTagId()); if (phraseUnit.isNew()) { String sql = "SELECT nextval('ftb_phrase_unit_punit_id_seq')"; LOG.info(sql);/* w ww . j a va 2 s. c o m*/ int phraseUnitId = jt.queryForInt(sql, paramSource); paramSource.addValue("punit_id", phraseUnitId); sql = "INSERT INTO ftb_phrase_unit (punit_id, punit_word_id, punit_phrase_id, punit_position, punit_lemma_id, punit_cat_id" + ", punit_subcat_id, punit_morph_id, punit_compound, punit_pos_in_phrase, punit_compound_next, punit_guessed_postag_id) " + "VALUES (:punit_id, :punit_word_id, :punit_phrase_id, :punit_position, :punit_lemma_id, :punit_cat_id" + ", :punit_subcat_id, :punit_morph_id, :punit_compound, :punit_pos_in_phrase, :punit_compound_next, :punit_guessed_postag_id)"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); phraseUnit.setId(phraseUnitId); } else { paramSource.addValue("punit_id", phraseUnit.getId()); String sql = "UPDATE ftb_phrase_unit" + " SET punit_word_id = :punit_word_id" + ", punit_phrase_id=:punit_phrase_id" + ", punit_position=:punit_position" + ", punit_lemma_id=:punit_lemma_id" + ", punit_cat_id=:punit_cat_id" + ", punit_subcat_id=:punit_subcat_id" + ", punit_morph_id=:punit_morph_id" + ", punit_compound=:punit_compound" + ", punit_pos_in_phrase=:punit_pos_in_phrase" + ", punit_compound_next=:punit_compound_next" + ", punit_guessed_postag_id=:punit_guessed_postag_id" + " WHERE punit_id=:punit_id"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:org.jumpmind.metl.core.runtime.component.SqlExecutor.java
@Override public void handle(final Message inputMessage, final ISendMessageCallback callback, boolean unitOfWorkBoundaryReached) { results.clear();/*from w ww . j ava 2 s . c om*/ NamedParameterJdbcTemplate template = getJdbcTemplate(); int sqlCount = 0; int resultCount = 0; int inboundRecordCount = 0; Iterator<?> inboundPayload = null; if (PER_ENTITY.equals(runWhen) && inputMessage instanceof ContentMessage<?>) { inboundPayload = ((Collection<?>) ((ContentMessage<?>) inputMessage).getPayload()).iterator(); inboundRecordCount = ((Collection<?>) ((ContentMessage<?>) inputMessage).getPayload()).size(); } else if (PER_MESSAGE.equals(runWhen) && !(inputMessage instanceof ControlMessage)) { inboundPayload = null; inboundRecordCount = 1; } else if (PER_UNIT_OF_WORK.equals(runWhen) && inputMessage instanceof ControlMessage) { inboundPayload = null; inboundRecordCount = 1; } for (int i = 0; i < inboundRecordCount; i++) { Object entity = inboundPayload != null && inboundPayload.hasNext() ? inboundPayload.next() : null; for (String sql : this.sqls) { String sqlToExecute = prepareSql(sql, inputMessage, entity); Map<String, Object> paramMap = prepareParams(sqlToExecute, inputMessage, entity, runWhen); log(LogLevel.INFO, "About to run: %s", sqlToExecute); log(LogLevel.INFO, "Passing params: %s", paramMap); resultCount = template.update(sqlToExecute, paramMap); getComponentStatistics().incrementNumberEntitiesProcessed(resultCount); sqlCount++; } } if (callback != null && sqlCount > 0) { callback.sendTextMessage(null, convertResultsToTextPayload(results)); } log(LogLevel.INFO, "Ran %d sql statements", sqlCount); }
From source file:org.qifu.sys.SysEventLogSupport.java
public static void log(String userId, String sysId, String executeEventId, boolean permit) { if (StringUtils.isBlank(userId) || StringUtils.isBlank(sysId) || StringUtils.isBlank(executeEventId)) { log.warn("parameter has null value, userId=" + userId + ", sysId=" + sysId + ", executeEventId=" + executeEventId);/*w w w .j av a 2 s . c o m*/ return; } NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) AppContext .getBean("namedParameterJdbcTemplate"); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("oid", SimpleUtils.getUUIDStr()); paramMap.put("user", userId); paramMap.put("sysId", sysId); paramMap.put("executeEvent", (executeEventId.length() > 255 ? executeEventId.substring(0, 255) : executeEventId)); paramMap.put("isPermit", (permit ? "Y" : "N")); paramMap.put("cuserid", "SYS"); paramMap.put("cdate", new Date()); try { namedParameterJdbcTemplate.update( "insert into tb_sys_event_log(OID, USER, SYS_ID, EXECUTE_EVENT, IS_PERMIT, CUSERID, CDATE) " + "values(:oid, :user, :sysId, :executeEvent, :isPermit, :cuserid, :cdate)", paramMap); } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage().toString()); } }
From source file:org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplateTests.java
public void testUpdate() throws SQLException { mockPreparedStatement.setObject(1, new Integer(1)); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setObject(2, new Integer(1)); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeUpdate(); ctrlPreparedStatement.setReturnValue(1); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); }/*from ww w . java2 s.c o m*/ mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(mockDataSource); Map params = new HashMap(); params.put("perfId", new Integer(1)); params.put("priceId", new Integer(1)); int rowsAffected = jt.update(UPDATE_NAMED_PARAMETERS, params); assertEquals(1, rowsAffected); }
From source file:org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplateTests.java
public void testUpdateWithTypedParameters() throws SQLException { mockPreparedStatement.setObject(1, new Integer(1), Types.DECIMAL); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setObject(2, new Integer(1), Types.INTEGER); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeUpdate(); ctrlPreparedStatement.setReturnValue(1); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); }/*w ww .ja v a2s .c om*/ mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(mockDataSource); Map params = new HashMap(); params.put("perfId", new SqlParameterValue(Types.DECIMAL, new Integer(1))); params.put("priceId", new SqlParameterValue(Types.INTEGER, new Integer(1))); int rowsAffected = jt.update(UPDATE_NAMED_PARAMETERS, params); assertEquals(1, rowsAffected); }
From source file:rapture.repo.integration.PgIndexCreationTest.java
private void insertValue(NamedParameterJdbcTemplate jdbcTemplate, int i) throws SQLException { String value = String.format( "{\"id\": " + "\"%s\", \"max\": 2, \"message\": \"what upz\", \"lastSeen\": 12345, \"progress\": 1}", i);/*from w w w .j av a 2s . co m*/ PGobject valueJson = new PGobject(); valueJson.setType("jsonb"); valueJson.setValue(value); SqlParameterSource params = new MapSqlParameterSource().addValue("keyIn", "key" + i).addValue("contentIn", valueJson); jdbcTemplate.update("INSERT INTO activity\n" + "VALUES(:keyIn, :contentIn, now());\n", params); }