[ https://issues.apache.org/jira/browse/KNOX-2128?focusedWorklogId=371784&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-371784 ]
ASF GitHub Bot logged work on KNOX-2128: ---------------------------------------- Author: ASF GitHub Bot Created on: 14/Jan/20 18:52 Start Date: 14/Jan/20 18:52 Worklog Time Spent: 10m Work Description: lmccay commented on 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: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 371784) Time Spent: 2.5h (was: 2h 20m) > Custom DataSource and SQL Commands for KnoxShell and KnoxShellTable > ------------------------------------------------------------------- > > Key: KNOX-2128 > URL: https://issues.apache.org/jira/browse/KNOX-2128 > Project: Apache Knox > Issue Type: New Feature > Components: KnoxShell > Reporter: Larry McCay > Assignee: Larry McCay > Priority: Major > Labels: kip-14 > Fix For: 1.4.0 > > Time Spent: 2.5h > Remaining Estimate: 0h > > As described in > [KIP-14|https://cwiki.apache.org/confluence/display/KNOX/KIP-14+-+KnoxShell+Improvements+for+Tabular+Data] > , GroovyShell allows for the extension of the shell itself with custom > commands. By providing commands for the management of DataSource > configuration and use in SQL queries, we can simplify the interaction with > SQL engines and databases for JDBC-based database access in KnoxShell to make > for a powerful scripting and shell environment. > DataSource and SQL commands really go hand in hand here and will be done at > the same time. > * Datasources (:datasource|:ds) CRUD and select operations for a set of JDBC > datasources that are persisted to disk in the user home directory > * SQL (:SQL|:sql) SQL query execution with persisted SQL history per > datasource > Examples: > {code} > :ds add test_ds connectStr driverClass authn_type > {code} > The above will add a new datasource to the KnoxShell environment with the > name test_ds the required connectStr, the classname of the driver to use and > either "basic" or "none" for authentication requirements. > Invoking the above will actually result in a table rendering of all the > currently configured datasources. > When there are more than one, the following command must be used to select > the datasource to use for SQL commands: > {code} > :ds select test_ds > {code} > This command selects the desired datasource by name and sets it as the select > datasource context within the environment. > If there is only one datasource in the environment, its selection is implied > and the explicit selection isn't required with the above command. > Once a datasource is selected the SQL command may be used to interact with > the datasource. > {code} > :sql assign books > {code} > The above command will present the user with a Java Swing dialog to prompt > for a SQL statement, challenge the user for authentication if required and > leverage the KnoxShellTable JDBC builder API to submit the SQL query to the > selected datasource and return the resultset in a KnoxShellTable variable in > KnoxShell environment with the name books. It will also result in the > rendering of the tablular result. > The KnoxShellTable variable called "books" may then be used directly within > the KnoxShell environment using the KnoxShellTable fluent API to select, > filter, sort and join with other tables - as desired. > {code} > :ds remove test_ds > {code} > The above command invocation will remove the configured datasource and > deselect it - if selected and persist the changes. > > -- This message was sent by Atlassian Jira (v8.3.4#803005)