Example #1
0
  private void renderQueryOutput(PrintStream out, OutputFormat outputFormat, boolean interactive) {
    StatusPrinter statusPrinter = null;
    @SuppressWarnings("resource")
    PrintStream errorChannel = interactive ? out : System.err;

    if (interactive) {
      statusPrinter = new StatusPrinter(client, out);
      statusPrinter.printInitialStatusUpdates();
    } else {
      waitForData();
    }

    if ((!client.isFailed()) && (!client.isGone()) && (!client.isClosed())) {
      QueryResults results = client.isValid() ? client.current() : client.finalResults();
      if (results.getUpdateType() != null) {
        renderUpdate(out, results);
      } else if (results.getColumns() == null) {
        errorChannel.printf("Query %s has no columns\n", results.getId());
        return;
      } else {
        renderResults(out, outputFormat, interactive, results.getColumns());
      }
    }

    if (statusPrinter != null) {
      statusPrinter.printFinalInfo();
    }

    if (client.isClosed()) {
      errorChannel.println("Query aborted by user");
    } else if (client.isGone()) {
      errorChannel.println("Query is gone (server restarted?)");
    } else if (client.isFailed()) {
      renderFailure(errorChannel);
    }
  }
Example #2
0
 public void renderOutput(PrintStream out, OutputFormat outputFormat, boolean interactive) {
   Thread clientThread = Thread.currentThread();
   SignalHandler oldHandler =
       Signal.handle(
           SIGINT,
           signal -> {
             if (ignoreUserInterrupt.get() || client.isClosed()) {
               return;
             }
             userAbortedQuery.set(true);
             client.close();
             clientThread.interrupt();
           });
   try {
     renderQueryOutput(out, outputFormat, interactive);
   } finally {
     Signal.handle(SIGINT, oldHandler);
     Thread.interrupted(); // clear interrupt status
   }
 }