use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.
the class QueryCriteria method addAsCollection.
private void addAsCollection(JsonArray posValues, Collection collection, CouchbaseConverter converter) {
JsonArray ja = JsonValue.ja();
for (Object e : collection) {
ja.add(String.valueOf(convert(converter, e)));
}
posValues.add(ja);
}
use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.
the class QueryCriteria method in.
public QueryCriteria in(@Nullable Object... o) {
operator = "IN";
format = "%1$s in %3$s";
value = new Object[1];
if (o.length > 0) {
if (o[0] instanceof JsonArray || o[0] instanceof List || o[0] instanceof Object[]) {
if (o.length != 1) {
throw new RuntimeException("IN cannot take multiple lists");
}
if (o[0] instanceof Object[]) {
value[0] = o[0];
} else if (o[0] instanceof JsonArray) {
JsonArray ja = ((JsonArray) o[0]);
value[0] = ja.toList().toArray();
} else if (o[0] instanceof List) {
List l = ((List) o[0]);
value[0] = l.toArray();
}
} else {
// Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
if (o instanceof Object[]) {
value[0] = o;
} else {
// notIn((Object) new String[] { "Alabama", "Florida" }));
throw new CouchbaseException("unhandled parameters " + o);
}
}
}
return this;
}
use of com.couchbase.client.java.json.JsonArray 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;
}
use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.
the class StringBasedN1qlQueryParser method addAsArray.
private void addAsArray(JsonArray posValues, Object o) {
Object[] array = (Object[]) o;
JsonArray ja = JsonValue.ja();
for (Object e : array) {
ja.add(String.valueOf(couchbaseConverter.convertForWriteIfNeeded(e)));
}
posValues.add(ja);
}
use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.
the class StringBasedN1qlQueryParser method addAsArray.
private void addAsArray(JsonObject namedValues, String placeholder, Object o) {
Object[] array = (Object[]) o;
JsonArray ja = JsonValue.ja();
for (Object e : array) {
ja.add(String.valueOf(couchbaseConverter.convertForWriteIfNeeded(e)));
}
namedValues.put(placeholder, ja);
}
Aggregations