Package com.clickhouse.client.http
Class ClickHouseHttpConnection
- java.lang.Object
-
- com.clickhouse.client.http.ClickHouseHttpConnection
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
HttpUrlConnectionImpl
public abstract class ClickHouseHttpConnection extends Object implements AutoCloseable
-
-
Field Summary
Fields Modifier and Type Field Description protected ClickHouseConfigconfigprotected Map<String,String>defaultHeadersprotected ClickHouseNodeserverprotected Stringurl
-
Constructor Summary
Constructors Modifier Constructor Description protectedClickHouseHttpConnection(ClickHouseNode server, ClickHouseRequest<?> request)
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Field Detail
-
config
protected final ClickHouseConfig config
-
server
protected final ClickHouseNode server
-
url
protected final String url
-
-
Constructor Detail
-
ClickHouseHttpConnection
protected ClickHouseHttpConnection(ClickHouseNode server, ClickHouseRequest<?> request)
-
-
Method Detail
-
closeQuietly
protected void closeQuietly()
-
getBaseUrl
protected String getBaseUrl()
-
mergeHeaders
protected Map<String,String> mergeHeaders(Map<String,String> requestHeaders)
Creates a merged map.- Parameters:
requestHeaders- request headers- Returns:
-
post
protected abstract ClickHouseHttpResponse post(String query, InputStream data, List<ClickHouseExternalTable> tables, Map<String,String> headers) throws IOException
Posts query and data to server.- Parameters:
query- non-blank querydata- optionally input stream for batch updatingtables- optionally external tables for queryheaders- optionally request headers- Returns:
- response
- Throws:
IOException- when error occured posting request and/or server failed to respond
-
isReusable
protected boolean isReusable()
Checks whether the connection is reusable or not. This method will be called inClickHouseHttpClient.checkConnection(ClickHouseHttpConnection, ClickHouseNode, ClickHouseNode, ClickHouseRequest)for making a decision of whether to create a new connection. In addition to that, if a connection is NOT reusable, it will be closed right after corresponding ClickHouseResponse is closed.- Returns:
- true if it's reusable; false otherwise
-
ping
public abstract boolean ping(int timeout)
Sends a request to<baseUrl>/pingfor liveness detection.- Parameters:
timeout- timeout in millisecond- Returns:
- true if server responded
Ok.; false otherwise
-
update
public ClickHouseHttpResponse update(String query) throws IOException
- Throws:
IOException
-
update
public ClickHouseHttpResponse update(String query, Map<String,String> headers) throws IOException
- Throws:
IOException
-
update
public ClickHouseHttpResponse update(String query, InputStream data) throws IOException
- Throws:
IOException
-
update
public ClickHouseHttpResponse update(String query, InputStream data, Map<String,String> headers) throws IOException
- Throws:
IOException
-
query
public ClickHouseHttpResponse query(String query) throws IOException
- Throws:
IOException
-
query
public ClickHouseHttpResponse query(String query, Map<String,String> headers) throws IOException
- Throws:
IOException
-
query
public ClickHouseHttpResponse query(String query, List<ClickHouseExternalTable> tables) throws IOException
- Throws:
IOException
-
query
public ClickHouseHttpResponse query(String query, List<ClickHouseExternalTable> tables, Map<String,String> headers) throws IOException
- Throws:
IOException
-
-