Mercurial > hg > monetdb-java
diff src/main/java/org/monetdb/jdbc/MonetDriver.java @ 793:5bfe3357fb1c monetdbs
Use the new url parser
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Wed, 06 Dec 2023 16:17:13 +0100 (16 months ago) |
parents | 2f36ac68ac35 |
children | 04a27386789f |
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetDriver.java +++ b/src/main/java/org/monetdb/jdbc/MonetDriver.java @@ -8,7 +8,12 @@ package org.monetdb.jdbc; -import java.net.URI; +import org.monetdb.mcl.net.MonetUrlParser; +import org.monetdb.mcl.net.Parameter; +import org.monetdb.mcl.net.Target; +import org.monetdb.mcl.net.ValidationError; + +import java.net.URISyntaxException; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; @@ -97,56 +102,24 @@ public final class MonetDriver implement if (!acceptsURL(url)) return null; - final Properties props = new Properties(); - // set the optional properties and their defaults here - props.put("port", "50000"); - props.put("debug", "false"); - props.put("language", "sql"); // mal, sql, <future> - props.put("so_timeout", "0"); + Target target = new Target(); - if (info != null) - props.putAll(info); - info = props; - - // remove leading "jdbc:" so the rest is a valid hierarchical URI - final URI uri; try { - uri = new URI(url.substring(5)); - } catch (java.net.URISyntaxException e) { - return null; + if (info != null) { + for (String key : info.stringPropertyNames()) { + String value = info.getProperty(key); + if (key.equals(Parameter.HOST.name)) + value = Target.unpackHost(value); + target.setString(key, value); + } + } + MonetUrlParser.parse(target, url.substring(5)); + } catch (ValidationError | URISyntaxException e) { + throw new SQLException(e.getMessage()); } - final String uri_host = uri.getHost(); - if (uri_host == null) - return null; - info.put("host", uri_host); - - int uri_port = uri.getPort(); - if (uri_port > 0) - info.put("port", Integer.toString(uri_port)); - - // check the database - String uri_path = uri.getPath(); - if (uri_path != null && !uri_path.isEmpty()) { - uri_path = uri_path.substring(1).trim(); - if (!uri_path.isEmpty()) - info.put("database", uri_path); - } - - final String uri_query = uri.getQuery(); - if (uri_query != null) { - int pos; - // handle additional connection properties separated by the & character - final String args[] = uri_query.split("&"); - for (int i = 0; i < args.length; i++) { - pos = args[i].indexOf('='); - if (pos > 0) - info.put(args[i].substring(0, pos), args[i].substring(pos + 1)); - } - } - - // finally return the Connection object as requested - return new MonetConnection(info); + // finally return the Connection object as requested + return new MonetConnection(target); } /**