Skip to content

Commit 334881f

Browse files
committed
added getOption(key, default) for CommonSettings
1 parent 1c642ac commit 334881f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

client-v2/src/main/java/com/clickhouse/client/api/insert/InsertSettings.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ public InsertSettings appCompressedData(boolean enabled, String compressionMetho
162162
* @deprecated because of typo
163163
*/
164164
public boolean isClientRequestEnabled() {
165-
Boolean flag = (Boolean) settings.getOption(ClientConfigProperties.COMPRESS_CLIENT_REQUEST.getKey());
166-
return flag != null && flag;
165+
return isClientCompressionEnabled();
167166
}
168167

169168
/**
@@ -172,8 +171,10 @@ public boolean isClientRequestEnabled() {
172171
* @return true if client compression is enabled
173172
*/
174173
public boolean isClientCompressionEnabled() {
175-
Boolean flag = (Boolean) settings.getOption(ClientConfigProperties.COMPRESS_CLIENT_REQUEST.getKey());
176-
return flag != null && flag;
174+
return (boolean) settings.getOption(
175+
ClientConfigProperties.COMPRESS_CLIENT_REQUEST.getKey(),
176+
false
177+
);
177178
}
178179

179180
/**

client-v2/src/main/java/com/clickhouse/client/api/internal/CommonSettings.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ public Object getOption(String option) {
3232
return settings.get(option);
3333
}
3434

35+
/**
36+
* Gets a configuration option. If not set then defaultValue is returned.
37+
*
38+
* @param option - config option key
39+
* @param defaultValue - default option to return when option is not set
40+
* @return configuration option value
41+
*/
42+
public Object getOption(String option, Object defaultValue) {
43+
return settings.getOrDefault(option, defaultValue);
44+
}
45+
3546
public boolean hasOption(String option) {
3647
return settings.containsKey(option);
3748
}

0 commit comments

Comments
 (0)