You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/10/18 15:49:36 UTC

[camel] branch camel-3.21.x updated: CAMEL-20010 (#11759)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.21.x by this push:
     new c34b5668d4b CAMEL-20010 (#11759)
c34b5668d4b is described below

commit c34b5668d4b5150b51936a280267731316944ef2
Author: Bruno Mendola <18...@users.noreply.github.com>
AuthorDate: Wed Oct 18 17:48:45 2023 +0200

    CAMEL-20010 (#11759)
    
    * CAMEL-20010 Preserve default queries in JdbcMessageIdRepository to avoid replacing the table name more than once
    
    * CAMEL-20010 Use String#replace instead of replaceFirst to avoid unnecessary usage of regular expressions
    
    ---------
    
    Co-authored-by: Bruno Mendola <br...@dedagroup.it>
---
 .../idempotent/jdbc/JdbcMessageIdRepository.java   | 36 ++++++++++++++--------
 1 file changed, 23 insertions(+), 13 deletions(-)

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 37b62f97ae7..af70a6c5a1e 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
@@ -32,17 +32,27 @@ import org.springframework.transaction.support.TransactionTemplate;
 public class JdbcMessageIdRepository extends AbstractJdbcMessageIdRepository {
 
     protected static final String DEFAULT_TABLENAME = "CAMEL_MESSAGEPROCESSED";
+    protected static final String DEFAULT_TABLE_EXISTS_STRING = "SELECT 1 FROM CAMEL_MESSAGEPROCESSED WHERE 1 = 0";
+    protected static final String DEFAULT_CREATE_STRING
+            = "CREATE TABLE CAMEL_MESSAGEPROCESSED (processorName VARCHAR(255), messageId VARCHAR(100), "
+              + "createdAt TIMESTAMP, PRIMARY KEY (processorName, messageId))";
+    protected static final String DEFAULT_QUERY_STRING
+            = "SELECT COUNT(*) FROM CAMEL_MESSAGEPROCESSED WHERE processorName = ? AND messageId = ?";
+    protected static final String DEFAULT_INSERT_STRING
+            = "INSERT INTO CAMEL_MESSAGEPROCESSED (processorName, messageId, createdAt) VALUES (?, ?, ?)";
+    protected static final String DEFAULT_DELETE_STRING
+            = "DELETE FROM CAMEL_MESSAGEPROCESSED WHERE processorName = ? AND messageId = ?";
+    protected static final String DEFAULT_CLEAR_STRING = "DELETE FROM CAMEL_MESSAGEPROCESSED WHERE processorName = ?";
 
     private boolean createTableIfNotExists = true;
     private String tableName;
 
-    private String tableExistsString = "SELECT 1 FROM CAMEL_MESSAGEPROCESSED WHERE 1 = 0";
-    private String createString = "CREATE TABLE CAMEL_MESSAGEPROCESSED (processorName VARCHAR(255), messageId VARCHAR(100), "
-                                  + "createdAt TIMESTAMP, PRIMARY KEY (processorName, messageId))";
-    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 = ?";
+    private String tableExistsString = DEFAULT_TABLE_EXISTS_STRING;
+    private String createString = DEFAULT_CREATE_STRING;
+    private String queryString = DEFAULT_QUERY_STRING;
+    private String insertString = DEFAULT_INSERT_STRING;
+    private String deleteString = DEFAULT_DELETE_STRING;
+    private String clearString = DEFAULT_CLEAR_STRING;
 
     public JdbcMessageIdRepository() {
     }
@@ -65,12 +75,12 @@ public class JdbcMessageIdRepository extends AbstractJdbcMessageIdRepository {
 
         if (tableName != null) {
             // update query strings from default table name to the new table name
-            tableExistsString = tableExistsString.replaceFirst(DEFAULT_TABLENAME, tableName);
-            createString = createString.replaceFirst(DEFAULT_TABLENAME, tableName);
-            queryString = queryString.replaceFirst(DEFAULT_TABLENAME, tableName);
-            insertString = insertString.replaceFirst(DEFAULT_TABLENAME, tableName);
-            deleteString = deleteString.replaceFirst(DEFAULT_TABLENAME, tableName);
-            clearString = clearString.replaceFirst(DEFAULT_TABLENAME, tableName);
+            tableExistsString = DEFAULT_TABLE_EXISTS_STRING.replace(DEFAULT_TABLENAME, tableName);
+            createString = DEFAULT_CREATE_STRING.replace(DEFAULT_TABLENAME, tableName);
+            queryString = DEFAULT_QUERY_STRING.replace(DEFAULT_TABLENAME, tableName);
+            insertString = DEFAULT_INSERT_STRING.replace(DEFAULT_TABLENAME, tableName);
+            deleteString = DEFAULT_DELETE_STRING.replace(DEFAULT_TABLENAME, tableName);
+            clearString = DEFAULT_CLEAR_STRING.replace(DEFAULT_TABLENAME, tableName);
         }
     }