public void removeMessageGroup(Object groupId) {

    final String groupKey = getKey(groupId);

    for (UUID messageIds : this.getMessageIdsForGroup(groupId)) {
      this.removeMessage(messageIds);
    }

    jdbcTemplate.update(
        getQuery(Query.REMOVE_GROUP_TO_MESSAGE_JOIN),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug("Removing relationships for the group with group key=" + groupKey);
            }
            ps.setString(1, groupKey);
            ps.setString(2, region);
          }
        });

    jdbcTemplate.update(
        getQuery(Query.DELETE_MESSAGE_GROUP),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug("Marking messages with group key=" + groupKey);
            }
            ps.setString(1, groupKey);
            ps.setString(2, region);
          }
        });
  }
Esempio n. 2
0
 private void insert(SUser u) {
   jdbcOperations.update(
       INSERT_SUSER,
       u.getId(),
       u.getPassword(),
       u.getFirstName(),
       u.getLastName(),
       u.getEmail(),
       u.getCreateDT());
 }
Esempio n. 3
0
 private void update(SUser u) {
   jdbcOperations.update(
       UPDATE_SUSER,
       u.getPassword(),
       u.getFirstName(),
       u.getLastName(),
       u.getEmail(),
       u.getCreateDT(),
       u.getId());
 }
