Mercurial > hg > monetdb-java
changeset 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 |
files | example/OnClientExample.java onclient.txt src/main/java/org/monetdb/jdbc/MonetConnection.java src/main/java/org/monetdb/jdbc/MonetDownloadHandler.java src/main/java/org/monetdb/jdbc/MonetUploadHandler.java src/main/java/org/monetdb/mcl/net/MapiSocket.java src/main/java/org/monetdb/util/FileTransferHandler.java tests/OnClientTester.java |
diffstat | 8 files changed, 73 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/example/OnClientExample.java +++ b/example/OnClientExample.java @@ -1,5 +1,5 @@ import org.monetdb.jdbc.MonetConnection; -import org.monetdb.jdbc.MonetUploadHandler; +import org.monetdb.jdbc.MonetConnection.UploadHandler; import java.io.BufferedReader; import java.io.IOException; @@ -78,7 +78,7 @@ public class OnClientExample { } - private static class MyUploader implements MonetUploadHandler { + private static class MyUploader implements UploadHandler { private final Path uploadDir; private final boolean filesAreUtf8;
--- a/onclient.txt +++ b/onclient.txt @@ -26,7 +26,7 @@ these requests from the server: MyUploader handler = new MyUploadHandler(); conn.unwrap(MonetConnection.class).setUploadHandler(handler); -Here, MyUploadHandler is an implementation of the interface MonetUploadHandler, +Here, MyUploadHandler is an implementation of the interface MonetConnection.UploadHandler, whose main component is the method /** @@ -69,7 +69,7 @@ is no way to signal errors to the server The interface for downloading is similar to that for uploading. Class org.monetdb.util.FileTransferHandler provides a default implementation of -both MonetUploadHandler and MonetDownloadHandler. You pass it a directory name -and a flag indicating whether the contents of that directory can be assumed to -be UTF-8 encoded. It is intended for situations where you do not need to -generate or transform data while uploading. \ No newline at end of file +both MonetConnection.UploadHandler and MonetConnection.DownloadHandler. You +pass it a directory name and a flag indicating whether the contents of that +directory can be assumed to be UTF-8 encoded. It is intended for situations +where you do not need to generate or transform data while uploading. \ No newline at end of file
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java @@ -152,8 +152,8 @@ public class MonetConnection private DatabaseMetaData dbmd; /** Handlers for ON CLIENT requests */ - private MonetUploadHandler uploadHandler; - private MonetDownloadHandler downloadHandler; + private UploadHandler uploadHandler; + private DownloadHandler downloadHandler; /** * Constructor of a Connection for MonetDB. At this moment the @@ -1676,33 +1676,33 @@ public class MonetConnection //== end methods of interface java.sql.Connection /** - * Registers a {@link MonetUploadHandler} to support for example COPY ON CLIENT + * Registers a {@link UploadHandler} to support for example COPY ON CLIENT * * @param uploadHandler the handler to register, or null to deregister */ - public void setUploadHandler(MonetUploadHandler uploadHandler) { + public void setUploadHandler(UploadHandler uploadHandler) { this.uploadHandler = uploadHandler; } /** - * Returns the currently registerered {@link MonetUploadHandler}, or null + * Returns the currently registerered {@link UploadHandler}, or null */ - public MonetUploadHandler getUploadHandler() { + public UploadHandler getUploadHandler() { return uploadHandler; } /** - * Registers a {@link MonetDownloadHandler} to support for example COPY ON CLIENT + * Registers a {@link DownloadHandler} to support for example COPY ON CLIENT * * @param downloadHandler the handler to register, or null to deregister */ - public void setDownloadHandler(MonetDownloadHandler downloadHandler) { + public void setDownloadHandler(DownloadHandler downloadHandler) { this.downloadHandler = downloadHandler; } /** - * Returns the currently registerered {@link MonetDownloadHandler} handler, or null + * Returns the currently registerered {@link DownloadHandler} handler, or null */ - public MonetDownloadHandler getDownloadHandler() { + public DownloadHandler getDownloadHandler() { return downloadHandler; } @@ -3267,7 +3267,46 @@ public class MonetConnection } /** - * Handle passed to {@link MonetUploadHandler} to allow communication with the server + * Callback for sending files for COPY ON CLIENT + * + * To be registered with {@link MonetConnection#setUploadHandler(UploadHandler)} + */ + + public static interface UploadHandler { + /** + * Called if the server sends a request to write a file. + * + * Use the given handle to receive data or send errors to the server. + * + * @param handle Handle to communicate with the server + * @param name Name of the file the server would like to read. Make sure to validate this before reading from + * the file system + * @param textMode Whether this is text or binary data. + */ + void handleUpload(Upload handle, String name, boolean textMode, int offset) throws IOException; + } + + /** + * Callback for receiving files with COPY ON CLIENT + * + * To be registered with {@link MonetConnection#setDownloadHandler(DownloadHandler)} + */ + public static interface DownloadHandler { + /** + * Called if the server sends a request to write a file. + * + * Use the given handle to send data or errors to the server. + * + * @param handle Handle to communicate with the server + * @param name Name of the file the server would like to write. Make sure to validate this before writing to + * the file system + * @param textMode Whether this is text or binary data. + */ + void handleDownload(Download handle, String name, boolean textMode) throws IOException; + } + + /** + * Handle passed to {@link UploadHandler} to allow communication with the server */ public static class Upload { private final MapiSocket server; @@ -3416,7 +3455,7 @@ public class MonetConnection } /** - * Handle passed to {@link MonetDownloadHandler} to allow communication with the server + * Handle passed to {@link DownloadHandler} to allow communication with the server */ public static class Download { private final MapiSocket server;
deleted file mode 100644 --- a/src/main/java/org/monetdb/jdbc/MonetDownloadHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.monetdb.jdbc; - -import java.io.IOException; - -/** - * Callback for receiving files with COPY ON CLIENT - * - * To be registered with {@link MonetConnection#setDownloadHandler(MonetDownloadHandler)} - */ -public interface MonetDownloadHandler { - /** - * Called if the server sends a request to write a file. - * - * Use the given handle to send data or errors to the server. - * - * @param handle Handle to communicate with the server - * @param name Name of the file the server would like to write. Make sure to validate this before writing to - * the file system - * @param textMode Whether this is text or binary data. - */ - void handleDownload(MonetConnection.Download handle, String name, boolean textMode) throws IOException; -} \ No newline at end of file
deleted file mode 100644 --- a/src/main/java/org/monetdb/jdbc/MonetUploadHandler.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.monetdb.jdbc; - -import java.io.IOException; - -/** - * Callback for sending files for COPY ON CLIENT - * - * To be registered with {@link MonetConnection#setUploadHandler(MonetUploadHandler)} - */ - -public interface MonetUploadHandler { - /** - * Called if the server sends a request to write a file. - * - * Use the given handle to receive data or send errors to the server. - * - * @param handle Handle to communicate with the server - * @param name Name of the file the server would like to read. Make sure to validate this before reading from - * the file system - * @param textMode Whether this is text or binary data. - */ - void handleUpload(MonetConnection.Upload handle, String name, boolean textMode, int offset) throws IOException; -} \ No newline at end of file
--- a/src/main/java/org/monetdb/mcl/net/MapiSocket.java +++ b/src/main/java/org/monetdb/mcl/net/MapiSocket.java @@ -1173,7 +1173,7 @@ public class MapiSocket { /* cannot (yet /** * Return an UploadStream for use with for example COPY FROM filename ON CLIENT. * - * Building block for {@link org.monetdb.jdbc.MonetUploadHandler}. + * Building block for {@link MonetConnection.UploadHandler}. * @param chunkSize chunk size for the upload stream */ public UploadStream uploadStream(int chunkSize) { @@ -1183,7 +1183,7 @@ public class MapiSocket { /* cannot (yet /** * Return an UploadStream for use with for example COPY FROM filename ON CLIENT. * - * Building block for {@link org.monetdb.jdbc.MonetUploadHandler}. + * Building block for {@link MonetConnection.UploadHandler}. */ public UploadStream uploadStream() { return new UploadStream(); @@ -1192,7 +1192,7 @@ public class MapiSocket { /* cannot (yet /** * Return a DownloadStream for use with for example COPY INTO filename ON CLIENT * - * Building block for {@link org.monetdb.jdbc.MonetDownloadHandler}. + * Building block for {@link MonetConnection.DownloadHandler}. * @return */ public DownloadStream downloadStream() { @@ -1216,7 +1216,7 @@ public class MapiSocket { /* cannot (yet /** * Stream of data sent to the server * - * Building block for {@link org.monetdb.jdbc.MonetUploadHandler}. + * Building block for {@link MonetConnection.UploadHandler}. * * An UploadStream has a chunk size. Every chunk size bytes, the server gets * the opportunity to abort the upload. @@ -1359,7 +1359,7 @@ public class MapiSocket { /* cannot (yet /** * Stream of data received from the server * - * Building block for {@link org.monetdb.jdbc.MonetDownloadHandler}. + * Building block for {@link MonetConnection.DownloadHandler}. */ public static class DownloadStream extends InputStream {
--- a/src/main/java/org/monetdb/util/FileTransferHandler.java +++ b/src/main/java/org/monetdb/util/FileTransferHandler.java @@ -1,8 +1,6 @@ package org.monetdb.util; import org.monetdb.jdbc.MonetConnection; -import org.monetdb.jdbc.MonetDownloadHandler; -import org.monetdb.jdbc.MonetUploadHandler; import java.io.BufferedReader; import java.io.IOException; @@ -17,11 +15,11 @@ import java.nio.file.StandardOpenOption; /** * Sample implement of ON CLIENT handling * - * Can be registered with {@link MonetConnection#setUploadHandler(MonetUploadHandler)} - * and {@link MonetConnection#setDownloadHandler(MonetDownloadHandler)}. + * Can be registered with {@link MonetConnection#setUploadHandler(MonetConnection.UploadHandler)} + * and {@link MonetConnection#setDownloadHandler(MonetConnection.DownloadHandler)}. * Implements uploads and downloads by reading and writing files on the file system. */ -public class FileTransferHandler implements MonetUploadHandler, MonetDownloadHandler { +public class FileTransferHandler implements MonetConnection.UploadHandler, MonetConnection.DownloadHandler { private final Path root; private final boolean utf8Encoded;
--- a/tests/OnClientTester.java +++ b/tests/OnClientTester.java @@ -1,6 +1,6 @@ import org.monetdb.jdbc.MonetConnection; -import org.monetdb.jdbc.MonetDownloadHandler; -import org.monetdb.jdbc.MonetUploadHandler; +import org.monetdb.jdbc.MonetConnection.UploadHandler; +import org.monetdb.jdbc.MonetConnection.DownloadHandler; import java.io.*; import java.nio.charset.StandardCharsets; @@ -149,7 +149,7 @@ public final class OnClientTester extend public void test_UploadFromStream() throws SQLException, Failure { prepare(); - MonetUploadHandler handler = new MonetUploadHandler() { + UploadHandler handler = new UploadHandler() { final String data = "1|one\n2|two\n3|three\n"; @Override @@ -165,7 +165,7 @@ public final class OnClientTester extend public void test_UploadFromReader() throws SQLException, Failure { prepare(); - MonetUploadHandler handler = new MonetUploadHandler() { + UploadHandler handler = new UploadHandler() { final String data = "1|one\n2|two\n3|three\n"; @Override @@ -181,7 +181,7 @@ public final class OnClientTester extend public void test_UploadFromReaderOffset() throws SQLException, Failure { prepare(); - MonetUploadHandler handler = new MonetUploadHandler() { + UploadHandler handler = new UploadHandler() { final String data = "1|one\n2|two\n3|three\n"; @Override @@ -214,7 +214,7 @@ public final class OnClientTester extend queryInt("SELECT 42 -- check if the connection still works", 42); } - static class MyUploadHandler implements MonetUploadHandler { + static class MyUploadHandler implements UploadHandler { private final int rows; private final int errorAt; private final String errorMessage; @@ -266,7 +266,7 @@ public final class OnClientTester extend } } - static class MyDownloadHandler implements MonetDownloadHandler { + static class MyDownloadHandler implements DownloadHandler { private final int errorAtByte; private final String errorMessage; private int attempts = 0;