Class QueryClient
- java.lang.Object
-
- org.apache.sling.testing.clients.AbstractSlingClient
-
- org.apache.sling.testing.clients.SlingClient
-
- org.apache.sling.testing.clients.query.QueryClient
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.http.client.HttpClient
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 nodesThe servlet is exposed under "/system/testing/query".
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()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueryClient.QueryType
Query types, as defined inorg.apache.jackrabbit.oak.query.QueryEngineImpl
-
Nested classes/interfaces inherited from class org.apache.sling.testing.clients.SlingClient
SlingClient.Builder, SlingClient.InternalBuilder<T extends SlingClient>
-
-
Field Summary
-
Fields inherited from class org.apache.sling.testing.clients.SlingClient
CLIENT_CONNECTION_TIMEOUT_PROP, DEFAULT_NODE_TYPE, SUDO_COOKIE_NAME
-
-
Constructor Summary
Constructors Constructor Description QueryClient(URI url, String user, String password)
Convenience constructorQueryClient(org.apache.http.impl.client.CloseableHttpClient http, SlingClientConfig config)
Constructor used by adaptTo
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
doCount(String query, QueryClient.QueryType type)
Executes a query on the server and returns only the number of rows in the resultcom.fasterxml.jackson.databind.JsonNode
doQuery(String query, QueryClient.QueryType type)
Executes a query on the server and returns the results as a jsonprotected com.fasterxml.jackson.databind.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 byinstallServlet()
-
Methods inherited from class org.apache.sling.testing.clients.SlingClient
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, endImpersonation, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUser, getUUId, getUUID, impersonate, importContent, importContent, importJson, move, setPropertiesString, setPropertyString, setPropertyStringArray, upload, waitExists, waitUntilExists
-
Methods inherited from class org.apache.sling.testing.clients.AbstractSlingClient
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, getValue, getValues, hasValue
-
-
-
-
Constructor Detail
-
QueryClient
public QueryClient(org.apache.http.impl.client.CloseableHttpClient http, SlingClientConfig config) throws ClientException
Constructor used by adaptTo- Parameters:
http
- underlying HttpClientconfig
- config state- Throws:
ClientException
- if the client cannot be created
-
QueryClient
public QueryClient(URI url, String user, String password) throws ClientException
Convenience constructor- Parameters:
url
- host urluser
- usernamepassword
- password- Throws:
ClientException
- if the client cannot be constructed
-
-
Method Detail
-
doQuery
public com.fasterxml.jackson.databind.JsonNode doQuery(String query, QueryClient.QueryType type) throws ClientException, InterruptedException
Executes a query on the server and returns the results as a json- Parameters:
query
- query to be executedtype
- type of the query- Returns:
- the results in json as exported by
QueryServlet
- Throws:
ClientException
- if the request failed to executeInterruptedException
- to mark that this method blocks
-
doCount
public long doCount(String query, QueryClient.QueryType type) throws ClientException, InterruptedException
Executes a query on the server and returns only the number of rows in the result- Parameters:
query
- query to be executedtype
- type of the query- Returns:
- total results returned by the query
- Throws:
ClientException
- if the request failed to executeInterruptedException
- to mark that this method blocks
-
getPlan
public String getPlan(String query, QueryClient.QueryType type) throws ClientException, InterruptedException
Retrieves the plan of the query. Useful for determining which index is used- Parameters:
query
- query to be executedtype
- type of the query- Returns:
- total results returned by the query
- Throws:
ClientException
- if the request failed to executeInterruptedException
- to mark that this method blocks
-
doQuery
protected com.fasterxml.jackson.databind.JsonNode doQuery(String query, QueryClient.QueryType type, boolean showResults, boolean explain) throws ClientException, InterruptedException
- Throws:
ClientException
InterruptedException
-
installServlet
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
- Returns:
- this
- Throws:
ClientException
- if the installation failsInterruptedException
- to mark that this method blocks
-
uninstallServlet
public QueryClient uninstallServlet() throws ClientException
Deletes all the resources created byinstallServlet()
- Returns:
- this
- Throws:
ClientException
- if any of the resources fails to uninstall
-
-