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);
}
}
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();
}
}
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);
}
}
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());
}
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());
}
Aggregations