Search in sources :

Example 6 with QueryOptions

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

the class QueryCollectionIntegrationTest method toQueryOptions.

private static QueryOptions toQueryOptions(CommonOptions<?>.BuiltCommonOptions options) {
    QueryOptions result = queryOptions();
    options.timeout().ifPresent(result::timeout);
    options.retryStrategy().ifPresent(result::retryStrategy);
    return result;
}
Also used : QueryOptions(com.couchbase.client.java.query.QueryOptions)

Example 7 with QueryOptions

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

the class QueryIntegrationTest method handlesPreparedStatementsWithNamedArgs.

@Test
void handlesPreparedStatementsWithNamedArgs() {
    String id = insertDoc();
    for (int i = 0; i < 10; i++) {
        QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonObject.create().put("id", id)).adhoc(false);
        QueryResult result = cluster.query("select " + bucketName + ".* from " + bucketName + " where meta().id=$id", options);
        List<JsonObject> rows = result.rowsAs(JsonObject.class);
        assertEquals(1, rows.size());
        assertEquals(FOO_CONTENT, rows.get(0));
    }
}
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 8 with QueryOptions

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

the class QueryIntegrationTest method handlesPreparedStatementsWithPositionalArgs.

@Test
void handlesPreparedStatementsWithPositionalArgs() {
    String id = insertDoc();
    for (int i = 0; i < 10; i++) {
        QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonArray.from(id)).adhoc(false);
        QueryResult result = cluster.query("select " + bucketName + ".* from " + bucketName + " where meta().id=$1", options);
        List<JsonObject> rows = result.rowsAs(JsonObject.class);
        assertEquals(1, rows.size());
        assertEquals(FOO_CONTENT, rows.get(0));
    }
}
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 9 with QueryOptions

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

the class QueryIntegrationTest method consistentWith.

@Test
void consistentWith() {
    String id = UUID.randomUUID().toString();
    MutationResult mr = collection.insert(id, FOO_CONTENT);
    QueryOptions options = queryOptions().consistentWith(MutationState.from(mr.mutationToken().get())).parameters(JsonArray.from(id));
    QueryResult result = cluster.query("select  " + bucketName + ".* from " + bucketName + " where meta().id=$1", options);
    List<JsonObject> rows = result.rowsAs(JsonObject.class);
    assertEquals(1, rows.size());
    assertEquals(FOO_CONTENT, rows.get(0));
}
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) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with QueryOptions

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

the class QueryIntegrationTest method reactivePositionalParameterizedSelectQuery.

@Test
void reactivePositionalParameterizedSelectQuery() {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonArray.from(id));
    Mono<ReactiveQueryResult> result = cluster.reactive().query("select * from " + bucketName + " where meta().id=$1", options);
    List<JsonObject> rows = result.flux().flatMap(ReactiveQueryResult::rowsAsObject).collectList().block();
    assertNotNull(rows);
    assertEquals(1, rows.size());
}
Also used : 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)

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