1
1
package com .clickhouse .client .api .insert ;
2
2
3
- import com .clickhouse .client .ClickHouseProtocol ;
4
3
import com .clickhouse .client .api .Client ;
5
4
import com .clickhouse .client .api .ClientConfigProperties ;
6
- import com .clickhouse .client .api .enums .Protocol ;
7
- import com .clickhouse .client .api .internal .ValidationUtils ;
5
+ import com .clickhouse .client .api .internal .CommonSettings ;
8
6
import org .apache .hc .core5 .http .HttpHeaders ;
9
7
10
8
import java .util .Collection ;
11
- import java .util .HashMap ;
12
9
import java .util .Map ;
13
10
14
11
public class InsertSettings {
15
12
private static final int DEFAULT_INPUT_STREAM_BATCH_SIZE = 8196 ;
16
13
17
14
private int inputStreamCopyBufferSize ;
18
- private String operationId ;
19
- Map <String , Object > rawSettings ;
15
+ CommonSettings settings ;
20
16
21
17
public InsertSettings () {
22
- rawSettings = new HashMap <> ();
18
+ settings = new CommonSettings ();
23
19
setDefaults ();
24
20
}
25
21
26
22
public InsertSettings (Map <String , Object > settings ) {
27
- rawSettings = new HashMap <> ();
23
+ this . settings = new CommonSettings ();
28
24
setDefaults ();
29
- rawSettings .putAll (settings );
25
+ for (Map .Entry <String , Object > entry : settings .entrySet ()) {
26
+ this .settings .setOption (entry .getKey (), entry .getValue ());
27
+ }
30
28
}
31
29
32
30
private void setDefaults () {// Default settings, for now a very small list
@@ -40,7 +38,7 @@ private void setDefaults() {// Default settings, for now a very small list
40
38
* @return configuration option value
41
39
*/
42
40
public Object getOption (String option ) {
43
- return rawSettings . get (option );
41
+ return settings . getOption (option );
44
42
}
45
43
46
44
/**
@@ -51,10 +49,7 @@ public Object getOption(String option) {
51
49
* @param value - configuration option value
52
50
*/
53
51
public InsertSettings setOption (String option , Object value ) {
54
- rawSettings .put (option , value );
55
- if (option .equals (ClientConfigProperties .PRODUCT_NAME .getKey ())) {
56
- rawSettings .put (ClientConfigProperties .CLIENT_NAME .getKey (), value );
57
- }
52
+ settings .setOption (option , value );
58
53
return this ;
59
54
}
60
55
@@ -64,7 +59,7 @@ public InsertSettings setOption(String option, Object value) {
64
59
* @return all settings
65
60
*/
66
61
public Map <String , Object > getAllSettings () {
67
- return rawSettings ;
62
+ return settings . getAllSettings () ;
68
63
}
69
64
70
65
/**
@@ -79,14 +74,14 @@ public InsertSettings setDeduplicationToken(String token) {
79
74
}
80
75
81
76
public String getQueryId () {
82
- return ( String ) rawSettings . get ( ClientConfigProperties . QUERY_ID . getKey () );
77
+ return settings . getQueryId ( );
83
78
}
84
79
85
80
/**
86
81
* Sets the query id. This id will be sent to the server and can be used to identify the query.
87
82
*/
88
83
public InsertSettings setQueryId (String queryId ) {
89
- rawSettings . put ( ClientConfigProperties . QUERY_ID . getKey (), queryId );
84
+ settings . setQueryId ( queryId );
90
85
return this ;
91
86
}
92
87
@@ -108,7 +103,7 @@ public InsertSettings setInputStreamCopyBufferSize(int size) {
108
103
* Should not be called directly.
109
104
*/
110
105
public String getOperationId () {
111
- return this . operationId ;
106
+ return settings . getOperationId () ;
112
107
}
113
108
114
109
/**
@@ -118,21 +113,20 @@ public String getOperationId() {
118
113
* @param operationId - operation id
119
114
*/
120
115
public InsertSettings setOperationId (String operationId ) {
121
- this . operationId = operationId ;
116
+ settings . setOperationId ( operationId ) ;
122
117
return this ;
123
118
}
124
119
125
120
/**
126
121
* Sets database to be used for a request.
127
122
*/
128
123
public InsertSettings setDatabase (String database ) {
129
- ValidationUtils .checkNonBlank (database , "database" );
130
- rawSettings .put ("database" , database );
124
+ settings .setDatabase (database );
131
125
return this ;
132
126
}
133
127
134
128
public String getDatabase () {
135
- return ( String ) rawSettings . get ( "database" );
129
+ return settings . getDatabase ( );
136
130
}
137
131
138
132
/**
@@ -141,12 +135,12 @@ public String getDatabase() {
141
135
* @param enabled - indicates if client request compression is enabled
142
136
*/
143
137
public InsertSettings compressClientRequest (boolean enabled ) {
144
- this . rawSettings . put (ClientConfigProperties .COMPRESS_CLIENT_REQUEST .getKey (), enabled );
138
+ settings . setOption (ClientConfigProperties .COMPRESS_CLIENT_REQUEST .getKey (), enabled );
145
139
return this ;
146
140
}
147
141
148
142
public InsertSettings useHttpCompression (boolean enabled ) {
149
- this . rawSettings . put (ClientConfigProperties .USE_HTTP_COMPRESSION .getKey (), enabled );
143
+ settings . setOption (ClientConfigProperties .USE_HTTP_COMPRESSION .getKey (), enabled );
150
144
return this ;
151
145
}
152
146
@@ -156,48 +150,67 @@ public InsertSettings useHttpCompression(boolean enabled) {
156
150
* @param enabled - if application provides compressed data
157
151
*/
158
152
public InsertSettings appCompressedData (boolean enabled , String compressionMethod ) {
159
- this . rawSettings . put (ClientConfigProperties .APP_COMPRESSED_DATA .getKey (), enabled );
153
+ settings . setOption (ClientConfigProperties .APP_COMPRESSED_DATA .getKey (), enabled );
160
154
useHttpCompression (true );
161
155
httpHeader (HttpHeaders .CONTENT_ENCODING , compressionMethod );
162
156
return this ;
163
157
}
164
158
159
+ /**
160
+ *
161
+ * @return true if client compression is enabled
162
+ * @deprecated because of typo
163
+ */
165
164
public boolean isClientRequestEnabled () {
166
- return (Boolean ) rawSettings .get ("decompress" );
165
+ return isClientCompressionEnabled ();
166
+ }
167
+
168
+ /**
169
+ * Returns indication if client request should be compressed (client side compression).
170
+ *
171
+ * @return true if client compression is enabled
172
+ */
173
+ public boolean isClientCompressionEnabled () {
174
+ return (boolean ) settings .getOption (
175
+ ClientConfigProperties .COMPRESS_CLIENT_REQUEST .getKey (),
176
+ false
177
+ );
167
178
}
168
179
169
180
/**
170
181
* Defines list of headers that should be sent with current request. The Client will use a header value
171
182
* defined in {@code headers} instead of any other.
172
183
*
173
- * @see Client.Builder#httpHeaders(Map)
174
- * @param key - header name.
184
+ * @param key - header name.
175
185
* @param value - header value.
176
186
* @return same instance of the builder
187
+ * @see Client.Builder#httpHeaders(Map)
177
188
*/
178
189
public InsertSettings httpHeader (String key , String value ) {
179
- rawSettings . put ( ClientConfigProperties . httpHeader (key ) , value );
190
+ settings . httpHeader (key , value );
180
191
return this ;
181
192
}
182
193
183
194
/**
184
195
* {@see #httpHeader(String, String)} but for multiple values.
185
- * @param key - name of the header
196
+ *
197
+ * @param key - name of the header
186
198
* @param values - collection of values
187
199
* @return same instance of the builder
188
200
*/
189
201
public InsertSettings httpHeader (String key , Collection <String > values ) {
190
- rawSettings . put ( ClientConfigProperties . httpHeader (key ), ClientConfigProperties . commaSeparated ( values ) );
202
+ settings . httpHeader (key , values );
191
203
return this ;
192
204
}
193
205
194
206
/**
195
207
* {@see #httpHeader(String, String)} but for multiple headers.
208
+ *
196
209
* @param headers - map of headers
197
210
* @return same instance of the builder
198
211
*/
199
212
public InsertSettings httpHeaders (Map <String , String > headers ) {
200
- headers . forEach ( this :: httpHeader );
213
+ settings . httpHeaders ( headers );
201
214
return this ;
202
215
}
203
216
@@ -206,24 +219,25 @@ public InsertSettings httpHeaders(Map<String, String> headers) {
206
219
* defined in {@code settings} instead of any other.
207
220
* Operation settings may override these values.
208
221
*
209
- * @see Client.Builder#serverSetting(String, Collection)
210
- * @param name - name of the setting
222
+ * @param name - name of the setting
211
223
* @param value - value of the setting
212
224
* @return same instance of the builder
225
+ * @see Client.Builder#serverSetting(String, Collection)
213
226
*/
214
227
public InsertSettings serverSetting (String name , String value ) {
215
- rawSettings . put ( ClientConfigProperties . serverSetting (name ) , value );
228
+ settings . serverSetting (name , value );
216
229
return this ;
217
230
}
218
231
219
232
/**
220
233
* {@see #serverSetting(String, String)} but for multiple values.
221
- * @param name - name of the setting without special prefix
234
+ *
235
+ * @param name - name of the setting without special prefix
222
236
* @param values - collection of values
223
237
* @return same instance of the builder
224
238
*/
225
239
public InsertSettings serverSetting (String name , Collection <String > values ) {
226
- rawSettings . put ( ClientConfigProperties . serverSetting (name ), ClientConfigProperties . commaSeparated ( values ) );
240
+ settings . serverSetting (name , values );
227
241
return this ;
228
242
}
229
243
@@ -233,7 +247,7 @@ public InsertSettings serverSetting(String name, Collection<String> values) {
233
247
* @param dbRoles
234
248
*/
235
249
public InsertSettings setDBRoles (Collection <String > dbRoles ) {
236
- rawSettings . put ( ClientConfigProperties . SESSION_DB_ROLES . getKey (), dbRoles );
250
+ settings . setDBRoles ( dbRoles );
237
251
return this ;
238
252
}
239
253
@@ -243,25 +257,21 @@ public InsertSettings setDBRoles(Collection<String> dbRoles) {
243
257
* @return list of DB roles
244
258
*/
245
259
public Collection <String > getDBRoles () {
246
- return ( Collection < String >) rawSettings . get ( ClientConfigProperties . SESSION_DB_ROLES . getKey () );
260
+ return settings . getDBRoles ( );
247
261
}
248
262
249
263
/**
250
264
* Sets the comment that will be added to the query log record associated with the query.
265
+ *
251
266
* @param logComment - comment to be added to the log
252
267
* @return same instance of the builder
253
268
*/
254
269
public InsertSettings logComment (String logComment ) {
255
- this .logComment = logComment ;
256
- if (logComment != null && !logComment .isEmpty ()) {
257
- rawSettings .put (ClientConfigProperties .SETTING_LOG_COMMENT .getKey (), logComment );
258
- }
270
+ settings .logComment (logComment );
259
271
return this ;
260
272
}
261
273
262
- private String logComment = null ;
263
-
264
274
public String getLogComment () {
265
- return logComment ;
275
+ return settings . getLogComment () ;
266
276
}
267
277
}
0 commit comments