Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.clickhouse.client;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.Map.Entry;
import com.clickhouse.client.config.ClickHouseClientOption;
import com.clickhouse.client.config.ClickHouseDefaults;
import com.clickhouse.client.config.ClickHouseSslMode;
import com.clickhouse.config.ClickHouseBufferingMode;
import com.clickhouse.config.ClickHouseOption;
import com.clickhouse.config.ClickHouseRenameMethod;
import com.clickhouse.data.ClickHouseChecker;
import com.clickhouse.data.ClickHouseCompression;
import com.clickhouse.data.ClickHouseDataConfig;
import com.clickhouse.data.ClickHouseFormat;
import com.clickhouse.data.ClickHouseVersion;
/**
* An immutable class holding client-specific options like
* {@link ClickHouseCredentials} and {@link ClickHouseNodeSelector} etc.
*/
public class ClickHouseConfig implements ClickHouseDataConfig {
static final class ClientOptions {
static final ClientOptions INSTANCE = new ClientOptions();
final Map customOptions;
final Map sensitiveOptions;
private ClientOptions() {
Map m = new LinkedHashMap<>();
Map s = new LinkedHashMap<>();
for (ClickHouseOption o : ClickHouseClientOption.class.getEnumConstants()) {
if (o.isSensitive()) {
s.put(o.getKey(), o);
}
}
try {
for (ClickHouseClient c : ClickHouseClientBuilder.loadClients()) {
Class extends ClickHouseOption> clazz = c.getOptionClass();
if (clazz == null || clazz == ClickHouseClientOption.class) {
continue;
}
for (ClickHouseOption o : clazz.getEnumConstants()) {
m.put(o.getKey(), o);
if (o.isSensitive()) {
s.put(o.getKey(), o);
}
}
}
} catch (Exception e) {
// ignore
}
customOptions = m.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(m);
sensitiveOptions = s.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(s);
}
}
private static final long serialVersionUID = 7794222888859182491L;
static final String PARAM_OPTION = "option";
public static final String TYPE_NAME = "Config";
protected static final Map mergeOptions(List list) {
if (list == null || list.isEmpty()) {
return Collections.emptyMap();
}
Map options = new HashMap<>();
List cl = new ArrayList<>(list.size());
for (ClickHouseConfig c : list) {
if (c != null) {
boolean duplicated = false;
for (ClickHouseConfig conf : cl) {
if (conf == c) {
duplicated = true;
break;
}
}
if (duplicated) {
continue;
}
options.putAll(c.options);
cl.add(c);
}
}
return options;
}
protected static final ClickHouseCredentials mergeCredentials(List list) {
if (list == null || list.isEmpty()) {
return null;
}
ClickHouseCredentials credentials = null;
for (ClickHouseConfig c : list) {
if (c != null && c.credentials != null) {
credentials = c.credentials;
break;
}
}
return credentials;
}
protected static final ClickHouseNodeSelector mergeNodeSelector(List list) {
if (list == null || list.isEmpty()) {
return null;
}
ClickHouseNodeSelector nodeSelector = null;
for (ClickHouseConfig c : list) {
if (c != null && c.nodeSelector != null) {
nodeSelector = c.nodeSelector;
break;
}
}
return nodeSelector;
}
protected static final Object mergeMetricRegistry(List list) {
if (list == null || list.isEmpty()) {
return null;
}
Object metricRegistry = null;
for (ClickHouseConfig c : list) {
if (c != null && c.metricRegistry.isPresent()) {
metricRegistry = c.metricRegistry.get();
break;
}
}
return metricRegistry;
}
/**
* Converts given key-value pairs to a mutable map of corresponding
* {@link ClickHouseOption}.
*
* @param props key-value pairs
* @return non-null mutable map of client options
*/
public static Map toClientOptions(Map, ?> props) {
Map options = new HashMap<>();
if (props != null && !props.isEmpty()) {
Map customOptions = ClientOptions.INSTANCE.customOptions;
for (Entry, ?> e : props.entrySet()) {
if (e.getKey() == null || e.getValue() == null) {
continue;
}
String key = e.getKey().toString();
// no need to enable option overidding for now
ClickHouseOption o = ClickHouseClientOption.fromKey(key);
if (o == null) {
o = customOptions.get(key);
}
if (o != null) {
options.put(o, ClickHouseOption.fromString(e.getValue().toString(), o.getValueType()));
}
}
}
return options;
}
// common options optimized for read
private final boolean async;
private final boolean autoDiscovery;
private final Map customSettings; // serializable
private final String clientName;
private final boolean compressRequest;
private final ClickHouseCompression compressAlgorithm;
private final int compressLevel;
private final boolean decompressResponse;
private final ClickHouseCompression decompressAlgorithm;
private final int decompressLevel;
private final int connectionTimeout;
private final String database;
private final ClickHouseFormat format;
private final int maxBufferSize;
private final int bufferSize;
private final int bufferQueueVariation;
private final int readBufferSize;
private final int writeBufferSize;
private final int requestChunkSize;
private final ClickHouseBufferingMode requestBuffering;
private final ClickHouseBufferingMode responseBuffering;
private final int maxExecutionTime;
private final int maxMapperCache;
private final int maxQueuedBuffers;
private final int maxQueuedRequests;
private final long maxResultRows;
private final int maxThreads;
private final String productName;
private final int nodeCheckInterval;
private final int failover;
private final int retry;
private final boolean repeatOnSessionLock;
private final boolean reuseValueWrapper;
private final boolean serverInfo;
private final TimeZone serverTimeZone;
private final ClickHouseVersion serverVersion;
private final int sessionTimeout;
private final boolean sessionCheck;
private final int socketTimeout;
private final boolean ssl;
private final ClickHouseSslMode sslMode;
private final String sslRootCert;
private final String sslCert;
private final String sslKey;
private final int transactionTimeout;
private final boolean widenUnsignedTypes;
private final boolean useBinaryString;
private final boolean useBlockingQueue;
private final boolean useCompilation;
private final boolean useObjectsInArray;
private final boolean useNoProxy;
private final boolean useServerTimeZone;
private final boolean useServerTimeZoneForDates;
private final TimeZone timeZoneForDate;
private final TimeZone useTimeZone;
// client specific options
private final Map options;
private final ClickHouseCredentials credentials;
private final transient Optional