changeset 795:04a27386789f monetdbs

MonetDriver: Use only the properties if URL is exactly "jdbc:monetdb:" Normally, parsing the URL clears host, port, etc. That means that an application that already has everything as Properties has to extract those from the Properties and construct a URL, which is inconvenient and error-prone.
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 07 Dec 2023 08:54:34 +0100 (16 months ago)
parents a418afda6b21
children d2f14f2b28b3
files src/main/java/org/monetdb/jdbc/MonetDriver.java
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetDriver.java
+++ b/src/main/java/org/monetdb/jdbc/MonetDriver.java
@@ -70,7 +70,11 @@ public final class MonetDriver implement
 	 */
 	@Override
 	public boolean acceptsURL(final String url) {
-		return url != null && url.startsWith("jdbc:monetdb://");
+        if (url == null)
+			return false;
+        if (url.startsWith("jdbc:monetdb:") || url.startsWith("jdbc:monetdbs:"))
+			return true;
+        return false;
 	}
 
 	/**
@@ -105,6 +109,7 @@ public final class MonetDriver implement
 		Target target = new Target();
 
 		try {
+			// If properties are given, add those first
 			if (info != null) {
 				for (String key : info.stringPropertyNames()) {
 					String value = info.getProperty(key);
@@ -113,7 +118,13 @@ public final class MonetDriver implement
 					target.setString(key, value);
 				}
 			}
-			MonetUrlParser.parse(target, url.substring(5));
+
+			// If url is exactly "jdbc:monetdb:", use just the properties.
+			// This is different from, say, jdbc:monetdb://, because the
+			// latter will clear preexisting host, port, TLS and database settings.
+			// Useful in combination with Target.toProperties().
+			if (!url.equals("jdbc:monetdb:"))
+				MonetUrlParser.parse(target, url.substring(5));
 		} catch (ValidationError | URISyntaxException e) {
 			throw new SQLException(e.getMessage());
 		}