diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java
index b4fc4937d1..efaa7807c5 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/config/ActiveMQDefaultConfiguration.java
@@ -403,7 +403,10 @@ public final class ActiveMQDefaultConfiguration {
private static String DEFAULT_STORE_TYPE = "FILE";
// Default database url. Derby database is used by default.
- private static String DEFAULT_DATABASE_URL = "jdbc:derby:data/derby;create=true";
+ private static String DEFAULT_DATABASE_URL = null;
+
+ // Default JDBC Driver class name
+ private static String DEFAULT_JDBC_DRIVER_CLASS_NAME = null;
// Default message table name, used with Database storage type
private static String DEFAULT_MESSAGE_TABLE_NAME = "MESSAGES";
@@ -1096,4 +1099,8 @@ public final class ActiveMQDefaultConfiguration {
public static String getDefaultBindingsTableName() {
return DEFAULT_BINDINGS_TABLE_NAME;
}
+
+ public static String getDefaultDriverClassName() {
+ return DEFAULT_JDBC_DRIVER_CLASS_NAME;
+ }
}
diff --git a/artemis-jdbc-store/pom.xml b/artemis-jdbc-store/pom.xml
index a0430b4a80..86fe1a6e5b 100644
--- a/artemis-jdbc-store/pom.xml
+++ b/artemis-jdbc-store/pom.xml
@@ -56,6 +56,7 @@
org.apache.derby
derby
+ test
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
index c2ffa9659e..b44f22501b 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
@@ -22,26 +22,16 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.derby.jdbc.AutoloadedDriver;
public class JDBCUtils {
- public static Driver getDriver() throws Exception {
- Driver dbDriver = null;
- // Load Database driver, sets Derby Autoloaded Driver as lowest priority.
- List drivers = Collections.list(DriverManager.getDrivers());
- if (drivers.size() <= 2 && drivers.size() > 0) {
- dbDriver = drivers.get(0);
- boolean isDerby = dbDriver instanceof AutoloadedDriver;
+ public static Driver getDriver(String className) throws Exception {
- if (drivers.size() > 1 && isDerby) {
- dbDriver = drivers.get(1);
- }
+ try {
+ Driver driver = (Driver) Class.forName(className).newInstance();
- if (isDerby) {
+ // Shutdown the derby if using the derby embedded driver.
+ if (className.equals("org.apache.derby.jdbc.EmbeddedDriver")) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
@@ -53,12 +43,14 @@ public class JDBCUtils {
}
});
}
+ return driver;
}
- else {
- String error = drivers.isEmpty() ? "No DB driver found on class path" : "Too many DB drivers on class path, not sure which to use";
- throw new RuntimeException(error);
+ catch (ClassNotFoundException cnfe) {
+ throw new RuntimeException("Could not find class: " + className);
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Unable to instantiate driver class: ", e);
}
- return dbDriver;
}
public static void createTableIfNotExists(Connection connection, String tableName, String sql) throws SQLException {
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java
index cc7462ba58..e7a0165de5 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/journal/JDBCJournalImpl.java
@@ -56,6 +56,8 @@ public class JDBCJournalImpl implements Journal {
private final String tableName;
+ private final String jdbcDriverClass;
+
private Connection connection;
private List records;
@@ -88,9 +90,10 @@ public class JDBCJournalImpl implements Journal {
// Sequence ID for journal records
private AtomicLong seq = new AtomicLong(0);
- public JDBCJournalImpl(String jdbcUrl, String tableName) {
+ public JDBCJournalImpl(String jdbcUrl, String tableName, String jdbcDriverClass) {
this.tableName = tableName;
this.jdbcUrl = jdbcUrl;
+ this.jdbcDriverClass = jdbcDriverClass;
timerThread = "Timer JDBC Journal(" + tableName + ")";
records = new ArrayList<>();
@@ -98,8 +101,15 @@ public class JDBCJournalImpl implements Journal {
@Override
public void start() throws Exception {
- dbDriver = JDBCUtils.getDriver();
- connection = dbDriver.connect(jdbcUrl, new Properties());
+ dbDriver = JDBCUtils.getDriver(jdbcDriverClass);
+
+ try {
+ connection = dbDriver.connect(jdbcUrl, new Properties());
+ }
+ catch (SQLException e) {
+ ActiveMQJournalLogger.LOGGER.error("Unable to connect to database using URL: " + jdbcUrl);
+ throw new RuntimeException("Error connecting to database", e);
+ }
JDBCUtils.createTableIfNotExists(connection, tableName, JDBCJournalRecord.createTableSQL(tableName));
@@ -109,8 +119,8 @@ public class JDBCJournalImpl implements Journal {
deleteJournalRecords = connection.prepareStatement(JDBCJournalRecord.deleteRecordsSQL(tableName));
deleteJournalTxRecords = connection.prepareStatement(JDBCJournalRecord.deleteJournalTxRecordsSQL(tableName));
- syncTimer = new Timer(timerThread, true);
- syncTimer.scheduleAtFixedRate(new JDBCJournalSync(this), SYNC_DELAY * 2, SYNC_DELAY);
+
+ syncTimer.schedule(new JDBCJournalSync(this), SYNC_DELAY * 2, SYNC_DELAY);
started = true;
}
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java
index f284af0ba4..8ff62eeee6 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java
@@ -27,6 +27,7 @@ public class DatabaseStorageConfiguration implements StoreConfiguration {
private String jdbcConnectionUrl = ActiveMQDefaultConfiguration.getDefaultDatabaseUrl();
+ private String jdbcDriverClassName = ActiveMQDefaultConfiguration.getDefaultDriverClassName();
@Override
public StoreType getStoreType() {
return StoreType.DATABASE;
@@ -55,4 +56,12 @@ public class DatabaseStorageConfiguration implements StoreConfiguration {
public String getJdbcConnectionUrl() {
return jdbcConnectionUrl;
}
+
+ public void setJdbcDriverClassName(String jdbcDriverClassName) {
+ this.jdbcDriverClassName = jdbcDriverClassName;
+ }
+
+ public String getJdbcDriverClassName() {
+ return jdbcDriverClassName;
+ }
}
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
index 793abd2678..12ac5e19ed 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
@@ -1150,6 +1150,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
conf.setBindingsTableName(getString(storeNode, "bindings-table-name", conf.getBindingsTableName(), Validators.NO_CHECK));
conf.setMessageTableName(getString(storeNode, "message-table-name", conf.getMessageTableName(), Validators.NO_CHECK));
conf.setJdbcConnectionUrl(getString(storeNode, "jdbc-connection-url", conf.getJdbcConnectionUrl(), Validators.NO_CHECK));
+ conf.setJdbcDriverClassName(getString(storeNode, "jdbc-driver-class-name", conf.getJdbcDriverClassName(), Validators.NO_CHECK));
return conf;
}
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JDBCJournalStorageManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JDBCJournalStorageManager.java
index 4616e78d61..f23b58bfb9 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JDBCJournalStorageManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JDBCJournalStorageManager.java
@@ -42,10 +42,10 @@ public class JDBCJournalStorageManager extends JournalStorageManager {
protected void init(Configuration config, IOCriticalErrorListener criticalErrorListener) {
DatabaseStorageConfiguration dbConf = (DatabaseStorageConfiguration) config.getStoreConfiguration();
- Journal localBindings = new JDBCJournalImpl(dbConf.getJdbcConnectionUrl(), dbConf.getBindingsTableName());
+ Journal localBindings = new JDBCJournalImpl(dbConf.getJdbcConnectionUrl(), dbConf.getBindingsTableName(), dbConf.getJdbcDriverClassName());
bindingsJournal = localBindings;
- Journal localMessage = new JDBCJournalImpl(dbConf.getJdbcConnectionUrl(), dbConf.getMessageTableName());
+ Journal localMessage = new JDBCJournalImpl(dbConf.getJdbcConnectionUrl(), dbConf.getMessageTableName(), dbConf.getJdbcDriverClassName());
messageJournal = localMessage;
}
diff --git a/artemis-server/src/main/resources/schema/artemis-configuration.xsd b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
index 2f7145468a..ef6f1063e8 100644
--- a/artemis-server/src/main/resources/schema/artemis-configuration.xsd
+++ b/artemis-server/src/main/resources/schema/artemis-configuration.xsd
@@ -1516,6 +1516,13 @@
+
+
+
+ The JDBC Driver class name
+
+
+
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
index 06f989163f..3581924422 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
@@ -395,6 +395,7 @@ public abstract class ActiveMQTestBase extends Assert {
dbStorageConfiguration.setJdbcConnectionUrl(getTestJDBCConnectionUrl());
dbStorageConfiguration.setBindingsTableName("BINDINGS");
dbStorageConfiguration.setMessageTableName("MESSAGES");
+ dbStorageConfiguration.setJdbcDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
configuration.setStoreConfiguration(dbStorageConfiguration);
diff --git a/artemis-server/src/test/resources/database-store-config.xml b/artemis-server/src/test/resources/database-store-config.xml
index e387c2cc24..7d08ad4912 100644
--- a/artemis-server/src/test/resources/database-store-config.xml
+++ b/artemis-server/src/test/resources/database-store-config.xml
@@ -24,6 +24,7 @@
jdbc:derby:target/derby/database-store;create=true
BINDINGS_TABLE
MESSAGE_TABLE
+ org.apache.derby.jdbc.EmbeddedDriver
diff --git a/docs/user-manual/en/persistence.md b/docs/user-manual/en/persistence.md
index e5bcf81526..83180b7ccd 100644
--- a/docs/user-manual/en/persistence.md
+++ b/docs/user-manual/en/persistence.md
@@ -376,6 +376,7 @@ To configure Apache ActiveMQ Artemis to use a database for persisting messages a
jdbc:derby:target/derby/database-store;create=true
BINDINGS_TABLE
MESSAGE_TABLE
+ org.apache.derby.jdbc.EmbeddedDriver
```
@@ -392,6 +393,11 @@ To configure Apache ActiveMQ Artemis to use a database for persisting messages a
The name of the table in which messages and related data will be persisted for the ActiveMQ Artemis server. Specifying table names allows users to share single database amongst multiple servers, without interference.
+- `jdbc-driver-class-name`
+
+ The fully qualified class name of the desired database Driver.
+
+
## Configuring Apache ActiveMQ Artemis for Zero Persistence
In some situations, zero persistence is sometimes required for a
diff --git a/pom.xml b/pom.xml
index aae8f1fddb..8294bd044e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -208,6 +208,7 @@
org.apache.derby
derby
${apache.derby.version}
+ test
org.eclipse.paho
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java
index d978f08076..ac2188de39 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jdbc/store/journal/JDBCJournalTest.java
@@ -18,7 +18,6 @@ package org.apache.activemq.artemis.tests.integration.jdbc.store.journal;
import java.util.ArrayList;
import java.util.List;
-import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -41,16 +40,16 @@ public class JDBCJournalTest {
private static final String JOURNAL_TABLE_NAME = "MESSAGE_JOURNAL";
+ private static final String DRIVER_CLASS = "org.apache.derby.jdbc.EmbeddedDriver";
+
private JDBCJournalImpl journal;
private String jdbcUrl;
- private Properties jdbcConnectionProperties;
-
@Before
public void setup() throws Exception {
jdbcUrl = "jdbc:derby:target/data;create=true";
- journal = new JDBCJournalImpl(jdbcUrl, JOURNAL_TABLE_NAME);
+ journal = new JDBCJournalImpl(jdbcUrl, JOURNAL_TABLE_NAME, DRIVER_CLASS);
journal.start();
}