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:
java.io.Closeable,java.lang.AutoCloseable,org.apache.http.client.HttpClient
public class QueryClient extends SlingClient
Sling client for performing oak queries.
Uses a custom servlet
QueryServletto 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 classQueryClient.QueryTypeQuery 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
-
-
Constructor Summary
Constructors Constructor Description QueryClient(java.net.URI url, java.lang.String user, java.lang.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 longdoCount(java.lang.String query, QueryClient.QueryType type)Executes a query on the server and returns only the number of rows in the resultorg.codehaus.jackson.JsonNodedoQuery(java.lang.String query, QueryClient.QueryType type)Executes a query on the server and returns the results as a jsonprotected org.codehaus.jackson.JsonNodedoQuery(java.lang.String query, QueryClient.QueryType type, boolean showResults, boolean explain)java.lang.StringgetPlan(java.lang.String query, QueryClient.QueryType type)Retrieves the plan of the query.QueryClientinstallServlet()Installs the servlet to be able to perform queries.QueryClientuninstallServlet()Deletes all the resources created byinstallServlet()-
Methods inherited from class org.apache.sling.testing.clients.SlingClient
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUUId, getUUID, 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, getUser, getValue, getValues, hasValue
-
-
-
-
Constructor Detail
-
QueryClient
public QueryClient(org.apache.http.impl.client.CloseableHttpClient http, SlingClientConfig config) throws ClientExceptionConstructor used by adaptTo- Parameters:
http- underlying HttpClientconfig- config state- Throws:
ClientException- if the client cannot be created
-
QueryClient
public QueryClient(java.net.URI url, java.lang.String user, java.lang.String password) throws ClientExceptionConvenience constructor- Parameters:
url- host urluser- usernamepassword- password- Throws:
ClientException- if the client cannot be constructed
-
-
Method Detail
-
doQuery
public org.codehaus.jackson.JsonNode doQuery(java.lang.String query, QueryClient.QueryType type) throws ClientException, java.lang.InterruptedExceptionExecutes 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 executejava.lang.InterruptedException- to mark that this method blocks
-
doCount
public long doCount(java.lang.String query, QueryClient.QueryType type) throws ClientException, java.lang.InterruptedExceptionExecutes 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 executejava.lang.InterruptedException- to mark that this method blocks
-
getPlan
public java.lang.String getPlan(java.lang.String query, QueryClient.QueryType type) throws ClientException, java.lang.InterruptedExceptionRetrieves 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 executejava.lang.InterruptedException- to mark that this method blocks
-
doQuery
protected org.codehaus.jackson.JsonNode doQuery(java.lang.String query, QueryClient.QueryType type, boolean showResults, boolean explain) throws ClientException, java.lang.InterruptedException- Throws:
ClientExceptionjava.lang.InterruptedException
-
installServlet
public QueryClient installServlet() throws ClientException, java.lang.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 failsjava.lang.InterruptedException- 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
-
-