turcsanyip commented on a change in pull request #5003:
URL: https://github.com/apache/nifi/pull/5003#discussion_r614074414
##########
File path:
nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java
##########
@@ -460,45 +455,21 @@ public void onConfigured(final ConfigurationContext
context) throws Initializati
});
}
- private Long extractMillisWithInfinite(PropertyValue prop) {
- return "-1".equals(prop.getValue()) ? -1 :
prop.asTimePeriod(TimeUnit.MILLISECONDS);
+ private Driver getDriver(final String driverName, final String url) {
+ try {
+ final Class<?> clazz = Class.forName(driverName);
+ final Driver driver = DriverManager.getDriver(url);
+
+ return (driver == null)
Review comment:
`DriverManager` never returns `null` but throws `SQLException` if no
suitable driver found.
To handle that case, the exception handling needs to be improved, like this:
- try-catch for `Class.forName()` and handle `ClassNotFoundException` as
failure
- try-catch for `DriverManager.getDriver()` and handle `SQLException` as
falling back to direct instantiation
- try-catch for `clazz.newInstance()` and handle `IllegalAccessException`
and `InstantiationException` as failure
However, this complicated error handling is not needed in my opinion. JDBC
compliant drivers must register themselves and if the provided jdbc url is
correct, then `DriverManager.getDriver(url)` should find the driver.
So the following would simply be enough:
```
Class.forName(driverClass);
return DriverManager.getDriver(jdbcUrl);
```
Though I do not insist on it. The fallback mechanism can be implemented just
for sure.
Additional info from JDBC spec
(http://download.oracle.com/otn-pub/jcp/jdbc-4_1-mrel-spec/jdbc4.1-fr-spec.pdf):
> JDBC drivers must implement the Driver interface, and the implementation
must contain a static initializer that will be called when the driver is
loaded. This initializer registers a new instance of itself with the
DriverManager.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]