Skip to content

Commit

Permalink
Merge pull request #45540 from yrodiere/agroal-no-driver-service-loading
Browse files Browse the repository at this point in the history
Don't load JDBC drivers through the service loader without using them
  • Loading branch information
gsmet authored Jan 13, 2025
2 parents 429c2d0 + 0262be6 commit f2d0581
Showing 1 changed file with 0 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.quarkus.agroal.runtime;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.Statement;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -157,9 +154,6 @@ public AgroalDataSource createDataSource(String dataSourceName) {
"Datasource " + dataSourceName + " does not have a JDBC URL and should not be created");
}

// we first make sure that all available JDBC drivers are loaded in the current TCCL
loadDriversInTCCL();

AgroalDataSourceSupport.Entry matchingSupportEntry = agroalDataSourceSupport.entries.get(dataSourceName);
String resolvedDriverClass = matchingSupportEntry.resolvedDriverClass;
Class<?> driver;
Expand Down Expand Up @@ -354,21 +348,4 @@ public boolean isValid(Connection connection) {
poolConfiguration.flushOnClose(dataSourceJdbcRuntimeConfig.flushOnClose());
}

/**
* Uses the {@link ServiceLoader#load(Class) ServiceLoader to load the JDBC drivers} in context
* of the current {@link Thread#getContextClassLoader() TCCL}
*/
private static void loadDriversInTCCL() {
// load JDBC drivers in the current TCCL
final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
final Iterator<Driver> iterator = drivers.iterator();
while (iterator.hasNext()) {
try {
// load the driver
iterator.next();
} catch (Throwable t) {
// ignore
}
}
}
}

0 comments on commit f2d0581

Please sign in to comment.