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_SYNC
A function that can be used in a flatMap to convert anAsyncN1qlQueryResult
to aN1qlQueryResult
.static String
ENCODED_PLAN_ENABLED_PROPERTY
protected static String
ERROR_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
.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 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 PreparedPayload
extractPreparedPayloadFromResponse(PrepareStatement prepared, JsonObject response)
Extracts thePreparedPayload
from the server's response during a PREPARE.int
invalidateQueryCache()
Invalidates and clears the query cache.boolean
isEncodedPlanEnabled()
protected rx.Observable<PreparedPayload>
prepare(Statement statement)
Queries a N1QL secondary index and prepare an execution plan via the given statement inString
form.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 anAsyncN1qlQueryResult
to 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_SIZE
queries.- 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_SIZE
queries.- 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_SIZE
queries.- 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_SIZE
queries.- 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 returnedObservable
can 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 inString
form. Statement can contain placeholders. The resultingPreparedPayload
can be cached and (re)used later in aPreparedN1qlQuery
. The returnedObservable
can 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
PreparedPayload
that can be cached and reused later inPreparedN1qlQuery
.
-
extractPreparedPayloadFromResponse
protected PreparedPayload extractPreparedPayloadFromResponse(PrepareStatement prepared, JsonObject response)
Extracts thePreparedPayload
from 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.
-
-