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.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.aliyun.odps.jdbc.utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import com.aliyun.odps.sqa.FallbackPolicy;
import com.aliyun.odps.utils.GsonObjectBuilder;
import com.aliyun.odps.utils.StringUtils;
import com.google.gson.reflect.TypeToken;
public class ConnectionResource {
private static final String JDBC_ODPS_URL_PREFIX = "jdbc:odps:";
private static final String CHARSET_DEFAULT_VALUE = "UTF-8";
private static final String LIFECYCLE_DEFAULT_VALUE = "3";
private static final String MAJOR_VERSION_DEFAULT_VALUE = "default";
private static final String INTERACTIVE_SERVICE_NAME_DEFAULT_VALUE = "public.default";
private static final String READ_TIMEOUT_DEFAULT_VALUE = "-1";
private static final String CONNECT_TIMEOUT_DEFAULT_VALUE = "-1";
/**
* keys to retrieve properties from url.
*/
private static final String ODPS_CONF_URL_KEY = "odps_config";
private static final String ACCESS_ID_URL_KEY = "accessId";
private static final String ACCESS_KEY_URL_KEY = "accessKey";
private static final String PROJECT_URL_KEY = "project";
private static final String EXECUTE_PROJECT_URL_KEY = "executeProject";
private static final String CHARSET_URL_KEY = "charset";
private static final String LOGVIEW_URL_KEY = "logview";
private static final String TUNNEL_ENDPOINT_URL_KEY = "tunnelEndpoint";
private static final String TUNNEL_RESULT_RETRY_TIME_URL_KEY = "tunnelRetryTime";
private static final String LOG_CONF_FILE_URL_KEY = "logConfFile";
private static final String INTERACTIVE_MODE_URL_KEY = "interactiveMode";
private static final String SERVICE_NAME_URL_KEY = "interactiveServiceName";
private static final String MAJOR_VERSION_URL_KEY = "majorVersion";
private static final String ENABLE_ODPS_LOGGER_URL_KEY = "enableOdpsLogger";
private static final String TABLE_LIST_URL_KEY = "tableList";
private static final String FALLBACK_FOR_UNKNOWN_URL_KEY = "fallbackForUnknownError";
private static final String FALLBACK_FOR_RESOURCE_URL_KEY = "fallbackForResourceNotEnough";
private static final String FALLBACK_FOR_UPGRADING_URL_KEY = "fallbackForUpgrading";
private static final String FALLBACK_FOR_TIMEOUT_URL_KEY = "fallbackForRunningTimeout";
private static final String FALLBACK_FOR_UNSUPPORTED_URL_KEY = "fallbackForUnsupportedFeature";
private static final String ALWAYS_FALLBACK_URL_KEY = "alwaysFallback";
private static final String DISABLE_FALLBACK_URL_KEY = "disableFallback";
private static final String FALLBACK_QUOTA_URL_KEY = "fallbackQuota";
private static final String ATTACH_TIMEOUT_URL_KEY = "attachTimeout";
private static final String AUTO_SELECT_LIMIT_URL_KEY = "autoSelectLimit";
//Unit: result record row count, only applied in interactive mode
private static final String INSTANCE_TUNNEL_MAX_RECORD_URL_KEY = "instanceTunnelMaxRecord";
//Unit: Bytes, only applied in interactive mode
private static final String INSTANCE_TUNNEL_MAX_SIZE_URL_KEY = "instanceTunnelMaxSize";
private static final String STS_TOKEN_URL_KEY = "stsToken";
private static final String DISABLE_CONN_SETTING_URL_KEY = "disableConnectionSetting";
private static final String USE_PROJECT_TIME_ZONE_URL_KEY = "useProjectTimeZone";
private static final String ENABLE_LIMIT_URL_KEY = "enableLimit";
private static final String AUTO_LIMIT_FALLBACK_URL_KEY = "autoLimitFallback";
private static final String SETTINGS_URL_KEY = "settings";
private static final String ODPS_NAMESPACE_SCHEMA_URL_KEY = "odpsNamespaceSchema";
private static final String SCHEMA_URL_KEY = "schema";
private static final String READ_TIMEOUT_URL_KEY = "readTimeout";
private static final String CONNECT_TIMEOUT_URL_KRY = "connectTimeout";
private static final String ENABLE_COMMAND_API_URL_KEY = "enableCommandApi";
private static final String USE_INSTANCE_TUNNEL_URL_KEY = "useInstanceTunnel";
private static final String HTTPS_CHECK_URL_KEY = "httpsCheck";
private static final String LOG_LEVEL_URL_KEY = "logLevel";
private static final String TUNNEL_READ_TIMEOUT_URL_KEY = "tunnelReadTimeout";
private static final String TUNNEL_CONNECT_TIMEOUT_URL_KRY = "tunnelConnectTimeout";
private static final String TUNNEL_DOWNLOAD_USE_SINGLE_READER_URL_KEY = "tunnelDownloadUseSingleReader";
private static final String RETRY_TIME_URL_KEY = "retryTime";
private static final String SKIP_SQL_REWRITE_URL_KEY = "skipSqlRewrite";
private static final String QUOTA_NAME_URL_KEY = "quotaName";
private static final String SKIP_SQL_INJECT_CHECK_URL_KEY = "skipSqlInjectCheck";
private static final String LOGVIEW_VERSION_URL_KEY = "logviewVersion";
private static final String TIME_ZONE_URL_KEY = "timezone";
/**
* Keys to retrieve properties from info.
*
* public since they are accessed in getPropInfo()
*/
public static final String ACCESS_ID_PROP_KEY = "access_id";
public static final String ACCESS_KEY_PROP_KEY = "access_key";
public static final String PROJECT_PROP_KEY = "project_name";
public static final String EXECUTE_PROJECT_PROP_KEY = "execute_project_name";
public static final String CHARSET_PROP_KEY = "charset";
public static final String LOGVIEW_HOST_PROP_KEY = "logview_host";
public static final String TUNNEL_ENDPOINT_PROP_KEY = "tunnel_endpoint";
public static final String TUNNEL_RESULT_RETRY_TIME_PROP_KEY = "tunnel_retry_time";
public static final String LOG_CONF_FILE_PROP_KEY = "log_conf_file";
public static final String INTERACTIVE_MODE_PROP_KEY = "interactive_mode";
public static final String SERVICE_NAME_PROP_KEY = "interactive_service_name";
public static final String MAJOR_VERSION_PROP_KEY = "major_version";
public static final String ENABLE_ODPS_LOGGER_PROP_KEY = "enable_odps_logger";
public static final String TABLE_LIST_PROP_KEY = "table_list";
private static final String FALLBACK_FOR_UNKNOWN_PROP_KEY = "fallback_for_unknownerror";
private static final String FALLBACK_FOR_RESOURCE_PROP_KEY = "fallback_for_resourcenotenough";
private static final String FALLBACK_FOR_UPGRADING_PROP_KEY = "fallback_for_upgrading";
private static final String FALLBACK_FOR_TIMEOUT_PROP_KEY = "fallback_for_runningtimeout";
private static final String FALLBACK_FOR_UNSUPPORTED_PROP_KEY = "fallback_for_unsupportedfeature";
private static final String ALWAYS_FALLBACK_PROP_KEY = "always_fallback";
private static final String DISABLE_FALLBACK_PROP_KEY = "disable_fallback";
private static final String FALLBACK_QUOTA_PROP_KEY = "fallback_quota";
private static final String ATTACH_TIMEOUT_PROP_KEY = "attach_timeout";
private static final String AUTO_SELECT_LIMIT_PROP_KEY = "auto_select_limit";
//Unit: result record row count, only applied in interactive mode
private static final String INSTANCE_TUNNEL_MAX_RECORD_PROP_KEY = "instance_tunnel_max_record";
//Unit: Bytes, only applied in interactive mode
private static final String INSTANCE_TUNNEL_MAX_SIZE_PROP_KEY = "instance_tunnel_max_size";
private static final String STS_TOKEN_PROP_KEY = "sts_token";
private static final String DISABLE_CONN_SETTING_PROP_KEY = "disable_connection_setting";
private static final String USE_PROJECT_TIME_ZONE_PROP_KEY = "use_project_time_zone";
private static final String ENABLE_LIMIT_PROP_KEY = "enable_limit";
// only applied in non-interactive mode
private static final String AUTO_FALLBACK_PROP_KEY = "auto_limit_fallback";
private static final String SETTINGS_PROP_KEY = "settings";
// This is to support DriverManager.getConnection(url, user, password) API,
// which put the 'user' and 'password' to the 'info'.
// So the `access_id` and `access_key` have aliases.
private static final String ACCESS_ID_PROP_KEY_ALT = "user";
private static final String ACCESS_KEY_PROP_KEY_ALT = "password";
private static final String ODPS_NAMESPACE_SCHEMA_PROP_KEY = "odps_namespace_schema";
private static final String SCHEMA_PROP_KEY = "schema";
private static final String READ_TIMEOUT_PROP_KEY = "read_timeout";
private static final String CONNECT_TIMEOUT_PROP_KEY = "connect_timeout";
private static final String ENABLE_COMMAND_API_PROP_KEY = "enable_command_api";
private static final String USE_INSTANCE_TUNNEL_PROP_KEY = "use_instance_tunnel";
private static final String HTTPS_CHECK_PROP_KEY = "https_check";
private static final String LOG_LEVEL_PROP_KEY = "log_level";
private static final String TUNNEL_READ_TIMEOUT_PROP_KEY = "tunnel_read_timeout";
private static final String TUNNEL_CONNECT_TIMEOUT_PROP_KEY = "tunnel_connect_timeout";
private static final String TUNNEL_DOWNLOAD_USE_SINGLE_READER_PROP_KEY = "tunnel_download_use_single_reader";
private static final String RETRY_TIME_PROP_KEY = "retry_time";
private static final String SKIP_SQL_REWRITE_PROP_KEY = "skip_sql_rewrite";
private static final String SKIP_SQL_INJECT_CHECK_PROP_KEY = "skip_sql_inject_check";
private static final String QUOTA_NAME_PROP_KEY = "quota_name";
private static final String VERBOSE_PROP_KEY = "verbose";
private static final String LOGVIEW_VERSION_PROP_KEY = "logview_version";
private String endpoint;
private String accessId;
private String accessKey;
private String project;
private String executeProject;
private String charset;
private String logview;
private String tunnelEndpoint;
private String logConfFile;
private boolean interactiveMode;
private String interactiveServiceName;
private String majorVersion;
private String fallbackQuota;
private boolean enableOdpsLogger = false;
private Map>> tables = new HashMap<>();
private FallbackPolicy fallbackPolicy = FallbackPolicy.alwaysFallbackPolicy();
private Long autoSelectLimit;
private Long countLimit;
private Long sizeLimit;
private Long attachTimeout;
private int tunnelRetryTime;
private String stsToken;
private boolean disableConnSetting = false;
private boolean useProjectTimeZone = false;
private boolean enableLimit = false;
private boolean autoLimitFallback = false;
private boolean enableCommandApi = false;
private boolean useInstanceTunnel = true;
private boolean httpsCheck = false;
private boolean skipSqlRewrite = false;
private boolean skipSqlInjectCheck = false;
private boolean verbose = false;
private String quotaName;
private int logviewVersion;
public Boolean isOdpsNamespaceSchema() {
return odpsNamespaceSchema;
}
public String getSchema() {
return schema;
}
// null => use tenant flag
// true/false => use session flag
private Boolean odpsNamespaceSchema = null;
private String schema;
private Map settings = new HashMap<>();
private String readTimeout;
private String connectTimeout;
private String logLevel;
private String tunnelReadTimeout;
private String tunnelConnectTimeout;
private boolean tunnelDownloadUseSingleReader = false;
private int retryTime;
private String timeZone;
public static boolean acceptURL(String url) {
return (url != null) && url.startsWith(JDBC_ODPS_URL_PREFIX);
}
public ConnectionResource(String url, Properties info) {
Map paramsInURL = extractParamsFromUrl(url);
init(info, paramsInURL);
}
@SuppressWarnings("rawtypes")
void init(Properties info, Map paramsInURL) {
List