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

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


The following commit(s) were added to refs/heads/main by this push:
     new e98f9f2c79 [AMQ-9806] Add H2 database support (#1535)
e98f9f2c79 is described below

commit e98f9f2c79b3aa3be2a94383487d177d6a7476a9
Author: Matt Pavlovich <[email protected]>
AuthorDate: Wed Feb 11 07:44:47 2026 -0600

    [AMQ-9806] Add H2 database support (#1535)
---
 .../activemq/store/jdbc/adapter/H2JDBCAdapter.java | 38 ++++++++++++++++++
 .../activemq/store/jdbc/h2_database_engine_driver  | 17 ++++++++
 activemq-unit-tests/pom.xml                        |  6 +++
 .../activemq/store/jdbc/JDBCStoreBrokerTest.java   | 16 ++++++--
 .../org/apache/activemq/store/jdbc/h2/H2DB.java    | 45 ++++++++++++++++++++++
 .../store/jdbc/h2/H2JDBCStoreBrokerTest.java       | 37 ++++++++++++++++++
 pom.xml                                            |  7 ++++
 7 files changed, 163 insertions(+), 3 deletions(-)

diff --git 
a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/H2JDBCAdapter.java
 
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/H2JDBCAdapter.java
new file mode 100644
index 0000000000..4d1560ca1b
--- /dev/null
+++ 
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/adapter/H2JDBCAdapter.java
@@ -0,0 +1,38 @@
+/**
+ * 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.activemq.store.jdbc.adapter;
+
+import org.apache.activemq.store.jdbc.Statements;
+
+/**
+ * 
+ * @org.apache.xbean.XBean element="h2-jdbc-adapter"
+ */
+public class H2JDBCAdapter extends BytesJDBCAdapter {
+
+    @Override
+    public void setStatements(Statements statements) {
+        statements.setBinaryDataType("BLOB");
+        super.setStatements(statements);
+    }
+
+    @Override
+    public String limitQuery(String query) {
+        return query + " LIMIT " + getMaxRows();
+    }
+
+}
diff --git 
a/activemq-jdbc-store/src/main/resources/META-INF/services/org/apache/activemq/store/jdbc/h2_database_engine_driver
 
b/activemq-jdbc-store/src/main/resources/META-INF/services/org/apache/activemq/store/jdbc/h2_database_engine_driver
new file mode 100644
index 0000000000..1513234f44
--- /dev/null
+++ 
b/activemq-jdbc-store/src/main/resources/META-INF/services/org/apache/activemq/store/jdbc/h2_database_engine_driver
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+class=org.apache.activemq.store.jdbc.adapter.H2JDBCAdapter
\ No newline at end of file
diff --git a/activemq-unit-tests/pom.xml b/activemq-unit-tests/pom.xml
index 78b0293807..5355b12e6a 100644
--- a/activemq-unit-tests/pom.xml
+++ b/activemq-unit-tests/pom.xml
@@ -128,6 +128,12 @@
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <scope>test</scope>
+      <optional>true</optional>
+    </dependency>
     <dependency>
       <groupId>org.apache.derby</groupId>
       <artifactId>derby</artifactId>
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
index c19516f550..c2abc1ccf6 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCStoreBrokerTest.java
@@ -22,19 +22,29 @@ import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.BrokerTest;
 import org.apache.derby.jdbc.EmbeddedDataSource;
 
+import javax.sql.DataSource;
+
 public class JDBCStoreBrokerTest extends BrokerTest {
 
+    protected void configureJDBCPersistenceAdapter(JDBCPersistenceAdapter 
jdbc, final String name) throws Exception {
+
+    }
+
+    @Override
     protected BrokerService createBroker() throws Exception {
         BrokerService broker = new BrokerService();
-        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
+        var jdbc = new JDBCPersistenceAdapter();
+        configureJDBCPersistenceAdapter(jdbc, "JDBCStoreBrokerTest");
         jdbc.deleteAllMessages();
         broker.setPersistenceAdapter(jdbc);
         return broker;
     }
-    
+
     protected BrokerService x_createRestartedBroker() throws Exception {
         BrokerService broker = new BrokerService();
-        broker.setPersistenceAdapter(new JDBCPersistenceAdapter());
+        var jdbc = new JDBCPersistenceAdapter();
+        configureJDBCPersistenceAdapter(jdbc, "JDBCStoreBrokerTest");
+        broker.setPersistenceAdapter(jdbc);
         return broker;
     }
     
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/h2/H2DB.java 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/h2/H2DB.java
new file mode 100644
index 0000000000..31b7afeafb
--- /dev/null
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/h2/H2DB.java
@@ -0,0 +1,45 @@
+/**
+ * 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.activemq.store.jdbc.h2;
+
+import javax.sql.DataSource;
+import org.h2.jdbcx.JdbcDataSource;
+
+import java.io.IOException;
+
+public class H2DB {
+
+    public static DataSource createDataSource(String db) throws IOException {
+        var ds = new JdbcDataSource();
+        ds.setURL(createURL(db));
+        ds.setUser(getUser());
+        ds.setPassword(getPassword());
+        return ds;
+    }
+
+    public static String createURL(String db) {
+        return "jdbc:h2:./target/h2-db/" + db + "/" + db + 
"-h2.db;DB_CLOSE_DELAY=-1";
+    }
+
+    public static String getUser() {
+        return "sa";
+    }
+
+    public static String getPassword() {
+        return "";
+    }
+}
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/h2/H2JDBCStoreBrokerTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/h2/H2JDBCStoreBrokerTest.java
new file mode 100644
index 0000000000..38e19327be
--- /dev/null
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/h2/H2JDBCStoreBrokerTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.activemq.store.jdbc.h2;
+
+import junit.framework.Test;
+import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
+import org.apache.activemq.store.jdbc.JDBCStoreBrokerTest;
+import org.apache.activemq.store.jdbc.adapter.H2JDBCAdapter;
+
+import javax.sql.DataSource;
+
+public class H2JDBCStoreBrokerTest extends JDBCStoreBrokerTest {
+
+    @Override
+    protected void configureJDBCPersistenceAdapter(final 
JDBCPersistenceAdapter jdbc, String dbname) throws Exception {
+        jdbc.setDataSource(H2DB.createDataSource("H2JDBCStoreBrokerTest"));
+        jdbc.setAdapter(new H2JDBCAdapter());
+    }
+
+    public static Test suite() {
+        return suite(H2JDBCStoreBrokerTest.class);
+    }
+}
diff --git a/pom.xml b/pom.xml
index 6760202787..de68cdb6f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,6 +77,7 @@
     <jmock-version>2.13.1</jmock-version>
     <jolokia-version>2.4.3</jolokia-version>
     <junit-version>4.13.2</junit-version>
+    <h2-version>2.4.240</h2-version>
     <hamcrest-version>1.3</hamcrest-version>
     <karaf-version>4.4.9</karaf-version>
     <log4j-version>2.25.3</log4j-version>
@@ -769,6 +770,12 @@
         <version>${org-apache-derby-version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>com.h2database</groupId>
+        <artifactId>h2</artifactId>
+        <version>${h2-version}</version>
+      </dependency>
+
       <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-dbcp2</artifactId>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to