Changeset: 78e83a4d647d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=78e83a4d647d
Added Files:
        java/tests/Test_FetchSize.java
        sql/jdbc/tests/Tests/Test_FetchSize.SQL.bat
        sql/jdbc/tests/Tests/Test_FetchSize.SQL.sh
        sql/jdbc/tests/Tests/Test_FetchSize.stable.err
        sql/jdbc/tests/Tests/Test_FetchSize.stable.out
Modified Files:
        java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
        java/tests/build.xml
        sql/jdbc/tests/Tests/All
Branch: Jun2016
Log Message:

Added a dummy implementation for ResultSet.setFetchSize() just to avoid 
throwing unwanted exception.
Updated ResultSet.getFetchSize(), since accord to the JDBC specifications we 
support, the value of the hint should be returned once it's set.
Added a test to ensure that setting the fetch size for a ResultSet does not 
affect the fetch size of this Statement.


diffs (286 lines):

diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java 
b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -99,6 +99,9 @@ public class MonetResultSet extends Mone
        /** The warnings for this ResultSet object */
        private SQLWarning warnings;
 
+       /** Just a dummy variable to keep store the fetchsize set. */
+       private int fetchSize;
+
        /**
         * Main constructor backed by the given Header.
         *
@@ -115,6 +118,9 @@ public class MonetResultSet extends Mone
                this.header = header;
                this.type = header.getRSType();
                this.concurrency = header.getRSConcur();
+               /* if we have a header object, the fetchSize used for this 
result set
+                  is the header's cacheSize */
+               this.fetchSize = header.getCacheSize();
                // well there is only one supported concurrency, so we don't 
have to
                // bother about that
 
@@ -164,6 +170,8 @@ public class MonetResultSet extends Mone
                this.tupleCount = results;
 
                this.tlp = new TupleLineParser(columns.length);
+               
+               this.fetchSize = 0;
        }
 
        //== methods of interface ResultSet
