Changeset: 724a0061db63 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=724a0061db63
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/embedded/EmbeddedConnection.java
        
src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedLanguage.java
        
src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
        src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
        src/main/java/nl/cwi/monetdb/mcl/connection/mapi/OldMapiSocket.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
        src/main/java/nl/cwi/monetdb/mcl/responses/UpdateResponse.java
Branch: embedded
Log Message:

Only some rare data types mapping is missing on the JDBC embedded connection. I 
will now be testing extensively, then adding these mappings to finish the JDBC 
embedded connection.


diffs (287 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
@@ -131,6 +131,10 @@ public abstract class MonetConnection ex
         return ourSavior;
     }
 
+    public AbstractProtocol getProtocol() {
+        return this.protocol;
+    }
+
     /**
      * Connects to the given host and port, logging in as the given user. If 
followRedirect is false, a
      * RedirectionException is thrown when a redirect is encountered.
@@ -154,15 +158,10 @@ public abstract class MonetConnection ex
 
     public abstract String getJDBCURL();
 
-    public AbstractProtocol getProtocol() {
-        return this.protocol;
-    }
-
     public abstract void sendControlCommand(ControlCommands con, int data) 
throws SQLException;
 
-    public abstract ResponseList createResponseList(int fetchSize, int 
maxRows, int resultSetType, int resultSetConcurrency) throws SQLException;
-
-    public abstract void setServerMaxRows(int maxRows) throws SQLException;
+    public abstract ResponseList createResponseList(int fetchSize, int 
maxRows, int resultSetType,
+                                                    int resultSetConcurrency) 
throws SQLException;
 
     /**
      * Releases this Connection object's database and JDBC resources 
immediately instead of waiting for them to be
@@ -1494,7 +1493,7 @@ public abstract class MonetConnection ex
                 // don't do work if it's not needed
                 if (language == MapiLanguage.LANG_SQL && size != curReplySize 
&&
                         !Arrays.deepEquals(templ, 
language.getCommandTemplates())) {
-                    setServerMaxRows(size);
+                    sendControlCommand(ControlCommands.REPLY_SIZE, size);
                     // store the reply size after a successful change
                     curReplySize = size;
                 }
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
@@ -668,12 +668,12 @@ public class MonetStatement extends Mone
                jdbcTypes[0] = MonetDriver.getJavaType(types[0]);
 
                if (header instanceof UpdateResponse) {
-                       String lastid = ((UpdateResponse)header).getLastid();
-                       if (lastid.equals("-1")) {
+                       int lastid = ((UpdateResponse)header).getLastid();
+                       if (lastid ==-1) {
                                results = new String[1][1];
                        } else {
                                results = new String[1][1];
-                               results[0][0] = lastid;
+                               results[0][0] = Integer.toString(lastid);
                        }
                } else {
                        results = new String[1][1];
@@ -869,7 +869,7 @@ public class MonetStatement extends Mone
        public int getUpdateCount() throws SQLException {
                int ret = -1;
                if (header instanceof UpdateResponse) {
-                       ret = ((UpdateResponse)header).getCount();
+                       ret =  ((UpdateResponse)header).getCount();
                } else if (header instanceof SchemaResponse) {
                        ret = ((SchemaResponse)header).getState();
                }
diff --git 
a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java 
b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java
--- 
a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java
+++ 
b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java
@@ -85,7 +85,6 @@ public final class EmbeddedConnection ex
 
     @Override
     public void sendControlCommand(ControlCommands con, int data) throws 
SQLException {
-        try {
             switch (con) {
                 case AUTO_COMMIT:
                     
((EmbeddedProtocol)protocol).getEmbeddedConnection().sendAutocommitCommand(data);
@@ -95,16 +94,13 @@ public final class EmbeddedConnection ex
                     break;
                 case CLOSE:
                     
((EmbeddedProtocol)protocol).getEmbeddedConnection().sendCloseCommand(data);
+                    break;
                 case REPLY_SIZE:
-                    throw new SQLException("Cannot set reply size on a 
Embedded connection!", "M1M05");
+                    
((EmbeddedProtocol)protocol).getEmbeddedConnection().sendReplySizeCommand(data);
             }
-            protocol.waitUntilPrompt();
             if (protocol.getCurrentServerResponseHeader() == 
ServerResponses.ERROR) {
                 throw new SQLException(protocol.getRemainingStringLine(0));
             }
-        } catch (IOException ex) {
-            throw new SQLException(ex);
-        }
     }
 
     @Override
@@ -112,8 +108,4 @@ public final class EmbeddedConnection ex
         return new MonetConnection.ResponseList(this.getDefFetchsize(), 
maxRows, resultSetType, resultSetConcurrency);
     }
 
-    @Override
-    public void setServerMaxRows(int maxRows) throws SQLException {
-        
((EmbeddedProtocol)protocol).getEmbeddedConnection().setMaxRows(maxRows);
-    }
 }
diff --git 
a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedLanguage.java 
b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedLanguage.java
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedLanguage.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedLanguage.java
@@ -8,9 +8,9 @@ import nl.cwi.monetdb.mcl.connection.IMo
 public enum EmbeddedLanguage implements IMonetDBLanguage {
 
     /** the SQL language */
