lmccay commented on a change in pull request #231: KNOX-2128 - Custom
DataSource and SQL Commands for KnoxShell and KnoxShellTable
URL: https://github.com/apache/knox/pull/231#discussion_r366512363
##########
File path:
gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/JDBCKnoxShellTableBuilder.java
##########
@@ -109,12 +107,15 @@ public KnoxShellTable sql(String sql) throws
IOException, SQLException {
return this.table;
}
- private Connection createConnection() throws SQLException {
- if (StringUtils.isNotBlank(username) && pass != null) {
- return DriverManager.getConnection(connectionUrl, username, pass);
- } else {
- return DriverManager.getConnection(connectionUrl);
+ public Connection createConnection() throws SQLException {
+ Connection con = null;
+ if (username != null && pass != null) {
+ con = DriverManager.getConnection(connectionUrl, username, pass);
+ }
+ else {
+ con = DriverManager.getConnection(connectionUrl);
}
+ return con;
Review comment:
package protected will not be sufficient since it is required to called as
part of the fluent API for "applications" that want to own the management of
the connection rather than rely on it to be opened and closed within the call
itself.
See this sort of code where the connection is externalized:
protected Connection getConnection(KnoxDataSource ds, String user, String
pass) throws SQLException, Exception {
Connection conn = getConnectionFromSession(ds);
if (conn == null) {
if (user != null && pass != null) {
conn = KnoxShellTable.builder().jdbc()
.connectTo(ds.getConnectStr())
.driver(ds.getDriver())
.username(user)
.password(pass)
.createConnection();
}
else {
conn = KnoxShellTable.builder().jdbc()
.connectTo(ds.getConnectStr())
.driver(ds.getDriver())
.createConnection();
}
HashMap<String, Connection> connections =
(HashMap<String, Connection>) getVariables()
.getOrDefault(KNOXDATASOURCE_CONNECTIONS,
new HashMap<String, Connection>());
connections.put(ds.getName(), conn);
getVariables().put(KNOXDATASOURCE_CONNECTIONS, connections);
}
return conn;
}
----------------------------------------------------------------
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]
With regards,
Apache Git Services