Changeset: eeb71f7d36bf for monetdb-java URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=eeb71f7d36bf Modified Files: example/MJDBCTest.java example/SQLcopyinto.java src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetDataSource.java src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiStartOfHeaderParser.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParser.java src/main/java/nl/cwi/monetdb/merovingian/Control.java src/main/java/nl/cwi/monetdb/util/Extract.java src/main/java/nl/cwi/monetdb/util/SQLRestore.java Branch: embedded Log Message:
Fixed a bug on the JDBC MAPI connection from the old code! Fixed the connection properties for an JDBC Embedded connection. To start a JDBC Embedded connection, the user must start the embedded database beforehand with the method MonetDBEmbeddedDatabase.StartDatabase(). diffs (truncated from 525 to 300 lines): diff --git a/example/MJDBCTest.java b/example/MJDBCTest.java --- a/example/MJDBCTest.java +++ b/example/MJDBCTest.java @@ -17,8 +17,7 @@ import java.sql.*; */ public class MJDBCTest { public static void main(String[] args) throws Exception { - // make sure the driver is loaded - Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); + //Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); // turn on debugging (disabled) //nl.cwi.monetdb.jdbc.MonetConnection.setDebug(true); Connection con = DriverManager.getConnection("jdbc:monetdb://localhost/notused", "monetdb", "monetdb"); diff --git a/example/SQLcopyinto.java b/example/SQLcopyinto.java --- a/example/SQLcopyinto.java +++ b/example/SQLcopyinto.java @@ -43,7 +43,7 @@ public class SQLcopyinto { // of course also be done simultaneously with the JDBC // connection being kept connected - MapiConnection server = new MapiConnection(null, "database",null, "sql", true,"localhost", 50000 ); + MapiConnection server = new MapiConnection(null, null, "sql", false, true,"localhost", 50000, "database"); try { List warning = server.connect("monetdb", "monetdb"); 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 @@ -54,8 +54,6 @@ public abstract class MonetConnection ex protected final Properties conn_props; /** The language to connect with */ protected IMonetDBLanguage language; - /** The database to connect to */ - protected String database; /** Authentication hash method */ protected final String hash; /** An optional thread that is used for sending large queries */ @@ -79,7 +77,7 @@ public abstract class MonetConnection ex private Map<Statement,?> statements = new WeakHashMap<Statement, Object>(); /** The number of results we receive from the server at once */ private int curReplySize = -1; // the server by default uses -1 (all) - /** Whether or not BLOB is mapped to BINARY within the driver */ + /** Whether or not BLOB is mapped to LONGVARBINARY within the driver */ private final boolean blobIsBinary; /** Whether or not CLOB is mapped to LONGVARCHAR within the driver */ private final boolean clobIsLongChar; @@ -93,10 +91,9 @@ public abstract class MonetConnection ex * * @throws IOException if an error occurs */ - public MonetConnection(Properties props, String database, String hash, IMonetDBLanguage language, - boolean blobIsBinary, boolean clobIsLongChar) throws IOException { + public MonetConnection(Properties props, String hash, IMonetDBLanguage language, boolean blobIsBinary, + boolean clobIsLongChar) throws IOException { this.conn_props = props; - this.database = database; this.hash = hash; this.language = language; this.blobIsBinary = blobIsBinary; @@ -800,7 +797,7 @@ public abstract class MonetConnection ex */ @Override public String toString() { - return "MonetDB Connection (" + this.getJDBCURL() + ") " + (closed ? "connected" : "disconnected"); + return "MonetDB Connection (" + this.getJDBCURL() + ") " + (closed ? "disconnected" : "connected"); } //== Java 1.6 methods (JDBC 4.0) @@ -1068,8 +1065,8 @@ public abstract class MonetConnection ex // only set value for supported property names if (name.equals("host") || name.equals("port") || name.equals("user") || name.equals("password") || name.equals("database") || name.equals("language") || name.equals("so_timeout") || - name.equals("debug") || name.equals("hash") || name.equals("treat_blob_as_binary") || - name.equals("treat_clob_as_longvarchar") || name.equals("embedded") || name.equals("directory")) { + name.equals("hash") || name.equals("treat_blob_as_binary") || name.equals("follow_redirects") || + name.equals("treat_clob_as_longvarchar") || name.equals("embedded")) { conn_props.setProperty(name, value); } else { addWarning("setClientInfo: " + name + "is not a recognised property", "01M07"); diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetDataSource.java b/src/main/java/nl/cwi/monetdb/jdbc/MonetDataSource.java --- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDataSource.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDataSource.java @@ -35,7 +35,7 @@ public class MonetDataSource extends Mon private String description = "MonetDB database"; private String url = "jdbc:monetdb://localhost/"; private int loginTimeout; - private String embeddedDirectory; + private boolean isEmbedded; private final MonetDriver driver = new MonetDriver(); // the following properties are also standard: @@ -73,9 +73,8 @@ public class MonetDataSource extends Mon if (loginTimeout > 0) { props.put("so_timeout", Integer.toString(loginTimeout)); } - if(embeddedDirectory != null) { + if(isEmbedded) { props.put("embedded", "true"); - props.put("directory", embeddedDirectory); } return driver.connect(url, props); } @@ -160,7 +159,7 @@ public class MonetDataSource extends Mon * * @param url the connection URL */ - public void setDatabaseName(String url) { + public void setURL(String url) { this.url = url; } @@ -183,21 +182,21 @@ public class MonetDataSource extends Mon } /** - * Gets the embedded connection directory. If null, then a MAPI connection will be created instead. + * Gets the embedded connection directory. If not, then a MAPI connection will be created instead. * - * @return The embedded connection directory String. If null, then a MAPI connection will be created instead. + * @return If the connection will be embedded. If not, then a MAPI connection will be created instead. */ - public String getEmbeddedDirectory() { - return embeddedDirectory; + public boolean isEmbedded() { + return isEmbedded; } /** - * Sets the embedded connection directory, thus making the connection embedded. + * Sets the connection to be embedded * - * @param embeddedDirectory The embedded connection directory to set + * @param isEmbedded A boolean to indicate if the connection will be embedded */ - public void setEmbeddedDirectory(String embeddedDirectory) { - this.embeddedDirectory = embeddedDirectory; + public void setIsEmbedded(boolean isEmbedded) { + this.isEmbedded = isEmbedded; } /** diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in --- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @@ -148,9 +148,24 @@ final public class MonetDriver implement prop.description = "Force the use of the given hash algorithm during challenge response (one of SHA1, MD5, plain)"; props.add(prop); - prop = new DriverPropertyInfo("language", "sql"); + prop = new DriverPropertyInfo("host", "localhost"); prop.required = false; - prop.description = "What language to use for MonetDB conversations (experts only)"; + prop.description = "The MonetDB server hostname (MAPI connection only)"; + props.add(prop); + + prop = new DriverPropertyInfo("port", PORT); + prop.required = false; + prop.description = "The port to connect to the MonetDB server (MAPI connection only)"; + props.add(prop); + + prop = new DriverPropertyInfo("so_timeout", "0"); + prop.required = false; + prop.description = "Defines the maximum time to wait in milliseconds on a blocking read socket call (MAPI connection only)"; // this corresponds to the Connection.setNetworkTimeout() method introduced in JDBC 4.1 + props.add(prop); + + prop = new DriverPropertyInfo("database", ""); + prop.required = false; + prop.description = "The database name to connect (MAPI connection only)"; props.add(prop); prop = new DriverPropertyInfo("follow_redirects", "true"); @@ -160,7 +175,7 @@ final public class MonetDriver implement prop = new DriverPropertyInfo("treat_blob_as_binary", "false"); prop.required = false; - prop.description = "Whether BLOBs on the server should be treated as BINARY types, thus mapped to byte[] (MAPI connection only)"; + prop.description = "Whether BLOBs on the server should be treated as LONGVARBINARY types, thus mapped to byte[] (MAPI connection only)"; props.add(prop); prop = new DriverPropertyInfo("treat_clob_as_longvarchar", "false"); @@ -168,9 +183,9 @@ final public class MonetDriver implement prop.description = "Whether CLOBs on the server should be treated as LONGVARCHAR types, thus mapped to String (MAPI connection only)"; props.add(prop); - prop = new DriverPropertyInfo("so_timeout", "0"); + prop = new DriverPropertyInfo("language", "sql"); prop.required = false; - prop.description = "Defines the maximum time to wait in milliseconds on a blocking read socket call (MAPI connection only)"; // this corresponds to the Connection.setNetworkTimeout() method introduced in JDBC 4.1 + prop.description = "What language to use for MonetDB conversations (experts only)"; props.add(prop); prop = new DriverPropertyInfo("embedded", "false"); @@ -178,11 +193,6 @@ final public class MonetDriver implement prop.description = "Whether or not to use an embedded MonetDB connection"; props.add(prop); - prop = new DriverPropertyInfo("directory", ""); - prop.required = false; - prop.description = "The directory of the database farm (Embedded connection only)"; - props.add(prop); - DriverPropertyInfo[] dpi = new DriverPropertyInfo[props.size()]; return props.toArray(dpi); } @@ -404,19 +414,12 @@ final public class MonetDriver implement boolean isEmbedded = Boolean.parseBoolean(props.getProperty("embedded", "false")); String language = props.getProperty("language", "sql"); - String username = props.getProperty("user", null); - String password = props.getProperty("password", null); - String database = props.getProperty("database"); - if (database == null || database.trim().isEmpty()) - throw new IllegalArgumentException("database should not be null or empty"); + String username = props.getProperty("user"); + String password = props.getProperty("password"); String hash = props.getProperty("hash"); int sockTimeout = 0; - //instantiate the connection - if(isEmbedded) { - String directory = props.getProperty("directory"); - if (directory == null || directory.trim().isEmpty()) - throw new IllegalArgumentException("directory should not be null or empty"); + if(isEmbedded) { //instantiate the connection try { if(EmbeddedConnectionClass == null) { EmbeddedConnectionClass = Class.forName("nl.cwi.monetdb.embedded.jdbc.EmbeddedConnection"); @@ -425,8 +428,8 @@ final public class MonetDriver implement throw new SQLException("EmbeddedConnection Class not found!"); } res = (MonetConnection) EmbeddedConnectionClass - .getDeclaredConstructor(Properties.class, String.class, String.class, String.class, String.class) - .newInstance(props, database, hash, language, directory); + .getDeclaredConstructor(Properties.class, String.class, String.class) + .newInstance(props, hash, language); } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException e) { throw new SQLException(e); @@ -439,6 +442,9 @@ final public class MonetDriver implement 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"); + String database = props.getProperty("database"); + if (database == null || database.trim().isEmpty()) + throw new IllegalArgumentException("database should not be null or empty"); boolean blobIsBinary = Boolean.valueOf(props.getProperty("treat_blob_as_binary", "false")); boolean clobIsLongChar = Boolean.valueOf(props.getProperty("treat_clob_as_longvarchar", "false")); @@ -472,7 +478,7 @@ final public class MonetDriver implement props.setProperty("so_timeout", "0"); } try { - res = new MapiConnection(props, database, hash, language, blobIsBinary, clobIsLongChar, hostname, port); + res = new MapiConnection(props, hash, language, blobIsBinary, clobIsLongChar, hostname, port, database); } catch (IOException e) { throw new SQLException(e); } @@ -491,7 +497,7 @@ final public class MonetDriver implement res.setSoTimeout(sockTimeout); } - try { + try { //atempt to connect and authenticate the user List<String> warnings = res.connect(username, password); if(warnings != null) { for (String warning : warnings) { @@ -508,15 +514,7 @@ final public class MonetDriver implement throw new SQLException("Unable to connect (" + con.getHostname() + ":" + con.getPort() + "): " + e.getMessage(), "08006"); } else { - try { - java.lang.reflect.Method method = EmbeddedConnectionClass.getMethod("getDirectory"); - String directory = (String) method.invoke(EmbeddedConnectionClass.cast(res)); - throw new SQLException("Unable to start the farm on the directory: " + directory + - " Details:" + e.getMessage(), "08006"); - } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | - IllegalAccessException | InvocationTargetException ex) { - throw new SQLException(e.getMessage()); - } + throw new SQLException("Unable to connect: " + e.getMessage(), "08006"); } } catch (ProtocolException e) { throw new SQLException(e.getMessage(), "08001"); @@ -529,8 +527,7 @@ final public class MonetDriver implement throw sqle; } - //set the timezone - if (res.getLanguage() == MapiLanguage.LANG_SQL) { + if (!isEmbedded && res.getLanguage() == MapiLanguage.LANG_SQL) { //set the timezone only in the MAPI connection // enable auto commit res.setAutoCommit(true); // set our time zone on the server diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java --- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -3257,22 +3257,6 @@ public class MonetResultSet extends Mone //== end methods of interface ResultSet /** _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list