comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 541:31df6a12fd41 onclient

Make the MonetUploadHandler and MonetDownloadHandler interfaces part of MonetConnection And rename them to UploadHandler and DownloadHandler
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 02 Sep 2021 14:27:20 +0200 (2021-09-02)
parents d3a96675969e
children d462000fc410
comparison
equal deleted inserted replaced
540:d3a96675969e 541:31df6a12fd41
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 /** Handlers for ON CLIENT requests */ 154 /** Handlers for ON CLIENT requests */
155 private MonetUploadHandler uploadHandler; 155 private UploadHandler uploadHandler;
156 private MonetDownloadHandler downloadHandler; 156 private DownloadHandler downloadHandler;
157 157
158 /** 158 /**
159 * Constructor of a Connection for MonetDB. At this moment the 159 * Constructor of a Connection for MonetDB. At this moment the
160 * current implementation limits itself to storing the given host, 160 * current implementation limits itself to storing the given host,
161 * database, username and password for later use by the 161 * database, username and password for later use by the
1674 } 1674 }
1675 1675
1676 //== end methods of interface java.sql.Connection 1676 //== end methods of interface java.sql.Connection
1677 1677
1678 /** 1678 /**
1679 * Registers a {@link MonetUploadHandler} to support for example COPY ON CLIENT 1679 * Registers a {@link UploadHandler} to support for example COPY ON CLIENT
1680 * 1680 *
1681 * @param uploadHandler the handler to register, or null to deregister 1681 * @param uploadHandler the handler to register, or null to deregister
1682 */ 1682 */
1683 public void setUploadHandler(MonetUploadHandler uploadHandler) { 1683 public void setUploadHandler(UploadHandler uploadHandler) {
1684 this.uploadHandler = uploadHandler; 1684 this.uploadHandler = uploadHandler;
1685 } 1685 }
1686 1686
1687 /** 1687 /**
1688 * Returns the currently registerered {@link MonetUploadHandler}, or null 1688 * Returns the currently registerered {@link UploadHandler}, or null
1689 */ 1689 */
1690 public MonetUploadHandler getUploadHandler() { 1690 public UploadHandler getUploadHandler() {
1691 return uploadHandler; 1691 return uploadHandler;
1692 } 1692 }
1693 /** 1693 /**
1694 * Registers a {@link MonetDownloadHandler} to support for example COPY ON CLIENT 1694 * Registers a {@link DownloadHandler} to support for example COPY ON CLIENT
1695 * 1695 *
1696 * @param downloadHandler the handler to register, or null to deregister 1696 * @param downloadHandler the handler to register, or null to deregister
1697 */ 1697 */
1698 public void setDownloadHandler(MonetDownloadHandler downloadHandler) { 1698 public void setDownloadHandler(DownloadHandler downloadHandler) {
1699 this.downloadHandler = downloadHandler; 1699 this.downloadHandler = downloadHandler;
1700 } 1700 }
1701 1701
1702 /** 1702 /**
1703 * Returns the currently registerered {@link MonetDownloadHandler} handler, or null 1703 * Returns the currently registerered {@link DownloadHandler} handler, or null
1704 */ 1704 */
1705 public MonetDownloadHandler getDownloadHandler() { 1705 public DownloadHandler getDownloadHandler() {
1706 return downloadHandler; 1706 return downloadHandler;
1707 } 1707 }
1708 1708
1709 1709
1710 //== internal helper methods which do not belong to the JDBC interface 1710 //== internal helper methods which do not belong to the JDBC interface
3265 handle.close(); 3265 handle.close();
3266 return handle.getError(); 3266 return handle.getError();
3267 } 3267 }
3268 3268
3269 /** 3269 /**
3270 * Handle passed to {@link MonetUploadHandler} to allow communication with the server 3270 * Callback for sending files for COPY ON CLIENT
3271 *
3272 * To be registered with {@link MonetConnection#setUploadHandler(UploadHandler)}
3273 */
3274
3275 public static interface UploadHandler {
3276 /**
3277 * Called if the server sends a request to write a file.
3278 *
3279 * Use the given handle to receive data or send errors to the server.
3280 *
3281 * @param handle Handle to communicate with the server
3282 * @param name Name of the file the server would like to read. Make sure to validate this before reading from
3283 * the file system
3284 * @param textMode Whether this is text or binary data.
3285 */
3286 void handleUpload(Upload handle, String name, boolean textMode, int offset) throws IOException;
3287 }
3288
3289 /**
3290 * Callback for receiving files with COPY ON CLIENT
3291 *
3292 * To be registered with {@link MonetConnection#setDownloadHandler(DownloadHandler)}
3293 */
3294 public static interface DownloadHandler {
3295 /**
3296 * Called if the server sends a request to write a file.
3297 *
3298 * Use the given handle to send data or errors to the server.
3299 *
3300 * @param handle Handle to communicate with the server
3301 * @param name Name of the file the server would like to write. Make sure to validate this before writing to
3302 * the file system
3303 * @param textMode Whether this is text or binary data.
3304 */
3305 void handleDownload(Download handle, String name, boolean textMode) throws IOException;
3306 }
3307
3308 /**
3309 * Handle passed to {@link UploadHandler} to allow communication with the server
3271 */ 3310 */
3272 public static class Upload { 3311 public static class Upload {
3273 private final MapiSocket server; 3312 private final MapiSocket server;
3274 private PrintStream print = null; 3313 private PrintStream print = null;
3275 private String error = null; 3314 private String error = null;
3414 } 3453 }
3415 } 3454 }
3416 } 3455 }
3417 3456
3418 /** 3457 /**
3419 * Handle passed to {@link MonetDownloadHandler} to allow communication with the server 3458 * Handle passed to {@link DownloadHandler} to allow communication with the server
3420 */ 3459 */
3421 public static class Download { 3460 public static class Download {
3422 private final MapiSocket server; 3461 private final MapiSocket server;
3423 private MapiSocket.DownloadStream stream = null; 3462 private MapiSocket.DownloadStream stream = null;
3424 private String error = null; 3463 private String error = null;