Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetDriver.java @ 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 (17 months ago) |
parents | 5bfe3357fb1c |
children | aa4108a5bc34 |
comparison
equal
deleted
inserted
replaced
794:a418afda6b21 | 795:04a27386789f |
---|---|
68 * @param url the URL of the database | 68 * @param url the URL of the database |
69 * @return true if this driver understands the given URL; false otherwise | 69 * @return true if this driver understands the given URL; false otherwise |
70 */ | 70 */ |
71 @Override | 71 @Override |
72 public boolean acceptsURL(final String url) { | 72 public boolean acceptsURL(final String url) { |
73 return url != null && url.startsWith("jdbc:monetdb://"); | 73 if (url == null) |
74 return false; | |
75 if (url.startsWith("jdbc:monetdb:") || url.startsWith("jdbc:monetdbs:")) | |
76 return true; | |
77 return false; | |
74 } | 78 } |
75 | 79 |
76 /** | 80 /** |
77 * Attempts to make a database connection to the given URL. The driver | 81 * Attempts to make a database connection to the given URL. The driver |
78 * should return "null" if it realizes it is the wrong kind of driver to | 82 * should return "null" if it realizes it is the wrong kind of driver to |
103 return null; | 107 return null; |
104 | 108 |
105 Target target = new Target(); | 109 Target target = new Target(); |
106 | 110 |
107 try { | 111 try { |
112 // If properties are given, add those first | |
108 if (info != null) { | 113 if (info != null) { |
109 for (String key : info.stringPropertyNames()) { | 114 for (String key : info.stringPropertyNames()) { |
110 String value = info.getProperty(key); | 115 String value = info.getProperty(key); |
111 if (key.equals(Parameter.HOST.name)) | 116 if (key.equals(Parameter.HOST.name)) |
112 value = Target.unpackHost(value); | 117 value = Target.unpackHost(value); |
113 target.setString(key, value); | 118 target.setString(key, value); |
114 } | 119 } |
115 } | 120 } |
116 MonetUrlParser.parse(target, url.substring(5)); | 121 |
122 // If url is exactly "jdbc:monetdb:", use just the properties. | |
123 // This is different from, say, jdbc:monetdb://, because the | |
124 // latter will clear preexisting host, port, TLS and database settings. | |
125 // Useful in combination with Target.toProperties(). | |
126 if (!url.equals("jdbc:monetdb:")) | |
127 MonetUrlParser.parse(target, url.substring(5)); | |
117 } catch (ValidationError | URISyntaxException e) { | 128 } catch (ValidationError | URISyntaxException e) { |
118 throw new SQLException(e.getMessage()); | 129 throw new SQLException(e.getMessage()); |
119 } | 130 } |
120 | 131 |
121 // finally return the Connection object as requested | 132 // finally return the Connection object as requested |