|
21 | 21 | import java.sql.Timestamp; |
22 | 22 | import java.util.Arrays; |
23 | 23 | import java.util.Collection; |
24 | | -import java.util.Collections; |
25 | 24 | import java.util.HashMap; |
26 | 25 | import java.util.Iterator; |
27 | 26 | import java.util.List; |
|
38 | 37 | import org.springframework.dao.IncorrectResultSizeDataAccessException; |
39 | 38 | import org.springframework.integration.store.AbstractMessageGroupStore; |
40 | 39 | import org.springframework.integration.store.MessageGroup; |
| 40 | +import org.springframework.integration.store.MessageGroupMetadata; |
41 | 41 | import org.springframework.integration.store.MessageMetadata; |
42 | 42 | import org.springframework.integration.store.MessageStore; |
43 | 43 | import org.springframework.integration.store.SimpleMessageGroup; |
@@ -334,11 +334,13 @@ public <T> Message<T> addMessage(final Message<T> message) { |
334 | 334 | @Override |
335 | 335 | public void addMessagesToGroup(Object groupId, Message<?>... messages) { |
336 | 336 | String groupKey = getKey(groupId); |
337 | | - Map<String, Object> groupInfo = getGroupMetadata(groupKey); |
| 337 | + MessageGroupMetadata groupMetadata = getGroupMetadata(groupKey); |
338 | 338 |
|
339 | | - Timestamp updatedDate = new Timestamp(System.currentTimeMillis()); |
340 | | - boolean groupNotExist = groupInfo.isEmpty(); |
341 | | - Timestamp createdDate = groupNotExist ? updatedDate : (Timestamp) groupInfo.get("CREATED_DATE"); |
| 339 | + boolean groupNotExist = groupMetadata == null; |
| 340 | + Timestamp createdDate = |
| 341 | + groupNotExist |
| 342 | + ? new Timestamp(System.currentTimeMillis()) |
| 343 | + : new Timestamp(groupMetadata.getTimestamp()); |
342 | 344 |
|
343 | 345 | for (Message<?> message : messages) { |
344 | 346 | addMessage(message); |
@@ -397,28 +399,39 @@ public int messageGroupSize(Object groupId) { |
397 | 399 |
|
398 | 400 | @Override |
399 | 401 | public MessageGroup getMessageGroup(Object groupId) { |
400 | | - String key = getKey(groupId); |
401 | | - Map<String, Object> groupInfo = getGroupMetadata(key); |
402 | | - |
403 | | - if (groupInfo.isEmpty()) { |
| 402 | + MessageGroupMetadata groupMetadata = getGroupMetadata(groupId); |
| 403 | + if (groupMetadata != null) { |
| 404 | + MessageGroup messageGroup = |
| 405 | + getMessageGroupFactory() |
| 406 | + .create(this, groupId, groupMetadata.getTimestamp(), groupMetadata.isComplete()); |
| 407 | + messageGroup.setLastModified(groupMetadata.getLastModified()); |
| 408 | + messageGroup.setLastReleasedMessageSequenceNumber(groupMetadata.getLastReleasedMessageSequenceNumber()); |
| 409 | + messageGroup.setCondition(groupMetadata.getCondition()); |
| 410 | + return messageGroup; |
| 411 | + } |
| 412 | + else { |
404 | 413 | return new SimpleMessageGroup(groupId); |
405 | 414 | } |
406 | | - |
407 | | - MessageGroup messageGroup = getMessageGroupFactory() |
408 | | - .create(this, groupId, ((Timestamp) groupInfo.get("CREATED_DATE")).getTime(), |
409 | | - ((Long) groupInfo.get("COMPLETE")) > 0); |
410 | | - messageGroup.setLastModified(((Timestamp) groupInfo.get("UPDATED_DATE")).getTime()); |
411 | | - messageGroup.setLastReleasedMessageSequenceNumber(((Long) groupInfo.get("LAST_RELEASED_SEQUENCE")).intValue()); |
412 | | - messageGroup.setCondition((String) groupInfo.get("CONDITION")); |
413 | | - return messageGroup; |
414 | 415 | } |
415 | 416 |
|
416 | | - private Map<String, Object> getGroupMetadata(String groupKey) { |
| 417 | + @Override |
| 418 | + public MessageGroupMetadata getGroupMetadata(Object groupId) { |
| 419 | + String key = getKey(groupId); |
417 | 420 | try { |
418 | | - return this.jdbcTemplate.queryForMap(getQuery(Query.GET_GROUP_INFO), groupKey, this.region); |
| 421 | + return this.jdbcTemplate.queryForObject(getQuery(Query.GET_GROUP_INFO), (rs, rowNum) -> { |
| 422 | + MessageGroupMetadata groupMetadata = new MessageGroupMetadata(); |
| 423 | + if (rs.getInt("COMPLETE") > 0) { |
| 424 | + groupMetadata.complete(); |
| 425 | + } |
| 426 | + groupMetadata.setTimestamp(rs.getTimestamp("CREATED_DATE").getTime()); |
| 427 | + groupMetadata.setLastModified(rs.getTimestamp("UPDATED_DATE").getTime()); |
| 428 | + groupMetadata.setLastReleasedMessageSequenceNumber(rs.getInt("LAST_RELEASED_SEQUENCE")); |
| 429 | + groupMetadata.setCondition(rs.getString("CONDITION")); |
| 430 | + return groupMetadata; |
| 431 | + }, key, this.region); |
419 | 432 | } |
420 | 433 | catch (IncorrectResultSizeDataAccessException ex) { |
421 | | - return Collections.emptyMap(); |
| 434 | + return null; |
422 | 435 | } |
423 | 436 | } |
424 | 437 |
|
|
0 commit comments