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