Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/mcl/net/Parameter.java @ 931:df18aa5c8a61
Add test for MonetDriver.getPropertyInfo(url, props).
The implementation is moved to Parameter.java which contains the list of connection parameters.
It currently only returns the mandatory connection parameters.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 24 Oct 2024 19:10:06 +0200 (6 months ago) |
parents | 2ec67179aa32 |
children | d416e9b6b3d0 |
comparison
equal
deleted
inserted
replaced
930:8611e23d2771 | 931:df18aa5c8a61 |
---|---|
10 * Copyright 1997 - July 2008 CWI. | 10 * Copyright 1997 - July 2008 CWI. |
11 */ | 11 */ |
12 | 12 |
13 package org.monetdb.mcl.net; | 13 package org.monetdb.mcl.net; |
14 | 14 |
15 import java.sql.DriverPropertyInfo; | |
15 import java.util.Calendar; | 16 import java.util.Calendar; |
17 import java.util.Properties; | |
16 | 18 |
17 /** | 19 /** |
18 * Enumerates things that can be configured on a connection to MonetDB. | 20 * Enumerates things that can be configured on a connection to MonetDB. |
19 */ | 21 */ |
20 public enum Parameter { | 22 public enum Parameter { |
23 // String name, ParameterType type, Object defaultValue, String description, boolean isCore | |
21 TLS("tls", ParameterType.Bool, false, "secure the connection using TLS", true), | 24 TLS("tls", ParameterType.Bool, false, "secure the connection using TLS", true), |
22 HOST("host", ParameterType.Str, "", "IP number, domain name or one of the special values `localhost` and `localhost.`", true), | 25 HOST("host", ParameterType.Str, "", "IP number, domain name or one of the special values `localhost` and `localhost.`", true), |
23 PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1 for 'not set'", true), | 26 PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1 for 'not set'", true), |
24 DATABASE("database", ParameterType.Str, "", "name of database to connect to", true), | 27 DATABASE("database", ParameterType.Str, "", "name of database to connect to", true), |
25 TABLESCHEMA("tableschema", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), | 28 TABLESCHEMA("tableschema", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), |
165 return defaultValue; | 168 return defaultValue; |
166 } | 169 } |
167 } | 170 } |
168 | 171 |
169 /** | 172 /** |
170 * Determine if this Parameter is onlyu relevant when TlS is enabled. | 173 * Determine if this Parameter is only relevant when TlS is enabled. |
171 * | 174 * |
172 * Such parameters need not be shown to the user unless the URL starts with <code>monetdbs://</code>. | 175 * Such parameters need not be shown to the user unless the URL starts with <code>monetdbs://</code>. |
173 * | 176 * |
174 * @return true if this Parameter is only relevant when TLS is enabled | 177 * @return true if this Parameter is only relevant when TLS is enabled |
175 */ | 178 */ |
182 return true; | 185 return true; |
183 default: | 186 default: |
184 return false; | 187 return false; |
185 } | 188 } |
186 } | 189 } |
190 | |
191 /** | |
192 * Gets information about the possible properties for this driver. | |
193 * | |
194 * The getPropertyInfo method is intended to allow a generic GUI tool to | |
195 * discover what properties it should prompt a human for in order to get | |
196 * enough information to connect to a database. Note that depending on the | |
197 * values the human has supplied so far, additional values may become | |
198 * necessary, so it may be necessary to iterate through several calls to the | |
199 * getPropertyInfo method. | |
200 * | |
201 * Note: This method is called from jdbc.MonetDriver.getPropertyInfo() | |
202 * | |
203 * @param info a proposed list of tag/value pairs that will be sent on | |
204 * connect open | |
205 * @return an array of DriverPropertyInfo objects describing possible | |
206 * properties. This array may be an empty array if no properties | |
207 * are required. | |
208 */ | |
209 public static DriverPropertyInfo[] getPropertyInfo(final Properties info, boolean requires_tls) { | |
210 final String tls = info != null ? info.getProperty("tls") : null; | |
211 final boolean tls_enabled = requires_tls || (tls != null && tls.equals("true")); | |
212 final int dpi_size = (tls_enabled ? 4 : 2); | |
213 final DriverPropertyInfo[] dpi = new DriverPropertyInfo[dpi_size]; | |
214 DriverPropertyInfo prop = null; | |
215 | |
216 // minimal required connection settings are "user" and "password" | |
217 prop = new DriverPropertyInfo("user", info != null ? info.getProperty("user") : null); | |
218 prop.required = true; | |
219 prop.description = "User loginname to use when authenticating on the database server"; | |
220 dpi[0] = prop; | |
221 | |
222 prop = new DriverPropertyInfo("password", info != null ? info.getProperty("password") : null); | |
223 prop.required = true; | |
224 prop.description = "Password to use when authenticating on the database server"; | |
225 dpi[1] = prop; | |
226 | |
227 if (tls_enabled && dpi_size > 2) { | |
228 // when tls is enabled or required also "tls" and "cert" become required | |
229 final String[] boolean_choices = new String[] { "true", "false" }; | |
230 | |
231 prop = new DriverPropertyInfo("tls", tls); | |
232 prop.required = true; | |
233 prop.description = "secure the connection using TLS"; | |
234 prop.choices = boolean_choices; | |
235 dpi[2] = prop; | |
236 | |
237 prop = new DriverPropertyInfo("cert", info != null ? info.getProperty("cert") : null); | |
238 prop.required = true; | |
239 prop.description = "path to TLS certificate to authenticate server with"; | |
240 dpi[3] = prop; | |
241 } | |
242 | |
243 return dpi; | |
244 } | |
187 } | 245 } |