risdenk commented on a change in pull request #241: KNOX-1742 - Simple SQL 
Client in KnoxShell for access to JDBC sources
URL: https://github.com/apache/knox/pull/241#discussion_r368778336
 
 

 ##########
 File path: 
gateway-shell/src/main/java/org/apache/knox/gateway/shell/jdbc/KnoxLine.java
 ##########
 @@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.shell.jdbc;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.knox.gateway.shell.CredentialCollectionException;
+import org.apache.knox.gateway.shell.Credentials;
+import org.apache.knox.gateway.shell.KnoxDataSource;
+import org.apache.knox.gateway.shell.KnoxSession;
+import org.apache.knox.gateway.shell.table.KnoxShellTable;
+
+public class KnoxLine {
+  String user;
+  String pass;
+  KnoxDataSource datasource;
+  Connection conn;
+
+  public void execute(String[] args)
+      throws ClassNotFoundException, SQLException, 
CredentialCollectionException {
+
+    Runtime.getRuntime().addShutdownHook(new Thread() {
+      @Override
+      public void run() {
+        System.out.println("Closing any open connections ...");
+        closeConnection();
+      }
+    });
+    executeShell();
+  }
+
+  private void executeShell() {
+    String sql;
+
+    System.out.println(" _                    _ _            ");
+    System.out.println("| | ___ __   _____  _| (_)_ __   ___ ");
+    System.out.println("| |/ / '_ \\ / _ \\ \\/ / | | '_ \\ / _ \\");
+    System.out.println("|   <| | | | (_) >  <| | | | | |  __/");
+    System.out.println("|_|\\_\\_| |_|\\___/_/\\_\\_|_|_| |_|\\\\__|");
+    System.out.println("powered by Apache Knox");
+    System.out.println("");
+    System.out.println("");
+
+    while(true) {
+      sql = System.console().readLine("knoxline> ");
+      if (sql != null && !sql.isEmpty()) {
+        if (sql.startsWith(":ds") || sql.startsWith(":datasource")) {
+          try {
+            processDataSourceCommand(sql);
+          } catch (CredentialCollectionException | SQLException e) {
+            e.printStackTrace();
+          }
+        }
+        else {
+          // Configure JDBC connection
+          if (datasource != null) {
+            System.out.println(sql);
+            try (Statement statement = conn.createStatement()) {
+              if (statement.execute(sql)) {
+                try (ResultSet resultSet = statement.getResultSet()) {
+                  KnoxShellTable table = 
KnoxShellTable.builder().jdbc().resultSet(resultSet);
+                  System.out.println(table.toString());
+                  System.out.println("\nRows: " + table.getRows().size() + 
"\n");
+                }
+              }
+            }
+            catch(SQLException e) {
+              //e.printStackTrace()
+              System.out.println("SQL Exception encountered... " + 
e.getMessage());
+  //            if 
(e.getMessage().contains("org.apache.thrift.transport.TTransportException")) {
+  //              System.out.println("reconnecting... ");
+  //              connection = DriverManager.getConnection( connectionString, 
user, pass );
 
 Review comment:
   Commented out code?

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to