# HG changeset patch
# User Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
# Date 1701935674 -3600
# Node ID 04a27386789f1d52776ef3bdef959b71079ca001
# Parent  a418afda6b21fd47a3fc1520220e919a0ddffd68
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.

diff --git a/src/main/java/org/monetdb/jdbc/MonetDriver.java b/src/main/java/org/monetdb/jdbc/MonetDriver.java
--- 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());
 		}