Package org.springframework.jdbc.support

Examples of org.springframework.jdbc.support.GeneratedKeyHolder


          public void doInTransactionWithoutResult(TransactionStatus transactionStatus)
          {
            try
            {
              Date timestamp = new Date();
              KeyHolder keyHolder = new GeneratedKeyHolder();
              jdbcTemplate.update(
                  getEbMSMessagePreparedStatement(
                      timestamp,
                      message.getMessageHeader().getCPAId(),
                      message.getMessageHeader().getConversationId(),
                      message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(),
                      message.getMessageHeader().getMessageData().getMessageId(),
                      message.getMessageHeader().getMessageData().getRefToMessageId(),
                      message.getMessageHeader().getFrom().getRole(),
                      message.getMessageHeader().getTo().getRole(),
                      message.getMessageHeader().getService().getType(),
                      message.getMessageHeader().getService().getValue(),
                      message.getMessageHeader().getAction(),
                      message.getOriginal(),
                      XMLMessageBuilder.getInstance(SignatureType.class).handle(new ObjectFactory().createSignature(message.getSignature())),
                      XMLMessageBuilder.getInstance(MessageHeader.class).handle(message.getMessageHeader()),
                      XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()),
                      XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()),
                      XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()),
                      XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()),
                      status
                  ),
                  keyHolder
              );
         
              for (DataSource attachment : message.getAttachments())
              {
                simpleJdbcTemplate.update
                (
                  "insert into ebms_attachment (" +
                    "ebms_message_id," +
                    "name," +
                    "content_type," +
                    "content" +
                  ") values (?,?,?,?)",
                  keyHolder.getKey().longValue(),
                  attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(),
                  attachment.getContentType().split(";")[0].trim(),
                  IOUtils.toByteArray(attachment.getInputStream())
                );
              }
             
              jdbcTemplate.update(
                  getEbMSMessagePreparedStatement(
                      timestamp,
                      messageError.getMessageHeader().getCPAId(),
                      messageError.getMessageHeader().getConversationId(),
                      messageError.getMessageHeader().getMessageData().getMessageId(),
                      messageError.getMessageHeader().getMessageData().getRefToMessageId(),
                      messageError.getMessageHeader().getFrom().getRole(),
                      messageError.getMessageHeader().getTo().getRole(),
                      messageError.getMessageHeader().getService().getType(),
                      messageError.getMessageHeader().getService().getValue(),
                      messageError.getMessageHeader().getAction(),
                      XMLMessageBuilder.getInstance(MessageHeader.class).handle(messageError.getMessageHeader()),
                      XMLMessageBuilder.getInstance(ErrorList.class).handle(messageError.getErrorList())
                  ),
                  keyHolder
              );
         
              simpleJdbcTemplate.update
              (
                "insert into ebms_send_event (" +
                  "ebms_message_id," +
                  "time" +
                ") values (?,?)",
                keyHolder.getKey().longValue(),
                //String.format(getDateFormat(),sendEvent.getTime())
                sendEvent.getTime()
              );
            }
            catch (Exception e)
