BePPPower commented on code in PR #14527: URL: https://github.com/apache/doris/pull/14527#discussion_r1034904260
########## fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java: ########## @@ -0,0 +1,431 @@ +// 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 org.apache.doris.external.jdbc; + +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.PrimitiveType; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.catalog.Type; +import org.apache.doris.common.FeConstants; +import org.apache.doris.common.util.Util; + +import com.google.common.collect.Lists; +import lombok.Data; +import lombok.Getter; +import org.apache.commons.codec.binary.Hex; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.Driver; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; +import java.util.Properties; + +@Getter +public class JdbcClient { + private static final Logger LOG = LogManager.getLogger(JdbcClient.class); + private static final String MYSQL = "MYSQL"; + // private static final String ORACLE = "ORACLE"; + // private static final String SQLSERVER = "SQLSERVER"; + // private static final String POSTGRESQL = "POSTGRESQL"; + private static final int HTTP_TIMEOUT_MS = 10000; + + private String dbType; + private String jdbcUser; + private String jdbcPasswd; + private String jdbcUrl; + private String driverUrl; + private String driverClass; + private String checkSum; + + private URLClassLoader classLoader = null; + + + public JdbcClient(String user, String password, String jdbcUrl, String driverUrl, String driverClass) { + this.jdbcUser = user; + this.jdbcPasswd = password; + this.jdbcUrl = jdbcUrl; + this.driverUrl = driverUrl; + this.driverClass = driverClass; + this.dbType = parseDbType(jdbcUrl); + this.checkSum = computeObjectChecksum(); + + try { + // TODO(ftw): The problem here is that the jar package is handled by FE + // and URLClassLoader may load the jar package directly into memory + URL[] urls = {new URL(driverUrl)}; + // set parent ClassLoader to null, we can achieve class loading isolation. + classLoader = URLClassLoader.newInstance(urls, null); + } catch (MalformedURLException e) { + throw new JdbcClientException("MalformedURLException to load class about " + driverUrl, e); + } + } + + public String parseDbType(String url) { + if (url.startsWith("jdbc:mysql")) { Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org