mgenereu commented on a change in pull request #5767: URL: https://github.com/apache/camel/pull/5767#discussion_r663976434
########## 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: Ideally the number for an idempotent repository is 1 per `processorName`/`messageId` combination. To be honest, I'm not even sure why the count is even involved in the code. I just respected it for either past or future implementations. The documentation for the `camel-sql` component even says: > When working with concurrent consumers it is crucial to create a unique constraint on the columns `processorName` and `messageId`. Because the syntax for this constraint differs from database to database, we do not show it here. This would result in the `COUNT(*)` always being 1. The Long or Integer expectation comes from COUNT(*) and its relationship to the maximum number of rows for the underlying SQL/JDBC implementation. For Derby, it's an Integer and for Snowflake, it's a Long. For this use case of idempotency, there's no reasonable way it could be an actual long. I would keep the existing integer code. I'll look into how to properly cast at the JDBC level and try to keep the SQL code a little more generic. -- 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-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org