Class TransactionQueryOptions

java.lang.Object
com.couchbase.client.java.transactions.TransactionQueryOptions

public class TransactionQueryOptions extends Object
Allows customizing various N1QL query options.

This object is NOT thread safe and must be constructed on a single thread.

  • Constructor Details

    • TransactionQueryOptions

      protected TransactionQueryOptions()
      The options should only be instantiated through the queryOptions() static method.
  • Method Details

    • queryOptions

      public static TransactionQueryOptions queryOptions()
      Creates new QueryOptions with all default params set.
      Returns:
      constructed QueryOptions with its default values.
    • raw

      public TransactionQueryOptions raw(String key, Object value)
      Allows providing custom JSON key/value pairs for advanced usage.

      If available, it is recommended to use the methods on this object to customize the query. This method should only be used if no such setter can be found (i.e. if an undocumented property should be set or you are using an older client and a new server-configuration property has been added to the cluster).

      Note that the value will be passed through a JSON encoder, so do not provide already encoded JSON as the value. If you want to pass objects or arrays, you can use JsonObject and JsonArray respectively.

      Parameters:
      key - the parameter name (key of the JSON property) or empty.
      value - the parameter value (value of the JSON property).
      Returns:
      the same QueryOptions for chaining purposes.
    • adhoc

      public TransactionQueryOptions adhoc(boolean adhoc)
      Allows turning this request into a prepared statement query.

      If set to

      false
      , the SDK will transparently perform "prepare and execute" logic the first time this query is seen and then subsequently reuse the prepared statement name when sending it to the server. If a query is executed frequently, this is a good way to speed it up since it will save the server the task of re-parsing and analyzing the query.

      If you are using prepared statements, make sure that if certain parts of the query string change you are using named or positional parameters. If the statement string itself changes it cannot be cached.

      Parameters:
      adhoc - if set to false this query will be turned into a prepared statement query.
      Returns:
      the same QueryOptions for chaining purposes.
    • scanConsistency

      public TransactionQueryOptions scanConsistency(QueryScanConsistency scanConsistency)
      Customizes the consistency guarantees for this query.

      Tuning the scan consistency allows to trade data "freshness" for latency and vice versa. By default QueryScanConsistency.REQUEST_PLUS is used for any queries inside a transaction, which means that the indexer will wait until any indexes used are consistent with all mutations at the time of the query. If this level of consistency is not required, use QueryScanConsistency.NOT_BOUNDED which will execute the query immediately with whatever data are in the index.

      Parameters:
      scanConsistency - the index scan consistency to be used for this query.
      Returns:
      this, for chaining purposes.
    • serializer

      public TransactionQueryOptions serializer(JsonSerializer serializer)
      Provides a custom JsonSerializer to be used for decoding the rows as they return from the server.

      If no serializer is provided, the default one from the ClusterEnvironment will be used (which is sufficient for most tasks at hand).

      Parameters:
      serializer - a custom serializer for this request.
      Returns:
      the same QueryOptions for chaining purposes.
    • profile

      public TransactionQueryOptions profile(QueryProfile profile)
      Customizes the server profiling level for this query.

      Note that you only want to tune this if you want to gather profiling/performance metrics for debugging. Turning this on in production (depending on the level) will likely have performance impact on the server query engine as a whole and on this query in particular!

      Parameters:
      profile - the custom query profile level for this query.
      Returns:
      the same QueryOptions for chaining purposes.
    • clientContextId

      public TransactionQueryOptions clientContextId(String clientContextId)
      Supports providing a custom client context ID for this query.

      If no client context ID is provided by the user, a UUID is generated and sent automatically so by default it is always possible to identify a query when debugging. If you do not want to send one, pass either null or an empty string to this method.

      Parameters:
      clientContextId - the client context ID - if null or empty it will not be sent.
      Returns:
      the same QueryOptions for chaining purposes.
    • scanWait

      public TransactionQueryOptions scanWait(Duration wait)
      Allows customizing how long the query engine is willing to wait until the index catches up to whatever scan consistency is asked for in this query.

      Note that if QueryScanConsistency.NOT_BOUNDED is used, this method doesn't do anything at all. If no value is provided to this method, the server default is used.

      Parameters:
      wait - the maximum duration the query engine is willing to wait before failing.
      Returns:
      the same QueryOptions for chaining purposes.
    • readonly

      public TransactionQueryOptions readonly(boolean readonly)
      Allows explicitly marking a query as being readonly and not mutating and documents on the server side.

      In addition to providing some security in that you are not accidentally modifying data, setting this flag to true also helps the client to more proactively retry and re-dispatch a query since then it can be sure it is idempotent. As a result, if your query is readonly then it is a good idea to set this flag.

      If set to true, then (at least) the following statements are not allowed:

      1. CREATE INDEX
      2. DROP INDEX
      3. INSERT
      4. MERGE
      5. UPDATE
      6. UPSERT
      7. DELETE
      Parameters:
      readonly - true if readonly should be set, false is the default and will use the server side default.
      Returns:
      the same QueryOptions for chaining purposes.
    • scanCap

      public TransactionQueryOptions scanCap(int scanCap)
      Supports customizing the maximum buffered channel size between the indexer and the query service.

      This is an advanced API and should only be tuned with care. Use 0 or a negative number to disable.

      Parameters:
      scanCap - the scan cap size, use 0 or negative number to disable.
      Returns:
      the same QueryOptions for chaining purposes.
    • pipelineBatch

      public TransactionQueryOptions pipelineBatch(int pipelineBatch)
      Supports customizing the number of items execution operators can batch for fetch from the KV layer on the server.

      This is an advanced API and should only be tuned with care.

      Parameters:
      pipelineBatch - the pipeline batch size.
      Returns:
      the same QueryOptions for chaining purposes.
    • pipelineCap

      public TransactionQueryOptions pipelineCap(int pipelineCap)
      Allows customizing the maximum number of items each execution operator can buffer between various operators on the server.

      This is an advanced API and should only be tuned with care.

      Parameters:
      pipelineCap - the pipeline cap size.
      Returns:
      the same QueryOptions for chaining purposes.
    • parameters

      public TransactionQueryOptions parameters(JsonObject named)
      Sets named parameters for this query.

      Note that named and positional parameters cannot be used at the same time. If one is set, the other one is "nulled" out and not being sent to the server.

      Parameters:
      named - JsonObject the named parameters.
      Returns:
      the same QueryOptions for chaining purposes.
    • parameters

      public TransactionQueryOptions parameters(JsonArray positional)
      Sets positional parameters for this query.

      Note that named and positional parameters cannot be used at the same time. If one is set, the other one is "nulled" out and not being sent to the server.

      Parameters:
      positional - JsonArray the positional parameters.
      Returns:
      the same QueryOptions for chaining purposes.
    • flexIndex

      public TransactionQueryOptions flexIndex(boolean flexIndex)
      Tells the query engine to use a flex index (utilizing the search service).
      Parameters:
      flexIndex - if a flex index should be used, false is the default.
      Returns:
      the same QueryOptions for chaining purposes.
    • builder

      @Internal public QueryOptions builder()