forked from databendlabs/databend-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientSettings.java
More file actions
194 lines (161 loc) · 6.65 KB
/
ClientSettings.java
File metadata and controls
194 lines (161 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.databend.client;
import java.util.HashMap;
import java.util.Map;
public class ClientSettings {
public static final Integer DEFAULT_QUERY_TIMEOUT = 300;
// seconds
public static final Integer DEFAULT_CONNECTION_TIMEOUT = 0;
public static final Integer DEFAULT_SOCKET_TIMEOUT = 0;
public static final int DEFAULT_RETRY_ATTEMPTS = 5;
public static final String X_Databend_Query_ID = "X-DATABEND-QUERY-ID";
public static final String X_DATABEND_VERSION= "X-DATABEND-VERSION";
public static final String X_DATABEND_ROUTE_HINT = "X-DATABEND-ROUTE-HINT";
public static final String X_DATABEND_STAGE_NAME = "X-DATABEND-STAGE-NAME";
public static final String X_DATABEND_RELATIVE_PATH = "X-DATABEND-RELATIVE-PATH";
public static final String X_DATABEND_STICKY_NODE = "X-DATABEND-STICKY-NODE";
public static final String DatabendWarehouseHeader = "X-DATABEND-WAREHOUSE";
public static final String DatabendTenantHeader = "X-DATABEND-TENANT";
private final String host;
private final DatabendSession session;
private final Integer queryTimeoutSecs;
private final Integer connectionTimeout;
private final Integer socketTimeout;
private final PaginationOptions paginationOptions;
private final StageAttachment stageAttachment;
private Map<String, String> additionalHeaders;
private final int retryAttempts;
// TODO(zhihanz) timezone and locale info
//ClientSettings for test case use
public ClientSettings(String host) {
this(host, DatabendSession.createDefault(), DEFAULT_QUERY_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_SOCKET_TIMEOUT, PaginationOptions.defaultPaginationOptions(), new HashMap<String, String>(), null, DEFAULT_RETRY_ATTEMPTS);
}
public ClientSettings(String host, String database) {
DatabendSession session = new DatabendSession.Builder().setDatabase(database).build();
this.host = host;
this.session = session;
this.queryTimeoutSecs = DEFAULT_QUERY_TIMEOUT;
this.connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
this.socketTimeout = DEFAULT_SOCKET_TIMEOUT;
this.paginationOptions = PaginationOptions.defaultPaginationOptions();
this.additionalHeaders = new HashMap<>();
this.stageAttachment = null;
this.retryAttempts = DEFAULT_RETRY_ATTEMPTS;
}
public ClientSettings(String host, DatabendSession session,
Integer queryTimeoutSecs,
Integer connectionTimeout,
Integer socketTimeout,
PaginationOptions paginationOptions,
Map<String, String> additionalHeaders,
StageAttachment stageAttachment,
int retryAttempts) {
this.host = host;
this.session = session;
this.queryTimeoutSecs = queryTimeoutSecs;
this.connectionTimeout = connectionTimeout;
this.socketTimeout = socketTimeout;
this.paginationOptions = paginationOptions;
this.additionalHeaders = additionalHeaders;
this.stageAttachment = stageAttachment;
this.retryAttempts = retryAttempts;
}
public static Builder builder() {
return new Builder();
}
public DatabendSession getSession() {
return session;
}
public String getHost() {
return host;
}
public Integer getQueryTimeoutSecs() {
return queryTimeoutSecs;
}
public Integer getConnectionTimeout() {
return connectionTimeout;
}
public Integer getSocketTimeout() {
return socketTimeout;
}
public PaginationOptions getPaginationOptions() {
return paginationOptions;
}
public Map<String, String> getAdditionalHeaders() {
return additionalHeaders;
}
public StageAttachment getStageAttachment() {
return stageAttachment;
}
public int getRetryAttempts() {
if (retryAttempts <= 0) {
return DEFAULT_RETRY_ATTEMPTS;
}
return retryAttempts;
}
public static class Builder {
private DatabendSession session;
private String host;
private Integer queryTimeoutSecs;
private Integer connectionTimeout;
private Integer socketTimeout;
private PaginationOptions paginationOptions;
private StageAttachment stageAttachment;
private Map<String, String> additionalHeaders;
private int retryAttempts;
public Builder setSession(DatabendSession session) {
this.session = session;
return this;
}
public Builder setHost(String host) {
this.host = host;
return this;
}
public Builder setConnectionTimeout(Integer timeout) {
this.connectionTimeout = timeout;
return this;
}
public Builder setSocketTimeout(Integer timeout) {
this.socketTimeout = timeout;
return this;
}
public Builder setQueryTimeoutSecs(Integer queryTimeoutSecs) {
if (queryTimeoutSecs <= 0) {
queryTimeoutSecs = DEFAULT_QUERY_TIMEOUT;
}
this.queryTimeoutSecs = queryTimeoutSecs;
return this;
}
public Builder setPaginationOptions(PaginationOptions paginationOptions) {
this.paginationOptions = paginationOptions;
return this;
}
public Builder setAdditionalHeaders(Map<String, String> additionalHeaders) {
this.additionalHeaders = additionalHeaders;
return this;
}
public Builder setRetryAttempts(int retryAttempts) {
this.retryAttempts = retryAttempts;
return this;
}
public Builder setStageAttachment(StageAttachment stageAttachment) {
this.stageAttachment = stageAttachment;
return this;
}
public ClientSettings build() {
return new ClientSettings(host, session, queryTimeoutSecs, connectionTimeout, socketTimeout, paginationOptions, additionalHeaders, stageAttachment, retryAttempts);
}
}
}