use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.
the class GetProjectionIntegrationTest method attributes_hobbies_0_type.
@Test
void attributes_hobbies_0_type() {
JsonObject decoded = collection.get(DOC_ID, getOptions().project("attributes.hobbies[0].type")).contentAsObject();
JsonArray arr = decoded.getObject("attributes").getArray("hobbies");
assertEquals(1, arr.size());
assertEquals("winter sports", arr.getObject(0).getString("type"));
assertEquals(1, decoded.size());
}
use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.
the class GetProjectionIntegrationTest method animals_0.
@Test
void animals_0() {
JsonObject decoded = collection.get(DOC_ID, getOptions().project("animals[0]")).contentAsObject();
JsonArray arr = decoded.getArray("animals");
assertEquals(1, arr.size());
assertEquals("cat", arr.get(0));
assertEquals(1, decoded.size());
}
use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.
the class GetProjectionIntegrationTest method animals.
@Test
void animals() {
JsonObject decoded = collection.get(DOC_ID, getOptions().project("animals")).contentAsObject();
JsonArray arr = decoded.getArray("animals");
assertEquals(3, arr.size());
assertEquals(1, decoded.size());
}
use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.
the class GetProjectionIntegrationTest method name.
@Test
void name() {
JsonObject decoded = collection.get(DOC_ID, getOptions().project("name")).contentAsObject();
assertEquals("Emmy-lou Dickerson", decoded.getString("name"));
assertEquals(1, decoded.size());
}
use of com.couchbase.client.java.json.JsonObject in project spring-data-couchbase by spring-projects.
the class StringBasedN1qlQueryParser method getNamedPlaceholderValues.
/**
* Get Named argument placeholders to use for parameters. $lastname, $city etc.
*
* @param accessor
* @return
*/
private JsonObject getNamedPlaceholderValues(ParameterAccessor accessor) {
JsonObject namedValues = JsonObject.create();
HashSet<String> pNames = new HashSet<>(parameterNames);
for (Parameter parameter : this.queryMethod.getParameters().getBindableParameters()) {
String placeholder = parameter.getPlaceholder();
Object rawValue = accessor.getBindableValue(parameter.getIndex());
Object value = couchbaseConverter.convertForWriteIfNeeded(rawValue);
if (placeholder != null && placeholder.charAt(0) == ':') {
placeholder = placeholder.replaceFirst(":", "");
putNamedValue(namedValues, placeholder, value);
if (pNames.contains(placeholder)) {
pNames.remove(placeholder);
} else {
throw new RuntimeException("parameter named " + placeholder + " does not match any named parameter " + parameterNames + " in " + statement);
}
} else {
if (parameter.getName().isPresent()) {
putNamedValue(namedValues, parameter.getName().get(), value);
} else {
throw new RuntimeException("cannot determine argument for named parameter. " + "Argument " + parameter.getIndex() + " to " + queryMethod.getClass().getName() + "." + queryMethod.getName() + "() needs @Param(\"name\") that matches a named parameter in " + statement);
}
}
}
if (!pNames.isEmpty()) {
throw new RuntimeException("no parameter found for " + pNames);
}
return namedValues;
}
Aggregations