diff --git a/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java b/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java index 30cccd96473..b376e39babd 100644 --- a/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java +++ b/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java @@ -23,6 +23,10 @@ import java.util.stream.Collectors; import static org.elasticsearch.xpack.sql.client.shared.StringUtils.EMPTY; +/** + * JDBC specific HTTP client. + * Since JDBC is not thread-safe, neither is this class. + */ public class JdbcHttpClient { private final HttpClient httpClient; private final JdbcConfiguration conCfg; diff --git a/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/HttpClient.java b/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/HttpClient.java index f72828f520c..1b885d5b1f9 100644 --- a/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/HttpClient.java +++ b/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/HttpClient.java @@ -38,7 +38,9 @@ import java.sql.SQLException; import java.util.function.Function; /** - * A specialized high-level REST client with support for SQL-related functions + * A specialized high-level REST client with support for SQL-related functions. + * Similar to JDBC and the underlying HTTP connection, this class is not thread-safe + * and follows a request-response flow. */ public class HttpClient { @@ -85,7 +87,7 @@ public class HttpClient { return response.isSucceeded(); } - private Response post(String path, Request request, + private Response post(String path, Request request, CheckedFunction responseParser) throws SQLException { BytesReference requestBytes = toXContent(request); diff --git a/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/shared/JreHttpUrlConnection.java b/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/shared/JreHttpUrlConnection.java index ee4e758c08a..2f6289ee395 100644 --- a/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/shared/JreHttpUrlConnection.java +++ b/plugin/sql/sql-shared-client/src/main/java/org/elasticsearch/xpack/sql/client/shared/JreHttpUrlConnection.java @@ -5,9 +5,6 @@ */ package org.elasticsearch.xpack.sql.client.shared; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; -import javax.sql.rowset.serial.SerialException; import java.io.BufferedInputStream; import java.io.Closeable; import java.io.IOException; @@ -33,8 +30,17 @@ import java.util.Base64; import java.util.function.Function; import java.util.zip.GZIPInputStream; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSocketFactory; +import javax.sql.rowset.serial.SerialException; + import static java.util.Collections.emptyMap; +/** + * Low-level http client using the built-in {@link HttpURLConnection}. + * As such, it has a stateless, on-demand, request-response flow without + * any connection pooling or sharing. + */ public class JreHttpUrlConnection implements Closeable { /** * State added to {@link SQLException}s when the server encounters an diff --git a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/util/ReflectionUtils.java b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/util/ReflectionUtils.java index 60fb6ce61b5..0ddccccf7dd 100644 --- a/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/util/ReflectionUtils.java +++ b/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/util/ReflectionUtils.java @@ -7,47 +7,12 @@ package org.elasticsearch.xpack.sql.util; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; -import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; import java.util.Arrays; public class ReflectionUtils { - @SuppressWarnings("unchecked") - public static Class detectType(Type t) { - if (t instanceof Class) { - return (Class) t; - } - if (t instanceof ParameterizedType) { - Type[] typeArguments = ((ParameterizedType) t).getActualTypeArguments(); - if (typeArguments.length != 1) { - throw new SqlIllegalArgumentException("Unexpected number of type arguments {} for {}", Arrays.toString(typeArguments), t); - } - - return detectType(typeArguments[0]); - } - if (t instanceof WildcardType) { - WildcardType wt = (WildcardType) t; - if (wt.getLowerBounds().length == 1) { - return detectType(wt.getLowerBounds()[0]); - } - Type[] upperBounds = wt.getUpperBounds(); - - if (upperBounds.length != 1) { - throw new SqlIllegalArgumentException("Unexpected number of upper bounds {} for {}", Arrays.toString(upperBounds), t); - } - - return detectType(upperBounds[0]); - } - if (t instanceof GenericArrayType) { - return detectType(((GenericArrayType) t).getGenericComponentType()); - } - - throw new SqlIllegalArgumentException("Unrecognized type {}", t); - } - @SuppressWarnings("unchecked") public static Class detectSuperTypeForRuleLike(Class c) { Class clazz = c;