Search in sources :

Example 11 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method asyncNamedParameterizedSelectQuery.

@Test
void asyncNamedParameterizedSelectQuery() throws Exception {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonObject.create().put("id", id));
    CompletableFuture<QueryResult> result = cluster.async().query("select * from " + bucketName + " where meta().id=$id", options);
    List<JsonObject> rows = result.get().rowsAs(JsonObject.class);
    assertEquals(1, rows.size());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method readOnlyViolation.

@Test
void readOnlyViolation() {
    QueryOptions options = queryOptions().readonly(true);
    CouchbaseException e = assertThrows(CouchbaseException.class, () -> cluster.query("INSERT INTO " + bucketName + " (KEY, VALUE) values (\"foo\", \"bar\")", options));
    assertEquals(1000, ((QueryErrorContext) e.context()).errors().get(0).code());
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method asyncSelect.

@Test
void asyncSelect() throws Exception {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS);
    CompletableFuture<QueryResult> result = cluster.async().query("select * from " + bucketName + " where meta().id=\"" + id + "\"", options);
    List<JsonObject> rows = result.get().rowsAs(JsonObject.class);
    assertEquals(1, rows.size());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method removeByQuery.

@Test
public void removeByQuery() {
    // 8
    QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
    Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("495"));
    List<RemoveResult> removeResults = couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName).withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all();
    assertEquals(saved.getId(), removeResults.get(0).getId());
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) QueryOptions(com.couchbase.client.java.query.QueryOptions) Test(org.junit.jupiter.api.Test)

Example 15 with QueryOptions

use of com.couchbase.client.java.query.QueryOptions in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method removeByQueryOptions.

@Test
public void removeByQueryOptions() {
    // 8 - options
    QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofNanos(10));
    assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection).withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all());
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) QueryOptions(com.couchbase.client.java.query.QueryOptions) Test(org.junit.jupiter.api.Test)

Aggregations

QueryOptions (com.couchbase.client.java.query.QueryOptions)40 Test (org.junit.jupiter.api.Test)31 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)19 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)18 QueryResult (com.couchbase.client.java.query.QueryResult)16 JsonObject (com.couchbase.client.java.json.JsonObject)15 Airport (org.springframework.data.couchbase.domain.Airport)10 ReducedQueryErrorContext (com.couchbase.client.core.error.context.ReducedQueryErrorContext)4 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)4 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 JsonArray (com.couchbase.client.java.json.JsonArray)2 MutationResult (com.couchbase.client.java.kv.MutationResult)2 Duration (java.time.Duration)2 RemoveResult (org.springframework.data.couchbase.core.RemoveResult)2 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)1 IndexFailureException (com.couchbase.client.core.error.IndexFailureException)1