changeset 88:1bba35253aaf embedded

Finished the mappings in the JDBC embedded connection. Now what is left to do is testing (the JDBC embedded connection needs extensive testing), compile for other OS than Linux, merge with the Dec16 branch (headless) and some possible optimizations.
author Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
date Wed, 04 Jan 2017 16:35:50 +0000 (2017-01-04)
parents 2b5e32efb1a4
children 6f74e01c57da
files src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.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/jdbc/MonetStatement.java src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.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/mcl/protocol/oldmapi/OldMapiTupleLineParser.java
diffstat 8 files changed, 49 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
@@ -149,7 +149,7 @@ public abstract class MonetConnection ex
      * Calling the method close on a Connection object that is already closed is a no-op.
      */
     @Override
-    public synchronized void close() {
+    public void close() {
         for (Statement st : statements.keySet()) {
             try {
                 st.close();
@@ -274,7 +274,8 @@ public abstract class MonetConnection ex
      * concurrency, and holdability
      */
     @Override
-    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+            throws SQLException {
         try {
             Statement ret = new MonetStatement(this, resultSetType, resultSetConcurrency, resultSetHoldability);
             // store it in the map for when we close...
@@ -288,11 +289,9 @@ public abstract class MonetConnection ex
     }
 
     /**
-     * Retrieves the current auto-commit mode for this Connection
-     * object.
+     * Retrieves the current auto-commit mode for this Connection object.
      *
-     * @return the current state of this Connection object's auto-commit
-     *         mode
+     * @return the current state of this Connection object's auto-commit mode
      * @see #setAutoCommit(boolean)
      */
     @Override
@@ -304,8 +303,7 @@ public abstract class MonetConnection ex
      * Retrieves this Connection object's current catalog name.
      *
      * @return the current catalog name or null if there is none
-     * @throws SQLException if a database access error occurs or the
-     *         current language is not SQL
+     * @throws SQLException if a database access error occurs or the current language is not SQL
      */
     @Override
     public String getCatalog() throws SQLException {
@@ -314,12 +312,9 @@ public abstract class MonetConnection ex
     }
 
     /**
-     * Retrieves the current holdability of ResultSet objects created
-     * using this Connection object.
+     * Retrieves the current holdability of ResultSet objects created using this Connection object.
      *
-     * @return the holdability, one of
-     *         ResultSet.HOLD_CURSORS_OVER_COMMIT or
-     *         ResultSet.CLOSE_CURSORS_AT_COMMIT
+     * @return the holdability, one of ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
      */
     @Override
     public int getHoldability() {
@@ -357,9 +352,8 @@ public abstract class MonetConnection ex
     }
 
     /**
-     * Retrieves the Map object associated with this Connection object.
-     * Unless the application has added an entry, the type map returned
-     * will be empty.
+     * Retrieves the Map object associated with this Connection object. Unless the application has added an entry,
+     * the type map returned will be empty.
      *
      * @return the java.util.Map object associated with this Connection object
      */
@@ -689,7 +683,7 @@ public abstract class MonetConnection ex
      */
     @Override
     public void setCatalog(String catalog) throws SQLException {
-        // silently ignore this request as MonetDB does not support catalogs
+        throw new SQLFeatureNotSupportedException("setCatalog(String catalog) not supported", "0A000");
     }
 
     /**
@@ -777,18 +771,15 @@ public abstract class MonetConnection ex
      * interface Connection are the possible transaction isolation
      * levels.
      *
-     * @param level one of the following Connection constants:
-     *        Connection.TRANSACTION_READ_UNCOMMITTED,
-     *        Connection.TRANSACTION_READ_COMMITTED,
-     *        Connection.TRANSACTION_REPEATABLE_READ, or
+     * @param level one of the following Connection constants: Connection.TRANSACTION_READ_UNCOMMITTED,
+     *        Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ, or
      *        Connection.TRANSACTION_SERIALIZABLE.
      */
     @Override
     public void setTransactionIsolation(int level) {
         if (level != TRANSACTION_SERIALIZABLE) {
             addWarning("MonetDB only supports fully serializable " +
-                    "transactions, continuing with transaction level " +
-                    "raised to TRANSACTION_SERIALIZABLE", "01M09");
+                    "transactions, continuing with transaction level raised to TRANSACTION_SERIALIZABLE", "01M09");
         }
     }
 
@@ -881,8 +872,7 @@ public abstract class MonetConnection ex
      */
     @Override
     public java.sql.Blob createBlob() throws SQLException {
-        byte[] buf = new byte[1];
-        return new MonetBlob(buf);
+        return new MonetBlob(new byte[1]);
     }
 
     /**
@@ -1116,8 +1106,7 @@ public abstract class MonetConnection ex
     public void setClientInfo(Properties props) throws java.sql.SQLClientInfoException {
         if (props != null) {
             for (Map.Entry<Object, Object> entry : props.entrySet()) {
-                setClientInfo(entry.getKey().toString(),
-                        entry.getValue().toString());
+                setClientInfo(entry.getKey().toString(), entry.getValue().toString());
             }
         }
     }
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
@@ -508,7 +508,15 @@ final public class MonetDriver implement
 				throw new SQLException("Unable to connect (" + con.getHostname() + ":"
 						+ con.getPort() + "): " + e.getMessage(), "08006");
 			} else {
-				throw new SQLException("Unable to connect the provided directory : " + e.getMessage(), "08006");
+                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());
+                }
 			}
 		} catch (ProtocolException e) {
 			throw new SQLException(e.getMessage(), "08001");
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -2573,11 +2573,12 @@ public class MonetResultSet extends Mone
 				case Types.LONGVARCHAR:
 				case Types.CLOB:
 					return new URL(currentBlock.getValueAsString(columnIndex - 1));
-			}
-			if(JdbcSQLTypes[columnIndex - 1] == Types.OTHER && "url".equals(types[columnIndex - 1])) {
-				return new URL(currentBlock.getValueAsString(columnIndex - 1));
-			} else {
-				throw new SQLException("Cannot convert " + types[columnIndex - 1] + " to an url", "M1M05");
+				case Types.OTHER:
+					if("url".equals(types[columnIndex - 1])) {
+						return new URL(currentBlock.getValueAsString(columnIndex - 1));
+					}
+				default:
+					throw new SQLException("Cannot convert " + types[columnIndex - 1] + " to an url", "M1M05");
 			}
 		} catch (IndexOutOfBoundsException e) {
 			throw newSQLInvalidColumnIndexException(columnIndex);
@@ -2587,9 +2588,8 @@ public class MonetResultSet extends Mone
 	}
 
 	/**
-	 * Retrieves the value of the designated column in the current row
-	 * of this ResultSet object as a java.net.URL object in the Java
-	 * programming language.
+	 * Retrieves the value of the designated column in the current row of this ResultSet object as a java.net.URL object
+	 * in the Java programming language.
 	 *
 	 * @param columnName the SQL name of the column
 	 * @return the column value as a java.net.URL object; if the value is SQL NULL, the value returned is null in the
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
@@ -773,12 +773,10 @@ public class MonetStatement extends Mone
 	}
 
 	/**
-	 * Retrieves the number of seconds the driver will wait for a
-	 * Statement object to execute.  If the limit is exceeded, a
-	 * SQLException is thrown.
+	 * Retrieves the number of seconds the driver will wait for a Statement object to execute. If the limit is exceeded,
+	 * a SQLException is thrown.
 	 *
-	 * @return the current query timeout limit in seconds; zero means
-	 *         there is no limit
+	 * @return the current query timeout limit in seconds; zero means there is no limit
 	 * @throws SQLException if a database access error occurs
 	 * @see #setQueryTimeout(int)
 	 */
@@ -807,11 +805,10 @@ public class MonetStatement extends Mone
 	}
 
 	/**
-	 * Retrieves the current result as a ResultSet object.  This method
-	 * should be called only once per result.
+	 * Retrieves the current result as a ResultSet object. This method should be called only once per result.
 	 *
-	 * @return the current result as a ResultSet object or null if the result
-	 *         is an update count or there are no more results
+	 * @return the current result as a ResultSet object or null if the result is an update count or there are no more
+	 * results
 	 * @throws SQLException if a database access error occurs
 	 */
 	@Override
@@ -821,8 +818,7 @@ public class MonetStatement extends Mone
 	}
 
 	/**
-	 * Retrieves the result set concurrency for ResultSet objects generated
-	 * by this Statement object.
+	 * Retrieves the result set concurrency for ResultSet objects generated by this Statement object.
 	 *
 	 * @return either ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
 	 */
@@ -832,11 +828,9 @@ public class MonetStatement extends Mone
 	}
 
 	/**
-	 * Retrieves the result set holdability for ResultSet objects
-	 * generated by this Statement object.
+	 * Retrieves the result set holdability for ResultSet objects generated by this Statement object.
 	 *
-	 * @return either ResultSet.HOLD_CURSORS_OVER_COMMIT or
-	 *         ResultSet.CLOSE_CURSORS_AT_COMMIT
+	 * @return either ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
 	 * @throws SQLException if a database access error occurs
 	 */
 	@Override
@@ -845,12 +839,9 @@ public class MonetStatement extends Mone
 	}
 
 	/**
-	 * Retrieves the result set type for ResultSet objects generated by this
-	 * Statement object.
+	 * Retrieves the result set type for ResultSet objects generated by this Statement object.
 	 *
-	 * @return one of ResultSet.TYPE_FORWARD_ONLY,
-	 *         ResultSet.TYPE_SCROLL_INSENSITIVE, or
-	 *         ResultSet.TYPE_SCROLL_SENSITIVE
+	 * @return one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
 	 */
 	@Override
 	public int getResultSetType() {
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
@@ -149,7 +149,7 @@ public class MapiConnection extends Mone
      * setting can be useful to break out of this indefinite wait. This option must be enabled prior to entering the
      * blocking operation to have effect.
      *
-     * @param s The specified timeout, in milliseconds.  A timeout of zero is interpreted as an infinite timeout.
+     * @param s The specified timeout, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
      */
     @Override
     public void setSoTimeout(int s)  {
@@ -167,7 +167,7 @@ public class MapiConnection extends Mone
     }
 
     @Override
-    public void closeUnderlyingConnection() throws IOException {
+    public synchronized void closeUnderlyingConnection() throws IOException {
         ((OldMapiProtocol)protocol).getSocket().close();
     }
 
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/newmapi/NewMapiProtocol.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/newmapi/NewMapiProtocol.java
@@ -76,7 +76,7 @@ public class NewMapiProtocol extends Abs
     }
 
     @Override
-    public void writeNextQuery(String prefix, String query, String suffix) throws IOException {
+    public synchronized void writeNextQuery(String prefix, String query, String suffix) throws IOException {
 
     }
 }
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
@@ -149,7 +149,7 @@ public class OldMapiProtocol extends Abs
     }
 
     @Override
-    public void writeNextQuery(String prefix, String query, String suffix) throws IOException {
+    public synchronized void writeNextQuery(String prefix, String query, String suffix) throws IOException {
         this.socket.writeNextLine(prefix, query, suffix);
         this.currentServerResponseHeader = ServerResponses.UNKNOWN; //reset reader state
     }
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParser.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParser.java
@@ -19,6 +19,7 @@ import java.nio.CharBuffer;
 import java.sql.Types;
 import java.text.ParsePosition;
 import java.util.Calendar;
+
 final class OldMapiTupleLineParser {
 
     private static final char[] NULL_STRING = "NULL".toCharArray();