changeset 658:108123ca6889

Add autocommit=true/false option to jdbc url
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Fri, 09 Sep 2022 15:20:55 +0200 (2022-09-09)
parents 8476d6f4378f
children 0b564ae68ac1
files release.txt src/main/java/org/monetdb/jdbc/MonetConnection.java src/main/java/org/monetdb/jdbc/MonetDriver.java.in
diffstat 3 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/release.txt
+++ b/release.txt
@@ -31,6 +31,7 @@ Supported connection properties are:
 	language=<sql or mal>              default is: sql
 	fetchsize=<nr of rows>             default is: 250; -1 means fetch everything at once
 	debug=true                         default is: false
+	autocommit=false                   default is: true
 	logfile=<name of logfile>
 	hash=<SHA512, SHA384, SHA256 or SHA1>
 
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -210,6 +210,13 @@ public class MonetConnection
 		if (hash != null)
 			conn_props.setProperty("hash", hash);
 
+		String autocommit_prop = props.getProperty("autocommit");
+		boolean initial_autocommit = true;
+		if (autocommit_prop != null) {
+			initial_autocommit = Boolean.parseBoolean(autocommit_prop);
+			conn_props.setProperty("initial_autocommit", Boolean.toString(initial_autocommit));
+		}
+
 		final String fetchsize_prop = props.getProperty("fetchsize");
 		if (fetchsize_prop != null) {
 			try {
@@ -288,6 +295,7 @@ public class MonetConnection
 		int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
 		int offsetSeconds = offsetMillis / 1000;
 		final HandshakeOptions handshakeOptions = new HandshakeOptions();
+		handshakeOptions.set(Setting.AutoCommit, initial_autocommit ? 1 : 0);
 		handshakeOptions.set(Setting.TimeZone, offsetSeconds);
 		handshakeOptions.set(Setting.ReplySize, defaultFetchSize);
 //		handshakeOptions.set(Setting.SizeHeader, 1);
@@ -388,8 +396,9 @@ public class MonetConnection
 
 		// the following initialisers are only valid when the language is SQL...
 		if (lang == LANG_SQL) {
-			// enable auto commit
-			setAutoCommit(true);
+			if (handshakeOptions.mustSend(Setting.AutoCommit)) {
+				setAutoCommit(handshakeOptions.get(Setting.AutoCommit) != 0);
+			}
 
 			// set our time zone on the server, if we haven't already
 			if (handshakeOptions.mustSend(Setting.TimeZone)) {
@@ -1822,6 +1831,7 @@ public class MonetConnection
 			name.equals("hash") ||
 			name.equals("treat_blob_as_binary") ||
 			name.equals("treat_clob_as_varchar") ||
+			name.equals("autocommit") ||
 			name.equals("so_timeout") ||
 			name.equals("fetchsize");	// only supported by servers from version 11.41.1 onwards
 	}
--- a/src/main/java/org/monetdb/jdbc/MonetDriver.java.in
+++ b/src/main/java/org/monetdb/jdbc/MonetDriver.java.in
@@ -195,7 +195,7 @@ public class MonetDriver implements Driv
 			return null;
 
 		final String[] boolean_choices = new String[] { "true", "false" };
-		final DriverPropertyInfo[] dpi = new DriverPropertyInfo[9];	// we currently support 9 connection properties
+		final DriverPropertyInfo[] dpi = new DriverPropertyInfo[10];	// we currently support 10 connection properties
 
 		DriverPropertyInfo prop = new DriverPropertyInfo("user", info != null ? info.getProperty("user") : null);
 		prop.required = true;
@@ -247,13 +247,11 @@ public class MonetDriver implements Driv
 		prop.description = "Defines the maximum time to wait in milliseconds on a blocking read socket call"; // this corresponds to the Connection.setNetworkTimeout() method introduced in JDBC 4.1
 		dpi[8] = prop;
 
-/* next property is no longer supported in: new MonetConnection(props)
-		prop = new DriverPropertyInfo("follow_redirects", "true");
+		prop = new DriverPropertyInfo("autocommit", "true");
 		prop.required = false;
-		prop.description = "Whether redirects issued by the server should be followed";
+		prop.description = "Whether the connection should start in auto-commit mode";
 		prop.choices = boolean_choices;
 		dpi[9] = prop;
-*/
 
 		return dpi;
 	}