From 7edbeb52199e2b1f5a3eb980bc889d731424512a Mon Sep 17 00:00:00 2001 From: Rikard Pavelic Date: Sat, 3 Feb 2018 10:18:11 +0100 Subject: [PATCH] CLC v1.9.3 Mono retring fix. Postgres migration apply fix - use simple query protocol to avoid statement hanging. Minor exception handling fixes. --- CommandLineClient/pom.xml | 4 +-- .../dslplatform/compiler/client/Context.java | 5 +++- .../client/parameters/DslCompiler.java | 17 +++++------ .../client/parameters/PostgresConnection.java | 28 +++++++++++-------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/CommandLineClient/pom.xml b/CommandLineClient/pom.xml index b3f47a6..1539ceb 100644 --- a/CommandLineClient/pom.xml +++ b/CommandLineClient/pom.xml @@ -4,7 +4,7 @@ com.dslplatform dsl-clc jar - 1.9.2 + 1.9.3 DSL Platform - Compiler Command-Line Client https://github.com/ngs-doo/dsl-compiler-client Command line client for interaction with DSL Platform compiler (https://dsl-platform.com) @@ -13,7 +13,7 @@ org.postgresql postgresql - 42.1.1.jre6 + 42.2.1.jre6 org.fusesource.jansi diff --git a/CommandLineClient/src/main/java/com/dslplatform/compiler/client/Context.java b/CommandLineClient/src/main/java/com/dslplatform/compiler/client/Context.java index 00375c1..c7a1838 100644 --- a/CommandLineClient/src/main/java/com/dslplatform/compiler/client/Context.java +++ b/CommandLineClient/src/main/java/com/dslplatform/compiler/client/Context.java @@ -132,7 +132,10 @@ public void error(final String value) { } public void error(final Exception ex) { - error(ex.getMessage()); + if (ex instanceof ExitException) return; + final String description = ex.getMessage(); + if (description == null) error(ex.getClass().getName() + " error without description"); + else error(description); if (withLog) { final StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); diff --git a/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/DslCompiler.java b/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/DslCompiler.java index 708d590..fdd4e2a 100644 --- a/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/DslCompiler.java +++ b/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/DslCompiler.java @@ -544,9 +544,13 @@ private static Either runCompilerFile( arguments.add(0, compiler.getAbsolutePath()); result = Utils.runCommand(context, mono.get(), compiler.getParentFile(), arguments); if(monoNativeFailure(result) && promptUserMonoRetry(context)) { - context.warning("Retrying in 1 second ..."); - context.error(result.explainError()); - sleep(1000); + context.warning("Retrying in 2 seconds ..."); + context.error(result.whyNot()); + try { + Thread.sleep(2000); + } catch (InterruptedException ignore) { + throw new ExitException(); + } result = Utils.runCommand(context, mono.get(), compiler.getParentFile(), arguments); } } else { @@ -835,11 +839,4 @@ static boolean monoNativeFailure(Either result) { return monoNativeFailure(commandResult.output) || monoNativeFailure(commandResult.error); } } - - private static void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException ignore) { - } - } } diff --git a/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/PostgresConnection.java b/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/PostgresConnection.java index af5eabc..f541189 100644 --- a/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/PostgresConnection.java +++ b/CommandLineClient/src/main/java/com/dslplatform/compiler/client/parameters/PostgresConnection.java @@ -3,7 +3,6 @@ import com.dslplatform.compiler.client.CompileParameter; import com.dslplatform.compiler.client.Context; import com.dslplatform.compiler.client.ExitException; -import org.postgresql.core.*; import java.sql.*; import java.util.*; @@ -125,10 +124,12 @@ public static void execute(final Context context, final String sql) throws ExitE final String connectionString = "jdbc:postgresql://" + context.get(INSTANCE); Connection conn; - final BaseStatement stmt; + final Statement stmt; try { - conn = DriverManager.getConnection(connectionString); - stmt = (BaseStatement) conn.createStatement(); + final Properties props = new Properties(); + props.setProperty("preferQueryMode", "simple"); + conn = DriverManager.getConnection(connectionString, props); + stmt = conn.createStatement(); } catch (SQLException e) { context.error("Error opening connection to " + connectionString); context.error(e); @@ -140,17 +141,21 @@ public static void execute(final Context context, final String sql) throws ExitE final long startAt = System.currentTimeMillis(); final boolean[] isDone = new boolean[1]; final boolean[] hasErrors = new boolean[1]; + final boolean[] waitingAnswer = new boolean[1]; final Thread waitResp = new Thread(new Runnable() { @Override public void run() { try { - stmt.executeWithFlags(sql, QueryExecutor.QUERY_EXECUTE_AS_SIMPLE); + stmt.execute(sql); hasErrors[0] = false; } catch (Exception ex) { context.error(ex); hasErrors[0] = true; } isDone[0] = true; + if (waitingAnswer[0]) { + context.show("Query finished while waiting for answer"); + } } }); waitResp.start(); @@ -165,12 +170,13 @@ public void run() { context.warning("Still waiting..."); } if (!isDone[0] && (timeout % 30 == 0) && context.canInteract()) { - String response = context.ask("Abort executing query [y/N]?"); - if ("y".equalsIgnoreCase(response)) { - if (!isDone[0]) { - context.error("Canceled SQL script execution"); - throw new ExitException(); - } + waitingAnswer[0] = true; + final String response = context.ask("Abort executing query [y/N]?"); + waitingAnswer[0] = false; + if ("y".equalsIgnoreCase(response) && !isDone[0]) { + stmt.cancel(); + context.error("Canceled SQL script execution"); + throw new ExitException(); } } }