Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 504:8aa70bd8d21f onclient
Register upload handler and download handler separately
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 19 Aug 2021 10:51:53 +0200 (2021-08-19) |
parents | 7e3987c16cde |
children | 8a014286dac2 |
comparison
equal
deleted
inserted
replaced
503:7e3987c16cde | 504:8aa70bd8d21f |
---|---|
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; | |
15 import java.net.SocketException; | 13 import java.net.SocketException; |
16 import java.net.SocketTimeoutException; | 14 import java.net.SocketTimeoutException; |
17 import java.sql.CallableStatement; | 15 import java.sql.CallableStatement; |
18 import java.sql.Connection; | 16 import java.sql.Connection; |
19 import java.sql.DatabaseMetaData; | 17 import java.sql.DatabaseMetaData; |
152 | 150 |
153 /** 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 */ |
154 private DatabaseMetaData dbmd; | 152 private DatabaseMetaData dbmd; |
155 | 153 |
156 /** A handler for ON CLIENT requests */ | 154 /** A handler for ON CLIENT requests */ |
157 private MonetFileTransfer fileTransfer; | 155 private MonetUploader uploader; |
158 | 156 |
159 /** | 157 /** |
160 * Constructor of a Connection for MonetDB. At this moment the | 158 * Constructor of a Connection for MonetDB. At this moment the |
161 * current implementation limits itself to storing the given host, | 159 * current implementation limits itself to storing the given host, |
162 * database, username and password for later use by the | 160 * database, username and password for later use by the |
1197 public void setTypeMap(final Map<String, Class<?>> map) { | 1195 public void setTypeMap(final Map<String, Class<?>> map) { |
1198 typeMap = map; | 1196 typeMap = map; |
1199 } | 1197 } |
1200 | 1198 |
1201 /** | 1199 /** |
1202 * Registers a MonetFileTransfer handler to support for example COPY ON CLIENT | 1200 * Registers a MonetUploader to support for example COPY ON CLIENT |
1203 * | 1201 * |
1204 * @param fileTransfer the handler to register, or null to deregister | 1202 * @param uploader the handler to register, or null to deregister |
1205 */ | 1203 */ |
1206 public void setFileTransfer(MonetFileTransfer fileTransfer) { | 1204 public void setUploader(MonetUploader uploader) { |
1207 this.fileTransfer = fileTransfer; | 1205 this.uploader = uploader; |
1208 } | 1206 } |
1209 | 1207 |
1210 /** | 1208 /** |
1211 * Returns the currently registerered MonetFileTransfer handler, or null | 1209 * Returns the currently registerered MonetUploader, or null |
1212 */ | 1210 */ |
1213 public MonetFileTransfer setFileTransfer() { | 1211 public MonetUploader getUploader() { |
1214 return fileTransfer; | 1212 return uploader; |
1215 } | 1213 } |
1216 | 1214 |
1217 /** | 1215 /** |
1218 * Returns a string identifying this Connection to the MonetDB server. | 1216 * Returns a string identifying this Connection to the MonetDB server. |
1219 * | 1217 * |
3207 return "JDBC does not support this file transfer yet: " + transferCommand; | 3205 return "JDBC does not support this file transfer yet: " + transferCommand; |
3208 } | 3206 } |
3209 } | 3207 } |
3210 | 3208 |
3211 private String handleUpload(String path, boolean textMode, int offset) throws IOException { | 3209 private String handleUpload(String path, boolean textMode, int offset) throws IOException { |
3212 if (fileTransfer == null) { | 3210 if (uploader == null) { |
3213 return "No file transfer handler has been registered"; | 3211 return "No file transfer handler has been registered"; |
3214 } | 3212 } |
3215 | 3213 |
3216 MonetUploadHandle handle = new MonetUploadHandle(server); | 3214 MonetUploadHandle handle = new MonetUploadHandle(server); |
3217 boolean wasFaking = server.setInsertFakeFlushes(false); | 3215 boolean wasFaking = server.setInsertFakeFlushes(false); |
3218 try { | 3216 try { |
3219 fileTransfer.handleUpload(handle, path, textMode, offset); | 3217 uploader.handleUpload(handle, path, textMode, offset); |
3220 if (!handle.hasBeenUsed()) { | 3218 if (!handle.hasBeenUsed()) { |
3221 String message = String.format("Call to %s.handleUpload for path '%s' sent neither data nor an error message", | 3219 String message = String.format("Call to %s.handleUpload for path '%s' sent neither data nor an error message", |
3222 fileTransfer.getClass().getCanonicalName(), path); | 3220 uploader.getClass().getCanonicalName(), path); |
3223 throw new IOException(message); | 3221 throw new IOException(message); |
3224 } | 3222 } |
3225 handle.close(); | 3223 handle.close(); |
3226 } finally { | 3224 } finally { |
3227 server.setInsertFakeFlushes(wasFaking); | 3225 server.setInsertFakeFlushes(wasFaking); |