Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 502:83354bd21320 onclient
Upload fake data when an upload request is received
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Tue, 17 Aug 2021 12:21:09 +0200 (2021-08-17) |
parents | 95d1b0a38aed |
children | 7e3987c16cde |
comparison
equal
deleted
inserted
replaced
501:eaad79c3235f | 502:83354bd21320 |
---|---|
8 | 8 |
9 package org.monetdb.jdbc; | 9 package org.monetdb.jdbc; |
10 | 10 |
11 import java.io.File; | 11 import java.io.File; |
12 import java.io.IOException; | 12 import java.io.IOException; |
13 import java.io.PrintStream; | |
14 import java.io.UnsupportedEncodingException; | |
13 import java.net.SocketException; | 15 import java.net.SocketException; |
14 import java.net.SocketTimeoutException; | 16 import java.net.SocketTimeoutException; |
15 import java.sql.CallableStatement; | 17 import java.sql.CallableStatement; |
16 import java.sql.Connection; | 18 import java.sql.Connection; |
17 import java.sql.DatabaseMetaData; | 19 import java.sql.DatabaseMetaData; |
3108 tmpLine = in.readLine(); | 3110 tmpLine = in.readLine(); |
3109 linetype = in.getLineType(); | 3111 linetype = in.getLineType(); |
3110 break; | 3112 break; |
3111 case FILETRANSFER: | 3113 case FILETRANSFER: |
3112 // Consume the command | 3114 // Consume the command |
3115 String transferCommand = in.readLine(); | |
3116 // Consume the fake prompt inserted by MapiSocket. | |
3113 String dummy = in.readLine(); | 3117 String dummy = in.readLine(); |
3114 // Consume the fake prompt inserted by MapiSocket. | 3118 // Handle the request |
3115 dummy = in.readLine(); | 3119 error = handleTransfer(transferCommand); |
3116 // Complain | 3120 if (error != null) { |
3117 out.writeLine("!HY000!JDBC driver does not support file transfer yet\n"); | 3121 out.writeLine("!HY000!" + error + "\n"); |
3122 } | |
3118 // Then prepare for the next iteration | 3123 // Then prepare for the next iteration |
3119 tmpLine = in.readLine(); | 3124 tmpLine = in.readLine(); |
3120 linetype = in.getLineType(); | 3125 linetype = in.getLineType(); |
3121 break; | 3126 break; |
3122 default: // Yeah... in Java this is correct! | 3127 default: // Yeah... in Java this is correct! |
3165 throw new SQLNonTransientConnectionException(e.getMessage() + " (mserver5 still alive?)", "08006"); | 3170 throw new SQLNonTransientConnectionException(e.getMessage() + " (mserver5 still alive?)", "08006"); |
3166 } | 3171 } |
3167 } | 3172 } |
3168 } | 3173 } |
3169 // }}} | 3174 // }}} |
3175 | |
3176 private String handleTransfer(String transferCommand) throws IOException { | |
3177 String[] parts = transferCommand.split(" " , 3); | |
3178 if (parts.length == 3) { | |
3179 if (parts[0].equals("r")) { | |
3180 int offset; | |
3181 try { | |
3182 offset = Integer.parseInt(parts[1]); | |
3183 } catch (NumberFormatException e) { | |
3184 return e.toString(); | |
3185 } | |
3186 return handleUpload(parts[2], true, offset); | |
3187 } | |
3188 if (parts[0].equals("r")) { | |
3189 int offset; | |
3190 try { | |
3191 offset = Integer.parseInt(parts[1]); | |
3192 } catch (NumberFormatException e) { | |
3193 return e.toString(); | |
3194 } | |
3195 return handleUpload(parts[2], false, offset); | |
3196 } | |
3197 } else if (parts.length == 2) { | |
3198 if (parts[0].equals("w")) { | |
3199 return handleDownload(parts[1]); | |
3200 } | |
3201 } | |
3202 return "JDBC does not support this file transfer yet: " + transferCommand; | |
3203 } | |
3204 | |
3205 private String handleUpload(String path, boolean textMode, int offset) throws IOException { | |
3206 boolean wasFaking = server.setInsertFakeFlushes(false); | |
3207 try { | |
3208 MapiSocket.UploadStream us = server.uploadStream(); | |
3209 us.write('\n'); | |
3210 PrintStream ps = null; | |
3211 try { | |
3212 ps = new PrintStream(us, false, "UTF-8"); | |
3213 } catch (UnsupportedEncodingException e) { | |
3214 return e.toString(); | |
3215 } | |
3216 for (int i = 0; i < 1200; i++) { | |
3217 ps.println("banana " + i); | |
3218 } | |
3219 ps.close(); | |
3220 return null; | |
3221 } finally { | |
3222 server.setInsertFakeFlushes(wasFaking); | |
3223 } | |
3224 } | |
3225 | |
3226 private String handleDownload(String path) { | |
3227 return "JDBC driver does not support downloads yet"; | |
3228 } | |
3170 } | 3229 } |