diff src/main/java/org/monetdb/mcl/net/Target.java @ 809:aa4108a5bc34 monetdbs

Move more URL and properties parsing responsibilities to Target
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Tue, 12 Dec 2023 12:03:24 +0100 (16 months ago)
parents 6b7778153d23
children 425592a53fcd
line wrap: on
line diff
--- a/src/main/java/org/monetdb/mcl/net/Target.java
+++ b/src/main/java/org/monetdb/mcl/net/Target.java
@@ -1,5 +1,7 @@
 package org.monetdb.mcl.net;
 
+import java.net.URISyntaxException;
+import java.util.Properties;
 import java.util.regex.Pattern;
 
 public class Target {
@@ -42,6 +44,12 @@ public class Target {
         this.timezone = (int)Parameter.TIMEZONE.getDefault();
     }
 
+    public Target(String url, Properties props) throws URISyntaxException, ValidationError {
+        this();
+        setProperties(props);
+        parseUrl(url);
+    }
+
     public void barrier() {
         if (userWasSet && !passwordWasSet)
             password = "";
@@ -89,6 +97,28 @@ public class Target {
         assign(parm, parm.getDefault());
     }
 
+    public void setProperties(Properties props) throws ValidationError {
+        if (props != null) {
+            for (String key : props.stringPropertyNames()) {
+                String value = props.getProperty(key);
+                if (key.equals(Parameter.HOST.name))
+                    value = Target.unpackHost(value);
+                setString(key, value);
+            }
+        }
+    }
+
+    public void parseUrl(String url) throws URISyntaxException, ValidationError {
+        if (url == null)
+            return;
+        if (url.startsWith("jdbc:"))
+            url = url.substring(5);
+        if (url.equals("monetdb:")) {
+            return;
+        }
+        MonetUrlParser.parse(this, url);
+    }
+
     private void assign(Parameter parm, Object value) {
         switch (parm) {
             case TLS: setTls((boolean)value); break;