Search in sources :

Example 31 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.

the class StringN1qlQueryCreator method complete.

@Override
protected Query complete(QueryCriteria criteria, Sort sort) {
    Query q = new StringQuery(parsedExpression.toString()).with(sort);
    JsonValue params = queryParser.getPlaceholderValues(accessor);
    if (params instanceof JsonArray) {
        q.setPositionalParameters((JsonArray) params);
    } else {
        q.setNamedParameters((JsonObject) params);
    }
    return q;
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) StringQuery(org.springframework.data.couchbase.core.query.StringQuery) Query(org.springframework.data.couchbase.core.query.Query) JsonValue(com.couchbase.client.java.json.JsonValue) StringQuery(org.springframework.data.couchbase.core.query.StringQuery)

Example 32 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.

the class QueryCriteriaTests method testIn.

@Test
void testIn() {
    String[] args = new String[] { "gump", "davis" };
    // the first arg is an array
    QueryCriteria c = where(i("name")).in((Object) args);
    assertEquals("`name` in [\"gump\",\"davis\"]", c.export());
    JsonArray parameters = JsonArray.create();
    assertEquals("`name` in $1", c.export(new int[1], parameters, null));
    assertEquals(arrayToString(args), parameters.get(0).toString());
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) Test(org.junit.jupiter.api.Test)

Example 33 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.

the class QueryCriteriaTests method testNestedAndCriteria.

@Test
void testNestedAndCriteria() {
    QueryCriteria c = where(i("name")).is("Bubba").and(where(i("age")).gt(12).or(i("country")).is("Austria"));
    JsonArray parameters = JsonArray.create();
    assertEquals("`name` = $1 and (`age` > $2 or `country` = $3)", c.export(new int[1], parameters, null));
    assertEquals("[\"Bubba\",12,\"Austria\"]", parameters.toString());
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) Test(org.junit.jupiter.api.Test)

Example 34 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.

the class QueryCriteriaTests method testNestedNotIn.

@Test
void testNestedNotIn() {
    QueryCriteria c = where(i("name")).is("Bubba").or(where(i("age")).gt(12).or(i("country")).is("Austria")).and(where(i("state")).notIn((Object) new String[] { "Alabama", "Florida" }));
    JsonArray parameters = JsonArray.create();
    assertEquals("`name` = $1 or (`age` > $2 or `country` = $3) and (not( (`state` in $4) ))", c.export(new int[1], parameters, null));
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) Test(org.junit.jupiter.api.Test)

Example 35 with JsonArray

use of com.couchbase.client.java.json.JsonArray in project spring-data-couchbase by spring-projects.

the class CouchbaseRepositoryQueryCollectionIntegrationTests method findBySimplePropertyWithOptions.

@Test
void findBySimplePropertyWithOptions() {
    AirportRepository ar = airportRepository.withScope(scopeName).withCollection(collectionName);
    Airport vie = new Airport("airports::vie", "vie", "loww");
    JsonArray positionalParams = JsonArray.create().add("\"this parameter will be overridden\"");
    try {
        Airport saved = ar.save(vie);
        Airport airport3 = ar.withOptions(QueryOptions.queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(positionalParams)).iata(vie.getIata());
        assertEquals(saved, airport3);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        ar.delete(vie);
    }
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) Airport(org.springframework.data.couchbase.domain.Airport) AirportRepository(org.springframework.data.couchbase.domain.AirportRepository) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) IndexFailureException(com.couchbase.client.core.error.IndexFailureException) Test(org.junit.jupiter.api.Test)

Aggregations

JsonArray (com.couchbase.client.java.json.JsonArray)48 Test (org.junit.jupiter.api.Test)26 JsonObject (com.couchbase.client.java.json.JsonObject)24 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)8 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)3 IndexFailureException (com.couchbase.client.core.error.IndexFailureException)3 List (java.util.List)3 Airport (org.springframework.data.couchbase.domain.Airport)3 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)2 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)2 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)2 JsonValue (com.couchbase.client.java.json.JsonValue)2 GetResult (com.couchbase.client.java.kv.GetResult)2 QueryOptions (com.couchbase.client.java.query.QueryOptions)2 SearchQuery (com.couchbase.client.java.search.SearchQuery)2 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Query (org.springframework.data.couchbase.core.query.Query)2 AirportRepositoryScanConsistencyTest (org.springframework.data.couchbase.domain.AirportRepositoryScanConsistencyTest)2