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()));
}
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);
}
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);
}
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);
}
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);
}
Aggregations