Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 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 |
comparison
equal
deleted
inserted
replaced
552:7b320303b579 | 553:50b15ee1cb5e |
---|---|
3018 curReplySize = size; | 3018 curReplySize = size; |
3019 } | 3019 } |
3020 // }}} set reply size | 3020 // }}} set reply size |
3021 | 3021 |
3022 // send query to the server | 3022 // send query to the server |
3023 String queryLine = (templ[0] == null ? "" : templ[0]) + query + (templ[1] == null ? "" : templ[1]); | 3023 String queryLine = templ[0] + query + templ[1]; |
3024 out.writeLine(queryLine); | 3024 out.writeLine(queryLine); |
3025 | 3025 |
3026 // go for new results | 3026 // go for new results |
3027 String tmpLine = in.readLine(); | 3027 String tmpLine = in.readLine(); |
3028 LineType linetype = in.getLineType(); | 3028 LineType linetype = in.getLineType(); |
3161 } | 3161 } |
3162 linetype = in.getLineType(); | 3162 linetype = in.getLineType(); |
3163 break; | 3163 break; |
3164 default: // Yeah... in Java this is correct! | 3164 default: // Yeah... in Java this is correct! |
3165 // we have something we don't expect/understand, let's make it an error message | 3165 // we have something we don't expect/understand, let's make it an error message |
3166 tmpLine = String.format("!M0M10!protocol violation, unexpected %s line: %s", linetype, tmpLine); | 3166 tmpLine = "!M0M10!protocol violation, unexpected " + linetype + " line: " + tmpLine; |
3167 // don't break; fall through... | 3167 // don't break; fall through... |
3168 case ERROR: | 3168 case ERROR: |
3169 // read everything till the prompt (should be | 3169 // read everything till the prompt (should be |
3170 // error) we don't know if we ignore some | 3170 // error) we don't know if we ignore some |
3171 // garbage here... but the log should reveal that | 3171 // garbage here... but the log should reveal that |
3209 } | 3209 } |
3210 } | 3210 } |
3211 // }}} | 3211 // }}} |
3212 | 3212 |
3213 private String handleTransfer(String transferCommand) throws IOException { | 3213 private String handleTransfer(String transferCommand) throws IOException { |
3214 String[] parts = transferCommand.split(" ", 3); | 3214 if (transferCommand.startsWith("r ")) { |
3215 if (transferCommand.startsWith("r ") && parts.length == 3) { | 3215 String[] parts = transferCommand.split(" ", 3); |
3216 final long offset; | 3216 if (parts.length == 3) { |
3217 try { | 3217 final long offset; |
3218 offset = Long.parseLong(parts[1]); | 3218 try { |
3219 } catch (NumberFormatException e) { | 3219 offset = Long.parseLong(parts[1]); |
3220 return e.toString(); | 3220 } catch (NumberFormatException e) { |
3221 } | 3221 return e.toString(); |
3222 return handleUpload(parts[2], true, offset); | 3222 } |
3223 return handleUpload(parts[2], true, offset); | |
3224 } | |
3223 } else if (transferCommand.startsWith("rb ")) { | 3225 } else if (transferCommand.startsWith("rb ")) { |
3224 return handleUpload(transferCommand.substring(3), false, 0); | 3226 return handleUpload(transferCommand.substring(3), false, 0); |
3225 } else if (transferCommand.startsWith("w ")) { | 3227 } else if (transferCommand.startsWith("w ")) { |
3226 return handleDownload(transferCommand.substring(2)); | 3228 return handleDownload(transferCommand.substring(2)); |
3227 } else { | 3229 } |
3228 return "JDBC does not support this file transfer yet: " + transferCommand; | 3230 return "JDBC does not support this file transfer yet: " + transferCommand; |
3229 } | |
3230 } | 3231 } |
3231 | 3232 |
3232 private String handleUpload(String path, boolean textMode, long offset) throws IOException { | 3233 private String handleUpload(String path, boolean textMode, long offset) throws IOException { |
3233 if (uploadHandler == null) { | 3234 if (uploadHandler == null) { |
3234 return "No file upload handler has been registered with the JDBC driver"; | 3235 return "No file upload handler has been registered with the JDBC driver"; |
3238 Upload handle = new Upload(server); | 3239 Upload handle = new Upload(server); |
3239 boolean wasFaking = server.setInsertFakePrompts(false); | 3240 boolean wasFaking = server.setInsertFakePrompts(false); |
3240 try { | 3241 try { |
3241 uploadHandler.handleUpload(handle, path, textMode, linesToSkip); | 3242 uploadHandler.handleUpload(handle, path, textMode, linesToSkip); |
3242 if (!handle.hasBeenUsed()) { | 3243 if (!handle.hasBeenUsed()) { |
3243 String message = String.format("Call to %s.handleUpload for path '%s' sent neither data nor an error message", | 3244 String message = "Call to " + uploadHandler.getClass().getCanonicalName() + ".handleUpload for path '" + path + "' sent neither data nor an error message"; |
3244 uploadHandler.getClass().getCanonicalName(), path); | |
3245 throw new IOException(message); | 3245 throw new IOException(message); |
3246 } | 3246 } |
3247 handle.close(); | 3247 handle.close(); |
3248 } finally { | 3248 } finally { |
3249 server.setInsertFakePrompts(wasFaking); | 3249 server.setInsertFakePrompts(wasFaking); |
3258 | 3258 |
3259 Download handle = new Download(server); | 3259 Download handle = new Download(server); |
3260 try { | 3260 try { |
3261 downloadHandler.handleDownload(handle, path, true); | 3261 downloadHandler.handleDownload(handle, path, true); |
3262 if (!handle.hasBeenUsed()) { | 3262 if (!handle.hasBeenUsed()) { |
3263 String message = String.format("Call to %s.handleDownload for path '%s' sent neither data nor an error message", | 3263 String message = "Call to " + downloadHandler.getClass().getCanonicalName() + ".handleDownload for path '" + path + "' sent neither data nor an error message"; |
3264 downloadHandler.getClass().getCanonicalName(), path); | |
3265 throw new IOException(message); | 3264 throw new IOException(message); |
3266 } | 3265 } |
3267 } finally { | 3266 } finally { |
3268 handle.close(); | 3267 handle.close(); |
3269 } | 3268 } |