This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/main by this push:
new d026776b11 refactor: replace Derby with H2 database (#2185) (#2311)
d026776b11 is described below
commit d026776b114883b10ab720fd620e11bb4bfefb82
Author: JB Onofré <[email protected]>
AuthorDate: Thu Mar 19 15:21:50 2026 +0100
refactor: replace Derby with H2 database (#2185) (#2311)
* refactor: replace Derby with H2 database (#2185)
Replace all Apache Derby references with H2 across the codebase:
source code, tests, examples, configuration files, and documentation.
* fix(jdbc): use correct H2 driver name and add test timeouts
H2's OsgiDataSourceFactory registers with osgi.jdbc.driver.name="H2 JDBC
Driver",
not "H2". The mismatch prevented pax-jdbc-config from finding the
DataSourceFactory,
causing the XATest to hang indefinitely waiting for the datasource.
Also add bounded timeouts to all polling loops in XATest to prevent CI
hangs if a
condition is never met.
---
.../src/main/feature/feature.xml | 18 +--
.../jdbc/provider/BookingServiceJdbcImpl.java | 8 +-
.../test/java/org/apache/karaf/itests/XATest.java | 62 ++++----
...ource-derby.cfg => org.ops4j.datasource-h2.cfg} | 54 +++----
jaas/modules/pom.xml | 6 +-
.../jaas/modules/jdbc/JdbcLoginModuleTest.java | 11 +-
.../apache/karaf/main/lock/DefaultJDBCLock.java | 6 +-
.../apache/karaf/main/lock/GenericJDBCLock.java | 3 -
.../lock/{DerbyJDBCLock.java => H2JDBCLock.java} | 74 +++++-----
main/src/main/resources/OSGI-INF/bundle.info | 2 +-
.../main/lock/DefaultJDBCLockIntegrationTest.java | 8 +-
.../karaf/main/lock/DefaultJDBCLockTest.java | 16 +--
...ionTest.java => H2JDBCLockIntegrationTest.java} | 116 +++++++--------
...{DerbyJDBCLockTest.java => H2JDBCLockTest.java} | 158 +++++++++------------
manual/src/main/asciidoc/user-guide/failover.adoc | 20 +--
manual/src/main/asciidoc/user-guide/jdbc.adoc | 54 ++-----
manual/src/main/asciidoc/user-guide/scheduler.adoc | 6 +-
.../java/org/apache/karaf/tooling/RunMojoTest.java | 8 +-
18 files changed, 278 insertions(+), 352 deletions(-)
diff --git
a/examples/karaf-jdbc-example/karaf-jdbc-example-features/src/main/feature/feature.xml
b/examples/karaf-jdbc-example/karaf-jdbc-example-features/src/main/feature/feature.xml
index f757422ef3..6c63cf3980 100644
---
a/examples/karaf-jdbc-example/karaf-jdbc-example-features/src/main/feature/feature.xml
+++
b/examples/karaf-jdbc-example/karaf-jdbc-example-features/src/main/feature/feature.xml
@@ -24,29 +24,29 @@
<feature name="karaf-jdbc-example-provider" version="${project.version}">
<config name="org.ops4j.datasource-karaf-example">
- osgi.jdbc.driver.name=derby
+ osgi.jdbc.driver.name=H2 JDBC Driver
dataSourceName=jdbc/karaf-example
- url=jdbc:derby:data/example/derby;create=true
+ url=jdbc:h2:./data/example/h2
</config>
-
+
<config name="org.apache.karaf.examples.jdbc">
###############################################
# Karaf Examples Registry Storage JDBC Configuration
###############################################
-
+
# Name of the JDBC datasource
datasource.name=jdbc/karaf-example
-
+
# Dialect (type of the database)
# The dialect is used to create the tables
- # Supported dialects are: generic, derby, mysql
- dialect=derby
+ # Supported dialects are: generic, h2, mysql
+ dialect=h2
</config>
-
+
<feature
version="${project.version}">karaf-jdbc-example-common</feature>
<feature>scr</feature>
<feature>jdbc</feature>
- <feature>pax-jdbc-derby</feature>
+ <feature>pax-jdbc-h2</feature>
<feature dependency="true">aries-blueprint</feature>
<bundle>mvn:org.apache.karaf.examples/karaf-jdbc-example-provider/${project.version}</bundle>
</feature>
diff --git
a/examples/karaf-jdbc-example/karaf-jdbc-example-provider/src/main/java/org/apache/karaf/examples/jdbc/provider/BookingServiceJdbcImpl.java
b/examples/karaf-jdbc-example/karaf-jdbc-example-provider/src/main/java/org/apache/karaf/examples/jdbc/provider/BookingServiceJdbcImpl.java
index f8e176abb9..9b8d1f32e2 100644
---
a/examples/karaf-jdbc-example/karaf-jdbc-example-provider/src/main/java/org/apache/karaf/examples/jdbc/provider/BookingServiceJdbcImpl.java
+++
b/examples/karaf-jdbc-example/karaf-jdbc-example-provider/src/main/java/org/apache/karaf/examples/jdbc/provider/BookingServiceJdbcImpl.java
@@ -43,10 +43,10 @@ public class BookingServiceJdbcImpl implements
BookingService {
private final static String DATABASE_SCHEMA = "KARAF_EXAMPLE";
- private final static String[] createTableQueryDerbyTemplate = new String[]
{
- "CREATE SCHEMA " + DATABASE_SCHEMA,
+ private final static String[] createTableQueryH2Template = new String[] {
+ "CREATE SCHEMA IF NOT EXISTS " + DATABASE_SCHEMA,
- "CREATE TABLE " + DATABASE_SCHEMA + ".BOOKING(id SMALLINT NOT NULL
GENERATED BY DEFAULT AS IDENTITY "
+ "CREATE TABLE IF NOT EXISTS " + DATABASE_SCHEMA + ".BOOKING(id
SMALLINT NOT NULL AUTO_INCREMENT "
+ " CONSTRAINT BOOKING_PK PRIMARY KEY, customer
VARCHAR(200) NOT NULL, flight VARCHAR(100))"};
/** Select queries */
@@ -106,7 +106,7 @@ public class BookingServiceJdbcImpl implements
BookingService {
if (!tables.next()) {
LOGGER.info("Tables does not exist");
// Tables does not exist so we create all the tables
- String[] createTemplate = createTemplate =
createTableQueryDerbyTemplate;
+ String[] createTemplate = createTableQueryH2Template;
try (Statement createStatement = connection.createStatement())
{
for (String s : createTemplate) {
createStatement.addBatch(s);
diff --git a/itests/test/src/test/java/org/apache/karaf/itests/XATest.java
b/itests/test/src/test/java/org/apache/karaf/itests/XATest.java
index 5d8207daeb..ab59596e4c 100644
--- a/itests/test/src/test/java/org/apache/karaf/itests/XATest.java
+++ b/itests/test/src/test/java/org/apache/karaf/itests/XATest.java
@@ -63,43 +63,47 @@ public class XATest extends BaseTest {
result.add(editConfigurationFilePut("etc/org.apache.karaf.features.cfg",
"featuresBoot",
"instance,package,log,ssh,framework,system,eventadmin,feature,shell,management,service,jaas,deployer,diagnostic,wrap,bundle,config,kar,aries-blueprint,artemis,jms,pax-jms-artemis"));
result.add(replaceConfigurationFile("etc/org.ops4j.connectionfactory-artemis.cfg",
getConfigFile("/org/apache/karaf/itests/features/org.ops4j.connectionfactory-artemis.cfg")));
-
result.add(replaceConfigurationFile("etc/org.ops4j.datasource-derby.cfg",
getConfigFile("/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg")));
+ result.add(replaceConfigurationFile("etc/org.ops4j.datasource-h2.cfg",
getConfigFile("/org/apache/karaf/itests/features/org.ops4j.datasource-h2.cfg")));
result.add(replaceConfigurationFile("etc/xa-test-camel.xml",
getConfigFile("/org/apache/karaf/itests/features/xa-test-camel.xml")));
return result.toArray(new Option[result.size()]);
}
+ private static final long TIMEOUT_MS = 120_000;
+
+ private String awaitCondition(String command, String expected, String
description) throws Exception {
+ long deadline = System.currentTimeMillis() + TIMEOUT_MS;
+ String output = executeCommand(command);
+ while (!output.contains(expected)) {
+ if (System.currentTimeMillis() > deadline) {
+ throw new AssertionError("Timeout waiting for " + description
+ + ". Last output: " + output);
+ }
+ Thread.sleep(500);
+ output = executeCommand(command);
+ }
+ return output;
+ }
+
@Test
public void test() throws Exception {
System.out.println("== Starting Artemis broker == ");
- String logDisplay = executeCommand("log:display");
- while (!logDisplay.contains("AMQ221007: Server is now live")) {
- Thread.sleep(500);
- logDisplay = executeCommand("log:display");
- }
+ awaitCondition("log:display", "AMQ221007: Server is now live",
"Artemis broker to start");
System.out.println("AMQ221007: Server is now live");
System.out.println(executeCommand("jms:info artemis"));
- System.out.println("== Installing Derby database == ");
+ System.out.println("== Installing H2 database == ");
featureService.installFeature("jdbc", NO_AUTO_REFRESH);
- featureService.installFeature("pax-jdbc-derby", NO_AUTO_REFRESH);
+ featureService.installFeature("pax-jdbc-h2", NO_AUTO_REFRESH);
featureService.installFeature("pax-jdbc-pool-transx", NO_AUTO_REFRESH);
System.out.println(" ");
- String dsList = executeCommand("jdbc:ds-list");
- while (!dsList.contains("OK")) {
- Thread.sleep(500);
- dsList = executeCommand("jdbc:ds-list");
- }
+ String dsList = awaitCondition("jdbc:ds-list", "OK", "H2 datasource to
become available");
System.out.println(dsList);
-
- System.out.println("== Creating table in Derby ==");
- System.out.println(executeCommand("jdbc:execute derby CREATE TABLE
messages (id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY, message
VARCHAR(1024) NOT NULL, CONSTRAINT primary_key PRIMARY KEY (id))"));
- String tableOutput = executeCommand("jdbc:query derby select * from
messages");
- while (!tableOutput.contains("MESSAGE")) {
- Thread.sleep(500);
- tableOutput = executeCommand("jdbc:query derby select * from
messages");
- }
+ System.out.println("== Creating table in H2 ==");
+ System.out.println(executeCommand("jdbc:execute h2 CREATE TABLE IF NOT
EXISTS messages (id INTEGER NOT NULL AUTO_INCREMENT, message VARCHAR(1024) NOT
NULL, CONSTRAINT primary_key PRIMARY KEY (id))"));
+
+ awaitCondition("jdbc:query h2 select * from messages", "MESSAGE",
"table creation");
System.out.println("== Table created ==");
System.out.println("== Installing Camel route ==");
@@ -114,22 +118,14 @@ public class XATest extends BaseTest {
Bundle bundle =
bundleContext.installBundle("blueprint:file:etc/xa-test-camel.xml");
bundle.start();
- String routeList = executeCommand("camel:route-list");
- while (!routeList.contains("Started")) {
- Thread.sleep(500);
- routeList = executeCommand("camel:route-list");
- }
+ String routeList = awaitCondition("camel:route-list", "Started",
"Camel route to start");
System.out.println(routeList);
- System.out.println("== Sending a message in Artemis broker that should
be consumed by Camel route and inserted into the Derby database");
+ System.out.println("== Sending a message in Artemis broker that should
be consumed by Camel route and inserted into the H2 database");
System.out.println(executeCommand("jms:send artemis MyQueue
'the-message'"));
- String output = executeCommand("jdbc:query derby select * from
messages");
-
- while (!output.contains("the-message")) {
- Thread.sleep(500);
- output = executeCommand("jdbc:query derby select * from messages");
- }
+ String output = awaitCondition("jdbc:query h2 select * from messages",
"the-message",
+ "message to be inserted into H2");
System.out.println(output);
diff --git
a/itests/test/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg
b/itests/test/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-h2.cfg
similarity index 85%
rename from
itests/test/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg
rename to
itests/test/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-h2.cfg
index 64ade0b1e8..d522c68d4e 100644
---
a/itests/test/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-derby.cfg
+++
b/itests/test/src/test/resources/org/apache/karaf/itests/features/org.ops4j.datasource-h2.cfg
@@ -1,27 +1,27 @@
-################################################################################
-#
-# 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.
-#
-################################################################################
-
-osgi.jdbc.driver.name = derby
-osgi.jndi.service.name = derby
-osgi.jdbc.driver.class = org.apache.derby.jdbc.EmbeddedDriver
-url = jdbc:derby:data/derby/test;create=true
-pool = transx
-xa = true
-user = sa
-password =
+################################################################################
+#
+# 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.
+#
+################################################################################
+
+osgi.jdbc.driver.name = H2 JDBC Driver
+osgi.jndi.service.name = h2
+osgi.jdbc.driver.class = org.h2.Driver
+url = jdbc:h2:./data/h2/test
+pool = transx
+xa = true
+user = sa
+password =
diff --git a/jaas/modules/pom.xml b/jaas/modules/pom.xml
index 466390786f..8c27386263 100644
--- a/jaas/modules/pom.xml
+++ b/jaas/modules/pom.xml
@@ -136,9 +136,9 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- <version>10.14.2.0</version>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>2.2.224</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git
a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/jdbc/JdbcLoginModuleTest.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/jdbc/JdbcLoginModuleTest.java
index fb7ed65eed..b2d9c4447b 100644
---
a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/jdbc/JdbcLoginModuleTest.java
+++
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/jdbc/JdbcLoginModuleTest.java
@@ -24,7 +24,7 @@ import java.util.Map;
import javax.security.auth.Subject;
import javax.sql.DataSource;
-import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.h2.jdbcx.JdbcDataSource;
import org.apache.karaf.jaas.boot.principal.GroupPrincipal;
import org.apache.karaf.jaas.boot.principal.RolePrincipal;
import org.apache.karaf.jaas.boot.principal.UserPrincipal;
@@ -43,18 +43,15 @@ import static org.junit.Assert.assertTrue;
public class JdbcLoginModuleTest {
- private EmbeddedDataSource dataSource;
+ private JdbcDataSource dataSource;
private Map<String, Object> options;
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
- System.setProperty("derby.stream.error.file", "target/derby.log");
-
// Create datasource
- dataSource = new EmbeddedDataSource();
- dataSource.setDatabaseName("memory:db");
- dataSource.setCreateDatabase("create");
+ dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
// Delete tables
try (Connection connection = dataSource.getConnection()) {
diff --git a/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
b/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
index 6445a740c2..adbd17d426 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/DefaultJDBCLock.java
@@ -330,10 +330,6 @@ public class DefaultJDBCLock implements Lock {
* @throws Exception
*/
Connection createConnection(String driver, String url, String username,
String password) throws Exception {
- if (url.toLowerCase().startsWith("jdbc:derby")) {
- url = (url.toLowerCase().contains("create=true")) ? url : url +
";create=true";
- }
-
try {
return doCreateConnection(driver, url, username, password);
} catch (Exception e) {
@@ -355,7 +351,7 @@ public class DefaultJDBCLock implements Lock {
*/
Connection doCreateConnection(String driver, String url, String username,
String password) throws ClassNotFoundException, SQLException {
Class.forName(driver);
- // results in a closed connection in Derby if the update lock table
request timed out
+ // results in a closed connection if the update lock table request
timed out
// DriverManager.setLoginTimeout(timeout);
return DriverManager.getConnection(url, username, password);
}
diff --git a/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
b/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
index 7a68354417..ec8d312702 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/GenericJDBCLock.java
@@ -181,9 +181,6 @@ public class GenericJDBCLock implements Lock {
this.statements = createStatements();
String url = this.url;
- if (url.toLowerCase().startsWith("jdbc:derby")) {
- url = (url.toLowerCase().contains("create=true")) ? url : url +
";create=true";
- }
boolean cacheEnabled =
Boolean.parseBoolean(props.getProperty(PROPERTY_LOCK_JDBC_CACHE,
DEFAULT_CACHE));
int validTimeout =
Integer.parseInt(props.getProperty(PROPERTY_LOCK_JDBC_VALID_TIMEOUT,
DEFAULT_VALID_TIMEOUT));
diff --git a/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
b/main/src/main/java/org/apache/karaf/main/lock/H2JDBCLock.java
similarity index 71%
rename from main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
rename to main/src/main/java/org/apache/karaf/main/lock/H2JDBCLock.java
index fce3d33699..cb8607f677 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/DerbyJDBCLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/H2JDBCLock.java
@@ -1,41 +1,33 @@
-/*
- * 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.karaf.main.lock;
-
-import java.sql.Connection;
-import org.apache.felix.utils.properties.Properties;
-
-/**
- * Represents an exclusive lock on a database,
- * used to avoid multiple Karaf instances attempting
- * to become master.
- */
-public class DerbyJDBCLock extends DefaultJDBCLock {
-
- public DerbyJDBCLock(Properties props) {
- super(props);
- }
-
- @Override
- Connection createConnection(String driver, String url, String username,
String password) throws Exception {
- url = (url.toLowerCase().contains("create=true")) ? url : url +
";create=true";
-
- return super.createConnection(driver, url, username, password);
- }
-}
+/*
+ * 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.karaf.main.lock;
+
+import org.apache.felix.utils.properties.Properties;
+
+/**
+ * Represents an exclusive lock on a database,
+ * used to avoid multiple Karaf instances attempting
+ * to become master.
+ */
+public class H2JDBCLock extends DefaultJDBCLock {
+
+ public H2JDBCLock(Properties props) {
+ super(props);
+ }
+}
diff --git a/main/src/main/resources/OSGI-INF/bundle.info
b/main/src/main/resources/OSGI-INF/bundle.info
index 1222eae499..01c6a876aa 100644
--- a/main/src/main/resources/OSGI-INF/bundle.info
+++ b/main/src/main/resources/OSGI-INF/bundle.info
@@ -29,7 +29,7 @@ h1. Description
This bundle is responsible for the main Karaf startup.
- In particular, it manages the bootstrap of low level Karaf services
such as the embedded Derby database, locking
+ In particular, it manages the bootstrap of low level Karaf services
such as the embedded H2 database, locking
facilities, etc.
h1. See also
diff --git
a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
index d262fefd83..2ecc346b6e 100644
---
a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
+++
b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockIntegrationTest.java
@@ -34,9 +34,9 @@ public class DefaultJDBCLockIntegrationTest extends
BaseJDBCLockIntegrationTest
@Override
public void setUp() throws Exception {
password = "root";
- driver = "org.apache.derby.jdbc.ClientDriver";
- url = "jdbc:derby://127.0.0.1:1527/test";
-
+ driver = "org.h2.Driver";
+ url = "jdbc:h2:tcp://127.0.0.1/test";
+
super.setUp();
}
@@ -48,7 +48,7 @@ public class DefaultJDBCLockIntegrationTest extends
BaseJDBCLockIntegrationTest
@Test
public void initShouldCreateTheDatabaseIfItNotExists() throws Exception {
String database = "test" + System.currentTimeMillis();
- url = "jdbc:derby://127.0.0.1:1527/" + database;
+ url = "jdbc:h2:tcp://127.0.0.1/" + database;
props.put("karaf.lock.jdbc.url", url);
lock = createLock(props);
lock.lock();
diff --git
a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
index 951c458250..ff6bb86a6a 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/DefaultJDBCLockTest.java
@@ -36,18 +36,18 @@ public class DefaultJDBCLockTest extends BaseJDBCLockTest {
@Override
public void setUp() throws Exception {
password = "root";
- driver = "org.apache.derby.jdbc.ClientDriver";
- url = "jdbc:derby://127.0.0.1:1527/test";
-
+ driver = "org.h2.Driver";
+ url = "jdbc:h2:tcp://127.0.0.1/test";
+
super.setUp();
}
-
+
DefaultJDBCLock createLock(Properties props) {
return new DefaultJDBCLock(props) {
@Override
Connection doCreateConnection(String driver, String url, String
username, String password) {
assertEquals(this.driver, driver);
- assertEquals(this.url + ";create=true", url);
+ assertEquals(this.url, url);
assertEquals(this.user, username);
assertEquals(this.password, password);
return connection;
@@ -67,8 +67,8 @@ public class DefaultJDBCLockTest extends BaseJDBCLockTest {
@Test
public void createConnectionShouldConcatinateOptionsCorrect() throws
SQLException {
- props.put("karaf.lock.jdbc.url", this.url + ";dataEncryption=false");
-
+ props.put("karaf.lock.jdbc.url", this.url + ";CIPHER=AES");
+
lock = new DefaultJDBCLock(props) {
@Override
boolean schemaExists() {
@@ -78,7 +78,7 @@ public class DefaultJDBCLockTest extends BaseJDBCLockTest {
@Override
Connection doCreateConnection(String driver, String url, String
username, String password) {
assertEquals(this.driver, driver);
- assertEquals(this.url + ";create=true", url);
+ assertEquals(this.url, url);
assertEquals(this.user, username);
assertEquals(this.password, password);
return connection;
diff --git
a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
b/main/src/test/java/org/apache/karaf/main/lock/H2JDBCLockIntegrationTest.java
similarity index 83%
rename from
main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
rename to
main/src/test/java/org/apache/karaf/main/lock/H2JDBCLockIntegrationTest.java
index ba9365d003..b60be038ed 100644
---
a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockIntegrationTest.java
+++
b/main/src/test/java/org/apache/karaf/main/lock/H2JDBCLockIntegrationTest.java
@@ -1,58 +1,58 @@
-/*
- * 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.karaf.main.lock;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.felix.utils.properties.Properties;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-
-@Ignore
-public class DerbyJDBCLockIntegrationTest extends BaseJDBCLockIntegrationTest {
-
- @Before
- @Override
- public void setUp() throws Exception {
- password = "root";
- driver = "org.apache.derby.jdbc.ClientDriver";
- url = "jdbc:derby://127.0.0.1:1527/test";
-
- super.setUp();
- }
-
- @Override
- DefaultJDBCLock createLock(Properties props) {
- return new DerbyJDBCLock(props);
- }
-
- @Test
- public void initShouldCreateTheDatabaseIfItNotExists() throws Exception {
- String database = "test" + System.currentTimeMillis();
- url = "jdbc:derby://127.0.0.1:1527/" + database;
- props.put("karaf.lock.jdbc.url", url);
- lock = createLock(props);
- lock.lock();
-
-
assertTrue(lock.lockConnection.getMetaData().getURL().contains(database));
- }
-}
+/*
+ * 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.karaf.main.lock;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.felix.utils.properties.Properties;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+@Ignore
+public class H2JDBCLockIntegrationTest extends BaseJDBCLockIntegrationTest {
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ password = "root";
+ driver = "org.h2.Driver";
+ url = "jdbc:h2:tcp://127.0.0.1/test";
+
+ super.setUp();
+ }
+
+ @Override
+ DefaultJDBCLock createLock(Properties props) {
+ return new H2JDBCLock(props);
+ }
+
+ @Test
+ public void initShouldCreateTheDatabaseIfItNotExists() throws Exception {
+ String database = "test" + System.currentTimeMillis();
+ url = "jdbc:h2:tcp://127.0.0.1/" + database;
+ props.put("karaf.lock.jdbc.url", url);
+ lock = createLock(props);
+ lock.lock();
+
+
assertTrue(lock.lockConnection.getMetaData().getURL().contains(database));
+ }
+}
diff --git
a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
b/main/src/test/java/org/apache/karaf/main/lock/H2JDBCLockTest.java
similarity index 59%
rename from main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
rename to main/src/test/java/org/apache/karaf/main/lock/H2JDBCLockTest.java
index fd96dcce26..1fcba9940c 100644
--- a/main/src/test/java/org/apache/karaf/main/lock/DerbyJDBCLockTest.java
+++ b/main/src/test/java/org/apache/karaf/main/lock/H2JDBCLockTest.java
@@ -1,92 +1,66 @@
-/*
- * 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.karaf.main.lock;
-
-import static org.junit.Assert.assertEquals;
-
-import java.sql.Connection;
-import java.util.logging.Level;
-
-import org.apache.felix.utils.properties.Properties;
-
-import org.junit.Before;
-import org.junit.Test;
-
-
-public class DerbyJDBCLockTest extends BaseJDBCLockTest {
-
- @Before
- @Override
- public void setUp() throws Exception {
- password = "root";
- driver = "org.apache.derby.jdbc.ClientDriver";
- url = "jdbc:derby://127.0.0.1:1527/test";
-
- super.setUp();
- }
-
- DerbyJDBCLock createLock(Properties props) {
- return new DerbyJDBCLock(props) {
- @Override
- Connection doCreateConnection(String driver, String url, String
username, String password) {
- assertEquals(this.driver, driver);
- assertEquals(this.url + ";create=true", url);
- assertEquals(this.user, username);
- assertEquals(this.password, password);
- return connection;
- }
-
- @Override
- long getCurrentTimeMillis() {
- return 1;
- }
-
- @Override
- public void log(Level level, String msg, Exception e) {
- // Suppress log
- }
- };
- }
-
- @Test
- public void createConnectionShouldConcatinateOptionsCorrect() {
- props.put("karaf.lock.jdbc.url", this.url + ";dataEncryption=false");
-
- lock = new DerbyJDBCLock(props) {
- @Override
- boolean schemaExists() {
- return true;
- }
-
- @Override
- Connection doCreateConnection(String driver, String url, String
username, String password) {
- assertEquals(this.driver, driver);
- assertEquals(this.url + ";create=true", url);
- assertEquals(this.user, username);
- assertEquals(this.password, password);
- return connection;
- }
-
- @Override
- long getCurrentTimeMillis() {
- return 1;
- }
- };
- }
-}
+/*
+ * 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.karaf.main.lock;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Connection;
+import java.util.logging.Level;
+
+import org.apache.felix.utils.properties.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class H2JDBCLockTest extends BaseJDBCLockTest {
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ password = "root";
+ driver = "org.h2.Driver";
+ url = "jdbc:h2:tcp://127.0.0.1/test";
+
+ super.setUp();
+ }
+
+ H2JDBCLock createLock(Properties props) {
+ return new H2JDBCLock(props) {
+ @Override
+ Connection doCreateConnection(String driver, String url, String
username, String password) {
+ assertEquals(this.driver, driver);
+ assertEquals(this.url, url);
+ assertEquals(this.user, username);
+ assertEquals(this.password, password);
+ return connection;
+ }
+
+ @Override
+ long getCurrentTimeMillis() {
+ return 1;
+ }
+
+ @Override
+ public void log(Level level, String msg, Exception e) {
+ // Suppress log
+ }
+ };
+ }
+}
diff --git a/manual/src/main/asciidoc/user-guide/failover.adoc
b/manual/src/main/asciidoc/user-guide/failover.adoc
index f5a4c85c0a..82dd03b8f7 100644
--- a/manual/src/main/asciidoc/user-guide/failover.adoc
+++ b/manual/src/main/asciidoc/user-guide/failover.adoc
@@ -76,8 +76,8 @@ karaf.lock=true
karaf.lock.class=org.apache.karaf.main.lock.DefaultJDBCLock
karaf.lock.level=50
karaf.lock.delay=10000
-karaf.lock.jdbc.url=jdbc:derby://dbserver:1527/sample
-karaf.lock.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+karaf.lock.jdbc.url=jdbc:h2:tcp://dbserver/sample
+karaf.lock.jdbc.driver=org.h2.Driver
karaf.lock.jdbc.user=user
karaf.lock.jdbc.password=password
karaf.lock.jdbc.table=KARAF_LOCK
@@ -92,8 +92,8 @@ karaf.lock.lostThreshold=0
* `karaf.lock.level` property is the container-level locking (see later for
details).
* `karaf.lock.delay` property is the interval period (in milliseconds) to
check if the lock has been released or not.
* `karaf.lock.lostThreshold` property is the count of attempts to re-acquire
the lock before shutting down.
-* `karaf.lock.jdbc.url` property contains the JDBC URL to the database (derby
in this example).
-* `karaf.lock.jdbc.driver` property contains the class name of the JDBC driver
to use (derby in this example).
+* `karaf.lock.jdbc.url` property contains the JDBC URL to the database (H2 in
this example).
+* `karaf.lock.jdbc.driver` property contains the class name of the JDBC driver
to use (H2 in this example).
* `karaf.lock.jdbc.user` property contains the username to use to connect to
the database.
* `karaf.lock.jdbc.password` property contains the password to use to connet
to the database.
* `karaf.lock.jdbc.table` property contains the database table to use for the
lock. Karaf will first try to find the table as specified in this property,
@@ -139,15 +139,15 @@ The `karaf.lock.jdbc.url` property contains a JDBC URL
which requires an active
database instance first before using the lock mechanism.
====
-*Lock on Derby*
+*Lock on H2*
-Apache Karaf supports Apache Derby database for locking. The lock
implementation class name to use is `org.apache.karaf.main.lock.DerbyJDBCLock`:
+Apache Karaf supports H2 database for locking. The lock implementation class
name to use is `org.apache.karaf.main.lock.H2JDBCLock`:
----
karaf.lock=true
-karaf.lock.class=org.apache.karaf.main.lock.DerbyJDBCLock
-karaf.lock.jdbc.url=jdbc:derby://127.0.0.1:1527/dbname
-karaf.lock.jdbc.driver=org.apache.derby.jdbc.ClientDriver
+karaf.lock.class=org.apache.karaf.main.lock.H2JDBCLock
+karaf.lock.jdbc.url=jdbc:h2:tcp://127.0.0.1/dbname
+karaf.lock.jdbc.driver=org.h2.Driver
karaf.lock.jdbc.user=user
karaf.lock.jdbc.password=password
karaf.lock.jdbc.table=KARAF_LOCK
@@ -155,7 +155,7 @@ karaf.lock.jdbc.clustername=karaf
karaf.lock.jdbc.timeout=30
----
-The Derby JDBC driver file name has to be copied in the `lib/ext` folder.
+The H2 JDBC driver file has to be copied in the `lib/ext` folder.
*Lock on MySQL*
diff --git a/manual/src/main/asciidoc/user-guide/jdbc.adoc
b/manual/src/main/asciidoc/user-guide/jdbc.adoc
index 4fbd142493..5bf3fc9674 100644
--- a/manual/src/main/asciidoc/user-guide/jdbc.adoc
+++ b/manual/src/main/asciidoc/user-guide/jdbc.adoc
@@ -26,8 +26,6 @@ NB: `jdbc` feature automatically installs the `pax-jdbc-*`
core features.
Pax JDBC provides ready to use adapters for different databases:
-* pax-jdbc-derby
-* pax-jdbc-derbyclient
* pax-jdbc-h2
* pax-jdbc-mariadb
* pax-jdbc-mysql
@@ -68,8 +66,6 @@ NB: don't forget to install the `pax-jdbc-*` features for the
database you want
----
pax-jdbc-db2
pax-jdbc-teradata
-pax-jdbc-derby
-pax-jdbc-derbyclient
pax-jdbc-h2
pax-jdbc-hsqldb
pax-jdbc-mariadb
@@ -128,10 +124,10 @@ OPTIONS
* the `-url` option is optional. It defines the JDBC URL to access to the
database.
* the `-p` option is optional. It defines the database password.
-For instance, to create an embedded Apache Derby database in Apache Karaf, you
can do:
+For instance, to create an embedded H2 database in Apache Karaf, you can do:
----
-karaf@root()> jdbc:ds-create -dn derby -url "jdbc:derby:test;create=true" test
+karaf@root()> jdbc:ds-create -dn "H2 JDBC Driver" -url "jdbc:h2:./test" test
----
We can see that this command created a configuration PID containing the
datasource properties.
@@ -162,9 +158,9 @@ The `jdbc:ds-list` command lists the JDBC datasources:
----
karaf@root()> jdbc:ds-list
-Name │ Service Id │ Product │ Version │ URL │
Status
-─────┼────────────┼────────────────┼──────────────────────┼─────────────────┼───────
-test │ 112 │ Apache Derby │ 10.8.2.2 - (1181258) │ jdbc:derby:test │
OK
+Name │ Service Id │ Product │ Version │ URL │ Status
+─────┼────────────┼─────────┼─────────┼────────────────┼───────
+test │ 112 │ H2 │ 2.2.224 │ jdbc:h2:./test │ OK
----
===== `jdbc:ds-info`
@@ -176,13 +172,13 @@ or service.id:
karaf@root()> jdbc:ds-info test
Property | Value
--------------------------------------------------
-driver.version | 10.8.2.2 - (1181258)
+driver.version | 2.2.224
service.id | 112
-username | APP
-db.version | 10.8.2.2 - (1181258)
-db.product | Apache Derby
-driver.name | Apache Derby Embedded JDBC Driver
-url | jdbc:derby:test
+username | SA
+db.version | 2.2.224
+db.product | H2
+driver.name | H2 JDBC Driver
+url | jdbc:h2:./test
----
===== `jdbc:execute`
@@ -224,31 +220,9 @@ The `jdbc:tables` command displays all tables available on
a given JDBC datasour
----
karaf@root()> jdbc:tables test
-REF_GENERATION | TYPE_NAME | TABLE_NAME | TYPE_CAT | REMARKS |
TYPE_SCHEM | TABLE_TYPE | TABLE_SCHEM | TABLE_CAT | SELF_REFERENCING_COL_NAME
-----------------------------------------------------------------------------------------------------------------------------------------------------
- | | SYSALIASES | | |
| SYSTEM TABLE | SYS | |
- | | SYSCHECKS | | |
| SYSTEM TABLE | SYS | |
- | | SYSCOLPERMS | | |
| SYSTEM TABLE | SYS | |
- | | SYSCOLUMNS | | |
| SYSTEM TABLE | SYS | |
- | | SYSCONGLOMERATES | | |
| SYSTEM TABLE | SYS | |
- | | SYSCONSTRAINTS | | |
| SYSTEM TABLE | SYS | |
- | | SYSDEPENDS | | |
| SYSTEM TABLE | SYS | |
- | | SYSFILES | | |
| SYSTEM TABLE | SYS | |
- | | SYSFOREIGNKEYS | | |
| SYSTEM TABLE | SYS | |
- | | SYSKEYS | | |
| SYSTEM TABLE | SYS | |
- | | SYSPERMS | | |
| SYSTEM TABLE | SYS | |
- | | SYSROLES | | |
| SYSTEM TABLE | SYS | |
- | | SYSROUTINEPERMS | | |
| SYSTEM TABLE | SYS | |
- | | SYSSCHEMAS | | |
| SYSTEM TABLE | SYS | |
- | | SYSSEQUENCES | | |
| SYSTEM TABLE | SYS | |
- | | SYSSTATEMENTS | | |
| SYSTEM TABLE | SYS | |
- | | SYSSTATISTICS | | |
| SYSTEM TABLE | SYS | |
- | | SYSTABLEPERMS | | |
| SYSTEM TABLE | SYS | |
- | | SYSTABLES | | |
| SYSTEM TABLE | SYS | |
- | | SYSTRIGGERS | | |
| SYSTEM TABLE | SYS | |
- | | SYSVIEWS | | |
| SYSTEM TABLE | SYS | |
- | | SYSDUMMY1 | | |
| SYSTEM TABLE | SYSIBM | |
- | | PERSON | | |
| TABLE | APP | |
+REF_GENERATION | TYPE_NAME | TABLE_NAME | TYPE_CAT | REMARKS |
TYPE_SCHEM | TABLE_TYPE | TABLE_SCHEM | TABLE_CAT |
SELF_REFERENCING_COL_NAME
+-------------------------------------------------------------------------------------------------------------------------------------------------------
+ | | PERSON | | |
| TABLE | PUBLIC | |
----
===== JMX JDBC MBean
diff --git a/manual/src/main/asciidoc/user-guide/scheduler.adoc
b/manual/src/main/asciidoc/user-guide/scheduler.adoc
index c06ea4ed88..ac28df6b0b 100644
--- a/manual/src/main/asciidoc/user-guide/scheduler.adoc
+++ b/manual/src/main/asciidoc/user-guide/scheduler.adoc
@@ -256,12 +256,12 @@ a farm or cluster of Karaf instances.
For instance, you can use a database as storage.
You can create the datasource to this database, using the regular Karaf `jdbc`
commands. For instance, to setup a `DataSource`
-for a remote Derby database, you can do:
+for a remote H2 database, you can do:
----
karaf@root()> feature:install jdbc
-karaf@root()> feature:install pax-jdbc-derbyclient
-karaf@root()> jdbc:ds-create -dn derbyclient -url
jdbc:derby://host:1527/karaf_scheduler scheduler
+karaf@root()> feature:install pax-jdbc-h2
+karaf@root()> jdbc:ds-create -dn "H2 JDBC Driver" -url
jdbc:h2:tcp://host/karaf_scheduler scheduler
karaf@root()> feature:install jndi
----
diff --git
a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/RunMojoTest.java
b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/RunMojoTest.java
index aff1a4ceaa..5e27ad2ebe 100644
---
a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/RunMojoTest.java
+++
b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/RunMojoTest.java
@@ -393,7 +393,7 @@ public class RunMojoTest extends EasyMockSupport {
project.setArtifact(artifact);
project.addAttachedArtifact(artifactFeaturesAttachment);
setPrivateField(mojo, "project", project);
- setPrivateField(mojo, "featuresToInstall", "liquibase-core,
ukelonn-db-derby-test, ukelonn");
+ setPrivateField(mojo, "featuresToInstall", "liquibase-core,
ukelonn-db-h2-test, ukelonn");
String[] featureRepos = {
"mvn:org.ops4j.pax.jdbc/pax-jdbc-features/LATEST/xml/features" };
setPrivateField(mojo, "featureRepositories", featureRepos);
mojo.deploy(context, featureService);
@@ -408,7 +408,7 @@ public class RunMojoTest extends EasyMockSupport {
*/
@Test
public void testStringSplit() {
- String[] split1 = "liquibase-core, ukelonn-db-derby-test,
ukelonn".split(" *, *");
+ String[] split1 = "liquibase-core, ukelonn-db-h2-test, ukelonn".split("
*, *");
assertEquals(3, split1.length);
String[] split2 = "liquibase-core".split(" *, *");
assertEquals(1, split2.length);
@@ -435,7 +435,7 @@ public class RunMojoTest extends EasyMockSupport {
@Test
public void testAddFeaturesNullFeatureService() throws SecurityException,
IllegalArgumentException, IllegalAccessException {
RunMojo mojo = new RunMojo();
- setPrivateField(mojo, "featuresToInstall", "liquibase-core,
ukelonn-db-derby-test, ukelonn");
+ setPrivateField(mojo, "featuresToInstall", "liquibase-core,
ukelonn-db-h2-test, ukelonn");
try {
mojo.addFeatures(null);
@@ -452,7 +452,7 @@ public class RunMojoTest extends EasyMockSupport {
replay(featureService);
RunMojo mojo = new RunMojo();
- setPrivateField(mojo, "featuresToInstall", "liquibase-core,
ukelonn-db-derby-test, ukelonn");
+ setPrivateField(mojo, "featuresToInstall", "liquibase-core,
ukelonn-db-h2-test, ukelonn");
mojo.addFeatures(featureService);
verify(featureService);
}