Search in sources :

Example 71 with JsonObject

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());
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 72 with JsonObject

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());
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 73 with JsonObject

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());
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 74 with JsonObject

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());
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 75 with JsonObject

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;
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) Parameter(org.springframework.data.repository.query.Parameter) JsonObject(com.couchbase.client.java.json.JsonObject) HashSet(java.util.HashSet)

Aggregations

JsonObject (com.couchbase.client.java.json.JsonObject)189 Test (org.junit.jupiter.api.Test)145 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)119 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)39 JsonArray (com.couchbase.client.java.json.JsonArray)18 QueryResult (com.couchbase.client.java.query.QueryResult)16 GetResult (com.couchbase.client.java.kv.GetResult)15 MutationResult (com.couchbase.client.java.kv.MutationResult)15 QueryOptions (com.couchbase.client.java.query.QueryOptions)15 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)15 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)6 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)6 Collection (com.couchbase.client.java.Collection)6 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)6 Duration (java.time.Duration)6 DisplayName (org.junit.jupiter.api.DisplayName)6 CouchbaseUtilTest (org.talend.components.couchbase.CouchbaseUtilTest)6 ArrayList (java.util.ArrayList)5 TestData (org.talend.components.couchbase.TestData)5 MutateInResult (com.couchbase.client.java.kv.MutateInResult)4