comparison src/main/java/org/monetdb/mcl/net/Parameter.java @ 834:5aa19bbed0d6 monetdbs

Comments and formatting
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Wed, 13 Dec 2023 15:39:47 +0100 (17 months ago)
parents f478317138d7
children 4d80fd66541d
comparison
equal deleted inserted replaced
813:a71afa48f269 834:5aa19bbed0d6
1 package org.monetdb.mcl.net; 1 package org.monetdb.mcl.net;
2 2
3 3
4 import java.util.Calendar; 4 import java.util.Calendar;
5 5
6 /**
7 * Enumerates things that can be configured on a connection to MonetDB.
8 */
6 public enum Parameter { 9 public enum Parameter {
7 TLS("tls", ParameterType.Bool, false, "secure the connection using TLS", true), 10 TLS("tls", ParameterType.Bool, false, "secure the connection using TLS", true),
8 HOST("host", ParameterType.Str, "", "IP number, domain name or one of the special values `localhost` and `localhost.`", true), 11 HOST("host", ParameterType.Str, "", "IP number, domain name or one of the special values `localhost` and `localhost.`", true),
9 PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1 for 'not set'", true), 12 PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1 for 'not set'", true),
10 DATABASE("database", ParameterType.Str, "", "name of database to connect to", true), 13 DATABASE("database", ParameterType.Str, "", "name of database to connect to", true),
11 TABLESCHEMA("tableschema", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), 14 TABLESCHEMA("tableschema", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true),
12 TABLE("table", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true), 15 TABLE("table", ParameterType.Str, "", "only used for REMOTE TABLE, otherwise unused", true),
13 SOCK("sock", ParameterType.Path, "", "path to Unix domain socket to connect to", false), 16 SOCK("sock", ParameterType.Path, "", "path to Unix domain socket to connect to", false),
14 SOCKDIR("sockdir", ParameterType.Path, "/tmp", "Directory for implicit Unix domain sockets (.s.monetdb.PORT)", false), 17 SOCKDIR("sockdir", ParameterType.Path, "/tmp", "Directory for implicit Unix domain sockets (.s.monetdb.PORT)", false),
15 CERT("cert", ParameterType.Path, "", "path to TLS certificate to authenticate server with", false), 18 CERT("cert", ParameterType.Path, "", "path to TLS certificate to authenticate server with", false),
16 CERTHASH("certhash", ParameterType.Str, "", "hash of server TLS certificate must start with these hex digits; overrides cert", false), 19 CERTHASH("certhash", ParameterType.Str, "", "hash of server TLS certificate must start with these hex digits; overrides cert", false),
17 CLIENTKEY("clientkey", ParameterType.Path, "", "path to TLS key (+certs) to authenticate with as client", false), 20 CLIENTKEY("clientkey", ParameterType.Path, "", "path to TLS key (+certs) to authenticate with as client", false),
18 CLIENTCERT("clientcert", ParameterType.Path, "", "path to TLS certs for 'clientkey', if not included there", false), 21 CLIENTCERT("clientcert", ParameterType.Path, "", "path to TLS certs for 'clientkey', if not included there", false),
19 USER("user", ParameterType.Str, "", "user name to authenticate as", false), 22 USER("user", ParameterType.Str, "", "user name to authenticate as", false),
20 PASSWORD("password", ParameterType.Str, "", "password to authenticate with", false), 23 PASSWORD("password", ParameterType.Str, "", "password to authenticate with", false),
21 LANGUAGE("language", ParameterType.Str, "sql", "for example, \"sql\", \"mal\", \"msql\", \"profiler\"", false), 24 LANGUAGE("language", ParameterType.Str, "sql", "for example, \"sql\", \"mal\", \"msql\", \"profiler\"", false),
22 AUTOCOMMIT("autocommit", ParameterType.Bool, true, "initial value of autocommit", false), 25 AUTOCOMMIT("autocommit", ParameterType.Bool, true, "initial value of autocommit", false),
23 SCHEMA("schema", ParameterType.Str, "", "initial schema", false), 26 SCHEMA("schema", ParameterType.Str, "", "initial schema", false),
24 TIMEZONE("timezone", ParameterType.Int, null, "client time zone as minutes east of UTC", false), 27 TIMEZONE("timezone", ParameterType.Int, null, "client time zone as minutes east of UTC", false),
25 BINARY("binary", ParameterType.Str, "on", "whether to use binary result set format (number or bool)", false), 28 BINARY("binary", ParameterType.Str, "on", "whether to use binary result set format (number or bool)", false),
26 REPLYSIZE("replysize", ParameterType.Int, 250, "rows beyond this limit are retrieved on demand, <1 means unlimited", false), 29 REPLYSIZE("replysize", ParameterType.Int, 250, "rows beyond this limit are retrieved on demand, <1 means unlimited", false),
27 FETCHSIZE("fetchsize", ParameterType.Int, null, "alias for replysize, specific to jdbc", false), 30 FETCHSIZE("fetchsize", ParameterType.Int, null, "alias for replysize, specific to jdbc", false),
28 HASH("hash", ParameterType.Str, "", "specific to jdbc", false), 31 HASH("hash", ParameterType.Str, "", "specific to jdbc", false),
29 DEBUG("debug", ParameterType.Bool, false, "specific to jdbc", false), 32 DEBUG("debug", ParameterType.Bool, false, "specific to jdbc", false),
30 LOGFILE("logfile", ParameterType.Str, "", "specific to jdbc", false), 33 LOGFILE("logfile", ParameterType.Str, "", "specific to jdbc", false),
31 34
32 SO_TIMEOUT("so_timeout", ParameterType.Int, 0, "abort if network I/O does not complete in this many milliseconds", false), 35 SO_TIMEOUT("so_timeout", ParameterType.Int, 0, "abort if network I/O does not complete in this many milliseconds", false), CLOB_AS_VARCHAR("treat_clob_as_varchar", ParameterType.Bool, true, "return CLOB/TEXT data as type VARCHAR instead of type CLOB", false), BLOB_AS_BINARY("treat_blob_as_binary", ParameterType.Bool, true, "return BLOB data as type BINARY instead of type BLOB", false),
33 CLOB_AS_VARCHAR("treat_clob_as_varchar", ParameterType.Bool, true, "return CLOB/TEXT data as type VARCHAR instead of type CLOB", false), 36 ;
34 BLOB_AS_BINARY("treat_blob_as_binary", ParameterType.Bool, true, "return BLOB data as type BINARY instead of type BLOB", false),
35 ;
36 37
37 public final String name; 38 public final String name;
38 public final ParameterType type; 39 public final ParameterType type;
39 private final Object defaultValue; 40 public final String description;
40 public final String description; 41 public final boolean isCore;
41 public final boolean isCore; 42 private final Object defaultValue;
42 43
43 Parameter(String name, ParameterType type, Object defaultValue, String description, boolean isCore) { 44 Parameter(String name, ParameterType type, Object defaultValue, String description, boolean isCore) {
44 this.name = name; 45 this.name = name;
45 this.type = type; 46 this.type = type;
46 this.isCore = isCore; 47 this.isCore = isCore;
47 this.defaultValue = defaultValue; 48 this.defaultValue = defaultValue;
48 this.description = description; 49 this.description = description;
49 } 50 }
50 51
51 public static Parameter forName(String name) { 52 public static Parameter forName(String name) {
52 switch (name) { 53 switch (name) {
53 case "tls": return TLS; 54 case "tls":
54 case "host": return HOST; 55 return TLS;
55 case "port": return PORT; 56 case "host":
56 case "database": return DATABASE; 57 return HOST;
57 case "tableschema": return TABLESCHEMA; 58 case "port":
58 case "table": return TABLE; 59 return PORT;
59 case "sock": return SOCK; 60 case "database":
60 case "sockdir": return SOCKDIR; 61 return DATABASE;
61 case "cert": return CERT; 62 case "tableschema":
62 case "certhash": return CERTHASH; 63 return TABLESCHEMA;
63 case "clientkey": return CLIENTKEY; 64 case "table":
64 case "clientcert": return CLIENTCERT; 65 return TABLE;
65 case "user": return USER; 66 case "sock":
66 case "password": return PASSWORD; 67 return SOCK;
67 case "language": return LANGUAGE; 68 case "sockdir":
68 case "autocommit": return AUTOCOMMIT; 69 return SOCKDIR;
69 case "schema": return SCHEMA; 70 case "cert":
70 case "timezone": return TIMEZONE; 71 return CERT;
71 case "binary": return BINARY; 72 case "certhash":
72 case "replysize": return REPLYSIZE; 73 return CERTHASH;
73 case "fetchsize": return FETCHSIZE; 74 case "clientkey":
74 case "hash": return HASH; 75 return CLIENTKEY;
75 case "debug": return DEBUG; 76 case "clientcert":
76 case "logfile": return LOGFILE; 77 return CLIENTCERT;
77 case "so_timeout": return SO_TIMEOUT; 78 case "user":
78 case "treat_clob_as_varchar": return CLOB_AS_VARCHAR; 79 return USER;
79 case "treat_blob_as_binary": return BLOB_AS_BINARY; 80 case "password":
80 default: return null; 81 return PASSWORD;
81 } 82 case "language":
82 } 83 return LANGUAGE;
84 case "autocommit":
85 return AUTOCOMMIT;
86 case "schema":
87 return SCHEMA;
88 case "timezone":
89 return TIMEZONE;
90 case "binary":
91 return BINARY;
92 case "replysize":
93 return REPLYSIZE;
94 case "fetchsize":
95 return FETCHSIZE;
96 case "hash":
97 return HASH;
98 case "debug":
99 return DEBUG;
100 case "logfile":
101 return LOGFILE;
102 case "so_timeout":
103 return SO_TIMEOUT;
104 case "treat_clob_as_varchar":
105 return CLOB_AS_VARCHAR;
106 case "treat_blob_as_binary":
107 return BLOB_AS_BINARY;
108 default:
109 return null;
110 }
111 }
83 112
84 public static boolean isIgnored(String name) { 113 /**
85 if (Parameter.forName(name) != null) 114 * Determine if a given setting can safely be ignored.
86 return false; 115 * The ground rule is that if we encounter an unknown setting
87 return name.contains("_"); 116 * without an underscore in the name, it is an error. If it has
88 } 117 * an underscore in its name, it can be ignored.
118 * @param name the name of the setting to check
119 * @return true if it can safely be ignored
120 */
121 public static boolean isIgnored(String name) {
122 if (Parameter.forName(name) != null)
123 return false;
124 return name.contains("_");
125 }
89 126
90 public Object getDefault() { 127 /**
91 switch (this) { 128 * Return a default value for the given setting, as an Object of the appropriate type.
92 case TIMEZONE: 129 * Note that the value returned for TIMEZONE may change if the system time zone
93 Calendar cal = Calendar.getInstance(); 130 * is changed or if Daylight Saving Time starts or ends.
94 int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); 131 * @return
95 int offsetSeconds = offsetMillis / 1000; 132 */
96 return (Integer)offsetSeconds; 133 public Object getDefault() {
97 default: 134 switch (this) {
98 return defaultValue; 135 case TIMEZONE:
99 } 136 Calendar cal = Calendar.getInstance();
100 } 137 int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
138 int offsetSeconds = offsetMillis / 1000;
139 return offsetSeconds;
140 default:
141 return defaultValue;
142 }
143 }
101 } 144 }