use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.
the class N1qlQueryCreatorTests method queryParametersJsonArray.
@Test
void queryParametersJsonArray() throws Exception {
String input = "findByFirstnameIn";
PartTree tree = new PartTree(input, User.class);
Method method = UserRepository.class.getMethod(input, JsonArray.class);
QueryMethod queryMethod = new QueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory());
JsonArray jsonArray = JsonArray.create();
jsonArray.add("Oliver");
jsonArray.add("Charles");
N1qlQueryCreator creator = new N1qlQueryCreator(tree, getAccessor(getParameters(method), jsonArray), queryMethod, converter, bucketName);
Query query = creator.createQuery();
Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
assertEquals(" WHERE `firstname` in $1", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(actualOptions);
assertEquals(expectedOptions.removeKey("client_context_id"), actualOptions.removeKey("client_context_id"));
}
use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.
the class CouchbaseArraySet method contains.
@Override
public boolean contains(Object t) {
// TODO subpar implementation for a Set, use ARRAY_CONTAINS when available
enforcePrimitive(t);
try {
GetResult result = collection.get(id, getOptions);
JsonArray current = result.contentAs(JsonArray.class);
for (Object in : current) {
if (safeEquals(in, t)) {
return true;
}
}
return false;
} catch (DocumentNotFoundException e) {
return false;
}
}
use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.
the class CouchbaseArraySet method remove.
@Override
public boolean remove(Object t) {
enforcePrimitive(t);
for (int i = 0; i < arraySetOptions.casMismatchRetries(); i++) {
try {
GetResult result = collection.get(id);
JsonArray current = result.contentAsArray();
long cas = result.cas();
int index = 0;
boolean found = false;
for (Object next : current) {
if (safeEquals(next, t)) {
found = true;
break;
}
index++;
}
String path = "[" + index + "]";
if (!found) {
return false;
} else {
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(path)), arraySetOptions.mutateInOptions().cas(cas));
return true;
}
} catch (CasMismatchException e) {
// retry
} catch (DocumentNotFoundException ex) {
return false;
}
}
throw new CouchbaseException("CouchbaseArraySet remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + arraySetOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.
the class ViewOptionsTest method shouldOutputSmallKeysInToString.
@Test
void shouldOutputSmallKeysInToString() {
JsonArray keysArray = JsonArray.from("foo", 3, true);
ViewOptions options = viewOptions().keys(keysArray);
assertEquals("", options.export());
assertEquals("ViewQuery{params=\"\", keys=\"{\"keys\":[\"foo\",3,true]}\"}", options.toString());
}
use of com.couchbase.client.java.json.JsonArray in project couchbase-jvm-clients by couchbase.
the class ViewOptionsTest method shouldHandleKeys.
@Test
void shouldHandleKeys() {
JsonArray keysArray = JsonArray.from("foo", 3, true);
ViewOptions options = viewOptions().keys(keysArray);
assertEquals("", options.export());
assertEquals(JsonObject.create().put("keys", keysArray).toString(), options.build().keys());
}
Aggregations