comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 505:8a014286dac2 onclient

Add stub code for downloading
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 19 Aug 2021 11:14:53 +0200 (2021-08-19)
parents 8aa70bd8d21f
children 2ae90050720c
comparison
equal deleted inserted replaced
504:8aa70bd8d21f 505:8a014286dac2
149 protected int lastSetQueryTimeout; // 0 means no timeout, which is the default on the server 149 protected int lastSetQueryTimeout; // 0 means no timeout, which is the default on the server
150 150
151 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */ 151 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */
152 private DatabaseMetaData dbmd; 152 private DatabaseMetaData dbmd;
153 153
154 /** A handler for ON CLIENT requests */ 154 /** Handlers for ON CLIENT requests */
155 private MonetUploader uploader; 155 private MonetUploader uploader;
156 private MonetDownloader downloader;
156 157
157 /** 158 /**
158 * Constructor of a Connection for MonetDB. At this moment the 159 * Constructor of a Connection for MonetDB. At this moment the
159 * current implementation limits itself to storing the given host, 160 * current implementation limits itself to storing the given host,
160 * database, username and password for later use by the 161 * database, username and password for later use by the
1208 /** 1209 /**
1209 * Returns the currently registerered MonetUploader, or null 1210 * Returns the currently registerered MonetUploader, or null
1210 */ 1211 */
1211 public MonetUploader getUploader() { 1212 public MonetUploader getUploader() {
1212 return uploader; 1213 return uploader;
1214 }
1215 /**
1216 * Registers a MonetDownloader to support for example COPY ON CLIENT
1217 *
1218 * @param downloader the handler to register, or null to deregister
1219 */
1220 public void setDownloader(MonetDownloader downloader) {
1221 this.downloader = downloader;
1222 }
1223
1224 /**
1225 * Returns the currently registerered MonetDownloadHandler handler, or null
1226 */
1227 public MonetDownloader getDownloader() {
1228 return downloader;
1213 } 1229 }
1214 1230
1215 /** 1231 /**
1216 * Returns a string identifying this Connection to the MonetDB server. 1232 * Returns a string identifying this Connection to the MonetDB server.
1217 * 1233 *
3199 return e.toString(); 3215 return e.toString();
3200 } 3216 }
3201 return handleUpload(parts[2], true, offset); 3217 return handleUpload(parts[2], true, offset);
3202 } else if (transferCommand.startsWith("rb ")) { 3218 } else if (transferCommand.startsWith("rb ")) {
3203 return handleUpload(transferCommand.substring(3), false, 0); 3219 return handleUpload(transferCommand.substring(3), false, 0);
3220 } else if (transferCommand.startsWith("w ")) {
3221 return handleDownload(transferCommand.substring(2));
3204 } else { 3222 } else {
3205 return "JDBC does not support this file transfer yet: " + transferCommand; 3223 return "JDBC does not support this file transfer yet: " + transferCommand;
3206 } 3224 }
3207 } 3225 }
3208 3226
3209 private String handleUpload(String path, boolean textMode, int offset) throws IOException { 3227 private String handleUpload(String path, boolean textMode, int offset) throws IOException {
3210 if (uploader == null) { 3228 if (uploader == null) {
3211 return "No file transfer handler has been registered"; 3229 return "No file upload handler has been registered with the JDBC driver";
3212 } 3230 }
3213 3231
3214 MonetUploadHandle handle = new MonetUploadHandle(server); 3232 MonetUploadHandle handle = new MonetUploadHandle(server);
3215 boolean wasFaking = server.setInsertFakeFlushes(false); 3233 boolean wasFaking = server.setInsertFakeFlushes(false);
3216 try { 3234 try {
3225 server.setInsertFakeFlushes(wasFaking); 3243 server.setInsertFakeFlushes(wasFaking);
3226 } 3244 }
3227 return handle.getError(); 3245 return handle.getError();
3228 } 3246 }
3229 3247
3230 private String handleDownload(String path) { 3248 private String handleDownload(String path) throws IOException {
3231 return "JDBC driver does not support downloads yet"; 3249 if (downloader == null) {
3250 return "No file download handler has been registered with the JDBC driver";
3251 }
3252
3253 MonetDownloadHandle handle = new MonetDownloadHandle(server);
3254 try {
3255 downloader.handleDownload(handle, path, true);
3256 if (!handle.hasBeenUsed()) {
3257 String message = String.format("Call to %s.handleDownload for path '%s' sent neither data nor an error message",
3258 downloader.getClass().getCanonicalName(), path);
3259 throw new IOException(message);
3260 }
3261 handle.close();
3262 } finally {
3263 //
3264 }
3265 return handle.getError();
3232 } 3266 }
3233 } 3267 }