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

baedke pushed a commit to branch OAK-11468
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/OAK-11468 by this push:
     new 00c32f7bcf OAK-11468: RDBDataSourceFactory unnecessarily loads the 
JDBC driver class explicitly.
00c32f7bcf is described below

commit 00c32f7bcf28717568835659257c1987ccd66e50
Author: Manfred Baedke <[email protected]>
AuthorDate: Mon Feb 17 11:52:33 2025 +0100

    OAK-11468: RDBDataSourceFactory unnecessarily loads the JDBC driver class 
explicitly.
    
    Removed unnecessary code.
---
 .../plugins/document/rdb/RDBDataSourceFactory.java | 70 ++++++----------------
 1 file changed, 17 insertions(+), 53 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 554c7db7e0..eaaa60f589 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
@@ -41,68 +41,32 @@ public class RDBDataSourceFactory {
 
     static final Logger LOG = 
LoggerFactory.getLogger(RDBDataSourceFactory.class);
 
-    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 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.debug("driver " + driverName + " not loaded", ex);
-                LOG.info("driver {} not loaded ({})", driverName, 
ex.getClass());
-            }
-        }
+    public static DataSource forJdbcUrl(String url, String username, String 
passwd) {
 
+        String classname = "org.apache.tomcat.jdbc.pool.DataSource";
         try {
-            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.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);
-                dsclazz.getMethod("setUrl", String.class).invoke(ds, url);
-                String interceptors = SystemPropertySupplier
-                        
.create("org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory.jdbcInterceptors",
-                                
"SlowQueryReport(threshold=10000);ConnectionState;StatementCache")
-                        .loggingTo(LOG).get();
-                if (!interceptors.isEmpty()) {
-                    dsclazz.getMethod("setJdbcInterceptors", 
String.class).invoke(ds, interceptors);
-                }
-                return new CloseableDataSource(ds);
-            } catch (Exception ex) {
-                String message = "trying to create datasource " + classname;
-                LOG.debug(message, ex);
-                LOG.info(message + " (" + ex.getMessage() + ")");
-                throw new DocumentStoreException(message, ex);
+            Class<?> dsclazz = Class.forName(classname);
+            DataSource ds = (DataSource) 
dsclazz.getDeclaredConstructor().newInstance();
+            dsclazz.getMethod("setDriverClassName", String.class).invoke(ds, 
DriverManager.getDriver(url).getClass().getName());
+            dsclazz.getMethod("setUsername", String.class).invoke(ds, 
username);
+            dsclazz.getMethod("setPassword", String.class).invoke(ds, passwd);
+            dsclazz.getMethod("setUrl", String.class).invoke(ds, url);
+            String interceptors = SystemPropertySupplier
+                    
.create("org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory.jdbcInterceptors",
+                            
"SlowQueryReport(threshold=10000);ConnectionState;StatementCache")
+                    .loggingTo(LOG).get();
+            if (!interceptors.isEmpty()) {
+                dsclazz.getMethod("setJdbcInterceptors", 
String.class).invoke(ds, interceptors);
             }
-        } catch (SQLException ex) {
-            String message = "failed to to obtain driver for " + url;
+            return new CloseableDataSource(ds);
+        } catch (Exception ex) {
+            String message = "trying to create datasource " + classname;
             LOG.debug(message, ex);
             LOG.info(message + " (" + ex.getMessage() + ")");
             throw new DocumentStoreException(message, ex);
         }
     }
 
-    public static DataSource forJdbcUrl(String url, String username, String 
passwd) {
-        return forJdbcUrl(url, username, passwd, null);
-    }
-
     /**
      * A {@link Closeable} {@link DataSource} based on a generic {@link Source}
      * .

Reply via email to