You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/07/04 20:16:05 UTC

[GitHub] [camel] mgenereu commented on a change in pull request #5767: [CAMEL-16770] Added JDBC Idempotent Repository caching

mgenereu commented on a change in pull request #5767:
URL: https://github.com/apache/camel/pull/5767#discussion_r663551449



##########
File path: components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcCachedMessageIdRepository.java
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.idempotent.jdbc;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+/**
+ * Caching version of {@link JdbcMessageIdRepository}
+ */
+public class JdbcCachedMessageIdRepository extends JdbcMessageIdRepository {
+    private final Map<String, Integer> cache = new HashMap<>();
+    private int hitCount;
+    private int missCount;
+    private String queryAllString
+            = "SELECT messageId, CAST(COUNT(*) AS INTEGER) AS messageCount FROM CAMEL_MESSAGEPROCESSED WHERE processorName = ? GROUP BY messageId";

Review comment:
       Actually, you brought up a good question for me around `jdbcTemplate`.  The SQL statement clause for COUNT(*) returns a long on some SQL servers and an integer on others.  While I was able to solve the problem on the SQL side for this low counts by casting (ANSI SQL-92 feature) to an integer, I feel like this should be done like the existing code in [JdbcMessageIdRepository.java](https://github.com/apache/camel/blob/5a5cd6ba81b45c08f872b8a5f84a15cae5f40ea5/components/camel-sql/src/main/java/org/apache/camel/processor/idempotent/jdbc/JdbcMessageIdRepository.java#L113) but I don't know how to cast two columns using `jdbcTemplate`. Are you or another Camel developer familiar with this so I can make this match the existing code style?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org