Esempio n. 4
0
 /**
  * Delete all rows from the specified tables.
  *
  * @param jdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
  * @param tableNames the names of the tables from which to delete
  * @return the total number of rows deleted from all specified tables
  */
 public static int deleteFromTables(JdbcOperations jdbcTemplate, String... tableNames) {
   int totalRowCount = 0;
   for (String tableName : tableNames) {
     int rowCount = jdbcTemplate.update("DELETE FROM " + tableName);
     totalRowCount += rowCount;
     if (LOG.isInfoEnabled()) {
       LOG.info("Deleted " + rowCount + " rows from table " + tableName);
     }
   }
   return totalRowCount;
 }
  @Test
  public void testJobLaunch() throws Exception {
    jdbcTemplate.update("DELETE from TRADE");
    int before = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);

    jobLauncherTestUtils.launchJob();

    checkOutputFile("target/test-outputs/CustomerReport1.txt");
    checkOutputFile("target/test-outputs/CustomerReport2.txt");
    checkOutputTable(before);
  }
 private void updateMessageGroup(final String groupId) {
   jdbcTemplate.update(
       getQuery(Query.UPDATE_GROUP),
       new PreparedStatementSetter() {
         public void setValues(PreparedStatement ps) throws SQLException {
           if (logger.isDebugEnabled()) {
             logger.debug("Updating MessageGroup: " + groupId);
           }
           ps.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
           ps.setString(2, groupId);
           ps.setString(3, region);
         }
       });
 }
 public Message<?> removeMessage(UUID id) {
   Message<?> message = getMessage(id);
   if (message == null) {
     return null;
   }
   int updated =
       jdbcTemplate.update(
           getQuery(Query.DELETE_MESSAGE),
           new Object[] {getKey(id), region},
           new int[] {Types.VARCHAR, Types.VARCHAR});
   if (updated != 0) {
     return message;
   }
   return null;
 }
  public MessageGroup addMessageToGroup(Object groupId, Message<?> message) {
    final String groupKey = getKey(groupId);
    final String messageId = getKey(message.getHeaders().getId());
    boolean groupNotExist =
        jdbcTemplate.queryForInt(this.getQuery(Query.GROUP_EXISTS), groupKey, region) < 1;

    final Timestamp updatedDate = new Timestamp(System.currentTimeMillis());

    final Timestamp createdDate =
        groupNotExist
            ? updatedDate
            : jdbcTemplate.queryForObject(
                getQuery(Query.GET_GROUP_CREATED_DATE),
                new Object[] {groupKey, region},
                Timestamp.class);

    if (groupNotExist) {
      try {
        this.doCreateMessageGroup(groupKey, createdDate);
      } catch (DuplicateKeyException e) {
        logger.warn("Lost race to create group; attempting update instead", e);
        this.doUpdateMessageGroup(groupKey, updatedDate);
      }
    } else {
      this.doUpdateMessageGroup(groupKey, updatedDate);
    }

    this.addMessage(message);

    jdbcTemplate.update(
        getQuery(Query.CREATE_GROUP_TO_MESSAGE),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug(
                  "Inserting message with id key="
                      + messageId
                      + " and created date="
                      + createdDate);
            }
            ps.setString(1, groupKey);
            ps.setString(2, messageId);
            ps.setString(3, region);
          }
        });
    return getMessageGroup(groupId);
  }
  public void completeGroup(Object groupId) {
    final long updatedDate = System.currentTimeMillis();
    final String groupKey = getKey(groupId);

    jdbcTemplate.update(
        getQuery(Query.COMPLETE_GROUP),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug("Completing MessageGroup: " + groupKey);
            }
            ps.setTimestamp(1, new Timestamp(updatedDate));
            ps.setString(2, groupKey);
            ps.setString(3, region);
          }
        });
  }
 private void doUpdateMessageGroup(final String groupKey, final Timestamp updatedDate) {
   jdbcTemplate.update(
       getQuery(Query.UPDATE_MESSAGE_GROUP),
       new PreparedStatementSetter() {
         public void setValues(PreparedStatement ps) throws SQLException {
           if (logger.isDebugEnabled()) {
             logger.debug(
                 "Updating message group with id key="
                     + groupKey
                     + " and updated date="
                     + updatedDate);
           }
           ps.setTimestamp(1, updatedDate);
           ps.setString(2, groupKey);
           ps.setString(3, region);
         }
       });
 }
  public MessageGroup removeMessageFromGroup(Object groupId, Message<?> messageToRemove) {
    final String groupKey = getKey(groupId);
    final String messageId = getKey(messageToRemove.getHeaders().getId());

    jdbcTemplate.update(
        getQuery(Query.REMOVE_MESSAGE_FROM_GROUP),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug("Removing message from group with group key=" + groupKey);
            }
            ps.setString(1, groupKey);
            ps.setString(2, messageId);
            ps.setString(3, region);
          }
        });
    this.removeMessage(messageToRemove.getHeaders().getId());
    this.updateMessageGroup(groupKey);
    return getMessageGroup(groupId);
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  public <T> Message<T> addMessage(final Message<T> message) {
    if (message.getHeaders().containsKey(SAVED_KEY)) {
      Message<T> saved = (Message<T>) getMessage(message.getHeaders().getId());
      if (saved != null) {
        if (saved.equals(message)) {
          return message;
        } // We need to save it under its own id
      }
    }

    final long createdDate = System.currentTimeMillis();
    Message<T> result =
        MessageBuilder.fromMessage(message)
            .setHeader(SAVED_KEY, Boolean.TRUE)
            .setHeader(CREATED_DATE_KEY, new Long(createdDate))
            .build();

    Map innerMap = (Map) new DirectFieldAccessor(result.getHeaders()).getPropertyValue("headers");
    // using reflection to set ID since it is immutable through MessageHeaders
    innerMap.put(MessageHeaders.ID, message.getHeaders().get(MessageHeaders.ID));

    final String messageId = getKey(result.getHeaders().getId());
    final byte[] messageBytes = serializer.convert(result);

    jdbcTemplate.update(
        getQuery(Query.CREATE_MESSAGE),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug("Inserting message with id key=" + messageId);
            }
            ps.setString(1, messageId);
            ps.setString(2, region);
            ps.setTimestamp(3, new Timestamp(createdDate));
            lobHandler.getLobCreator().setBlobAsBytes(ps, 4, messageBytes);
          }
        });
    return result;
  }
  public void setLastReleasedSequenceNumberForGroup(Object groupId, final int sequenceNumber) {
    Assert.notNull(groupId, "'groupId' must not be null");
    final long updatedDate = System.currentTimeMillis();
    final String groupKey = getKey(groupId);

    jdbcTemplate.update(
        getQuery(Query.UPDATE_LAST_RELEASED_SEQUENCE),
        new PreparedStatementSetter() {
          public void setValues(PreparedStatement ps) throws SQLException {
            if (logger.isDebugEnabled()) {
              logger.debug(
                  "Updating  the sequence number of the last released Message in the MessageGroup: "
                      + groupKey);
            }
            ps.setTimestamp(1, new Timestamp(updatedDate));
            ps.setInt(2, sequenceNumber);
            ps.setString(3, groupKey);
            ps.setString(4, region);
          }
        });
    this.updateMessageGroup(groupKey);
  }