11package com .clickhouse .client .api .insert ;
22
3- import com .clickhouse .client .ClickHouseProtocol ;
43import com .clickhouse .client .api .Client ;
54import 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 ;
86import org .apache .hc .core5 .http .HttpHeaders ;
97
108import java .util .Collection ;
11- import java .util .HashMap ;
129import java .util .Map ;
1310
1411public class InsertSettings {
1512 private static final int DEFAULT_INPUT_STREAM_BATCH_SIZE = 8196 ;
1613
1714 private int inputStreamCopyBufferSize ;
18- private String operationId ;
19- Map <String , Object > rawSettings ;
15+ CommonSettings settings ;
2016
2117 public InsertSettings () {
22- rawSettings = new HashMap <> ();
18+ settings = new CommonSettings ();
2319 setDefaults ();
2420 }
2521
2622 public InsertSettings (Map <String , Object > settings ) {
27- rawSettings = new HashMap <> ();
23+ this . settings = new CommonSettings ();
2824 setDefaults ();
29- rawSettings .putAll (settings );
25+ for (Map .Entry <String , Object > entry : settings .entrySet ()) {
26+ this .settings .setOption (entry .getKey (), entry .getValue ());
27+ }
3028 }
3129
3230 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
4038 * @return configuration option value
4139 */
4240 public Object getOption (String option ) {
43- return rawSettings . get (option );
41+ return settings . getOption (option );
4442 }
4543
4644 /**
@@ -51,10 +49,7 @@ public Object getOption(String option) {
5149 * @param value - configuration option value
5250 */
5351 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 );
5853 return this ;
5954 }
6055
@@ -64,7 +59,7 @@ public InsertSettings setOption(String option, Object value) {
6459 * @return all settings
6560 */
6661 public Map <String , Object > getAllSettings () {
67- return rawSettings ;
62+ return settings . getAllSettings () ;
6863 }
6964
7065 /**
@@ -79,14 +74,14 @@ public InsertSettings setDeduplicationToken(String token) {
7974 }
8075
8176 public String getQueryId () {
82- return ( String ) rawSettings . get ( ClientConfigProperties . QUERY_ID . getKey () );
77+ return settings . getQueryId ( );
8378 }
8479
8580 /**
8681 * Sets the query id. This id will be sent to the server and can be used to identify the query.
8782 */
8883 public InsertSettings setQueryId (String queryId ) {
89- rawSettings . put ( ClientConfigProperties . QUERY_ID . getKey (), queryId );
84+ settings . setQueryId ( queryId );
9085 return this ;
9186 }
9287
@@ -108,7 +103,7 @@ public InsertSettings setInputStreamCopyBufferSize(int size) {
108103 * Should not be called directly.
109104 */
110105 public String getOperationId () {
111- return this . operationId ;
106+ return settings . getOperationId () ;
112107 }
113108
114109 /**
@@ -118,21 +113,20 @@ public String getOperationId() {
118113 * @param operationId - operation id
119114 */
120115 public InsertSettings setOperationId (String operationId ) {
121- this . operationId = operationId ;
116+ settings . setOperationId ( operationId ) ;
122117 return this ;
123118 }
124119
125120 /**
126121 * Sets database to be used for a request.
127122 */
128123 public InsertSettings setDatabase (String database ) {
129- ValidationUtils .checkNonBlank (database , "database" );
130- rawSettings .put ("database" , database );
124+ settings .setDatabase (database );
131125 return this ;
132126 }
133127
134128 public String getDatabase () {
135- return ( String ) rawSettings . get ( "database" );
129+ return settings . getDatabase ( );
136130 }
137131
138132 /**
@@ -141,12 +135,12 @@ public String getDatabase() {
141135 * @param enabled - indicates if client request compression is enabled
142136 */
143137 public InsertSettings compressClientRequest (boolean enabled ) {
144- this . rawSettings . put (ClientConfigProperties .COMPRESS_CLIENT_REQUEST .getKey (), enabled );
138+ settings . setOption (ClientConfigProperties .COMPRESS_CLIENT_REQUEST .getKey (), enabled );
145139 return this ;
146140 }
147141
148142 public InsertSettings useHttpCompression (boolean enabled ) {
149- this . rawSettings . put (ClientConfigProperties .USE_HTTP_COMPRESSION .getKey (), enabled );
143+ settings . setOption (ClientConfigProperties .USE_HTTP_COMPRESSION .getKey (), enabled );
150144 return this ;
151145 }
152146
@@ -156,48 +150,67 @@ public InsertSettings useHttpCompression(boolean enabled) {
156150 * @param enabled - if application provides compressed data
157151 */
158152 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 );
160154 useHttpCompression (true );
161155 httpHeader (HttpHeaders .CONTENT_ENCODING , compressionMethod );
162156 return this ;
163157 }
164158
159+ /**
160+ *
161+ * @return true if client compression is enabled
162+ * @deprecated because of typo
163+ */
165164 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+ );
167178 }
168179
169180 /**
170181 * Defines list of headers that should be sent with current request. The Client will use a header value
171182 * defined in {@code headers} instead of any other.
172183 *
173- * @see Client.Builder#httpHeaders(Map)
174- * @param key - header name.
184+ * @param key - header name.
175185 * @param value - header value.
176186 * @return same instance of the builder
187+ * @see Client.Builder#httpHeaders(Map)
177188 */
178189 public InsertSettings httpHeader (String key , String value ) {
179- rawSettings . put ( ClientConfigProperties . httpHeader (key ) , value );
190+ settings . httpHeader (key , value );
180191 return this ;
181192 }
182193
183194 /**
184195 * {@see #httpHeader(String, String)} but for multiple values.
185- * @param key - name of the header
196+ *
197+ * @param key - name of the header
186198 * @param values - collection of values
187199 * @return same instance of the builder
188200 */
189201 public InsertSettings httpHeader (String key , Collection <String > values ) {
190- rawSettings . put ( ClientConfigProperties . httpHeader (key ), ClientConfigProperties . commaSeparated ( values ) );
202+ settings . httpHeader (key , values );
191203 return this ;
192204 }
193205
194206 /**
195207 * {@see #httpHeader(String, String)} but for multiple headers.
208+ *
196209 * @param headers - map of headers
197210 * @return same instance of the builder
198211 */
199212 public InsertSettings httpHeaders (Map <String , String > headers ) {
200- headers . forEach ( this :: httpHeader );
213+ settings . httpHeaders ( headers );
201214 return this ;
202215 }
203216
@@ -206,24 +219,25 @@ public InsertSettings httpHeaders(Map<String, String> headers) {
206219 * defined in {@code settings} instead of any other.
207220 * Operation settings may override these values.
208221 *
209- * @see Client.Builder#serverSetting(String, Collection)
210- * @param name - name of the setting
222+ * @param name - name of the setting
211223 * @param value - value of the setting
212224 * @return same instance of the builder
225+ * @see Client.Builder#serverSetting(String, Collection)
213226 */
214227 public InsertSettings serverSetting (String name , String value ) {
215- rawSettings . put ( ClientConfigProperties . serverSetting (name ) , value );
228+ settings . serverSetting (name , value );
216229 return this ;
217230 }
218231
219232 /**
220233 * {@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
222236 * @param values - collection of values
223237 * @return same instance of the builder
224238 */
225239 public InsertSettings serverSetting (String name , Collection <String > values ) {
226- rawSettings . put ( ClientConfigProperties . serverSetting (name ), ClientConfigProperties . commaSeparated ( values ) );
240+ settings . serverSetting (name , values );
227241 return this ;
228242 }
229243
@@ -233,7 +247,7 @@ public InsertSettings serverSetting(String name, Collection<String> values) {
233247 * @param dbRoles
234248 */
235249 public InsertSettings setDBRoles (Collection <String > dbRoles ) {
236- rawSettings . put ( ClientConfigProperties . SESSION_DB_ROLES . getKey (), dbRoles );
250+ settings . setDBRoles ( dbRoles );
237251 return this ;
238252 }
239253
@@ -243,25 +257,21 @@ public InsertSettings setDBRoles(Collection<String> dbRoles) {
243257 * @return list of DB roles
244258 */
245259 public Collection <String > getDBRoles () {
246- return ( Collection < String >) rawSettings . get ( ClientConfigProperties . SESSION_DB_ROLES . getKey () );
260+ return settings . getDBRoles ( );
247261 }
248262
249263 /**
250264 * Sets the comment that will be added to the query log record associated with the query.
265+ *
251266 * @param logComment - comment to be added to the log
252267 * @return same instance of the builder
253268 */
254269 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 );
259271 return this ;
260272 }
261273
262- private String logComment = null ;
263-
264274 public String getLogComment () {
265- return logComment ;
275+ return settings . getLogComment () ;
266276 }
267277}
0 commit comments