Changeset: 7307caacc2d5 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=7307caacc2d5
Added Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
        
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiServerResponseParser.java
        
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiStartOfHeaderParser.java
        
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java
        src/main/java/nl/cwi/monetdb/mcl/responses/AutoCommitResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/IIncompleteResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/IResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/SchemaResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/UpdateResponse.java
Removed Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
        src/main/java/nl/cwi/monetdb/mcl/parser/StartOfHeaderParser.java
        
src/main/java/nl/cwi/monetdb/mcl/parser/socket/SocketHeaderLineParser.java
        
src/main/java/nl/cwi/monetdb/mcl/parser/socket/SocketStartOfHeaderParser.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocolParser.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiConverter.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/UpdateResponse.java
Modified Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetClob.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/MonetPreparedStatement.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetSavepoint.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
        src/main/java/nl/cwi/monetdb/mcl/connection/EmbeddedConnection.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/connection/SendThread.java
        src/main/java/nl/cwi/monetdb/mcl/io/SocketConnection.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/TableResultHeaders.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/embedded/EmbeddedProtocol.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
Branch: embedded
Log Message:

Intermediary commit. Cross-implementation interface (for mapi connection with 
the old protocol, mapi connection with the new protocol and the embedded 
connection) almost done. The mcl layer processing is more memory efficient now.


diffs (truncated from 5595 to 300 lines):

diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
@@ -23,20 +23,20 @@ import java.io.*;
  * @author Fabian Groffen
  */
 public class MonetBlob implements Blob {
+
        private byte[] buf;
 
-       public MonetBlob(byte[] data) {
-               buf = data;
+       MonetBlob(byte[] buf) {
+               this.buf = buf;
        }
-       
-       static MonetBlob create(String in) {
+
+       MonetBlob(String in) {
                int len = in.length() / 2;
-               byte[] buf = new byte[len];
-               for (int i = 0; i < len; i++)
-                       buf[i] = (byte)Integer.parseInt(in.substring(2 * i, (2 
* i) + 2), 16);
-               return new MonetBlob(buf);
+               this.buf = new byte[len];
+               for (int i = 0; i < len; i++) {
+                       this.buf[i] = (byte) Integer.parseInt(in.substring(2 * 
i, (2 * i) + 2), 16);
+               }
        }
-       
 
        //== begin interface Blob
        
@@ -93,9 +93,7 @@ public class MonetBlob implements Blob {
         *         not support this method
         */
        @Override
-       public InputStream getBinaryStream(long pos, long length)
-               throws SQLException
-       {
+       public InputStream getBinaryStream(long pos, long length) throws 
SQLException {
                if (buf == null)
                        throw new SQLException("This Blob object has been 
freed", "M1M20");
                if (pos < 1)
@@ -261,9 +259,7 @@ public class MonetBlob implements Blob {
         *         BLOB value
         */
        @Override
-       public int setBytes(long pos, byte[] bytes, int offset, int len)
-               throws SQLException
-       {
+       public int setBytes(long pos, byte[] bytes, int offset, int len) throws 
SQLException {
                if (buf == null)
                        throw new SQLException("This Blob object has been 
freed", "M1M20");
                try {
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetClob.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetClob.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetClob.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetClob.java
@@ -26,7 +26,7 @@ public class MonetClob implements Clob {
        
        private StringBuilder buf;
 
-       public MonetClob(String in) {
+       MonetClob(String in) {
                buf = new StringBuilder(in);
        }
 
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
@@ -6,8 +6,12 @@ import nl.cwi.monetdb.mcl.connection.MCL
 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.mcl.protocol.AbstractProtocol;
+import nl.cwi.monetdb.mcl.protocol.ServerResponses;
+import nl.cwi.monetdb.mcl.responses.*;
 import nl.cwi.monetdb.mcl.connection.SendThread;
+import nl.cwi.monetdb.mcl.responses.DataBlockResponse;
+import nl.cwi.monetdb.mcl.responses.ResultSetResponse;
 
 import java.io.*;
 import java.net.SocketTimeoutException;
@@ -42,6 +46,19 @@ import java.util.concurrent.Executor;
  */
 public abstract class MonetConnection extends MonetWrapper implements 
Connection {
 
+    /** the default number of rows that are (attempted to) read at once */
+    private static int DEF_FETCHSIZE = 250;
+    /** The sequence counter */
+    private static int SeqCounter = 0;
+
+    public static int GetDefFetchsize() {
+        return DEF_FETCHSIZE;
+    }
+
+    public static int GetSeqCounter() {
+        return SeqCounter;
+    }
+
     /** the successful processed input properties */
     protected final Properties conn_props;
     /** The language to connect with */
@@ -81,6 +98,8 @@ public abstract class MonetConnection ex
 
     protected Debugger ourSavior;
 
+    protected AbstractProtocol<?> protocol;
+
     /**
      * Constructor of a Connection for MonetDB. At this moment the
      * current implementation limits itself to storing the given host,
@@ -103,8 +122,8 @@ public abstract class MonetConnection ex
         return language;
     }
 
-    public void setLanguage(MonetDBLanguage language) {
-        this.language = language;
+    public void setClosed(boolean closed) {
+        this.closed = closed;
     }
 
     public void setDebugging(String filename) throws IOException {
@@ -135,6 +154,10 @@ public abstract class MonetConnection ex
 
     public abstract String getJDBCURL();
 
+    public AbstractProtocol<?> getProtocol() {
+        return this.protocol;
+    }
+
     /**
      * Releases this Connection object's database and JDBC resources
      * immediately instead of waiting for them to be automatically
@@ -199,6 +222,17 @@ public abstract class MonetConnection ex
         warnings = null;
     }
 
+    private void createResponseList(String query) throws SQLException {
+        // create a container for the result
+        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
+        // send commit to the server
+        try {
+            l.processQuery(query);
+        } finally {
+            l.close();
+        }
+    }
+
     /**
      * Makes all changes made since the previous commit/rollback
      * permanent and releases any database locks currently held by this
@@ -213,15 +247,7 @@ public abstract class MonetConnection ex
     public void commit() throws SQLException {
         // note: can't use sendIndependentCommand here because we need
         // to process the auto_commit state the server gives
-
-        // create a container for the result
-        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
-        // send commit to the server
-        try {
-            l.processQuery("COMMIT");
-        } finally {
-            l.close();
-        }
+        this.createResponseList("COMMIT");
     }
 
     /**
@@ -619,13 +645,7 @@ public abstract class MonetConnection ex
         // note: can't use sendIndependentCommand here because we need
         // to process the auto_commit state the server gives
         // create a container for the result
-        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
-        // send the appropriate query string to the database
-        try {
-            l.processQuery("RELEASE SAVEPOINT " + sp.getName());
-        } finally {
-            l.close();
-        }
+        this.createResponseList("RELEASE SAVEPOINT " + sp.getName());
     }
 
     /**
@@ -643,13 +663,7 @@ public abstract class MonetConnection ex
         // note: can't use sendIndependentCommand here because we need
         // to process the auto_commit state the server gives
         // create a container for the result
-        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
-        // send rollback to the server
-        try {
-            l.processQuery("ROLLBACK");
-        } finally {
-            l.close();
-        }
+        this.createResponseList("ROLLBACK");
     }
 
     /**
@@ -673,13 +687,7 @@ public abstract class MonetConnection ex
         // note: can't use sendIndependentCommand here because we need
         // to process the auto_commit state the server gives
         // create a container for the result
-        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
-        // send the appropriate query string to the database
-        try {
-            l.processQuery("ROLLBACK TO SAVEPOINT " + sp.getName());
-        } finally {
-            l.close();
-        }
+        this.createResponseList("ROLLBACK TO SAVEPOINT " + sp.getName());
     }
 
     /**
@@ -710,7 +718,7 @@ public abstract class MonetConnection ex
     @Override
     public void setAutoCommit(boolean autoCommit) throws SQLException {
         if (this.autoCommit != autoCommit) {
-            sendControlCommand("auto_commit " + (autoCommit ? "1" : "0"));
+            this.sendControlCommand("auto_commit " + (autoCommit ? "1" : "0"));
             this.autoCommit = autoCommit;
         }
     }
@@ -774,13 +782,7 @@ public abstract class MonetConnection ex
         // note: can't use sendIndependentCommand here because we need
         // to process the auto_commit state the server gives
         // create a container for the result
-        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
-        // send the appropriate query string to the database
-        try {
-            l.processQuery("SAVEPOINT " + sp.getName());
-        } finally {
-            l.close();
-        }
+        this.createResponseList("SAVEPOINT " + sp.getName());
         return sp;
     }
 
@@ -806,13 +808,7 @@ public abstract class MonetConnection ex
         // note: can't use sendIndependentCommand here because we need
         // to process the auto_commit state the server gives
         // create a container for the result
-        ResponseList l = new ResponseList(0, 0, ResultSet.FETCH_FORWARD, 
ResultSet.CONCUR_READ_ONLY);
-        // send the appropriate query string to the database
-        try {
-            l.processQuery("SAVEPOINT " + sp.getName());
-        } finally {
-            l.close();
-        }
+        this.createResponseList("SAVEPOINT " + sp.getName());
         return sp;
     }
 
@@ -893,9 +889,7 @@ public abstract class MonetConnection ex
      * @since 1.6
      */
     @Override
-    public java.sql.Array createArrayOf(String typeName, Object[] elements)
-            throws SQLException
-    {
+    public java.sql.Array createArrayOf(String typeName, Object[] elements) 
throws SQLException {
         throw new SQLFeatureNotSupportedException("createArrayOf() not 
supported", "0A000");
     }
 
@@ -965,9 +959,7 @@ public abstract class MonetConnection ex
      * @since 1.6
      */
     @Override
-    public java.sql.Struct createStruct(String typeName, Object[] attributes)
-            throws SQLException
-    {
+    public java.sql.Struct createStruct(String typeName, Object[] attributes) 
throws SQLException {
         throw new SQLFeatureNotSupportedException("createStruct() not 
supported", "0A000");
     }
 
@@ -1329,10 +1321,12 @@ public abstract class MonetConnection ex
     public void sendIndependentCommand(String command) throws SQLException {
         synchronized (this) {
             try {
-                out.writeLine(language.getQueryTemplateIndex(0) + command + 
language.getQueryTemplateIndex(1));
-                String error = in.waitForPrompt();
-                if (error != null)
+                protocol.writeNextCommand(language.getQueryTemplateIndex(0), 
command.getBytes(), language.getQueryTemplateIndex(1));
+                protocol.waitUntilPrompt();
+                if (protocol.getCurrentServerResponseHeader() == 
ServerResponses.ERROR) {
+                    String error = protocol.getRemainingStringLine(0);
                     throw new SQLException(error.substring(6), 
error.substring(0, 5));
+                }
             } catch (SocketTimeoutException e) {
                 close(); // JDBC 4.1 semantics: abort()
                 throw new SQLException("connection timed out", "08M33");
@@ -1355,10 +1349,12 @@ public abstract class MonetConnection ex
         // send X command
         synchronized (this) {
             try {
-                out.writeLine(language.getCommandTemplateIndex(0) + command + 
language.getCommandTemplateIndex(1));
-                String error = in.waitForPrompt();
-                if (error != null)
+                protocol.writeNextCommand(language.getCommandTemplateIndex(0), 
command.getBytes(), language.getCommandTemplateIndex(1));
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to