changeset 696:07d60185eeb9

Eliminate hardcoded value 250 in the constructor of MonetPreparedStatement. For this an internal package method MonetConnection.getDefaultFetchSize() is added. Also use this method in constructor of MonetStatement to let getFetchSize() return the proper fetchSize instead of 0.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 23 Nov 2022 20:28:17 +0100 (2022-11-23)
parents a5b840eebf77
children 68422d7f3961
files src/main/java/org/monetdb/jdbc/MonetConnection.java src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java src/main/java/org/monetdb/jdbc/MonetStatement.java tests/JDBC_API_Tester.java
diffstat 4 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -2175,6 +2175,15 @@ public class MonetConnection
 	private static int seqCounter = 0;
 
 	/**
+	 * returns default fetchSize as set at connection moment
+	 *
+	 * @return defaultFetchSize
+	 */
+	protected int getDefaultFetchSize() {
+		return defaultFetchSize;
+	}
+
+	/**
 	 * A Response is a message sent by the server to indicate some
 	 * action has taken place, and possible results of that action.
 	 */
--- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
@@ -136,8 +136,9 @@ public class MonetPreparedStatement
 		// so all the parameters can be read into one DataBlockResponse.
 		// see also: https://github.com/MonetDB/MonetDB/issues/7337
 		int currentFetchSize = super.getFetchSize();
-		if (currentFetchSize == 0)
-			currentFetchSize = 250;	// 250 is the DEF_FETCHSIZE, see MonetConnection.java
+		if (currentFetchSize == 0) {
+			currentFetchSize = connection.getDefaultFetchSize();
+		}
 		if (countParamMarkers > currentFetchSize) {
 			super.setFetchSize(countParamMarkers);
 		}
--- a/src/main/java/org/monetdb/jdbc/MonetStatement.java
+++ b/src/main/java/org/monetdb/jdbc/MonetStatement.java
@@ -104,6 +104,7 @@ public class MonetStatement
 
 		this.connection = connection;
 		this.queryTimeout = connection.lastSetQueryTimeout;
+		this.fetchSize = connection.getDefaultFetchSize();
 
 		this.resultSetType = resultSetType;
 		this.resultSetConcurrency = resultSetConcurrency;
@@ -621,10 +622,9 @@ public class MonetStatement
 
 	/**
 	 * Retrieves the number of result set rows that is the default fetch size
-	 * for ResultSet objects generated from this Statement object. If this
-	 * Statement object has not set a fetch size by calling the method
-	 * setFetchSize, or the method setFetchSize was called as such to let
-	 * the driver ignore the hint, 0 is returned.
+	 * for ResultSet objects generated from this Statement object.
+	 * If this Statement object has not set a fetch size by calling the
+	 * method setFetchSize, the return value is implementation-specific.
 	 *
 	 * @return the default fetch size for result sets generated from this
 	 *         Statement object
@@ -948,7 +948,7 @@ public class MonetStatement
 	/**
 	 * Gives the JDBC driver a hint as to the number of rows that should be
 	 * fetched from the database when more rows are needed. The number of rows
-	 * specified affects only result sets created using this statement. If the
+	 * specified affects only ResultSet created using this Statement. If the
 	 * value specified is zero, then the hint is ignored.
 	 *
 	 * @param rows the number of rows to fetch
--- a/tests/JDBC_API_Tester.java
+++ b/tests/JDBC_API_Tester.java
@@ -1549,7 +1549,7 @@ final public class JDBC_API_Tester {
 		closeStmtResSet(stmt, rs);
 
 		compareExpectedOutput("Test_FetchSize",
-			"Statement fetch size before set: 0\n" +
+			"Statement fetch size before set: 250\n" +
 			"ResultSet fetch size before set: 250\n" +
 			"Statement fetch size after set: 40\n" +
 			"ResultSet fetch size after set: 16384\n");