@InterfaceStability.Committed @InterfaceAudience.Public public class N1qlParams extends Object implements Serializable
Parameter Object for queries
that allows to fluently set most of the N1QL query parameters: - server side timeout - client context ID - scan consistency (with associated scan vector and/or scan wait if relevant) - max parallelism
Note that these are different from statement-related named parameters or positional parameters.
Modifier and Type | Method and Description |
---|---|
N1qlParams |
adhoc(boolean adhoc)
Allows to specify if this query is adhoc or not.
|
static N1qlParams |
build()
Start building a
N1qlParams , allowing to customize an N1QL request. |
N1qlParams |
consistency(ScanConsistency consistency)
Sets scan consistency.
|
N1qlParams |
consistentWith(Document... documents)
Sets the
Document s resulting of a mutation this query should be consistent with. |
N1qlParams |
consistentWith(DocumentFragment... fragments)
Sets the
DocumentFragment s resulting of a mutation this query should be consistent with. |
N1qlParams |
consistentWith(MutationState mutationState)
Sets the
MutationState this query should be consistent with. |
N1qlParams |
disableMetrics(boolean disableMetrics)
If set to true (false being the default), the metrics object will not be returned from N1QL and as a result be more efficient.
|
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
hasServerSideTimeout()
Helper method to check if a custom server side timeout has been applied on the params.
|
void |
injectParams(JsonObject queryJson)
Modifies the given N1QL query (as a
JsonObject ) to reflect these N1qlParams . |
boolean |
isAdhoc()
True if this query is adhoc, false otherwise.
|
N1qlParams |
maxParallelism(int maxParallelism)
Allows to override the default maximum parallelism for the query execution on the server side.
|
N1qlParams |
pretty(boolean pretty)
If set to false, the server will be instructed to remove extra whitespace from the JSON response in order to save bytes.
|
N1qlParams |
rawParam(String name,
Object value)
Allows to specify an arbitrary, raw N1QL param.
|
N1qlParams |
scanWait(long wait,
TimeUnit unit)
If the
NOT_BOUNDED scan consistency has been chosen, does nothing. |
N1qlParams |
serverSideTimeout(long timeout,
TimeUnit unit)
Sets a maximum timeout for processing on the server side.
|
String |
toString() |
N1qlParams |
withContextId(String clientContextId)
Adds a client context ID to the request, that will be sent back in the response, allowing clients to meaningfully trace requests/responses when many are exchanged.
|
N1qlParams |
withCredentials(List<Credential> credentials)
Allows to add a list of credentials (in the form of
Credential objects) to this request. |
N1qlParams |
withCredentials(String login,
String password)
Allows to add a credential username/password pair to this request.
|
public void injectParams(JsonObject queryJson)
Modifies the given N1QL query (as a JsonObject
) to reflect these N1qlParams
.
queryJson
- the N1QL querypublic static N1qlParams build()
Start building a N1qlParams
, allowing to customize an N1QL request.
N1qlParams
public N1qlParams serverSideTimeout(long timeout, TimeUnit unit)
Sets a maximum timeout for processing on the server side.
timeout
- the duration of the timeout.unit
- the unit of the timeout, from nanoseconds to hours.N1qlParams
for chaining.public N1qlParams withContextId(String clientContextId)
Adds a client context ID to the request, that will be sent back in the response, allowing clients to meaningfully trace requests/responses when many are exchanged.
clientContextId
- the client context ID (null to send none)N1qlParams
for chaining.public N1qlParams disableMetrics(boolean disableMetrics)
If set to true (false being the default), the metrics object will not be returned from N1QL and as a result be more efficient. Note that if metrics are disabled you are loosing information to diagnose problems - so use with care!
disableMetrics
- true if disabled, false otherwise (false = default).N1qlParams
for chaining.public N1qlParams consistency(ScanConsistency consistency)
Sets scan consistency.
Note that NOT_BOUNDED
will unset the scanWait
if it was set.
N1qlParams
for chaining.@InterfaceStability.Committed public N1qlParams consistentWith(Document... documents)
Sets the Document
s resulting of a mutation this query should be consistent with.
documents
- the documents returned from a mutation.N1qlParams
for chaining.@InterfaceStability.Committed public N1qlParams consistentWith(DocumentFragment... fragments)
Sets the DocumentFragment
s resulting of a mutation this query should be consistent with.
fragments
- the fragments returned from a mutation.N1qlParams
for chaining.@InterfaceStability.Committed public N1qlParams consistentWith(MutationState mutationState)
Sets the MutationState
this query should be consistent with.
mutationState
- the mutation state which accumulates tokens from one or more mutation results.N1qlParams
for chaining.public N1qlParams scanWait(long wait, TimeUnit unit)
If the NOT_BOUNDED scan consistency
has been chosen, does nothing.
Otherwise, sets the maximum time the client is willing to wait for an index to catch up to the vector timestamp in the request.
wait
- the duration.unit
- the unit for the duration.N1qlParams
for chaining.public N1qlParams maxParallelism(int maxParallelism)
Allows to override the default maximum parallelism for the query execution on the server side.
maxParallelism
- the maximum parallelism for this query, 0 or negative values disable it.N1qlParams
for chaining.public N1qlParams adhoc(boolean adhoc)
Allows to specify if this query is adhoc or not.
If it is not adhoc (so performed often), the client will try to perform optimizations transparently based on the server capabilities, like preparing the statement and then executing a query plan instead of the raw query.
adhoc
- if the query is adhoc, default is true (plain execution).N1qlParams
for chaining.public N1qlParams withCredentials(List<Credential> credentials)
Allows to add a list of credentials (in the form of Credential
objects) to this request. Credentials for usernames that were previously set by a similar call are replaced.
credentials
- the list of credentials to add to the request.N1qlParams
for chaining.public N1qlParams withCredentials(String login, String password)
Allows to add a credential username/password pair to this request. If a credential for that username was previously set by a similar call, it is replaced.
login
- the username/bucketname to add a credential for.password
- the associated password.N1qlParams
for chaining.public N1qlParams pretty(boolean pretty)
If set to false, the server will be instructed to remove extra whitespace from the JSON response in order to save bytes. In performance-critical environments as well as large responses this is recommended in order to cut down on network traffic.
Note that this option is only supported in Couchbase Server 4.5.1 or later.
pretty
- if set to false, pretty responses are disabled.N1qlParams
for chaining.@InterfaceStability.Uncommitted public N1qlParams rawParam(String name, Object value)
Allows to specify an arbitrary, raw N1QL param.
Use with care and only provide options that are supported by the server and are not exposed as part of the overall stable API in the N1qlParams
class.
name
- the name of the property.value
- the value of the property, only JSON value types are supported.N1qlParams
for chaining.public boolean hasServerSideTimeout()
Helper method to check if a custom server side timeout has been applied on the params.
public boolean isAdhoc()
True if this query is adhoc, false otherwise.
Copyright © 2015 Couchbase, Inc.