Search in sources :

Example 31 with QueryOptions

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

the class QueryIntegrationTest method handlesPreparedStatements.

/**
 * This test is intentionally kept generic, since we want to make sure with every query version
 * that we run against we have a version that works. Also, we perform the same query multiple times
 * to make sure a primed and non-primed cache both work out of the box.
 */
@Test
void handlesPreparedStatements() {
    String id = insertDoc();
    for (int i = 0; i < 10; i++) {
        QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).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 32 with QueryOptions

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

the class QueryIntegrationTest method blockingSelect.

@Test
void blockingSelect() {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS);
    QueryResult result = cluster.query("select * from " + bucketName + " where meta().id=\"" + id + "\"", options);
    assertNotNull(result.metaData().requestId());
    assertFalse(result.metaData().clientContextId().isEmpty());
    assertEquals(QueryStatus.SUCCESS, result.metaData().status());
    assertTrue(result.metaData().warnings().isEmpty());
    assertEquals(1, result.rowsAs(JsonObject.class).size());
    assertTrue(result.metaData().signature().isPresent());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 33 with QueryOptions

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

the class QueryIntegrationTest method blockingNamedParameterizedSelectQuery.

@Test
void blockingNamedParameterizedSelectQuery() {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonObject.create().put("id", id));
    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 34 with QueryOptions

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

the class QueryIntegrationTest method exerciseAllOptions.

@Test
void exerciseAllOptions() {
    String id = insertDoc();
    QueryOptions options = queryOptions().adhoc(true).clientContextId("123").maxParallelism(3).metrics(true).pipelineBatch(1).pipelineCap(1).readonly(true).scanCap(10).scanConsistency(QueryScanConsistency.REQUEST_PLUS).scanWait(Duration.ofMillis(50));
    QueryResult result = cluster.query("select * from " + bucketName + " where meta().id=\"" + id + "\"", options);
    assertEquals(QueryStatus.SUCCESS, result.metaData().status());
    assertEquals("123", result.metaData().clientContextId());
    assertTrue(result.metaData().metrics().isPresent());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 35 with QueryOptions

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

the class QueryIntegrationTest method noProfileRequestedGivesEmptyProfile.

@Test
void noProfileRequestedGivesEmptyProfile() {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS);
    QueryResult result = cluster.query("select * from " + bucketName + " where meta().id=\"" + id + "\"", options);
    assertFalse(result.metaData().profile().isPresent());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) 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