|
11 | 11 | import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader; |
12 | 12 | import com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader; |
13 | 13 | import com.clickhouse.client.api.data_formats.internal.MapBackedRecord; |
| 14 | +import com.clickhouse.client.api.enums.Protocol; |
| 15 | +import com.clickhouse.client.api.enums.ProxyType; |
14 | 16 | import com.clickhouse.client.api.insert.DataSerializationException; |
15 | 17 | import com.clickhouse.client.api.insert.InsertResponse; |
16 | 18 | import com.clickhouse.client.api.insert.InsertSettings; |
|
46 | 48 | import java.time.Duration; |
47 | 49 | import java.time.temporal.ChronoUnit; |
48 | 50 | import java.util.ArrayList; |
| 51 | +import java.util.Collections; |
49 | 52 | import java.util.HashMap; |
50 | 53 | import java.util.HashSet; |
51 | 54 | import java.util.List; |
@@ -187,12 +190,12 @@ public Builder addEndpoint(String endpoint) { |
187 | 190 | * @param host - Endpoint host |
188 | 191 | * @param port - Endpoint port |
189 | 192 | */ |
190 | | - public Builder addEndpoint(Protocol protocol, String host, int port) { |
| 193 | + public Builder addEndpoint(Protocol protocol, String host, int port, boolean secure) { |
191 | 194 | ValidationUtils.checkNonBlank(host, "host"); |
192 | 195 | ValidationUtils.checkNotNull(protocol, "protocol"); |
193 | 196 | ValidationUtils.checkRange(port, 1, ValidationUtils.TCP_PORT_NUMBER_MAX, "port"); |
194 | 197 |
|
195 | | - String endpoint = String.format("%s://%s:%d", protocol.toString().toLowerCase(), host, port); |
| 198 | + String endpoint = String.format("%s%s://%s:%d", protocol.toString().toLowerCase(), secure ? "s": "", host, port); |
196 | 199 | this.addEndpoint(endpoint); |
197 | 200 | return this; |
198 | 201 | } |
@@ -377,6 +380,17 @@ public Builder setDefaultDatabase(String database) { |
377 | 380 | return this; |
378 | 381 | } |
379 | 382 |
|
| 383 | + public Builder addProxy(ProxyType type, String host, int port) { |
| 384 | + ValidationUtils.checkNotNull(type, "type"); |
| 385 | + ValidationUtils.checkNonBlank(host, "host"); |
| 386 | + ValidationUtils.checkRange(port, 1, ValidationUtils.TCP_PORT_NUMBER_MAX, "port"); |
| 387 | + |
| 388 | + this.configuration.put(String.valueOf(ClickHouseClientOption.PROXY_TYPE), type.toString()); |
| 389 | + this.configuration.put(String.valueOf(ClickHouseClientOption.PROXY_HOST), host); |
| 390 | + this.configuration.put(String.valueOf(ClickHouseClientOption.PROXY_PORT), String.valueOf(port)); |
| 391 | + return this; |
| 392 | + } |
| 393 | + |
380 | 394 | public Client build() { |
381 | 395 | // check if endpoint are empty. so can not initiate client |
382 | 396 | if (this.endpoints.isEmpty()) { |
@@ -574,10 +588,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data, |
574 | 588 | * @param format - format of the data in the stream |
575 | 589 | * @return {@code CompletableFuture<InsertResponse>} - a promise to insert response |
576 | 590 | */ |
577 | | - public CompletableFuture<InsertResponse> insert(String tableName, |
578 | | - InputStream data, |
579 | | - ClickHouseFormat format) |
580 | | - { |
| 591 | + public CompletableFuture<InsertResponse> insert(String tableName, InputStream data, ClickHouseFormat format) { |
581 | 592 | return insert(tableName, data, format, new InsertSettings()); |
582 | 593 | } |
583 | 594 |
|
@@ -867,4 +878,18 @@ private String startOperation() { |
867 | 878 | globalClientStats.put(operationId, new ClientStatisticsHolder()); |
868 | 879 | return operationId; |
869 | 880 | } |
| 881 | + |
| 882 | + public String toString() { |
| 883 | + return "Client{" + |
| 884 | + "endpoints=" + endpoints + |
| 885 | + '}'; |
| 886 | + } |
| 887 | + |
| 888 | + public Map<String, String> getConfiguration() { |
| 889 | + return Collections.unmodifiableMap(configuration); |
| 890 | + } |
| 891 | + |
| 892 | + public Set<String> getEndpoints() { |
| 893 | + return Collections.unmodifiableSet(endpoints); |
| 894 | + } |
870 | 895 | } |
0 commit comments