Skip to content

Commit

Permalink
CLC v1.9.3
Browse files Browse the repository at this point in the history
Mono retring fix.
Postgres migration apply fix - use simple query protocol to avoid statement hanging.
Minor exception handling fixes.
  • Loading branch information
zapov committed Feb 3, 2018
1 parent 63b94d6 commit 7edbeb5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CommandLineClient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.dslplatform</groupId>
<artifactId>dsl-clc</artifactId>
<packaging>jar</packaging>
<version>1.9.2</version>
<version>1.9.3</version>
<name>DSL Platform - Compiler Command-Line Client</name>
<url>https://github.com/ngs-doo/dsl-compiler-client</url>
<description>Command line client for interaction with DSL Platform compiler (https://dsl-platform.com)</description>
Expand All @@ -13,7 +13,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1.jre6</version>
<version>42.2.1.jre6</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,13 @@ private static Either<byte[]> 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 {
Expand Down Expand Up @@ -835,11 +839,4 @@ static boolean monoNativeFailure(Either<Utils.CommandResult> result) {
return monoNativeFailure(commandResult.output) || monoNativeFailure(commandResult.error);
}
}

private static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException ignore) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
}
}
}
Expand Down

0 comments on commit 7edbeb5

Please sign in to comment.