Search in sources :

Example 21 with JsonArray

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

the class CouchbaseRepositoryQueryIntegrationTests method findBySimplePropertyWithOptions.

@Test
void findBySimplePropertyWithOptions() {
    Airport vie = new Airport("airports::vie", "vie", "low9");
    JsonArray positionalParams = JsonArray.create().add("this parameter will be overridden");
    // JsonObject namedParams = JsonObject.create().put("$1", vie.getIata());
    try {
        Airport saved = airportRepository.save(vie);
        // Duration of 1 nano-second will cause timeout
        assertThrows(AmbiguousTimeoutException.class, () -> airportRepository.withOptions(QueryOptions.queryOptions().timeout(Duration.ofNanos(1))).iata(vie.getIata()));
        Airport airport3 = airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(positionalParams)).iata(vie.getIata());
        assertEquals(saved, airport3);
    } finally {
        airportRepository.delete(vie);
    }
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) Airport(org.springframework.data.couchbase.domain.Airport) AirportRepositoryScanConsistencyTest(org.springframework.data.couchbase.domain.AirportRepositoryScanConsistencyTest) Test(org.junit.jupiter.api.Test)

Example 22 with JsonArray

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

the class ReactiveCouchbaseRepositoryQueryCollectionIntegrationTests method findBySimplePropertyWithOptions.

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

Example 23 with JsonArray

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

the class CouchbaseRepositoryQueryIntegrationTests method findByEnum.

@Test
void findByEnum() {
    Airport vie = null;
    Airport zzz = null;
    try {
        vie = new Airport("airports::vie", "vie", "loww");
        vie = airportRepository.save(vie);
        zzz = airportRepository.save(vie.withId("airports::zzz").withIata("zzz"));
        Airport airport2 = airportRepository.findByIata(Iata.vie);
        assertNotNull(airport2, "should have found " + vie);
        assertEquals(airport2.getId(), vie.getId());
        Airport airport3 = airportRepository.findByIataIn(new Iata[] { Iata.vie, Iata.xxx });
        assertNotNull(airport3, "should have found " + vie);
        assertEquals(airport3.getId(), vie.getId());
        java.util.Collection<Iata> iatas = new ArrayList<>();
        iatas.add(Iata.vie);
        iatas.add(Iata.xxx);
        Airport airport4 = airportRepository.findByIataIn(iatas);
        assertNotNull(airport4, "should have found " + vie);
        assertEquals(airport4.getId(), vie.getId());
        Airport airport5 = airportRepository.findByIataIn(Iata.vie, Iata.xxx);
        assertNotNull(airport5, "should have found " + vie);
        assertEquals(airport5.getId(), vie.getId());
        JsonArray iatasJson = JsonArray.ja();
        iatasJson.add(Iata.vie.toString());
        iatasJson.add(Iata.xxx.toString());
        Airport airport6 = airportRepository.findByIataIn(iatasJson);
        assertNotNull(airport6, "should have found " + vie);
        assertEquals(airport6.getId(), vie.getId());
    } finally {
        airportRepository.delete(vie);
        airportRepository.delete(zzz);
    }
}
Also used : JsonArray(com.couchbase.client.java.json.JsonArray) Airport(org.springframework.data.couchbase.domain.Airport) Iata(org.springframework.data.couchbase.domain.Iata) ArrayList(java.util.ArrayList) AirportRepositoryScanConsistencyTest(org.springframework.data.couchbase.domain.AirportRepositoryScanConsistencyTest) Test(org.junit.jupiter.api.Test)

Example 24 with JsonArray

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

the class QueryCriteriaTests method testNotIn.

@Test
void testNotIn() {
    String[] args = new String[] { "gump", "davis" };
    // the first arg is an array
    QueryCriteria c = where(i("name")).notIn((Object) args);
    assertEquals("not( (`name` in [\"gump\",\"davis\"]) )", c.export());
    // this tests creating parameters from the args.
    JsonArray parameters = JsonArray.create();
    assertEquals("not( (`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 25 with JsonArray

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

the class QueryCriteriaTests method testNestedOrCriteria.

@Test
void testNestedOrCriteria() {
    QueryCriteria c = where(i("name")).is("Bubba").or(where(i("age")).gt(12).or(i("country")).is("Austria"));
    JsonArray parameters = JsonArray.create();
    assertEquals("`name` = $1 or (`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)

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