Changeset: bb0d66ad7dc6 for monetdb-java URL: https://dev.monetdb.org/hg/monetdb-java/rev/bb0d66ad7dc6 Added Files: src/main/java/nl/cwi/monetdb/mcl/connection/Debugger.java src/main/java/nl/cwi/monetdb/mcl/connection/MCLException.java src/main/java/nl/cwi/monetdb/mcl/connection/MonetDBConnectionFactory.java src/main/java/nl/cwi/monetdb/responses/AutoCommitResponse.java src/main/java/nl/cwi/monetdb/responses/DataBlockResponse.java src/main/java/nl/cwi/monetdb/responses/IResponse.java src/main/java/nl/cwi/monetdb/responses/ResponseList.java src/main/java/nl/cwi/monetdb/responses/ResultSetResponse.java src/main/java/nl/cwi/monetdb/responses/SchemaResponse.java src/main/java/nl/cwi/monetdb/responses/SendThread.java src/main/java/nl/cwi/monetdb/responses/UpdateResponse.java src/main/java/nl/cwi/monetdb/util/ChannelSecurity.java Removed Files: src/main/java/nl/cwi/monetdb/mcl/MCLException.java src/main/java/nl/cwi/monetdb/mcl/connection/AbstractMonetDBConnection.java src/main/java/nl/cwi/monetdb/mcl/connection/DeleteMe.java src/main/java/nl/cwi/monetdb/mcl/io/SocketIOHandler.java Modified Files: 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/connection/EmbeddedMonetDB.java src/main/java/nl/cwi/monetdb/mcl/connection/MapiConnection.java src/main/java/nl/cwi/monetdb/mcl/connection/MonetDBLanguage.java src/main/java/nl/cwi/monetdb/mcl/io/SocketConnection.java src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocolParser.java src/main/java/nl/cwi/monetdb/mcl/protocol/newmapi/NewMapiProtocol.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java src/main/java/nl/cwi/monetdb/merovingian/Control.java src/main/java/nl/cwi/monetdb/util/SQLRestore.java Branch: embedded Log Message:
More done diffs (truncated from 6677 to 300 lines): 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 @@ -1,2698 +1,1287 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. - */ - package nl.cwi.monetdb.jdbc; -import java.io.File; -import java.io.IOException; -import java.net.SocketException; -import java.net.SocketTimeoutException; -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.NClob; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Savepoint; -import java.sql.Statement; -import java.sql.Struct; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.WeakHashMap; -import java.util.concurrent.Executor; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - 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.AbstractMCLReader; -import nl.cwi.monetdb.mcl.io.AbstractMCLWriter; -import nl.cwi.monetdb.mcl.connection.EmbeddedMonetDB; -import nl.cwi.monetdb.mcl.connection.DeleteMe; -import nl.cwi.monetdb.mcl.connection.AbstractMonetDBConnection; -import nl.cwi.monetdb.mcl.parser.HeaderLineParser; -import nl.cwi.monetdb.mcl.parser.StartOfHeaderParser; +import nl.cwi.monetdb.mcl.connection.MCLException; +import nl.cwi.monetdb.mcl.connection.Debugger; +import nl.cwi.monetdb.mcl.connection.MonetDBLanguage; import nl.cwi.monetdb.mcl.parser.MCLParseException; +import nl.cwi.monetdb.responses.ResponseList; +import nl.cwi.monetdb.responses.SendThread; + +import java.io.*; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.sql.*; +import java.util.*; +import java.util.concurrent.Executor; /** * A {@link Connection} suitable for the MonetDB database. - * + * * This connection represents a connection (session) to a MonetDB * database. SQL statements are executed and results are returned within * the context of a connection. This Connection object holds a physical * connection to the MonetDB database. - * + * * A Connection object's database should able to provide information * describing its tables, its supported SQL grammar, its stored * procedures, the capabilities of this connection, and so on. This * information is obtained with the getMetaData method. - * + * * Note: By default a Connection object is in auto-commit mode, which * means that it automatically commits changes after executing each * statement. If auto-commit mode has been disabled, the method commit * must be called explicitly in order to commit changes; otherwise, * database changes will not be saved. - * + * * The current state of this connection is that it nearly implements the * whole Connection interface. * * @author Fabian Groffen * @version 1.2 */ -public class MonetConnection extends MonetWrapper implements Connection { - - /** A connection to mserver5 either through MAPI with TCP or embedded */ - private final AbstractMonetDBConnection server; - /** The Reader from the server */ - private final AbstractMCLReader in; - /** The Writer to the server */ - private final AbstractMCLWriter out; - /** A StartOfHeaderParser declared for reuse. */ - private final StartOfHeaderParser sohp; - - /** Whether this Connection is closed (and cannot be used anymore) */ - private boolean closed; +public abstract class MonetConnection extends MonetWrapper implements Connection { - /** Whether this Connection is in autocommit mode */ - private boolean autoCommit = true; - - /** The stack of warnings for this Connection object */ - private SQLWarning warnings = null; - /** The Connection specific mapping of user defined types to Java - * types */ - private Map<String,Class<?>> typeMap = new HashMap<String,Class<?>>() {/** - * - */ - private static final long serialVersionUID = 1L; - { - put("inet", INET.class); - put("url", URL.class); - } - }; + /** the successful processed input properties */ + private final Properties conn_props; - // See javadoc for documentation about WeakHashMap if you don't know what - // it does !!!NOW!!! (only when you deal with it of course) - /** A Map containing all (active) Statements created from this Connection */ - 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 */ - private final boolean blobIsBinary; + /** The language to connect with */ + protected MonetDBLanguage currentMonetDBLanguage = MonetDBLanguage.LANG_SQL; + /** 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 */ + private SendThread sendThread; + /** Whether this Connection is closed (and cannot be used anymore) */ + private boolean closed; + /** Whether this Connection is in autocommit mode */ + private boolean autoCommit = true; + /** The stack of warnings for this Connection object */ + private SQLWarning warnings; + /** The Connection specific mapping of user defined types to Java types */ + private Map<String,Class<?>> typeMap = new HashMap<String,Class<?>>() { + private static final long serialVersionUID = 1L; { + put("inet", INET.class); + put("url", URL.class); + } + }; - /** - * Constructor of a Connection for MonetDB. At this moment the - * current implementation limits itself to storing the given host, - * database, username and password for later use by the - * createStatement() call. This constructor is only accessible to - * classes from the jdbc package. - * - * @param props a Property hashtable holding the properties needed for - * connecting - * @throws SQLException if a database error occurs - * @throws IllegalArgumentException is one of the arguments is null or empty - */ - MonetConnection(Properties props) - throws SQLException, IllegalArgumentException - { - 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")); - blobIsBinary = Boolean.valueOf(props.getProperty("treat_blob_as_binary")); + // See javadoc for documentation about WeakHashMap if you don't know what + // it does !!!NOW!!! (only when you deal with it of course) + /** A Map containing all (active) Statements created from this Connection */ + private Map<Statement,?> statements = new WeakHashMap<Statement, Object>(); - if(isEmbedded) { - String directory = props.getProperty("directory"); - if (directory == null || directory.trim().isEmpty()) - throw new IllegalArgumentException("directory should not be null or empty"); + /** The number of results we receive from the server at once */ + private int curReplySize = -1; // the server by default uses -1 (all) - server = new EmbeddedMonetDB("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; + /** Whether or not BLOB is mapped to BINARY within the driver */ + private final boolean blobIsBinary; - try { - port = Integer.parseInt(props.getProperty("port")); - } catch (NumberFormatException e) { - } - try { - sockTimeout = Integer.parseInt(props.getProperty("so_timeout")); - } catch (NumberFormatException e) { - } + protected boolean isDebugging; + + protected Debugger ourSavior; - // 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 DeleteMe(hostname, port, database, username, debug, language, hash); - try { - server.setSoTimeout(sockTimeout); - } catch (SocketException e) { - addWarning("The socket timeout could not be set", "M1M05"); - } - server.setLanguage(language); - } + /** + * Constructor of a Connection for MonetDB. At this moment the + * current implementation limits itself to storing the given host, + * database, username and password for later use by the + * createStatement() call. This constructor is only accessible to + * classes from the jdbc package. + * + * @throws IOException if an error occurs + */ + public MonetConnection(Properties props, String database, String hash, String language, boolean blobIsBinary, boolean isDebugging) throws IOException { + this.conn_props = props; + this.database = database; + this.hash = hash; + this.currentMonetDBLanguage = MonetDBLanguage.GetLanguageFromString(language); + this.blobIsBinary = blobIsBinary; + this.isDebugging = isDebugging; + } - // we're debugging here... uhm, should be off in real life - if (debug) { - try { - String fname = props.getProperty("logfile", "monet_" + - System.currentTimeMillis() + ".log"); - File f = new File(fname); - int ext = fname.lastIndexOf('.'); - if (ext < 0) ext = fname.length(); - String pre = fname.substring(0, ext); - String suf = fname.substring(ext); - - for (int i = 1; f.exists(); i++) { - f = new File(pre + "-" + i + suf); - } + public MonetDBLanguage getCurrentMonetDBLanguage() { + return currentMonetDBLanguage; + } - server.debug(f.getAbsolutePath()); - } catch (IOException ex) { - throw new SQLException("Opening logfile failed: " + ex.getMessage(), "08M01"); - } - } + public void setCurrentMonetDBLanguage(MonetDBLanguage currentMonetDBLanguage) { + this.currentMonetDBLanguage = currentMonetDBLanguage; + } - try { - List<String> warnings = server.connect(username, password); - if(warnings != null) { - for (String warning : warnings) { - addWarning(warning, "01M02"); - } - } - - in = server.getReader(); - out = server.getWriter(); - String error = in.waitForPrompt(); _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
