From 193d9b6002d14e5d00ed9584ae0fcc014962aba9 Mon Sep 17 00:00:00 2001 From: David Syer Date: Mon, 26 Apr 2010 16:30:22 +0000 Subject: [PATCH] RESOLVED - issue INT-1010, INT-1050, INT-1100 --- .../integration/jdbc/JdbcMessageStore.java | 6 -- .../jdbc/JdbcMessageStoreTests.java | 14 ---- .../integration/store/MessageStore.java | 5 -- .../integration/store/SimpleMessageStore.java | 79 +++++++++---------- 4 files changed, 38 insertions(+), 66 deletions(-) diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java index 1a1dedad89..9b879e4c0f 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java @@ -49,8 +49,6 @@ public class JdbcMessageStore implements MessageStore { private static final String LIST_MESSAGES_BY_CORRELATION_KEY = "SELECT STORE_ID, MESSAGE_ID, CORRELATION_KEY, MESSAGE_BYTES, VERSION from %PREFIX%MESSAGE where CORRELATION_KEY=?"; - private static final String LIST_ALL_MESSAGES = "SELECT STORE_ID, MESSAGE_ID, CORRELATION_KEY, MESSAGE_BYTES, VERSION from %PREFIX%MESSAGE"; - private static final String GET_MESSAGE = "SELECT STORE_ID, MESSAGE_ID, CORRELATION_KEY, MESSAGE_BYTES, VERSION from %PREFIX%MESSAGE where MESSAGE_ID=?"; private static final String DELETE_MESSAGE = "DELETE from %PREFIX%MESSAGE where MESSAGE_ID=?"; @@ -205,10 +203,6 @@ public class JdbcMessageStore implements MessageStore { return list.get(0); } - public List> list() { - return jdbcTemplate.query(getQuery(LIST_ALL_MESSAGES), new MessageMapper()); - } - public List> list(Object correlationId) { return jdbcTemplate.query(getQuery(LIST_MESSAGES_BY_CORRELATION_KEY), new Object[] { getKey(correlationId) }, new MessageMapper()); diff --git a/org.springframework.integration.jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java b/org.springframework.integration.jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java index 8dfc616c91..78a7a7ffbe 100644 --- a/org.springframework.integration.jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java +++ b/org.springframework.integration.jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java @@ -15,11 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.core.Message; import org.springframework.integration.message.MessageBuilder; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.jdbc.SimpleJdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @@ -36,12 +34,9 @@ public class JdbcMessageStoreTests { private JdbcMessageStore messageStore; - private SimpleJdbcTemplate jdbcTemplate; - @Before public void init() { messageStore = new JdbcMessageStore(dataSource, messageIncrementer); - jdbcTemplate = new SimpleJdbcTemplate(dataSource); } @Test @@ -71,15 +66,6 @@ public class JdbcMessageStoreTests { assertEquals("Y", messageStore.get(message.getHeaders().getId()).getHeaders().getCorrelationId()); } - @Test - @Transactional - public void testAddAndList() throws Exception { - Message message = MessageBuilder.withPayload("foo").build(); - messageStore.put(message); - assertEquals(1, SimpleJdbcTestUtils.countRowsInTable(jdbcTemplate, "INT_MESSAGE")); - assertEquals(1, messageStore.list().size()); - } - @Test @Transactional public void testAddAndListByCorrelationId() throws Exception { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/store/MessageStore.java b/org.springframework.integration/src/main/java/org/springframework/integration/store/MessageStore.java index a9229eec2f..94993307eb 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/store/MessageStore.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/store/MessageStore.java @@ -55,11 +55,6 @@ public interface MessageStore { */ Message delete(UUID id); - /** - * Return all Messages currently in the MessageStore. - */ - List> list(); - /** * Return all Messages currently in the MessageStore that * contain the provided correlationId header value. diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java b/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java index be4e74c614..a5a1155bd5 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java @@ -29,25 +29,27 @@ import org.springframework.integration.util.UpperBound; import org.springframework.util.Assert; /** - * Map-based implementation of {@link MessageStore} that enforces a maximum capacity. - * + * Map-based implementation of {@link MessageStore} that enforces a maximum + * capacity. + * * @author Iwein Fuld * @author Mark Fisher * @since 2.0 */ public class SimpleMessageStore implements MessageStore { - private final Map> map; + private final Map> map; + private final UpperBound upperBound; /** - * Creates a SimpleMessageStore with a maximum size limited by the given capacity, or unlimited - * size if the given capacity is less than 1. + * Creates a SimpleMessageStore with a maximum size limited by the given + * capacity, or unlimited size if the given capacity is less than 1. */ public SimpleMessageStore(int capacity) { - this.map = new ConcurrentHashMap>(); - this.upperBound = new UpperBound(capacity); - } + this.map = new ConcurrentHashMap>(); + this.upperBound = new UpperBound(capacity); + } /** * Creates a SimpleMessageStore with unlimited capacity @@ -56,48 +58,43 @@ public class SimpleMessageStore implements MessageStore { this(0); } - @SuppressWarnings("unchecked") - public Message put(Message message) { - if (!upperBound.tryAcquire(0)){ - throw new MessagingException(this.getClass().getSimpleName() + - " was out of capacity at, try constructing it with a larger capacity."); + public Message put(Message message) { + if (!upperBound.tryAcquire(0)) { + throw new MessagingException(this.getClass().getSimpleName() + + " was out of capacity at, try constructing it with a larger capacity."); } - return (Message) this.map.put(message.getHeaders().getId(), message); - } + return (Message) this.map.put(message.getHeaders().getId(), message); + } - public Message get(UUID key) { - return (key != null) ? this.map.get(key) : null; - } + public Message get(UUID key) { + return (key != null) ? this.map.get(key) : null; + } - public List> list() { - return new ArrayList>(this.map.values()); - } - - public Message delete(UUID key) { + public Message delete(UUID key) { if (key != null) { upperBound.release(); return this.map.remove(key); } - else return null; - } + else + return null; + } - public int size() { - return this.map.size(); - } + public int size() { + return this.map.size(); + } - - public List> list(Object correlationKey) { - Assert.notNull(correlationKey, "'correlationKey' must not be null"); - List> matched = new ArrayList>(); - Collection> values = map.values(); - for (Message message : values) { - Object correlationId = message.getHeaders().getCorrelationId(); - if (correlationId != null && correlationId.equals(correlationKey)) { - matched.add(message); - } - } - return matched; - } + public List> list(Object correlationKey) { + Assert.notNull(correlationKey, "'correlationKey' must not be null"); + List> matched = new ArrayList>(); + Collection> values = map.values(); + for (Message message : values) { + Object correlationId = message.getHeaders().getCorrelationId(); + if (correlationId != null && correlationId.equals(correlationKey)) { + matched.add(message); + } + } + return matched; + } }