Search in sources :

Example 1 with QueryScanConsistency

use of com.couchbase.client.java.query.QueryScanConsistency in project spring-data-couchbase by spring-projects.

the class OptionsBuilder method buildQueryOptions.

static QueryOptions buildQueryOptions(Query query, QueryOptions options, QueryScanConsistency scanConsistency) {
    options = options != null ? options : QueryOptions.queryOptions();
    if (query.getParameters() != null) {
        if (query.getParameters() instanceof JsonArray) {
            options.parameters((JsonArray) query.getParameters());
        } else {
            options.parameters((JsonObject) query.getParameters());
        }
    }
    Meta meta = query.getMeta() != null ? query.getMeta() : new Meta();
    QueryOptions.Built optsBuilt = options.build();
    JsonObject optsJson = getQueryOpts(optsBuilt);
    QueryScanConsistency metaQueryScanConsistency = meta.get(SCAN_CONSISTENCY) != null ? ((ScanConsistency) meta.get(SCAN_CONSISTENCY)).query() : null;
    QueryScanConsistency qsc = fromFirst(QueryScanConsistency.NOT_BOUNDED, getScanConsistency(optsJson), scanConsistency, metaQueryScanConsistency);
    Duration timeout = fromFirst(Duration.ofSeconds(0), getTimeout(optsBuilt), meta.get(TIMEOUT));
    RetryStrategy retryStrategy = fromFirst(null, getRetryStrategy(optsBuilt), meta.get(RETRY_STRATEGY));
    if (qsc != null) {
        options.scanConsistency(qsc);
    }
    if (timeout != null) {
        options.timeout(timeout);
    }
    if (retryStrategy != null) {
        options.retryStrategy(retryStrategy);
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("query options: {}", getQueryOpts(options.build()));
    }
    return options;
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject) QueryScanConsistency(com.couchbase.client.java.query.QueryScanConsistency) Duration(java.time.Duration) QueryOptions(com.couchbase.client.java.query.QueryOptions) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy)

Example 2 with QueryScanConsistency

use of com.couchbase.client.java.query.QueryScanConsistency in project spring-data-couchbase by spring-projects.

the class CouchbaseRepositoryBase method buildQueryScanConsistency.

/**
 * Get the QueryScanConsistency from <br>
 * 1. The method annotation (method *could* be available from crudMethodMetadata)<br>
 * 2. The repository<br>
 * 3. The entity<br>
 * 4. otherwise null<br>
 * This can be overriden in the operation method by<br>
 * 1. Options.scanConsistency (?)<br>
 * AbstractCouchbaseQueryBase.applyAnnotatedConsistencyIfPresent() <br>
 * CouchbaseRepository get picked up? If I have the following, will the annotation be picked up?<br>
 * Only via crudMethodMetadata<br>
 * \@ScanConsistency(query=QueryScanConsistency.REQUEST_PLUS)<br>
 * List<T> findAll();<br>
 */
QueryScanConsistency buildQueryScanConsistency() {
    ScanConsistency sc = crudMethodMetadata.getScanConsistency();
    QueryScanConsistency fromMeta = sc != null ? sc.query() : null;
    QueryScanConsistency fromAnnotation = OptionsBuilder.annotationAttribute(ScanConsistency.class, "query", QueryScanConsistency.NOT_BOUNDED, new AnnotatedElement[] { getJavaType(), repositoryInterface });
    return OptionsBuilder.fromFirst(QueryScanConsistency.NOT_BOUNDED, fromMeta, fromAnnotation);
}
Also used : QueryScanConsistency(com.couchbase.client.java.query.QueryScanConsistency) ScanConsistency(org.springframework.data.couchbase.repository.ScanConsistency) QueryScanConsistency(com.couchbase.client.java.query.QueryScanConsistency)

Aggregations

QueryScanConsistency (com.couchbase.client.java.query.QueryScanConsistency)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 JsonArray (com.couchbase.client.java.json.JsonArray)1 JsonObject (com.couchbase.client.java.json.JsonObject)1 QueryOptions (com.couchbase.client.java.query.QueryOptions)1 Duration (java.time.Duration)1 ScanConsistency (org.springframework.data.couchbase.repository.ScanConsistency)1