SQL: add comments on JDBC thread-safety (or rather lack of)
Original commit: elastic/x-pack-elasticsearch@6ea5adc6a8
This commit is contained in:
parent
2c66b058f3
commit
34fe0beb30
|
@ -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;
|
||||
|
|
|
@ -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 <Request extends AbstractSqlRequest, Response> Response post(String path, Request request,
|
||||
private <Request extends AbstractSqlRequest, Response> Response post(String path, Request request,
|
||||
CheckedFunction<XContentParser, Response, IOException> responseParser)
|
||||
throws SQLException {
|
||||
BytesReference requestBytes = toXContent(request);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <E> Class<E> detectType(Type t) {
|
||||
if (t instanceof Class<?>) {
|
||||
return (Class<E>) 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 <E> Class<E> detectSuperTypeForRuleLike(Class<?> c) {
|
||||
Class<?> clazz = c;
|
||||
|
|
Loading…
Reference in New Issue