View Full Code Here


          public void doInTransactionWithoutResult(TransactionStatus transactionStatus)
          {
            try
            {
              Date timestamp = new Date();
              KeyHolder keyHolder = new GeneratedKeyHolder();
              jdbcTemplate.update(
                  getEbMSMessagePreparedStatement(
                      timestamp,
                      message.getMessageHeader().getCPAId(),
                      message.getMessageHeader().getConversationId(),
                      message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(),
                      message.getMessageHeader().getMessageData().getMessageId(),
                      message.getMessageHeader().getMessageData().getRefToMessageId(),
                      message.getMessageHeader().getFrom().getRole(),
                      message.getMessageHeader().getTo().getRole(),
                      message.getMessageHeader().getService().getType(),
                      message.getMessageHeader().getService().getValue(),
                      message.getMessageHeader().getAction(),
                      message.getOriginal(),
                      XMLMessageBuilder.getInstance(SignatureType.class).handle(new ObjectFactory().createSignature(message.getSignature())),
                      XMLMessageBuilder.getInstance(MessageHeader.class).handle(message.getMessageHeader()),
                      XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()),
                      XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()),
                      XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()),
                      XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()),
                      status
                  ),
                  keyHolder
              );
         
              for (DataSource attachment : message.getAttachments())
              {
                simpleJdbcTemplate.update
                (
                  "insert into ebms_attachment (" +
                    "ebms_message_id," +
                    "name," +
                    "content_type," +
                    "content" +
                  ") values (?,?,?,?)",
                  keyHolder.getKey().longValue(),
                  attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(),
                  attachment.getContentType().split(";")[0].trim(),
                  IOUtils.toByteArray(attachment.getInputStream())
                );
              }
             
              jdbcTemplate.update(
                  getEbMSMessagePreparedStatement(
                      timestamp,
                      acknowledgment.getMessageHeader().getCPAId(),
                      acknowledgment.getMessageHeader().getConversationId(),
                      acknowledgment.getMessageHeader().getMessageData().getMessageId(),
                      acknowledgment.getMessageHeader().getMessageData().getRefToMessageId(),
                      acknowledgment.getMessageHeader().getFrom().getRole(),
                      acknowledgment.getMessageHeader().getTo().getRole(),
                      acknowledgment.getMessageHeader().getService().getType(),
                      acknowledgment.getMessageHeader().getService().getValue(),
                      acknowledgment.getMessageHeader().getAction(),
                      XMLMessageBuilder.getInstance(MessageHeader.class).handle(acknowledgment.getMessageHeader()),
                      XMLMessageBuilder.getInstance(Acknowledgment.class).handle(acknowledgment.getAcknowledgment())
                  ),
                  keyHolder
              );
         
              simpleJdbcTemplate.update
              (
                "insert into ebms_send_event (" +
                  "ebms_message_id," +
                  "time" +
                ") values (?,?)",
                keyHolder.getKey().longValue(),
                //String.format(getDateFormat(),sendTime)
                sendEvent.getTime()
              );
            }
            catch (Exception e)
