You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2024/08/22 11:58:51 UTC
(jackrabbit-oak) 01/01: OAK-11053: RDB utils/fixtures: silence stack traces, slightly refactor
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch OAK-11053
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit bd76a69070f41e379690160dbbb247012d6ad5c8
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Aug 22 12:58:32 2024 +0100
OAK-11053: RDB utils/fixtures: silence stack traces, slightly refactor
---
.../plugins/document/rdb/RDBDataSourceFactory.java | 50 +++++++++++-----------
.../oak/plugins/document/DocumentStoreFixture.java | 3 +-
2 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
index fe9ca370fe..554c7db7e0 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
@@ -26,12 +26,12 @@ import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
-import java.util.logging.Logger;
import javax.sql.DataSource;
import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@@ -39,41 +39,40 @@ import org.slf4j.LoggerFactory;
*/
public class RDBDataSourceFactory {
- private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(RDBDataSourceFactory.class);
+ static final Logger LOG = LoggerFactory.getLogger(RDBDataSourceFactory.class);
- public static DataSource forJdbcUrl(String url, String username, String passwd, String driverName) {
+ public static DataSource forJdbcUrl(String url, String username, String passwd, String specifiedDriverName) {
+
+ String driverName = specifiedDriverName;
// load driver class when specified
if (driverName != null && !driverName.isEmpty()) {
- LOG.info("trying to load {}", driverName);
+ LOG.info("trying to load specified driver {}", driverName);
+ } else {
+ // otherwise try to determine driver from JDBC URL
+ driverName = RDBJDBCTools.driverForDBType(RDBJDBCTools.jdbctype(url));
+ if (driverName != null && !driverName.isEmpty()) {
+ LOG.info("trying to load defaulted driver {}", driverName);
+ }
+ }
+ if (driverName != null && !driverName.isEmpty()) {
try {
Class.forName(driverName);
} catch (ClassNotFoundException ex) {
- LOG.error("driver " + driverName + " not loaded", ex);
- }
- } else {
- // try to determine driver from JDBC URL
- String defaultDriver = RDBJDBCTools.driverForDBType(RDBJDBCTools.jdbctype(url));
- if (defaultDriver != null && !defaultDriver.isEmpty()) {
- LOG.info("trying to load {}", defaultDriver);
-
- try {
- Class.forName(defaultDriver);
- } catch (ClassNotFoundException ex) {
- LOG.error("driver " + defaultDriver + " not loaded", ex);
- }
+ LOG.debug("driver " + driverName + " not loaded", ex);
+ LOG.info("driver {} not loaded ({})", driverName, ex.getClass());
}
}
try {
- LOG.debug("Getting driver for " + url);
+ LOG.info("Getting driver for {}", url);
Driver d = DriverManager.getDriver(url);
String classname = "org.apache.tomcat.jdbc.pool.DataSource";
try {
Class<?> dsclazz = Class.forName(classname);
- DataSource ds = (DataSource) dsclazz.newInstance();
+ DataSource ds = (DataSource) dsclazz.getDeclaredConstructor().newInstance();
dsclazz.getMethod("setDriverClassName", String.class).invoke(ds, d.getClass().getName());
dsclazz.getMethod("setUsername", String.class).invoke(ds, username);
dsclazz.getMethod("setPassword", String.class).invoke(ds, passwd);
@@ -88,12 +87,14 @@ public class RDBDataSourceFactory {
return new CloseableDataSource(ds);
} catch (Exception ex) {
String message = "trying to create datasource " + classname;
- LOG.info(message, ex);
+ LOG.debug(message, ex);
+ LOG.info(message + " (" + ex.getMessage() + ")");
throw new DocumentStoreException(message, ex);
}
} catch (SQLException ex) {
- String message = "trying to obtain driver for " + url;
- LOG.info(message, ex);
+ String message = "failed to to obtain driver for " + url;
+ LOG.debug(message, ex);
+ LOG.info(message + " (" + ex.getMessage() + ")");
throw new DocumentStoreException(message, ex);
}
}
@@ -139,6 +140,7 @@ public class RDBDataSourceFactory {
return c.isInstance(this) || c.isInstance(this.ds) || this.ds.isWrapperFor(c);
}
+ @SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> c) throws SQLException {
return c.isInstance(this) ? (T) this : c.isInstance(this.ds) ? (T) this.ds : this.ds.unwrap(c);
@@ -171,9 +173,7 @@ public class RDBDataSourceFactory {
return this.ds.getConnection(user, passwd);
}
- // needed in Java 7...
- @SuppressWarnings("unused")
- public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new SQLFeatureNotSupportedException();
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
index 8d47934e45..3a4efe9db2 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreFixture.java
@@ -186,7 +186,8 @@ public abstract class DocumentStoreFixture {
try {
dataSource = new RDBDataSourceWrapper(RDBDataSourceFactory.forJdbcUrl(url, username, passwd));
} catch (Exception ex) {
- LOG.info("Database instance not available at " + url + ", skipping tests...", ex);
+ LOG.debug("Database instance not available at " + url + ", skipping tests...", ex);
+ LOG.info("Database instance not available at {} because of '{}', skipping tests...", url, ex.getMessage());
}
}