public class QueryClient extends SlingClient
Sling client for performing oak queries.
Uses a custom servlet QueryServlet
to execute the query on the server
and return the results as a json. If the servlet is not yet present, it automatically
installs it and creates the corresponding nodes
The servlet is exposed under .
The servlet is not automatically uninstalled to avoid too much noise on the instance.
The caller should take care of it, if needed, by calling uninstallServlet()
Modifier and Type | Class and Description |
---|---|
static class |
QueryClient.QueryType
Query types, as defined in
org.apache.jackrabbit.oak.query.QueryEngineImpl |
SlingClient.Builder, SlingClient.InternalBuilder<T extends SlingClient>
DEFAULT_NODE_TYPE
Constructor and Description |
---|
QueryClient(org.apache.http.impl.client.CloseableHttpClient http,
SlingClientConfig config)
Constructor used by adaptTo
|
QueryClient(URI url,
String user,
String password)
Convenience constructor
|
Modifier and Type | Method and Description |
---|---|
long |
doCount(String query,
QueryClient.QueryType type)
Executes a query on the server and returns only the number of rows in the result
|
org.codehaus.jackson.JsonNode |
doQuery(String query,
QueryClient.QueryType type)
Executes a query on the server and returns the results as a json
|
protected org.codehaus.jackson.JsonNode |
doQuery(String query,
QueryClient.QueryType type,
boolean showResults,
boolean explain) |
String |
getPlan(String query,
QueryClient.QueryType type)
Retrieves the plan of the query.
|
QueryClient |
installServlet()
Installs the servlet to be able to perform queries.
|
QueryClient |
uninstallServlet()
Deletes all the resources created by
installServlet() |
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUUId, getUUID, importContent, importContent, importJson, move, setPropertiesString, setPropertyString, setPropertyStringArray, upload, waitExists, waitUntilExists
adaptTo, addValue, close, doDelete, doGet, doGet, doGet, doHead, doPatch, doPost, doPost, doPut, doRawRequest, doRequest, doStreamGet, doStreamPost, doStreamRequest, execute, execute, execute, execute, execute, execute, execute, execute, getClientId, getConnectionManager, getCookieStore, getCredentialsProvider, getParams, getPassword, getPath, getPath, getUrl, getUrl, getUrl, getUser, getValue, getValues, hasValue
public QueryClient(org.apache.http.impl.client.CloseableHttpClient http, SlingClientConfig config) throws ClientException
http
- underlying HttpClientconfig
- config stateClientException
- if the client cannot be createdpublic QueryClient(URI url, String user, String password) throws ClientException
url
- host urluser
- usernamepassword
- passwordClientException
- if the client cannot be constructedpublic org.codehaus.jackson.JsonNode doQuery(String query, QueryClient.QueryType type) throws ClientException, InterruptedException
query
- query to be executedtype
- type of the queryQueryServlet
ClientException
- if the request failed to executeInterruptedException
- to mark that this method blockspublic long doCount(String query, QueryClient.QueryType type) throws ClientException, InterruptedException
query
- query to be executedtype
- type of the queryClientException
- if the request failed to executeInterruptedException
- to mark that this method blockspublic String getPlan(String query, QueryClient.QueryType type) throws ClientException, InterruptedException
query
- query to be executedtype
- type of the queryClientException
- if the request failed to executeInterruptedException
- to mark that this method blocksprotected org.codehaus.jackson.JsonNode doQuery(String query, QueryClient.QueryType type, boolean showResults, boolean explain) throws ClientException, InterruptedException
ClientException
InterruptedException
public QueryClient installServlet() throws ClientException, InterruptedException
Installs the servlet to be able to perform queries.
By default, methods of this client automatically install the servlet if needed, so there is no need to explicitly call from outside
ClientException
- if the installation failsInterruptedException
- to mark that this method blockspublic QueryClient uninstallServlet() throws ClientException
installServlet()
ClientException
- if any of the resources fails to uninstallCopyright © 2007–2018 The Apache Software Foundation. All rights reserved.