Mercurial > hg > monetdb-java
changeset 553:50b15ee1cb5e onclient
Process suggestions from Martin
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 16 Sep 2021 10:21:48 +0200 (2021-09-16) |
parents | 7b320303b579 |
children | 9fa67487f38a |
files | src/main/java/org/monetdb/jdbc/MonetConnection.java src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java src/main/java/org/monetdb/mcl/io/LineType.java |
diffstat | 3 files changed, 33 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java @@ -3020,7 +3020,7 @@ public class MonetConnection // }}} set reply size // send query to the server - String queryLine = (templ[0] == null ? "" : templ[0]) + query + (templ[1] == null ? "" : templ[1]); + String queryLine = templ[0] + query + templ[1]; out.writeLine(queryLine); // go for new results @@ -3163,7 +3163,7 @@ public class MonetConnection break; default: // Yeah... in Java this is correct! // we have something we don't expect/understand, let's make it an error message - tmpLine = String.format("!M0M10!protocol violation, unexpected %s line: %s", linetype, tmpLine); + tmpLine = "!M0M10!protocol violation, unexpected " + linetype + " line: " + tmpLine; // don't break; fall through... case ERROR: // read everything till the prompt (should be @@ -3211,22 +3211,23 @@ public class MonetConnection // }}} private String handleTransfer(String transferCommand) throws IOException { - String[] parts = transferCommand.split(" ", 3); - if (transferCommand.startsWith("r ") && parts.length == 3) { - final long offset; - try { - offset = Long.parseLong(parts[1]); - } catch (NumberFormatException e) { - return e.toString(); + if (transferCommand.startsWith("r ")) { + String[] parts = transferCommand.split(" ", 3); + if (parts.length == 3) { + final long offset; + try { + offset = Long.parseLong(parts[1]); + } catch (NumberFormatException e) { + return e.toString(); + } + return handleUpload(parts[2], true, offset); } - return handleUpload(parts[2], true, offset); } else if (transferCommand.startsWith("rb ")) { return handleUpload(transferCommand.substring(3), false, 0); } else if (transferCommand.startsWith("w ")) { return handleDownload(transferCommand.substring(2)); - } else { - return "JDBC does not support this file transfer yet: " + transferCommand; } + return "JDBC does not support this file transfer yet: " + transferCommand; } private String handleUpload(String path, boolean textMode, long offset) throws IOException { @@ -3240,8 +3241,7 @@ public class MonetConnection try { uploadHandler.handleUpload(handle, path, textMode, linesToSkip); if (!handle.hasBeenUsed()) { - String message = String.format("Call to %s.handleUpload for path '%s' sent neither data nor an error message", - uploadHandler.getClass().getCanonicalName(), path); + String message = "Call to " + uploadHandler.getClass().getCanonicalName() + ".handleUpload for path '" + path + "' sent neither data nor an error message"; throw new IOException(message); } handle.close(); @@ -3260,8 +3260,7 @@ public class MonetConnection try { downloadHandler.handleDownload(handle, path, true); if (!handle.hasBeenUsed()) { - String message = String.format("Call to %s.handleDownload for path '%s' sent neither data nor an error message", - downloadHandler.getClass().getCanonicalName(), path); + String message = "Call to " + downloadHandler.getClass().getCanonicalName() + ".handleDownload for path '" + path + "' sent neither data nor an error message"; throw new IOException(message); } } finally {
--- a/src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java +++ b/src/main/java/org/monetdb/mcl/io/BufferedMCLReader.java @@ -14,10 +14,6 @@ import java.io.InputStream; import java.io.Reader; import java.io.UnsupportedEncodingException; -import static org.monetdb.mcl.io.LineType.ERROR; -import static org.monetdb.mcl.io.LineType.PROMPT; -import static org.monetdb.mcl.io.LineType.UNKNOWN; - /** * Read text from a character-input stream, buffering characters so as * to provide a means for efficient reading of characters, arrays and @@ -47,7 +43,7 @@ import static org.monetdb.mcl.io.LineTyp public final class BufferedMCLReader extends BufferedReader { /** The type of the last line read */ - private LineType lineType = UNKNOWN; + private LineType lineType = LineType.UNKNOWN; /** * Create a buffering character-input stream that uses a @@ -93,7 +89,7 @@ public final class BufferedMCLReader ext public String readLine() throws IOException { String r = super.readLine(); setLineType(r); - if (lineType == ERROR && r != null && !r.matches("^![0-9A-Z]{5}!.+")) { + if (lineType == LineType.ERROR && r != null && !r.matches("^![0-9A-Z]{5}!.+")) { r = "!22000!" + r.substring(1); } return r; @@ -138,11 +134,11 @@ public final class BufferedMCLReader ext final StringBuilder ret = new StringBuilder(128); String tmp; - while (lineType != PROMPT) { + while (lineType != LineType.PROMPT) { tmp = readLine(); if (tmp == null) throw new IOException("Connection to server lost!"); - if (lineType == ERROR) + if (lineType == LineType.ERROR) ret.append('\n').append(tmp.substring(1)); } return ret.length() == 0 ? null : ret.toString().trim();
--- a/src/main/java/org/monetdb/mcl/io/LineType.java +++ b/src/main/java/org/monetdb/mcl/io/LineType.java @@ -56,32 +56,28 @@ public enum LineType { * Look at a mapi message and decide the LineType */ public static final LineType classify(String line) { - if (line == null) { - return UNKNOWN; + if (line != null) { + if (line.length() > 1) { + return classify(line.charAt(0), line.charAt(1)); + } else if (line.length() == 1) { + return classify(line.charAt(0), 0); + } } - if (line.length() > 1) { - return classify(line.charAt(0), line.charAt(1)); - } else if (line.length() == 1) { - return classify(line.charAt(0), 0); - } else { - return UNKNOWN; - } + return UNKNOWN; } /** * Look at a mapi message and decide the LineType */ public static final LineType classify(byte[] line) { - if (line == null) { - return UNKNOWN; + if (line != null) { + if (line.length > 1) { + return classify(line[0], line[1]); + } else if (line.length == 1) { + return classify(line[0], 0); + } } - if (line.length > 1) { - return classify(line[0], line[1]); - } else if (line.length == 1) { - return classify(line[0], 0); - } else { - return UNKNOWN; - } + return UNKNOWN; } private static final LineType classify(int ch0, int ch1) {