@@ -942,7 +950,30 @@ public class MonetResultSet extends Mone
         */
        @Override
        public int getFetchSize() throws SQLException {
-               return header.getCacheSize();
+               return fetchSize;
+       }
+
+       /**
+        * Gives the JDBC driver a hint as to the number of rows that should be
+        * fetched from the database when more rows are needed.  In MonetDB, 
this is
+        * actually a no-op, because even before a MonetResultSet object is
+        * created, the fetch size is already determined in the
+        * MonetConnection.ResultSetResponse passed to its constructor.  Since 
all
+        * data blocks for this whole result set are already allocated in
+        * MonetConnection.ResultSetResponse, it is too complicated and 
error-prone
+        * to still change the fetchSize here.  If one really needs to overwrite
+        * the default fetchSize, please use MonetStatement.setFetchSize() 
instead.
+        *
+        * @param rows the number of rows to fetch
+        * @throws SQLException if the condition 0 <= rows is not satisfied
+        */
+       @Override
+       public void setFetchSize(int rows) throws SQLException {
+               if (rows >= 0) {
+                       fetchSize = rows;
+               } else {
+                       throw new SQLException("Illegal fetch size value: " + 
rows, "M1M05");
+               }
        }
 
        /**
@@ -2793,8 +2824,6 @@ public class MonetResultSet extends Mone
        @Override
        public void setFetchDirection(int direction) throws SQLException { 
throw new SQLFeatureNotSupportedException("Method setFetchDirection not 
implemented yet, sorry!", "0A000"); }
        @Override
-       public void setFetchSize(int rows) throws SQLException { throw new 
SQLFeatureNotSupportedException("Method setFetchSize not implemented yet, 
sorry!", "0A000"); }
-       @Override
        public void updateArray(int columnIndex, Array x) throws SQLException { 
throw new SQLFeatureNotSupportedException("Method updateArray not implemented 
yet, sorry!", "0A000"); }
        @Override
        public void updateArray(String columnName, Array x) throws SQLException 
{ throw new SQLFeatureNotSupportedException("Method updateArray not implemented 
yet, sorry!", "0A000"); }
diff --git a/java/tests/Test_FetchSize.java b/java/tests/Test_FetchSize.java
new file mode 100644
--- /dev/null
+++ b/java/tests/Test_FetchSize.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+import java.sql.*;
+
+public class Test_FetchSize {
+       public static void main(String[] args) throws Exception {
+               Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
+               Connection con = DriverManager.getConnection(args[0]);
+               Statement stmt = con.createStatement();
+               ResultSet rs = stmt.executeQuery("SELECT * FROM _tables");
+
+               System.out.println("Statement fetch size before set: " + 
stmt.getFetchSize());
+               System.out.println("ResultSet fetch size before set: " + 
rs.getFetchSize());
+
+               rs.setFetchSize(16384);
+
+               System.out.println("Statement fetch size before set: " + 
stmt.getFetchSize());
+               System.out.println("ResultSet fetch size before set: " + 
rs.getFetchSize());
+
+               rs.close();
+               con.close();
+       }
+}
diff --git a/java/tests/build.xml b/java/tests/build.xml
--- a/java/tests/build.xml
+++ b/java/tests/build.xml
@@ -123,6 +123,7 @@ Copyright 1997 - July 2008 CWI, August 2
     <antcall target="Test_Sbatching" />
     <antcall target="Test_Smoreresults" />
     <antcall target="Test_Int128" />
+    <antcall target="Test_FetchSize" />
     <antcall target="BugConcurrent_clients_SF_1504657" />
     <antcall target="BugConcurrent_sequences" />
     <antcall target="BugDatabaseMetaData_Bug_3356" />
@@ -311,6 +312,12 @@ Copyright 1997 - July 2008 CWI, August 2
     </antcall>
   </target>
   
+  <target name="Test_FetchSize">
+    <antcall target="test_class">
+      <param name="test.class" value="Test_FetchSize" />
+    </antcall>
+  </target>
+  
   <target name="BugConcurrent_clients_SF_1504657">
     <antcall target="test_class">
       <param name="test.class" value="BugConcurrent_clients_SF_1504657" />
diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All
--- a/sql/jdbc/tests/Tests/All
+++ b/sql/jdbc/tests/Tests/All
@@ -22,6 +22,7 @@ HAVE_JDBCTESTS?Test_Rtimedate
 HAVE_JDBCTESTS?Test_Rsqldata
 HAVE_JDBCTESTS?Test_Sbatching
 HAVE_JDBCTESTS&HAVE_HGE?Test_Int128
+HAVE_JDBCTESTS?Test_FetchSize
 HAVE_JDBCCLIENT_JAR?Test_JdbcClient
 HAVE_JDBCTESTS?BugConcurrent_clients_SF_1504657
 HAVE_JDBCTESTS?BugConcurrent_sequences
diff --git a/sql/jdbc/tests/Tests/Test_FetchSize.SQL.bat 
b/sql/jdbc/tests/Tests/Test_FetchSize.SQL.bat
new file mode 100755
--- /dev/null
+++ b/sql/jdbc/tests/Tests/Test_FetchSize.SQL.bat
@@ -0,0 +1,1 @@
+@call "%TSTSRCDIR%\Test.SQL.bat" %*
diff --git a/sql/jdbc/tests/Tests/Test_FetchSize.SQL.sh 
b/sql/jdbc/tests/Tests/Test_FetchSize.SQL.sh
new file mode 100755
--- /dev/null
+++ b/sql/jdbc/tests/Tests/Test_FetchSize.SQL.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+$TSTSRCDIR/Test.SQL.sh $*
diff --git a/sql/jdbc/tests/Tests/Test_FetchSize.stable.err 
b/sql/jdbc/tests/Tests/Test_FetchSize.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/jdbc/tests/Tests/Test_FetchSize.stable.err
@@ -0,0 +1,40 @@
+stderr of test 'Test_FetchSize` in directory 'sql/jdbc/tests` itself:
+
+
+# 17:58:22 >  
+# 17:58:22 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=37078" "--set" 
"mapi_usock=/var/tmp/mtest-3537/.s.monetdb.37078" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/export/scratch2/zhang/monet-install/Jun2016/debug/var/MonetDB/mTests_sql_jdbc_tests"
 "--set" "embedded_r=yes"
+# 17:58:22 >  
+
+# builtin opt  gdk_dbpath = 
/export/scratch2/zhang/monet-install/Jun2016/debug/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 37078
+# cmdline opt  mapi_usock = /var/tmp/mtest-3537/.s.monetdb.37078
+# cmdline opt  monet_prompt = 
+# cmdline opt  gdk_dbpath = 
/export/scratch2/zhang/monet-install/Jun2016/debug/var/MonetDB/mTests_sql_jdbc_tests
+# cmdline opt  embedded_r = yes
+# cmdline opt  gdk_debug = 536870922
+
+# 17:58:23 >  
+# 17:58:23 >  "./Test_FetchSize.SQL.sh" "Test_FetchSize"
+# 17:58:23 >  
+
+
+# 17:58:23 >  
+# 17:58:23 >  java Test_FetchSize 
"jdbc:monetdb://toulouse:37078/mTests_sql_jdbc_tests?user=monetdb&password=monetdb"
+# 17:58:23 >  
+
+
+# 17:58:23 >  
+# 17:58:23 >  "Done."
+# 17:58:23 >  
+
diff --git a/sql/jdbc/tests/Tests/Test_FetchSize.stable.out 
b/sql/jdbc/tests/Tests/Test_FetchSize.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/jdbc/tests/Tests/Test_FetchSize.stable.out
@@ -0,0 +1,80 @@
+stdout of test 'Test_FetchSize` in directory 'sql/jdbc/tests` itself:
+
+
+# 17:58:22 >  
+# 17:58:22 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=37078" "--set" 
"mapi_usock=/var/tmp/mtest-3537/.s.monetdb.37078" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/export/scratch2/zhang/monet-install/Jun2016/debug/var/MonetDB/mTests_sql_jdbc_tests"
 "--set" "embedded_r=yes"
+# 17:58:22 >  
+
+# MonetDB 5 server v11.23.0
+# This is an unreleased version
+# Serving database 'mTests_sql_jdbc_tests', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs and 128bit 
integers dynamically linked
+# Found 15.589 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://toulouse.da.cwi.nl:37078/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-3537/.s.monetdb.37078
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+# MonetDB/R   module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 17_temporal.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 24_zorder.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 27_rejects.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 39_analytics_hge.sql
+# loading sql script: 40_geom.sql
+# loading sql script: 40_json.sql
+# loading sql script: 40_json_hge.sql
+# loading sql script: 41_md5sum.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 46_gsl.sql
+# loading sql script: 46_profiler.sql
+# loading sql script: 51_sys_schema_extension.sql
+# loading sql script: 72_fits.sql
+# loading sql script: 74_netcdf.sql
+# loading sql script: 75_shp.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 80_udf_hge.sql
+# loading sql script: 85_bam.sql
+# loading sql script: 90_generator.sql
+# loading sql script: 90_generator_hge.sql
+# loading sql script: 99_system.sql
+
+# 17:58:23 >  
+# 17:58:23 >  "./Test_FetchSize.SQL.sh" "Test_FetchSize"
+# 17:58:23 >  
+
+
+# 17:58:23 >  
+# 17:58:23 >  java Test_FetchSize 
"jdbc:monetdb://toulouse:37078/mTests_sql_jdbc_tests?user=monetdb&password=monetdb"
+# 17:58:23 >  
+
+Statement fetch size before set: 0
+ResultSet fetch size before set: 250
+Statement fetch size before set: 0
+ResultSet fetch size before set: 16384
+
+# 17:58:23 >  
+# 17:58:23 >  "Done."
+# 17:58:23 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to