Class N1qlQueryExecutor
- java.lang.Object
-
- com.couchbase.client.java.query.core.N1qlQueryExecutor
-
@Uncommitted @Private public class N1qlQueryExecutor extends Object
A class used to execute various N1QL queries.- Since:
- 2.2
- Author:
- Simon Baslé
-
-
Field Summary
Fields Modifier and Type Field Description static rx.functions.Func1<? super AsyncN1qlQueryResult,? extends rx.Observable<? extends N1qlQueryResult>>ASYNC_RESULT_TO_SYNCA function that can be used in a flatMap to convert anAsyncN1qlQueryResultto aN1qlQueryResult.static StringENCODED_PLAN_ENABLED_PROPERTYprotected static StringERROR_5000_SPECIFIC_MESSAGE
-
Constructor Summary
Constructors Modifier Constructor Description N1qlQueryExecutor(ClusterFacade core, String bucket, String password)Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade.N1qlQueryExecutor(ClusterFacade core, String bucket, String password, boolean encodedPlanEnabled)Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade.N1qlQueryExecutor(ClusterFacade core, String bucket, String username, String password)Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade.N1qlQueryExecutor(ClusterFacade core, String bucket, String username, String password, boolean encodedPlanEnabled)Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade.protectedN1qlQueryExecutor(ClusterFacade core, String bucket, String username, String password, LRUCache<String,PreparedPayload> lruCache, boolean encodedPlanEnabled)This constructor is for testing purpose, prefer usingN1qlQueryExecutor(ClusterFacade, String, String, String).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected rx.Observable<AsyncN1qlQueryResult>dispatchPrepared(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)rx.Observable<AsyncN1qlQueryResult>execute(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)protected rx.Observable<AsyncN1qlQueryResult>executePrepared(N1qlQuery query, PreparedPayload payload, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)Issues a proper N1QL EXECUTE, detecting if parameters must be added to it.protected rx.Observable<AsyncN1qlQueryResult>executeQuery(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)Internal: Queries a N1QL secondary index.protected PreparedPayloadextractPreparedPayloadFromResponse(PrepareStatement prepared, JsonObject response)Extracts thePreparedPayloadfrom the server's response during a PREPARE.intinvalidateQueryCache()Invalidates and clears the query cache.booleanisEncodedPlanEnabled()protected rx.Observable<PreparedPayload>prepare(Statement statement)Queries a N1QL secondary index and prepare an execution plan via the given statement inStringform.protected rx.Observable<AsyncN1qlQueryResult>prepareAndExecute(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)Issues a N1QL PREPARE, puts the plan in cache then EXECUTE it.protected rx.Observable<AsyncN1qlQueryResult>retryPrepareAndExecuteOnce(Throwable error, N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)In case the error warrants a retry, issue a PREPARE, followed by an update of the cache and an EXECUTE.
-
-
-
Field Detail
-
ERROR_5000_SPECIFIC_MESSAGE
protected static final String ERROR_5000_SPECIFIC_MESSAGE
- See Also:
- Constant Field Values
-
ENCODED_PLAN_ENABLED_PROPERTY
public static final String ENCODED_PLAN_ENABLED_PROPERTY
- See Also:
- Constant Field Values
-
ASYNC_RESULT_TO_SYNC
public static final rx.functions.Func1<? super AsyncN1qlQueryResult,? extends rx.Observable<? extends N1qlQueryResult>> ASYNC_RESULT_TO_SYNC
A function that can be used in a flatMap to convert anAsyncN1qlQueryResultto aN1qlQueryResult.
-
-
Constructor Detail
-
N1qlQueryExecutor
public N1qlQueryExecutor(ClusterFacade core, String bucket, String username, String password)
Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade. For queries that are not ad-hoc, it will cache up toQUERY_CACHE_SIZEqueries.- Parameters:
core- the core through which to send requests.bucket- the bucket to bootstrap from.username- the user authorized for bucket access.password- the password for the bucket.
-
N1qlQueryExecutor
public N1qlQueryExecutor(ClusterFacade core, String bucket, String password)
Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade. For queries that are not ad-hoc, it will cache up toQUERY_CACHE_SIZEqueries.- Parameters:
core- the core through which to send requests.bucket- the bucket to bootstrap from.password- the password for the bucket.
-
N1qlQueryExecutor
public N1qlQueryExecutor(ClusterFacade core, String bucket, String password, boolean encodedPlanEnabled)
Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade. For queries that are not ad-hoc, it will cache up toQUERY_CACHE_SIZEqueries.- Parameters:
core- the core through which to send requests.bucket- the bucket to bootstrap from.password- the password for the bucket.encodedPlanEnabled- true to include an encoded plan when running prepared queries, false otherwise.
-
N1qlQueryExecutor
public N1qlQueryExecutor(ClusterFacade core, String bucket, String username, String password, boolean encodedPlanEnabled)
Construct a new N1qlQueryExecutor that will send requests through the givenClusterFacade. For queries that are not ad-hoc, it will cache up toQUERY_CACHE_SIZEqueries.- Parameters:
core- the core through which to send requests.bucket- the bucket to bootstrap from.username- the user authorized for bucket access.password- the password for the user.encodedPlanEnabled- true to include an encoded plan when running prepared queries, false otherwise.
-
N1qlQueryExecutor
protected N1qlQueryExecutor(ClusterFacade core, String bucket, String username, String password, LRUCache<String,PreparedPayload> lruCache, boolean encodedPlanEnabled)
This constructor is for testing purpose, prefer usingN1qlQueryExecutor(ClusterFacade, String, String, String).
-
-
Method Detail
-
execute
public rx.Observable<AsyncN1qlQueryResult> execute(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)
-
executeQuery
protected rx.Observable<AsyncN1qlQueryResult> executeQuery(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)
Internal: Queries a N1QL secondary index. The returnedObservablecan error under the following conditions: - The producer outpaces the SDK:BackpressureException- The operation had to be cancelled while "in flight" on the wire:RequestCancelledException- Parameters:
query- the full query as a Json String, including all necessary parameters.- Returns:
- a result containing all found rows and additional information.
-
dispatchPrepared
protected rx.Observable<AsyncN1qlQueryResult> dispatchPrepared(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)
-
retryPrepareAndExecuteOnce
protected rx.Observable<AsyncN1qlQueryResult> retryPrepareAndExecuteOnce(Throwable error, N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)
In case the error warrants a retry, issue a PREPARE, followed by an update of the cache and an EXECUTE. Any failure in the EXECUTE won't continue the retry cycle.
-
prepareAndExecute
protected rx.Observable<AsyncN1qlQueryResult> prepareAndExecute(N1qlQuery query, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)
Issues a N1QL PREPARE, puts the plan in cache then EXECUTE it.
-
executePrepared
protected rx.Observable<AsyncN1qlQueryResult> executePrepared(N1qlQuery query, PreparedPayload payload, CouchbaseEnvironment env, long timeout, TimeUnit timeUnit)
Issues a proper N1QL EXECUTE, detecting if parameters must be added to it.
-
prepare
protected rx.Observable<PreparedPayload> prepare(Statement statement)
Queries a N1QL secondary index and prepare an execution plan via the given statement inStringform. Statement can contain placeholders. The resultingPreparedPayloadcan be cached and (re)used later in aPreparedN1qlQuery. The returnedObservablecan error under the following conditions: - The producer outpaces the SDK:BackpressureException- The operation had to be cancelled while on the wire or the retry strategy cancelled it instead of retrying:RequestCancelledException- Parameters:
statement- the statement to prepare a plan for.- Returns:
- a
PreparedPayloadthat can be cached and reused later inPreparedN1qlQuery.
-
extractPreparedPayloadFromResponse
protected PreparedPayload extractPreparedPayloadFromResponse(PrepareStatement prepared, JsonObject response)
Extracts thePreparedPayloadfrom the server's response during a PREPARE.
-
invalidateQueryCache
public int invalidateQueryCache()
Invalidates and clears the query cache.
-
isEncodedPlanEnabled
public boolean isEncodedPlanEnabled()
- Returns:
- true if prepared queries produced by this QueryExecutor will include an encoded plan, false otherwise.
-
-