camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [09/13] camel git commit: CAMEL-8478: IdempotentRepository - Add clear operation, align JdbcMessageIdRepository
Date Fri, 03 Jul 2015 20:23:53 GMT
CAMEL-8478: IdempotentRepository - Add clear operation, align JdbcMessageIdRepository


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/84e1d5da
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/84e1d5da
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/84e1d5da

Branch: refs/heads/master
Commit: 84e1d5dacb8e8f9c64186047a526cdafe99ce869
Parents: 02a6aa2
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri Jul 3 17:08:57 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Jul 3 17:08:57 2015 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java   |  2 +-
 .../jdbc/AbstractJdbcMessageIdRepository.java    | 19 +++++++++++++++++++
 .../idempotent/jdbc/JdbcMessageIdRepository.java |  6 ++++++
 .../jdbc/JdbcMessageIdRepositoryTest.java        |  9 ++++++---
 4 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/84e1d5da/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index 2f39177..b488277 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -202,8 +202,8 @@ public class JpaMessageIdRepository extends ServiceSupport implements
ExchangeId
                     while (it.hasNext()) {
                         Object item = it.next();
                         entityManager.remove(item);
-                        entityManager.flush();
                     }
+                    entityManager.flush();
                 }
                 return Boolean.TRUE;
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/84e1d5da/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/AbstractJdbcMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/AbstractJdbcMessageIdRepository.java
b/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/AbstractJdbcMessageIdRepository.java
index f6e565d..ca1d15b 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/AbstractJdbcMessageIdRepository.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/AbstractJdbcMessageIdRepository.java
@@ -94,6 +94,14 @@ public abstract class AbstractJdbcMessageIdRepository<T> extends
ServiceSupport
      * @return int number of rows deleted
      */
     protected abstract int delete(final T key);
+    
+    /**
+     * Operations that deletes all the rows
+     *
+     * @param key  the key
+     * @return int number of rows deleted
+     */
+    protected abstract int delete();
 
     /**
      * Creates the transaction template
@@ -164,6 +172,17 @@ public abstract class AbstractJdbcMessageIdRepository<T> extends
ServiceSupport
         });
         return rc.booleanValue();
     }
+    
+    @ManagedOperation(description = "Clear the store")
+    @Override
+    public void clear() {
+        transactionTemplate.execute(new TransactionCallback<Boolean>() {
+            public Boolean doInTransaction(TransactionStatus status) {
+                delete();
+                return Boolean.TRUE;
+            }
+        });
+    }
 
     @Override
     public boolean confirm(final T key) {

http://git-wip-us.apache.org/repos/asf/camel/blob/84e1d5da/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepository.java
b/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepository.java
index 3aec5e8..b7bf688 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepository.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepository.java
@@ -36,6 +36,7 @@ public class JdbcMessageIdRepository extends AbstractJdbcMessageIdRepository<Str
     private String queryString = "SELECT COUNT(*) FROM CAMEL_MESSAGEPROCESSED WHERE processorName
= ? AND messageId = ?";
     private String insertString = "INSERT INTO CAMEL_MESSAGEPROCESSED (processorName, messageId,
createdAt) VALUES (?, ?, ?)";
     private String deleteString = "DELETE FROM CAMEL_MESSAGEPROCESSED WHERE processorName
= ? AND messageId = ?";
+    private String clearString = "DELETE FROM CAMEL_MESSAGEPROCESSED WHERE processorName
= ?";
 
     public JdbcMessageIdRepository() {
     }
@@ -98,6 +99,11 @@ public class JdbcMessageIdRepository extends AbstractJdbcMessageIdRepository<Str
     protected int delete(String key) {
         return jdbcTemplate.update(deleteString, processorName, key);
     }
+    
+    @Override
+    protected int delete() {
+        return jdbcTemplate.update(clearString, processorName);
+    }
 
     public boolean isCreateTableIfNotExists() {
         return createTableIfNotExists;

http://git-wip-us.apache.org/repos/asf/camel/blob/84e1d5da/components/camel-sql/src/test/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepositoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/test/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepositoryTest.java
b/components/camel-sql/src/test/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepositoryTest.java
index 1a1f0aa..9a4b9b8 100644
--- a/components/camel-sql/src/test/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepositoryTest.java
+++ b/components/camel-sql/src/test/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepositoryTest.java
@@ -36,6 +36,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 public class JdbcMessageIdRepositoryTest extends CamelSpringTestSupport {
 
     protected static final String SELECT_ALL_STRING = "SELECT messageId FROM CAMEL_MESSAGEPROCESSED
WHERE processorName = ?";
+    protected static final String CLEAR_STRING = "DELETE FROM CAMEL_MESSAGEPROCESSED WHERE
processorName = ?";
     protected static final String PROCESSOR_NAME = "myProcessorName";
 
     protected JdbcTemplate jdbcTemplate;
@@ -111,13 +112,15 @@ public class JdbcMessageIdRepositoryTest extends CamelSpringTestSupport
{
         template.sendBodyAndHeader("direct:start", "three", "messageId", "3");
 
         assertMockEndpointsSatisfied();
+        
+        jdbcTemplate.update(CLEAR_STRING, PROCESSOR_NAME);
 
         // only message 1 and 3 should be in jdbc repo
         List<String> receivedMessageIds = jdbcTemplate.queryForList(SELECT_ALL_STRING,
String.class, PROCESSOR_NAME);
 
-        assertEquals(2, receivedMessageIds.size());
-        assertTrue("Should contain message 1", receivedMessageIds.contains("1"));
-        assertTrue("Should contain message 3", receivedMessageIds.contains("3"));
+        assertEquals(0, receivedMessageIds.size());
+        assertFalse("Should not contain message 1", receivedMessageIds.contains("1"));
+        assertFalse("Should not contain message 3", receivedMessageIds.contains("3"));
     }
     
     @Override


Mime
View raw message