Github user ijokarumawak commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1417#discussion_r97923254
--- Diff:
nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-api/src/main/java/org/apache/nifi/dbcp/DBCPService.java
---
@@ -31,4 +33,6 @@
@CapabilityDescription("Provides Database Connection Pooling Service.
Connections can be asked from pool and returned after usage.")
public interface DBCPService extends ControllerService {
public Connection getConnection() throws ProcessException;
+
+ public DataSource getDataSource() throws ProcessException;
--- End diff --
I concern a bit about exposing DataSource object, because
javax.sql.DataSouce has additional getConnection method that takes username and
password. It enables extension points accessing different user/privilege to the
data source without NiFi data flow manager's intention.
Since DataSource interface only has methods to create a Connection, is it
possible to create a DBCPService instance as following example code to work
with Spring framework? Instead of exposing DataSource instance?
```java
// Acquire DBCPService instance somehow.
final DBCPService dbcpService = null;
// Create DataSource instance extending BasicDataSource which
returns connection created by service.
final DataSource dataSource = new BasicDataSource() {
@Override
public Connection getConnection() throws SQLException {
return dbcpService.getConnection();
}
@Override
public Connection getConnection(String user, String pass)
throws SQLException {
throw new SQLException("User and password can not be
overwritten.");
}
};
// Write code using dataSource instance.
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---