Changeset: f1de7262d8d9 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/f1de7262d8d9
Added Files:
src/main/java/nl/cwi/monetdb/embedded/env/IEmbeddedConnection.java
src/main/java/nl/cwi/monetdb/mcl/connection/AbstractBufferedReader.java
src/main/java/nl/cwi/monetdb/mcl/connection/AbstractBufferedWriter.java
src/main/java/nl/cwi/monetdb/mcl/connection/AbstractMonetDBConnection.java
src/main/java/nl/cwi/monetdb/mcl/embedded/EmbeddedConnection.java
src/main/java/nl/cwi/monetdb/mcl/embedded/EmbeddedReader.java
src/main/java/nl/cwi/monetdb/mcl/embedded/EmbeddedWriter.java
src/main/java/nl/cwi/monetdb/mcl/net/BufferedMCLReader.java
src/main/java/nl/cwi/monetdb/mcl/net/BufferedMCLWriter.java
Removed Files:
src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java
src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLWriter.java
Modified Files:
example/SQLcopyinto.java
src/main/java/nl/cwi/monetdb/client/JdbcClient.java
src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
src/main/java/nl/cwi/monetdb/mcl/MCLException.java
src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java
src/main/java/nl/cwi/monetdb/mcl/parser/MCLParser.java
src/main/java/nl/cwi/monetdb/merovingian/Control.java
src/main/java/nl/cwi/monetdb/util/SQLRestore.java
Branch: embedded
Log Message:
First changes to the JDBC driver.
diffs (truncated from 2131 to 300 lines):
diff --git a/example/SQLcopyinto.java b/example/SQLcopyinto.java
--- a/example/SQLcopyinto.java
+++ b/example/SQLcopyinto.java
@@ -9,8 +9,10 @@
import java.sql.*;
import java.io.*;
import java.util.*;
+
+import nl.cwi.monetdb.mcl.connection.AbstractBufferedReader;
+import nl.cwi.monetdb.mcl.connection.AbstractBufferedWriter;
import nl.cwi.monetdb.mcl.net.*;
-import nl.cwi.monetdb.mcl.io.*;
/**
* This example demonstrates how the MonetDB JDBC driver can facilitate
@@ -45,22 +47,22 @@ public class SQLcopyinto {
// of course also be done simultaneously with the JDBC
// connection being kept connected
- MapiSocket server = new MapiSocket();
+ MapiSocket server = new MapiSocket("localhost", 50000,
"monetdb", "monetdb", false, "sql", "SHA256");
server.setDatabase("database");
server.setLanguage("sql");
try {
List warning =
- server.connect("localhost", 50000, "monetdb",
"monetdb");
+ server.connect( "monetdb", "monetdb");
if (warning != null) {
- for (Iterator it = warning.iterator();
it.hasNext(); ) {
-
System.out.println(it.next().toString());
+ for (Object aWarning : warning) {
+ System.out.println(aWarning.toString());
}
}
- BufferedMCLReader in = server.getReader();
- BufferedMCLWriter out = server.getWriter();
+ AbstractBufferedReader in = server.getReader();
+ AbstractBufferedWriter out = server.getWriter();
String error = in.waitForPrompt();
if (error != null)
diff --git a/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
b/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
--- a/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
+++ b/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
@@ -329,7 +329,7 @@ public final class JdbcClient {
// the most optimal way, but it works by just
scanning
// every table for loops in a recursive manor
for (Table t : tables) {
- Table.checkForLoop(t, new
ArrayList<>());
+ Table.checkForLoop(t, new
ArrayList<Table>());
}
// find the graph, at this point we know there
are no
diff --git a/src/main/java/nl/cwi/monetdb/embedded/env/IEmbeddedConnection.java
b/src/main/java/nl/cwi/monetdb/embedded/env/IEmbeddedConnection.java
new file mode 100644
--- /dev/null
+++ b/src/main/java/nl/cwi/monetdb/embedded/env/IEmbeddedConnection.java
@@ -0,0 +1,11 @@
+package nl.cwi.monetdb.embedded.env;
+
+/**
+ * Created by ferreira on 11/24/16.
+ */
+public interface IEmbeddedConnection {
+
+ long getConnectionPointer();
+
+ void closeConnectionImplementation();
+}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
--- a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java
@@ -22,15 +22,15 @@ import java.util.concurrent.ConcurrentHa
*
* @author <a href="mailto:[email protected]">Pedro
Ferreira</a>
*/
-public class MonetDBEmbeddedConnection {
+public class MonetDBEmbeddedConnection implements IEmbeddedConnection {
- protected final long connectionPointer;
+ private final long connectionPointer;
private final ConcurrentHashMap<Long, AbstractConnectionResult> results =
new ConcurrentHashMap<>();
protected MonetDBEmbeddedConnection(long connectionPointer) {
this.connectionPointer = connectionPointer; }
- protected long getConnectionPointer() { return connectionPointer; }
+ public long getConnectionPointer() { return connectionPointer; }
/**
* Gets the current schema set on the connection.
@@ -215,7 +215,7 @@ public class MonetDBEmbeddedConnection {
/**
* When the database is shuts down, this method is called instead
*/
- protected void closeConnectionImplementation() {
+ public void closeConnectionImplementation() {
for(AbstractConnectionResult res : this.results.values()) {
res.closeImplementation();
}
diff --git
a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
--- a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
+++ b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedDatabase.java
@@ -8,6 +8,8 @@
package nl.cwi.monetdb.embedded.env;
+import nl.cwi.monetdb.mcl.embedded.EmbeddedConnection;
+
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -112,7 +114,7 @@ public class MonetDBEmbeddedDatabase {
if(MonetDBEmbeddedDatabase == null) {
throw new MonetDBEmbeddedException("The database is not running!");
} else {
- for(MonetDBEmbeddedConnection mdbec :
MonetDBEmbeddedDatabase.connections.values()) {
+ for(IEmbeddedConnection mdbec :
MonetDBEmbeddedDatabase.connections.values()) {
mdbec.closeConnectionImplementation();
}
MonetDBEmbeddedDatabase.connections.clear();
@@ -136,7 +138,7 @@ public class MonetDBEmbeddedDatabase {
private final boolean sequentialFlag;
- private final ConcurrentHashMap<Long, MonetDBEmbeddedConnection>
connections = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap<Long, IEmbeddedConnection> connections =
new ConcurrentHashMap<>();
private MonetDBEmbeddedDatabase(String dbDirectory, boolean silentFlag,
boolean sequentialFlag) {
this.databaseDirectory = dbDirectory;
@@ -170,11 +172,20 @@ public class MonetDBEmbeddedDatabase {
return CompletableFuture.supplyAsync(() ->
this.createConnectionInternal());
}*/
+ public static void AddJDBCEmbeddedConnection(EmbeddedConnection con)
throws MonetDBEmbeddedException {
+ if(MonetDBEmbeddedDatabase == null) {
+ throw new MonetDBEmbeddedException("The database is not running!");
+ } else {
+ MonetDBEmbeddedDatabase.createJDBCConnectionInternal(con);
+
MonetDBEmbeddedDatabase.connections.put(con.getConnectionPointer(), con);
+ }
+ }
+
/**
* Removes a connection from this database.
*/
protected static void RemoveConnection(MonetDBEmbeddedConnection con) {
- MonetDBEmbeddedDatabase.connections.remove(con.connectionPointer);
+ MonetDBEmbeddedDatabase.connections.remove(con.getConnectionPointer());
}
/**
@@ -193,4 +204,9 @@ public class MonetDBEmbeddedDatabase {
* Internal implementation to create a connection on this database.
*/
private native MonetDBEmbeddedConnection createConnectionInternal() throws
MonetDBEmbeddedException;
+
+ /**
+ * Internal implementation to create a JDBC embeddded connection on this
database.
+ */
+ private native void createJDBCConnectionInternal(EmbeddedConnection emc)
throws MonetDBEmbeddedException;
}
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
@@ -44,9 +44,11 @@ import java.util.concurrent.locks.Reentr
import nl.cwi.monetdb.jdbc.types.INET;
import nl.cwi.monetdb.jdbc.types.URL;
import nl.cwi.monetdb.mcl.MCLException;
-import nl.cwi.monetdb.mcl.io.BufferedMCLReader;
-import nl.cwi.monetdb.mcl.io.BufferedMCLWriter;
+import nl.cwi.monetdb.mcl.connection.AbstractBufferedReader;
+import nl.cwi.monetdb.mcl.connection.AbstractBufferedWriter;
+import nl.cwi.monetdb.mcl.embedded.EmbeddedConnection;
import nl.cwi.monetdb.mcl.net.MapiSocket;
+import nl.cwi.monetdb.mcl.connection.AbstractMonetDBConnection;
import nl.cwi.monetdb.mcl.parser.HeaderLineParser;
import nl.cwi.monetdb.mcl.parser.MCLParseException;
import nl.cwi.monetdb.mcl.parser.StartOfHeaderParser;
@@ -77,22 +79,13 @@ import nl.cwi.monetdb.mcl.parser.StartOf
* @version 1.2
*/
public class MonetConnection extends MonetWrapper implements Connection {
- /** The hostname to connect to */
- private final String hostname;
- /** The port to connect on the host to */
- private final int port;
- /** The database to use (currently not used) */
- private final String database;
- /** The username to use when authenticating */
- private final String username;
- /** The password to use when authenticating */
- private final String password;
- /** A connection to mserver5 using a TCP socket */
- private final MapiSocket server;
+
+ /** A connection to mserver5 either through MAPI with TCP or embedded */
+ private final AbstractMonetDBConnection server;
/** The Reader from the server */
- private final BufferedMCLReader in;
+ private final AbstractBufferedReader in;
/** The Writer to the server */
- private final BufferedMCLWriter out;
+ private final AbstractBufferedWriter out;
/** A StartOfHeaderParser declared for reuse. */
private StartOfHeaderParser sohp = new StartOfHeaderParser();
@@ -125,20 +118,6 @@ public class MonetConnection extends Mon
/** The number of results we receive from the server at once */
private int curReplySize = -1; // the server by default uses -1 (all)
- /** A template to apply to each query (like pre and post fixes) */
- String[] queryTempl;
- /** A template to apply to each command (like pre and post fixes) */
- String[] commandTempl;
-
- /** the SQL language */
- final static int LANG_SQL = 0;
- /** the MAL language (officially *NOT* supported) */
- final static int LANG_MAL = 3;
- /** an unknown language */
- final static int LANG_UNKNOWN = -1;
- /** The language which is used */
- final int lang;
-
/** Whether or not BLOB is mapped to BINARY within the driver */
private final boolean blobIsBinary;
@@ -157,50 +136,58 @@ public class MonetConnection extends Mon
MonetConnection(Properties props)
throws SQLException, IllegalArgumentException
{
- this.hostname = props.getProperty("host");
- int port;
- try {
- port = Integer.parseInt(props.getProperty("port"));
- } catch (NumberFormatException e) {
- port = 0;
- }
- this.port = port;
- this.database = props.getProperty("database");
- this.username = props.getProperty("user");
- this.password = props.getProperty("password");
- String language = props.getProperty("language");
+ String database = props.getProperty("database");
+ if (database == null || database.trim().isEmpty())
+ throw new IllegalArgumentException("database should not
be null or empty");
+ boolean isEmbedded =
Boolean.parseBoolean(props.getProperty("embedded"));
+ String username = props.getProperty("user");
+ String password = props.getProperty("password");
boolean debug = Boolean.valueOf(props.getProperty("debug"));
- String hash = props.getProperty("hash");
blobIsBinary =
Boolean.valueOf(props.getProperty("treat_blob_as_binary"));
- int sockTimeout;
- try {
- sockTimeout =
Integer.parseInt(props.getProperty("so_timeout"));
- } catch (NumberFormatException e) {
- sockTimeout = 0;
+
+ if(isEmbedded) {
+ String directory = props.getProperty("directory");
+ if (directory == null || directory.trim().isEmpty())
+ throw new IllegalArgumentException("directory
should not be null or empty");
+
+ server = new EmbeddedConnection("localhost", -1,
database, username, debug, "sql", null, directory);
+ } else {
+ String hostname = props.getProperty("host");
+ String hash = props.getProperty("hash");
+ String language = props.getProperty("language");
+ int port = 0;
+ int sockTimeout = 0;
+
+ try {
+ port =
Integer.parseInt(props.getProperty("port"));
+ } catch (NumberFormatException e) {
+ }
+ try {
+ sockTimeout =
Integer.parseInt(props.getProperty("so_timeout"));
+ } catch (NumberFormatException e) {
+ }
+
+ // check input arguments
+ if (hostname == null || hostname.trim().isEmpty())
+ throw new IllegalArgumentException("hostname
should not be null or empty");
+ if (port == 0)
+ throw new IllegalArgumentException("port should
not be 0");
+ if (username == null || username.trim().isEmpty())
+ throw new IllegalArgumentException("user should
not be null or empty");
+ if (password == null || password.trim().isEmpty())
+ throw new IllegalArgumentException("password
should not be null or empty");
+ if (language == null || language.trim().isEmpty()) {
+ language = "sql";
+ addWarning("No language given, defaulting to
'sql'", "M1M05");
+ }
+ server = new MapiSocket(hostname, port, database,
username, debug, language, hash);
+ try {
+ server.setSoTimeout(sockTimeout);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list