|
7 | 7 | import java.util.stream.Collectors; |
8 | 8 |
|
9 | 9 | /** |
10 | | - * All known client settings at current version. |
11 | | - * |
| 10 | + * Enumerates all client properties that are known at release. |
12 | 11 | */ |
13 | | -public class ClientConfigProperties { |
| 12 | +public enum ClientConfigProperties { |
14 | 13 |
|
15 | | - public static final String HTTP_HEADER_PREFIX = "http_header_"; |
16 | | - |
17 | | - public static final String SERVER_SETTING_PREFIX = "clickhouse_setting_"; |
18 | | - |
19 | | - public static String commaSeparated(Collection<?> values) { |
20 | | - StringBuilder sb = new StringBuilder(); |
21 | | - for (Object value : values) { |
22 | | - sb.append(value.toString().replaceAll(",", "\\\\,")).append(","); |
23 | | - } |
24 | | - sb.setLength(sb.length() - 1); |
25 | | - return sb.toString(); |
26 | | - } |
27 | | - |
28 | | - public static List<String> valuesFromCommaSeparated(String value) { |
29 | | - if (value == null || value.isEmpty()) { |
30 | | - return Collections.emptyList(); |
31 | | - } |
32 | | - |
33 | | - return Arrays.stream(value.split("(?<!\\\\),")).map(s -> s.replaceAll("\\\\,", ",")) |
34 | | - .collect(Collectors.toList()); |
35 | | - } |
| 14 | + SESSION_DB_ROLES("session_db_roles"), |
36 | 15 |
|
37 | | - public static final String SESSION_DB_ROLES = "session_db_roles"; |
| 16 | + SETTING_LOG_COMMENT(serverSetting("log_comment")), |
38 | 17 |
|
39 | | - public static final String SETTING_LOG_COMMENT = SERVER_SETTING_PREFIX + "log_comment"; |
| 18 | + HTTP_USE_BASIC_AUTH("http_use_basic_auth"), |
40 | 19 |
|
41 | | - public static final String HTTP_USE_BASIC_AUTH = "http_use_basic_auth"; |
| 20 | + USER("user"), |
42 | 21 |
|
43 | | - public static final String USER = "user"; |
44 | | - |
45 | | - public static final String PASSWORD = "password"; |
| 22 | + PASSWORD("password"), |
46 | 23 |
|
47 | 24 | /** |
48 | 25 | * Maximum number of active connection in internal connection pool. |
49 | 26 | */ |
50 | | - public static final String HTTP_MAX_OPEN_CONNECTIONS = "max_open_connections"; |
| 27 | + HTTP_MAX_OPEN_CONNECTIONS("max_open_connections"), |
51 | 28 |
|
52 | 29 | /** |
53 | 30 | * HTTP keep-alive timeout override. |
54 | 31 | */ |
55 | | - public static final String HTTP_KEEP_ALIVE_TIMEOUT = "http_keep_alive_timeout"; |
| 32 | + HTTP_KEEP_ALIVE_TIMEOUT("http_keep_alive_timeout"), |
56 | 33 |
|
57 | | - public static final String USE_SERVER_TIMEZONE = "use_server_time_zone"; |
| 34 | + USE_SERVER_TIMEZONE("use_server_time_zone"), |
58 | 35 |
|
59 | | - public static final String USE_TIMEZONE = "use_time_zone"; |
| 36 | + USE_TIMEZONE("use_time_zone"), |
60 | 37 |
|
61 | | - public static final String SERVER_TIMEZONE = "server_time_zone"; |
| 38 | + SERVER_TIMEZONE("server_time_zone"), |
62 | 39 |
|
63 | | - public static final String ASYNC_OPERATIONS = "async"; |
| 40 | + ASYNC_OPERATIONS("async"), |
64 | 41 |
|
65 | | - public static final String CONNECTION_TTL = "connection_ttl"; |
| 42 | + CONNECTION_TTL("connection_ttl"), |
66 | 43 |
|
67 | | - public static final String CONNECTION_TIMEOUT = "connection_timeout"; |
| 44 | + CONNECTION_TIMEOUT("connection_timeout"), |
68 | 45 |
|
69 | | - public static final String CONNECTION_REUSE_STRATEGY = "connection_reuse_strategy"; |
| 46 | + CONNECTION_REUSE_STRATEGY("connection_reuse_strategy"), |
70 | 47 |
|
71 | | - public static final String SOCKET_OPERATION_TIMEOUT = "socket_timeout"; |
| 48 | + SOCKET_OPERATION_TIMEOUT("socket_timeout"), |
72 | 49 |
|
73 | | - public static final String SOCKET_RCVBUF_OPT = "socket_rcvbuf"; |
| 50 | + SOCKET_RCVBUF_OPT("socket_rcvbuf"), |
74 | 51 |
|
75 | | - public static final String SOCKET_SNDBUF_OPT = "socket_sndbuf"; |
| 52 | + SOCKET_SNDBUF_OPT("socket_sndbuf"), |
76 | 53 |
|
77 | | - public static final String SOCKET_REUSEADDR_OPT = "socket_reuseaddr"; |
| 54 | + SOCKET_REUSEADDR_OPT("socket_reuseaddr"), |
78 | 55 |
|
79 | | - public static final String SOCKET_KEEPALIVE_OPT = "socket_keepalive"; |
| 56 | + SOCKET_KEEPALIVE_OPT("socket_keepalive"), |
80 | 57 |
|
81 | | - public static final String SOCKET_TCP_NO_DELAY_OPT = "socket_tcp_nodelay"; |
| 58 | + SOCKET_TCP_NO_DELAY_OPT("socket_tcp_nodelay"), |
82 | 59 |
|
83 | | - public static final String SOCKET_LINGER_OPT = "socket_linger"; |
| 60 | + SOCKET_LINGER_OPT("socket_linger"), |
84 | 61 |
|
85 | | - public static final String DATABASE = "database"; |
| 62 | + DATABASE("database"), |
86 | 63 |
|
87 | | - public static final String COMPRESS_SERVER_RESPONSE = "compress"; // actually a server setting |
| 64 | + COMPRESS_SERVER_RESPONSE("compress"), // actually a server setting, but has client effect too |
88 | 65 |
|
89 | | - public static final String COMPRESS_CLIENT_REQUEST = "decompress"; // actually a server setting |
| 66 | + COMPRESS_CLIENT_REQUEST("decompress"), // actually a server setting, but has client effect too |
90 | 67 |
|
91 | | - public static final String USE_HTTP_COMPRESSION = "client.use_http_compression"; |
| 68 | + USE_HTTP_COMPRESSION("client.use_http_compression"), |
92 | 69 |
|
93 | | - public static final String COMPRESSION_LZ4_UNCOMPRESSED_BUF_SIZE = "compression.lz4.uncompressed_buffer_size"; |
| 70 | + COMPRESSION_LZ4_UNCOMPRESSED_BUF_SIZE("compression.lz4.uncompressed_buffer_size"), |
94 | 71 |
|
95 | | - public static final String PROXY_TYPE = "proxy_type"; // "http" |
| 72 | + PROXY_TYPE("proxy_type"), // "http" |
96 | 73 |
|
97 | | - public static final String PROXY_HOST = "proxy_host"; |
| 74 | + PROXY_HOST("proxy_host"), |
98 | 75 |
|
99 | | - public static final String PROXY_PORT = "proxy_port"; |
| 76 | + PROXY_PORT("proxy_port"), |
100 | 77 |
|
101 | | - public static final String PROXY_USER = "proxy_user"; |
| 78 | + PROXY_USER("proxy_user"), |
102 | 79 |
|
103 | | - public static final String PROXY_PASSWORD = "proxy_password"; |
| 80 | + PROXY_PASSWORD("proxy_password"), |
104 | 81 |
|
105 | | - public static final String MAX_EXECUTION_TIME = "max_execution_time"; |
| 82 | + MAX_EXECUTION_TIME("max_execution_time"), |
106 | 83 |
|
107 | | - public static final String SSL_TRUST_STORE = "trust_store"; |
| 84 | + SSL_TRUST_STORE("trust_store"), |
108 | 85 |
|
109 | | - public static final String SSL_KEYSTORE_TYPE = "key_store_type"; |
| 86 | + SSL_KEYSTORE_TYPE("key_store_type"), |
110 | 87 |
|
111 | | - public static final String SSL_KEY_STORE = "ssl_key_store"; |
| 88 | + SSL_KEY_STORE("ssl_key_store"), |
112 | 89 |
|
113 | | - public static final String SSL_KEY_STORE_PASSWORD = "key_store_password"; |
| 90 | + SSL_KEY_STORE_PASSWORD("key_store_password"), |
114 | 91 |
|
115 | | - public static final String SSL_KEY = "ssl_key"; |
| 92 | + SSL_KEY("ssl_key"), |
116 | 93 |
|
117 | | - public static final String CA_CERTIFICATE = "sslrootcert"; |
| 94 | + CA_CERTIFICATE("sslrootcert"), |
118 | 95 |
|
119 | | - public static final String SSL_CERTIFICATE = "sslcert"; |
| 96 | + SSL_CERTIFICATE("sslcert"), |
120 | 97 |
|
121 | | - public static final String RETRY_ON_FAILURE = "retry"; |
| 98 | + RETRY_ON_FAILURE("retry"), |
122 | 99 |
|
123 | | - public static final String INPUT_OUTPUT_FORMAT = "format"; |
| 100 | + INPUT_OUTPUT_FORMAT("format"), |
124 | 101 |
|
125 | | - public static final String MAX_THREADS_PER_CLIENT = "max_threads_per_client"; |
| 102 | + MAX_THREADS_PER_CLIENT("max_threads_per_client"), |
126 | 103 |
|
127 | | - public static final String QUERY_ID = "query_id"; // actually a server setting |
| 104 | + QUERY_ID("query_id"), // actually a server setting, but has client effect too |
128 | 105 |
|
129 | | - public static final String CLIENT_NETWORK_BUFFER_SIZE = "client_network_buffer_size"; |
| 106 | + CLIENT_NETWORK_BUFFER_SIZE("client_network_buffer_size"), |
130 | 107 |
|
131 | | - // -- Experimental features -- |
132 | 108 |
|
133 | | - /** |
134 | | - * Server will expect a string in JSON format and parse it into a JSON object. |
135 | | - */ |
136 | | - public static final String INPUT_FORMAT_BINARY_READ_JSON_AS_STRING = "input_format_binary_read_json_as_string"; |
| 109 | + ACCESS_TOKEN("access_token"), SSL_AUTH("ssl_authentication"), |
137 | 110 |
|
138 | | - /** |
139 | | - * Server will return a JSON object as a string. |
140 | | - */ |
141 | | - public static final String OUTPUT_FORMAT_BINARY_WRITE_JSON_AS_STRING = "output_format_binary_write_json_as_string"; |
| 111 | + CONNECTION_POOL_ENABLED("connection_pool_enabled"), |
| 112 | + |
| 113 | + CONNECTION_REQUEST_TIMEOUT("connection_request_timeout"), |
| 114 | + |
| 115 | + CLIENT_RETRY_ON_FAILURE("client_retry_on_failures"); |
142 | 116 |
|
| 117 | + private String key; |
| 118 | + |
| 119 | + ClientConfigProperties(String key) { |
| 120 | + this.key = key; |
| 121 | + } |
| 122 | + |
| 123 | + public String getKey() { |
| 124 | + return key; |
| 125 | + } |
| 126 | + |
| 127 | + public static final String HTTP_HEADER_PREFIX = "http_header_"; |
| 128 | + |
| 129 | + public static final String SERVER_SETTING_PREFIX = "clickhouse_setting_"; |
| 130 | + |
| 131 | + public static String serverSetting(String key) { |
| 132 | + return SERVER_SETTING_PREFIX + key; |
| 133 | + } |
| 134 | + |
| 135 | + public static String commaSeparated(Collection<?> values) { |
| 136 | + StringBuilder sb = new StringBuilder(); |
| 137 | + for (Object value : values) { |
| 138 | + sb.append(value.toString().replaceAll(",", "\\\\,")).append(","); |
| 139 | + } |
| 140 | + sb.setLength(sb.length() - 1); |
| 141 | + return sb.toString(); |
| 142 | + } |
| 143 | + |
| 144 | + public static List<String> valuesFromCommaSeparated(String value) { |
| 145 | + if (value == null || value.isEmpty()) { |
| 146 | + return Collections.emptyList(); |
| 147 | + } |
| 148 | + |
| 149 | + return Arrays.stream(value.split("(?<!\\\\),")).map(s -> s.replaceAll("\\\\,", ",")) |
| 150 | + .collect(Collectors.toList()); |
| 151 | + } |
143 | 152 | } |
0 commit comments