-    LANG_SQL(null, "sql"),
+    LANG_SQL(new String[]{null, null, null}, "sql"),
     /** an unknown language */
-    LANG_UNKNOWN(null, "unknown");
+    LANG_UNKNOWN(new String[]{null, null, null}, "unknown");
 
     EmbeddedLanguage(String[] queryTemplates, String representation) {
         this.queryTemplates = queryTemplates;
@@ -23,7 +23,7 @@ public enum EmbeddedLanguage implements 
 
     @Override
     public String getQueryTemplateIndex(int index) {
-        return queryTemplates[index];
+        return this.queryTemplates[index];
     }
 
     @Override
@@ -33,7 +33,7 @@ public enum EmbeddedLanguage implements 
 
     @Override
     public String[] getQueryTemplates() {
-        return queryTemplates;
+        return this.queryTemplates;
     }
 
     @Override
diff --git 
a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
 
b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
--- 
a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
+++ 
b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java
@@ -11,8 +11,6 @@ import nl.cwi.monetdb.mcl.responses.IRes
  */
 public class JDBCEmbeddedConnection extends MonetDBEmbeddedConnection {
 
-    private int maxRows = Integer.MAX_VALUE;
-
     private long lastResultSetPointer;
 
     private final ServerResponses[] lineResponse = new ServerResponses[4];
@@ -31,10 +29,6 @@ public class JDBCEmbeddedConnection exte
         super(connectionPointer);
     }
 
-    void setMaxRows(int maxRows) {
-        this.maxRows = maxRows;
-    }
-
     public ServerResponses getNextServerResponse() {
         return lineResponse[currentLineResponseState++];
     }
@@ -85,6 +79,10 @@ public class JDBCEmbeddedConnection exte
         this.sendCloseCommandInternal(this.connectionPointer, commandId);
     }
 
+    void sendReplySizeCommand(int size) {
+        this.sendReplySizeCommandInternal(this.connectionPointer, size);
+    }
+
     private native void getNextTableHeaderInternal(long resultSetPointer, 
String[] columnNames, int[] columnLengths,
                                                    String[] types, String[] 
tableNames);
 
@@ -98,4 +96,6 @@ public class JDBCEmbeddedConnection exte
     private native void sendReleaseCommandInternal(long connectionPointer, int 
commandId);
 
     private native void sendCloseCommandInternal(long connectionPointer, int 
commandId);
+
+    private native void sendReplySizeCommandInternal(long connectionPointer, 
int size);
 }
diff --git 
a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java 
b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
@@ -222,11 +222,6 @@ public class MapiConnection extends Mone
     }
 
     @Override
