Skip to content

Commit 4a0540d

Browse files
committed
merge main. a few fixes
1 parent 9b4c5d0 commit 4a0540d

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.clickhouse.client.api.Client;
44
import com.clickhouse.client.api.ClientConfigProperties;
55
import com.clickhouse.client.api.internal.CommonSettings;
6-
import com.clickhouse.client.api.query.QuerySettings;
76
import org.apache.hc.core5.http.HttpHeaders;
87

8+
import java.time.temporal.ChronoUnit;
99
import java.util.Collection;
1010
import java.util.Map;
1111

@@ -28,6 +28,11 @@ public InsertSettings(Map<String, Object> settings) {
2828
}
2929
}
3030

31+
private InsertSettings(CommonSettings settings) {
32+
this.settings = settings;
33+
setDefaults();
34+
}
35+
3136
private void setDefaults() {// Default settings, for now a very small list
3237
this.setInputStreamCopyBufferSize(DEFAULT_INPUT_STREAM_BATCH_SIZE);
3338
}
@@ -277,25 +282,24 @@ public String getLogComment() {
277282
}
278283

279284
public static InsertSettings merge(InsertSettings source, InsertSettings override) {
280-
InsertSettings merged = new InsertSettings();
281-
if (source != null) {
282-
merged.rawSettings.putAll(source.rawSettings);
283-
}
284-
if (override != null && override != source) {// avoid copying the literally same object
285-
merged.rawSettings.putAll(override.rawSettings);
286-
}
287-
return merged;
285+
CommonSettings mergedSettings = source.settings.copyAndMerge(override.settings);
286+
return new InsertSettings(mergedSettings);
288287
}
289288

290-
public void setNetworkTimeout(Long networkTimeout) {
291-
if (networkTimeout != null) {
292-
rawSettings.put(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey(), networkTimeout.intValue());
293-
} else {
294-
rawSettings.remove(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey());
295-
}
289+
/**
290+
* Sets a network operation timeout.
291+
* @param timeout
292+
* @param unit
293+
*/
294+
public void setNetworkTimeout(long timeout, ChronoUnit unit) {
295+
settings.setNetworkTimeout(timeout, unit);
296296
}
297297

298+
/**
299+
* Returns network timeout. Zero value is returned if no timeout is set.
300+
* @return timeout in ms.
301+
*/
298302
public Long getNetworkTimeout() {
299-
return (Long) rawSettings.get(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey());
303+
return settings.getNetworkTimeout();
300304
}
301305
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.clickhouse.client.api.Client;
44
import com.clickhouse.client.api.ClientConfigProperties;
55

6+
import java.time.Duration;
7+
import java.time.temporal.ChronoUnit;
68
import java.util.Collection;
79
import java.util.HashMap;
810
import java.util.Map;
@@ -217,6 +219,25 @@ public String getLogComment() {
217219
return logComment;
218220
}
219221

222+
/**
223+
* Sets a network operation timeout.
224+
* @param timeout
225+
* @param unit
226+
*/
227+
public void setNetworkTimeout(long timeout, ChronoUnit unit) {
228+
settings.put(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey(), Duration.of(timeout, unit).toMillis());
229+
}
230+
231+
/**
232+
* Returns network timeout. Zero value is returned if no timeout is set.
233+
* @return timeout in ms.
234+
*/
235+
public Long getNetworkTimeout() {
236+
return (Long) getOption(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey(),
237+
ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getDefaultValue());
238+
}
239+
240+
220241
public CommonSettings copyAndMerge(CommonSettings override) {
221242
CommonSettings copy = new CommonSettings();
222243
copy.settings.putAll(settings);

client-v2/src/main/java/com/clickhouse/client/api/query/QuerySettings.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.clickhouse.client.api.internal.ValidationUtils;
99
import com.clickhouse.data.ClickHouseFormat;
1010

11+
import java.time.temporal.ChronoUnit;
1112
import java.util.Collection;
12-
import java.util.HashMap;
1313
import java.util.Map;
1414
import java.util.TimeZone;
1515

@@ -269,16 +269,21 @@ public String getLogComment() {
269269
return settings.getLogComment();
270270
}
271271

272-
public void setNetworkTimeout(Long networkTimeout) {
273-
if (networkTimeout != null) {
274-
rawSettings.put(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey(), networkTimeout.intValue());
275-
} else {
276-
rawSettings.remove(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey());
277-
}
272+
/**
273+
* Sets a network operation timeout.
274+
* @param timeout
275+
* @param unit
276+
*/
277+
public void setNetworkTimeout(long timeout, ChronoUnit unit) {
278+
settings.setNetworkTimeout(timeout, unit);
278279
}
279280

281+
/**
282+
* Returns network timeout. Zero value is returned if no timeout is set.
283+
* @return timeout in ms.
284+
*/
280285
public Long getNetworkTimeout() {
281-
return (Long) rawSettings.get(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey());
286+
return settings.getNetworkTimeout();
282287
}
283288

284289
public static QuerySettings merge(QuerySettings source, QuerySettings override) {

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,7 @@ public void onNetworkTimeout() throws SQLException {
658658

659659
@Override
660660
public int getNetworkTimeout() throws SQLException {
661-
Long networkTimeout = defaultQuerySettings.getNetworkTimeout();
662-
return networkTimeout == null ? 0 : networkTimeout.intValue();
661+
return defaultQuerySettings.getNetworkTimeout().intValue();
663662
}
664663

665664
/**

0 commit comments

Comments
 (0)