Search in sources :

Example 1 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.

the class AsyncQueryIndexManager method getAllIndexes.

/**
 * Fetches all indexes from the bucket with custom options.
 * <p>
 * By default, this method will fetch all index on the bucket. If the indexes should be loaded for a collection,
 * both {@link GetAllQueryIndexesOptions#scopeName(String)} and
 * {@link GetAllQueryIndexesOptions#collectionName(String)} must be set. If all indexes for a scope should be loaded,
 * only the {@link GetAllQueryIndexesOptions#scopeName(String)} can be set.
 *
 * @param bucketName the name of the bucket to load the indexes from.
 * @param options the custom options to apply.
 * @return a {@link CompletableFuture} completing with a list of (potentially empty) indexes or failed with an error.
 * @throws CouchbaseException (async) if any other generic unhandled/unexpected errors.
 */
public CompletableFuture<List<QueryIndex>> getAllIndexes(final String bucketName, final GetAllQueryIndexesOptions options) {
    notNullOrEmpty(bucketName, "BucketName");
    notNull(options, "Options");
    final GetAllQueryIndexesOptions.Built builtOpts = options.build();
    String statement;
    JsonArray params;
    if (builtOpts.scopeName().isPresent() && builtOpts.collectionName().isPresent()) {
        statement = "SELECT idx.* FROM system:indexes AS idx" + " WHERE keyspace_id = ? AND bucket_id = ? AND scope_id = ?" + " AND `using` = \"gsi\"" + " ORDER BY is_primary DESC, name ASC";
        params = JsonArray.from(builtOpts.collectionName().get(), bucketName, builtOpts.scopeName().get());
    } else if (builtOpts.scopeName().isPresent()) {
        statement = "SELECT idx.* FROM system:indexes AS idx" + " WHERE bucket_id = ? AND scope_id = ?" + " AND `using` = \"gsi\"" + " ORDER BY is_primary DESC, name ASC";
        params = JsonArray.from(bucketName, builtOpts.scopeName().get());
    } else {
        statement = "SELECT idx.* FROM system:indexes AS idx" + " WHERE ((bucket_id IS MISSING AND keyspace_id = ?) OR bucket_id = ?)" + " AND `using` = \"gsi\"" + " ORDER BY is_primary DESC, name ASC";
        params = JsonArray.from(bucketName, bucketName);
    }
    return exec(READ_ONLY, statement, builtOpts, TracingIdentifiers.SPAN_REQUEST_MQ_GET_ALL_INDEXES, bucketName, params).thenApply(result -> result.rowsAsObject().stream().map(QueryIndex::new).collect(toList()));
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray)

Example 2 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.

the class ConjunctionQuery method injectParams.

@Override
protected void injectParams(JsonObject input) {
    if (childQueries.isEmpty()) {
        throw InvalidArgumentException.fromMessage("Compound query has no child query");
    }
    JsonArray conjuncts = JsonArray.create();
    for (SearchQuery childQuery : childQueries) {
        JsonObject childJson = JsonObject.create();
        childQuery.injectParamsAndBoost(childJson);
        conjuncts.add(childJson);
    }
    input.put("conjuncts", conjuncts);
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) SearchQuery(com.couchbase.client.java.search.SearchQuery) JsonObject(com.couchbase.client.java.json.JsonObject)

Example 3 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.

the class DisjunctionQuery method injectParams.

@Override
protected void injectParams(JsonObject input) {
    if (childQueries.isEmpty()) {
        throw InvalidArgumentException.fromMessage("Compound query has no child query");
    }
    if (childQueries.size() < min) {
        throw InvalidArgumentException.fromMessage("Disjunction query as fewer children than the configured minimum " + min);
    }
    if (min > 0) {
        input.put("min", min);
    }
    JsonArray disjuncts = JsonArray.create();
    for (SearchQuery childQuery : childQueries) {
        JsonObject childJson = JsonObject.create();
        childQuery.injectParamsAndBoost(childJson);
        disjuncts.add(childJson);
    }
    input.put("disjuncts", disjuncts);
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) SearchQuery(com.couchbase.client.java.search.SearchQuery) JsonObject(com.couchbase.client.java.json.JsonObject)

Example 4 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.

the class DateRangeFacet method injectParams.

@Override
public void injectParams(JsonObject queryJson) {
    super.injectParams(queryJson);
    JsonArray dateRange = JsonArray.create();
    for (DateRange dr : dateRanges) {
        JsonObject drJson = JsonObject.create();
        drJson.put("name", dr.name());
        if (dr.start() != null) {
            drJson.put("start", dr.start());
        }
        if (dr.end() != null) {
            drJson.put("end", dr.end());
        }
        dateRange.add(drJson);
    }
    queryJson.put("date_ranges", dateRange);
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject)

Example 5 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.

the class NumericRangeFacet method injectParams.

@Override
public void injectParams(JsonObject queryJson) {
    super.injectParams(queryJson);
    JsonArray numericRange = JsonArray.create();
    for (NumericRange nr : ranges) {
        JsonObject nrJson = JsonObject.create();
        nrJson.put("name", nr.name());
        if (nr.min() != null) {
            nrJson.put("min", nr.min());
        }
        if (nr.max() != null) {
            nrJson.put("max", nr.max());
        }
        numericRange.add(nrJson);
    }
    queryJson.put("numeric_ranges", numericRange);
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject)

Aggregations

JsonArray (com.couchbase.client.java.json.JsonArray)48 Test (org.junit.jupiter.api.Test)26 JsonObject (com.couchbase.client.java.json.JsonObject)24 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)8 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)3 IndexFailureException (com.couchbase.client.core.error.IndexFailureException)3 List (java.util.List)3 Airport (org.springframework.data.couchbase.domain.Airport)3 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)2 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)2 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)2 JsonValue (com.couchbase.client.java.json.JsonValue)2 GetResult (com.couchbase.client.java.kv.GetResult)2 QueryOptions (com.couchbase.client.java.query.QueryOptions)2 SearchQuery (com.couchbase.client.java.search.SearchQuery)2 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Query (org.springframework.data.couchbase.core.query.Query)2 AirportRepositoryScanConsistencyTest (org.springframework.data.couchbase.domain.AirportRepositoryScanConsistencyTest)2