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

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


The following commit(s) were added to refs/heads/main by this push:
     new baed04f25afe [CAMEL-23481] replace retired Apache Derby with H2 in 
camel-jdbc tests (#23672)
baed04f25afe is described below

commit baed04f25afe02d3eeb31c4f47b439cf54482fe8
Author: Torsten Mielke <[email protected]>
AuthorDate: Mon Jun 1 12:26:15 2026 +0200

    [CAMEL-23481] replace retired Apache Derby with H2 in camel-jdbc tests 
(#23672)
    
    * [CAMEL-23481] first preparation to replace Derby with HSQL
    
    * [CAMEL-23481] replacing retired Apache Derby with HSQL and MariaDB for
    stored procedures and stored function tests in sql-stored: component.
    While HSQL has support for stored procedures, it does not support
    SQL stored functions, neither does H2 support them.
    So using an embedded MariaDB4j instance to test SQL stored functions
    in class SqlFunctionDataSourceTest.
    Running an embedded MariaDB4j instance is slower to initialize,
    so using it only for the single test class SqlFunctionDataSourceTest.
    
    Made with help from AI tools.
    
    * [CAMEL-23481] need to reintroduce <derby-version> in parent/pom.xml until 
no component uses Derby.
    
    * [CAMEL-23481] - adding a few improvements for camel-sql
    - replace any tab characters with white spaces
    - upgrade MariaDB client to latest 3.5.8 release
    - restrict SqlFunctionDataSourceTest to be only run on Linux, MacOS and
      Windows
    
    Made with help from AI tools.
    
    * [CAMEL-23481] replace retired Apache Derby with H2 in camel-jdbc tests
    
    Apache Derby is a retired Apache project. Replaced with H2 database
    for all camel-jdbc tests.
    
    - Replaced Derby test dependencies with H2 in pom.xml
    - Updated SQL schema (init.sql) to use H2-compatible syntax:
      * Auto-increment: GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
      * CLOB definition simplified (removed size specification)
    - Changed embedded database type from DERBY to H2 in:
      * AbstractJdbcTestSupport.java
      * camelContext.xml (Spring XML example)
      * jdbc-component.adoc (documentation)
    - Made generated keys tests database-agnostic to handle differences:
      * H2 returns column name "ID" vs Derby's column index "1"
      * H2 returns Integer vs Derby's BigDecimal for auto-increment values
    
    All 42 tests pass successfully. No production code affected - Derby was
    only used in test scope.
    
    Made with help from AI tools.
    
    ---------
    
    Co-authored-by: Torsten Mielke <[email protected]>
---
 components/camel-jdbc/pom.xml                      | 13 +++-----
 .../camel-jdbc/src/main/docs/jdbc-component.adoc   |  2 +-
 .../jdbc/AbstractJdbcGeneratedKeysTest.java        | 16 ++++++---
 .../component/jdbc/AbstractJdbcTestSupport.java    |  2 +-
 .../apache/camel/component/jdbc/camelContext.xml   | 38 +++++++++++-----------
 .../camel-jdbc/src/test/resources/sql/init.sql     |  6 ++--
 6 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/components/camel-jdbc/pom.xml b/components/camel-jdbc/pom.xml
index 42987566c0f1..861bad9ea973 100644
--- a/components/camel-jdbc/pom.xml
+++ b/components/camel-jdbc/pom.xml
@@ -63,16 +63,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.derby</groupId>
-            <artifactId>derby</artifactId>
-            <version>${derby-version}</version>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>${h2-version}</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.derby</groupId>
-            <artifactId>derbytools</artifactId>
-            <version>${derby-version}</version>
-            <scope>test</scope>
-        </dependency>        
+
     </dependencies>
 </project>
diff --git a/components/camel-jdbc/src/main/docs/jdbc-component.adoc 
b/components/camel-jdbc/src/main/docs/jdbc-component.adoc
index 79fca7371d21..1228ae85b4ed 100644
--- a/components/camel-jdbc/src/main/docs/jdbc-component.adoc
+++ b/components/camel-jdbc/src/main/docs/jdbc-component.adoc
@@ -106,7 +106,7 @@ First we register our datasource in the Camel registry as 
`testdb`:
 [source,java]
 ----
 EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
-      .setType(EmbeddedDatabaseType.DERBY).addScript("sql/init.sql").build();
+      .setType(EmbeddedDatabaseType.H2).addScript("sql/init.sql").build();
 
 CamelContext context = ...
 context.getRegistry().bind("testdb", db);
diff --git 
a/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcGeneratedKeysTest.java
 
b/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcGeneratedKeysTest.java
index 0f9ed305ae0b..3d66b33cfa1e 100644
--- 
a/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcGeneratedKeysTest.java
+++ 
b/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcGeneratedKeysTest.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.jdbc;
 
-import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -55,7 +54,10 @@ public abstract class AbstractJdbcGeneratedKeysTest extends 
AbstractJdbcTestSupp
         assertEquals(1, generatedKeys.size());
 
         Map<String, Object> row = generatedKeys.get(0);
-        assertEquals(BigDecimal.valueOf(2), row.get("1"), "auto increment 
value should be 2");
+        // H2 returns column name "ID", Derby returns column index "1"
+        Object generatedKey = row.get("ID") != null ? row.get("ID") : 
row.get("1");
+        // H2 returns Integer, Derby returns BigDecimal - compare numeric 
values
+        assertEquals(2, ((Number) generatedKey).intValue(), "auto increment 
value should be 2");
 
         assertEquals(1, 
out.getMessage().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT),
                 "generated keys row count should be one");
@@ -93,7 +95,10 @@ public abstract class AbstractJdbcGeneratedKeysTest extends 
AbstractJdbcTestSupp
         assertEquals(1, generatedKeys.size());
 
         Map<String, Object> row = generatedKeys.get(0);
-        assertEquals(BigDecimal.valueOf(2), row.get("1"), "auto increment 
value should be 2");
+        // H2 returns column name "ID", Derby returns column index "1"
+        Object generatedKey = row.get("ID") != null ? row.get("ID") : 
row.get("1");
+        // H2 returns Integer, Derby returns BigDecimal - compare numeric 
values
+        assertEquals(2, ((Number) generatedKey).intValue(), "auto increment 
value should be 2");
 
         assertEquals(1, 
out.getMessage().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT),
                 "generated keys row count should be one");
@@ -131,7 +136,10 @@ public abstract class AbstractJdbcGeneratedKeysTest 
extends AbstractJdbcTestSupp
         assertEquals(1, generatedKeys.size());
 
         Map<String, Object> row = generatedKeys.get(0);
-        assertEquals(BigDecimal.valueOf(2), row.get("1"), "auto increment 
value should be 2");
+        // H2 returns column name "ID", Derby returns column index "1"
+        Object generatedKey = row.get("ID") != null ? row.get("ID") : 
row.get("1");
+        // H2 returns Integer, Derby returns BigDecimal - compare numeric 
values
+        assertEquals(2, ((Number) generatedKey).intValue(), "auto increment 
value should be 2");
 
         assertEquals(1, 
out.getMessage().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT),
                 "generated keys row count should be one");
diff --git 
a/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java
 
b/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java
index dd8ad687f086..81515f1281e2 100644
--- 
a/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java
+++ 
b/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/AbstractJdbcTestSupport.java
@@ -34,7 +34,7 @@ public abstract class AbstractJdbcTestSupport extends 
CamelTestSupport {
     public void setupResources() {
         db = new EmbeddedDatabaseBuilder()
                 .setName(getClass().getSimpleName())
-                .setType(EmbeddedDatabaseType.DERBY)
+                .setType(EmbeddedDatabaseType.H2)
                 .addScript("sql/init.sql").build();
     }
 
diff --git 
a/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml
 
b/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml
index 2e33116901eb..4f60df7d375a 100644
--- 
a/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml
+++ 
b/components/camel-jdbc/src/test/resources/org/apache/camel/component/jdbc/camelContext.xml
@@ -25,23 +25,23 @@
        http://www.springframework.org/schema/jdbc 
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
-  
-  <!-- START SNIPPET: example -->  
-  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
-    <route>
-                        <!-- trigger every second -->
-       <from uri="timer://kickoff?period=1000"/>
-       <setBody>
-         <constant>select * from customer</constant>
-       </setBody>
-       <to uri="jdbc:testdb"/>
-       <to uri="mock:result"/>
-    </route>
-  </camelContext>
-  
-  <!-- Just add a demo to show how to bind a data source for camel in Spring-->
-  <jdbc:embedded-database id="testdb" type="DERBY">
-       <jdbc:script location="classpath:sql/init.sql"/>
-  </jdbc:embedded-database>
-  <!-- END SNIPPET: example -->
+
+    <!-- START SNIPPET: example -->  
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
+        <route>
+            <!-- Trigger every second. -->
+            <from uri="timer://kickoff?period=1000"/>
+            <setBody>
+                <constant>SELECT * FROM customer</constant>
+            </setBody>
+            <to uri="jdbc:testdb"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
+
+    <!-- Just add a demo to show how to bind a data source for camel in 
Spring-->
+    <jdbc:embedded-database id="testdb" type="H2">
+        <jdbc:script location="classpath:sql/init.sql"/>
+    </jdbc:embedded-database>
+    <!-- END SNIPPET: example -->
 </beans>
diff --git a/components/camel-jdbc/src/test/resources/sql/init.sql 
b/components/camel-jdbc/src/test/resources/sql/init.sql
index 7ccf135f541c..ed90b7e446d3 100644
--- a/components/camel-jdbc/src/test/resources/sql/init.sql
+++ b/components/camel-jdbc/src/test/resources/sql/init.sql
@@ -20,8 +20,8 @@ insert into customer values('cust1','jstrachan');
 insert into customer values('cust2','nsandhu');
 insert into customer values('cust3','willem');
 
-create table tableWithAutoIncr (id int not null GENERATED ALWAYS AS IDENTITY, 
content varchar(10));
+create table tableWithAutoIncr (id integer GENERATED BY DEFAULT AS IDENTITY 
PRIMARY KEY, content varchar(10));
 insert into tableWithAutoIncr (content) values ('value1');
 
-create table tableWithClob (id varchar(15), picture clob(10M));
-insert into tableWithClob values ('id1', cast('\x0123456789ABCDEF' as clob));
\ No newline at end of file
+create table tableWithClob (id varchar(15), picture clob);
+insert into tableWithClob values ('id1', cast('\x0123456789ABCDEF' as clob));

Reply via email to