View Full Code Here

          public void doInTransactionWithoutResult(TransactionStatus transactionStatus)
          {
            try
            {
              Date timestamp = new Date();
              KeyHolder keyHolder = new GeneratedKeyHolder();
              jdbcTemplate.update(
                  getEbMSMessagePreparedStatement(
                      timestamp,
                      messageError.getMessageHeader().getCPAId(),
                      messageError.getMessageHeader().getConversationId(),
View Full Code Here

          public void doInTransactionWithoutResult(TransactionStatus transactionStatus)
          {
            try
            {
              Date timestamp = new Date();
              KeyHolder keyHolder = new GeneratedKeyHolder();
              jdbcTemplate.update(
                  getEbMSMessagePreparedStatement(
                      timestamp,
                      acknowledgment.getMessageHeader().getCPAId(),
                      acknowledgment.getMessageHeader().getConversationId(),
View Full Code Here

   *
   * @param sql
   * @param args
   */
  protected long insertWithIdReturn(final String sql, final Object... args) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
        PreparedStatement ps = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        for (int i = 1; i <= args.length; i++) {
          ps.setObject(i, args[i - 1]);
        }
        return ps;
      }

    }, keyHolder);
    return keyHolder.getKey().longValue();
  }
View Full Code Here

   * @param argsList
   */
  @SuppressWarnings("unchecked")
  protected <T extends Number> List<T> batchInsertWithIdReturn(final String sql, final List<Object[]> argsList) {
    Assert.notEmpty(argsList, "args can not be empty while batch insert");
    final KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.execute(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
        PreparedStatement ps = con.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        return ps;
      }
    }, new PreparedStatementCallback<int[]>() {
      private void setValues(PreparedStatement ps, int i) throws SQLException {
        Object[] args = argsList.get(i);
        int length = args.length;
        for (int j = 1; j <= length; j++) {
          ps.setObject(j, args[j - 1]);
        }
      }

      private int[] processResult(PreparedStatement ps, int[] rows) throws SQLException {
        List<Map<String, Object>> generatedKeys = keyHolder.getKeyList();
        generatedKeys.clear();
        ResultSet keys = ps.getGeneratedKeys();
        if (keys != null) {
          try {
            RowMapperResultSetExtractor<Map<String, Object>> rse = new RowMapperResultSetExtractor<Map<String, Object>>(
                new ColumnMapRowMapper(), rows.length);
            generatedKeys.addAll(rse.extractData(keys));
          } finally {
            JdbcUtils.closeResultSet(keys);
          }
        }
        return rows;
      }

      @Override
      public int[] doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
        int batchSize = argsList.size();
        if (JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
          for (int i = 0; i < batchSize; i++) {
            setValues(ps, i);
            ps.addBatch();
          }
          int[] rows = ps.executeBatch();
          return processResult(ps, rows);
        } else {
          List<Integer> rowsAffected = new ArrayList<Integer>();
          for (int i = 0; i < batchSize; i++) {
            setValues(ps, i);
            rowsAffected.add(ps.executeUpdate());
          }
          int[] rowsAffectedArray = new int[rowsAffected.size()];
          for (int i = 0; i < rowsAffectedArray.length; i++) {
            rowsAffectedArray[i] = rowsAffected.get(i);
          }
          return processResult(ps, rowsAffectedArray);
        }
      }
    });

    List<T> keys = new ArrayList<T>(argsList.size());
    List<Map<String, Object>> generatedKeys = keyHolder.getKeyList();
    int length = generatedKeys.size();
    for (int i = 0; i < length; i++) {
      Iterator<Object> keyIter = generatedKeys.get(i).values().iterator();
      if (keyIter.hasNext()) {
        Object key = keyIter.next();
View Full Code Here

 
 
  @Transactional
  @Override
  public void create(final InformationForm infoForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("information")+ "(sort_order, bottom, status) VALUES(?,?,?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, infoForm.getSortOrder());
        ps.setInt(2, infoForm.getBottom());
        ps.setShort(3, infoForm.getStatus());
        return ps;
      }
    }, keyHolder);
    Integer infoId = keyHolder.getKey().intValue();
    infoForm.setId(infoId);
    setAdditionalFormValues(infoForm);
  }
View Full Code Here

 
 
  @Transactional
  @Override
  public void create(final AttributeGroupForm attrGrpForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("attribute_group")+ "(sort_order) VALUES(?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, attrGrpForm.getSortOrder());
        return ps;
      }
    }, keyHolder);
    Integer attrGrpId = keyHolder.getKey().intValue();
    attrGrpForm.setId(attrGrpId);
    setAdditionalFormValues(attrGrpForm);
  }
View Full Code Here

 
 
  @Transactional
  @Override
  public void create(final AttributeForm attrForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("attribute")+ "(attribute_group_id, sort_order) VALUES(?, ?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, attrForm.getAttributeGroupId());
        ps.setInt(2, attrForm.getSortOrder());
        return ps;
      }
    }, keyHolder);
    Integer attrId = keyHolder.getKey().intValue();
    attrForm.setId(attrId);
    setAdditionalFormValues(attrForm);
  }
View Full Code Here

   
    final String origName = dlForm.getFileUpload().getOriginalFilename();
    final String ext = FilenameUtils.getExtension(origName);
    final String randomName = downloadFileService.generateRandomName()+"."+ext;
   
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
       
        String sql = "INSERT INTO " +quoteTable("download")+ "(filename, mask, remaining, date_added) VALUES(?,?,?,?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, randomName);
        ps.setString(2, dlForm.getMask());
        ps.setInt(3, dlForm.getRemaining());
        ps.setDate(4, new java.sql.Date(new Date().getTime()));
        return ps;
      }
    }, keyHolder);
    Integer dlId = keyHolder.getKey().intValue();
    dlForm.setId(dlId);
    setAdditionalFormValues(dlForm);
   
    downloadFileService.upload(dlForm.getFileUpload(), randomName);
   
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.support.GeneratedKeyHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.