-    public void setServerMaxRows(int maxRows) throws SQLException {
-        this.sendControlCommand(ControlCommands.REPLY_SIZE, maxRows);
-    }
-
-    @Override
     public List<String> connect(String user, String pass) throws IOException, 
ProtocolException, MCLException {
         // Wrap around the internal connect that needs to know if it should 
really make a TCP connection or not.
         List<String> res = connect(this.hostname, this.port, user, pass, true);
diff --git 
a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/OldMapiSocket.java 
b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/OldMapiSocket.java
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/OldMapiSocket.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/OldMapiSocket.java
@@ -93,8 +93,7 @@ public class OldMapiSocket extends Abstr
             while (len > 0) {
                 s = inStream.read(b, off, len);
                 if (s == -1) {
-                    // if we have read something before, we should have been
-                    // able to read the whole, so make this fatal
+                    // if we have read something before, we should have been 
able to read the whole, so make this fatal
                     if (off > 0) {
                         throw new IOException("Read from " + 
connection.getHostname() + ":" +
                                 connection.getPort() + ": Incomplete block 
read from stream");
@@ -207,7 +206,7 @@ public class OldMapiSocket extends Abstr
 
         public long skip(long n) throws IOException {
             long skip = n;
-            int t = 0;
+            int t;
             while (skip > 0) {
                 t = available();
                 if (skip > t) {
@@ -248,9 +247,8 @@ public class OldMapiSocket extends Abstr
         }
 
         /**
-         * writeBlock puts the data in the block on the stream.  The
-         * boolean last controls whether the block is sent with an
-         * indicator to note it is the last block of a sequence or not.
+         * writeBlock puts the data in the block on the stream. The boolean 
last controls whether the block is sent with
+         * an indicator to note it is the last block of a sequence or not.
          *
          * @param last whether this is the last block
          * @throws IOException if writing to the stream failed
@@ -259,15 +257,13 @@ public class OldMapiSocket extends Abstr
             if (last) {
                 // always fits, because of BLOCK's size
                 blocksize = (short) writePos;
-                // this is the last block, so encode least
-                // significant bit in the first byte (little-endian)
+                // this is the last block, so encode least significant bit in 
the first byte (little-endian)
                 blklen[0] = (byte) (blocksize << 1 & 0xFF | 1);
                 blklen[1] = (byte) (blocksize >> 7);
             } else {
                 // always fits, because of BLOCK's size
                 blocksize = (short) BLOCK;
-                // another block will follow, encode least
-                // significant bit in the first byte (little-endian)
+                // another block will follow, encode least significant bit in 
the first byte (little-endian)
                 blklen[0] = (byte) (blocksize << 1 & 0xFF);
                 blklen[1] = (byte) (blocksize >> 7);
             }
diff --git 
a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java 
b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
@@ -96,7 +96,7 @@ public class OldMapiProtocol extends Abs
     @Override
     public UpdateResponse getNextUpdateResponse() throws ProtocolException {
         int count = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); 
//The order cannot be switched!!
-        String lastId = 
OldMapiStartOfHeaderParser.GetNextResponseDataAsString(this);
+        int lastId = 
OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); //TODO test this!!
         return new UpdateResponse(lastId, count);
     }
 
diff --git a/src/main/java/nl/cwi/monetdb/mcl/responses/UpdateResponse.java 
b/src/main/java/nl/cwi/monetdb/mcl/responses/UpdateResponse.java
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/UpdateResponse.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/responses/UpdateResponse.java
@@ -10,17 +10,17 @@ package nl.cwi.monetdb.mcl.responses;
  */
 public class UpdateResponse implements IResponse {
 
-    private final String lastid;
+    private final int lastid;
 
     private final int count;
 
-    public UpdateResponse(String id, int cnt) {
+    public UpdateResponse(int lastid, int count) {
         // fill the blank finals
-        this.lastid = id;
-        this.count = cnt;
+        this.lastid = lastid;
+        this.count = count;
     }
 
-    public String getLastid() {
+    public int getLastid() {
         return lastid;
     }
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to