Search in sources :

Example 1 with CreatePrimaryQueryIndexOptions

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

the class QueryCollectionIntegrationTest method createPrimaryIndex.

private static CompletableFuture<Void> createPrimaryIndex(String bucketName, String scopeName, String collectionName) {
    CreatePrimaryQueryIndexOptions options = CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions();
    options.timeout(Duration.ofSeconds(300));
    final CreatePrimaryQueryIndexOptions.Built builtOpts = options.build();
    final String indexName = builtOpts.indexName().orElse(null);
    String keyspace = "`default`:`" + bucketName + "`.`" + scopeName + "`.`" + collectionName + "`";
    String statement = "CREATE PRIMARY INDEX ";
    if (indexName != null) {
        statement += (indexName) + " ";
    }
    // do not quote, this might be "default:bucketName.scopeName.collectionName"
    statement += "ON " + (keyspace);
    return exec(false, statement, builtOpts.with(), builtOpts).exceptionally(t -> {
        if (builtOpts.ignoreIfExists() && hasCause(t, IndexExistsException.class)) {
            return null;
        }
        throwIfUnchecked(t);
        throw new RuntimeException(t);
    }).thenApply(result -> null);
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) QueryOptions.queryOptions(com.couchbase.client.java.query.QueryOptions.queryOptions) QueryScanConsistency(com.couchbase.client.java.query.QueryScanConsistency) Capabilities(com.couchbase.client.test.Capabilities) MutationResult(com.couchbase.client.java.kv.MutationResult) AsyncUtils.block(com.couchbase.client.java.AsyncUtils.block) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterType(com.couchbase.client.test.ClusterType) QueryException(com.couchbase.client.core.error.QueryException) Function(java.util.function.Function) AfterAll(org.junit.jupiter.api.AfterAll) LinkedHashMap(java.util.LinkedHashMap) QueryResult(com.couchbase.client.java.query.QueryResult) MutationState(com.couchbase.client.java.kv.MutationState) CreatePrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions) BeforeAll(org.junit.jupiter.api.BeforeAll) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) CbThrowables.throwIfUnchecked(com.couchbase.client.core.util.CbThrowables.throwIfUnchecked) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) CbThrowables.hasCause(com.couchbase.client.core.util.CbThrowables.hasCause) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) QueryStatus(com.couchbase.client.java.query.QueryStatus) Predicate(java.util.function.Predicate) Mapper(com.couchbase.client.core.json.Mapper) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) UUID(java.util.UUID) DISABLE_QUERY_TESTS_FOR_CLUSTER(com.couchbase.client.java.manager.query.QueryIndexManagerIntegrationTest.DISABLE_QUERY_TESTS_FOR_CLUSTER) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) Test(org.junit.jupiter.api.Test) JsonArray(com.couchbase.client.java.json.JsonArray) QueryOptions(com.couchbase.client.java.query.QueryOptions) List(java.util.List) CollectionManager(com.couchbase.client.java.manager.collection.CollectionManager) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JsonObject(com.couchbase.client.java.json.JsonObject) CreatePrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions)

Example 2 with CreatePrimaryQueryIndexOptions

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

the class JavaIntegrationTests method createPrimaryIndex.

public static CompletableFuture<Void> createPrimaryIndex(Cluster cluster, String bucketName, String scopeName, String collectionName) {
    CreatePrimaryQueryIndexOptions options = CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions();
    options.timeout(Duration.ofSeconds(300));
    options.ignoreIfExists(true);
    final CreatePrimaryQueryIndexOptions.Built builtOpts = options.build();
    final String indexName = builtOpts.indexName().orElse(null);
    String keyspace = "default:`" + bucketName + "`.`" + scopeName + "`.`" + collectionName + "`";
    String statement = "CREATE PRIMARY INDEX ";
    if (indexName != null) {
        statement += (indexName) + " ";
    }
    // do not quote, this might be "default:bucketName.scopeName.collectionName"
    statement += "ON " + (keyspace);
    return exec(cluster, false, statement, builtOpts.with(), builtOpts).exceptionally(t -> {
        if (builtOpts.ignoreIfExists() && hasCause(t, IndexExistsException.class)) {
            return null;
        }
        throwIfUnchecked(t);
        throw new RuntimeException(t);
    }).thenApply(result -> null);
}
Also used : UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) PingResult(com.couchbase.client.core.diagnostics.PingResult) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) PingState(com.couchbase.client.core.diagnostics.PingState) ScopeSpec(com.couchbase.client.java.manager.collection.ScopeSpec) PingOptions(com.couchbase.client.java.diagnostics.PingOptions) Collection(com.couchbase.client.java.Collection) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) QueryResult(com.couchbase.client.java.query.QueryResult) FormBody(okhttp3.FormBody) BeforeAll(org.junit.jupiter.api.BeforeAll) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) CbThrowables.throwIfUnchecked(com.couchbase.client.core.util.CbThrowables.throwIfUnchecked) ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) UpsertSearchIndexOptions(com.couchbase.client.java.manager.search.UpsertSearchIndexOptions) COUCHBASE_TEMPLATE(org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMPLATE) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) Request(okhttp3.Request) CbThrowables.hasCause(com.couchbase.client.core.util.CbThrowables.hasCause) Predicate(java.util.function.Predicate) Mapper(com.couchbase.client.core.json.Mapper) Util.waitUntilCondition(org.springframework.data.couchbase.util.Util.waitUntilCondition) UUID(java.util.UUID) Credentials(okhttp3.Credentials) Scope(com.couchbase.client.java.Scope) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) List(java.util.List) Bucket(com.couchbase.client.java.Bucket) QueryOptions(com.couchbase.client.java.query.QueryOptions) ClusterOptions(com.couchbase.client.java.ClusterOptions) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) REACTIVE_COUCHBASE_TEMPLATE(org.springframework.data.couchbase.config.BeanNames.REACTIVE_COUCHBASE_TEMPLATE) JsonObject(com.couchbase.client.java.json.JsonObject) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions) CollectionNotFoundException(com.couchbase.client.core.error.CollectionNotFoundException) SearchResult(com.couchbase.client.java.search.result.SearchResult) CouchbaseClientFactory(org.springframework.data.couchbase.CouchbaseClientFactory) AsyncUtils.block(com.couchbase.client.java.AsyncUtils.block) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) CompletableFuture(java.util.concurrent.CompletableFuture) QueryException(com.couchbase.client.core.error.QueryException) Function(java.util.function.Function) ScopeNotFoundException(com.couchbase.client.core.error.ScopeNotFoundException) LinkedHashMap(java.util.LinkedHashMap) CommonOptions(com.couchbase.client.java.CommonOptions) CreatePrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions) Response(okhttp3.Response) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ReactiveCouchbaseTemplate(org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate) IOException(java.io.IOException) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) ApplicationContext(org.springframework.context.ApplicationContext) TimeUnit(java.util.concurrent.TimeUnit) CouchbaseTemplate(org.springframework.data.couchbase.core.CouchbaseTemplate) OkHttpClient(okhttp3.OkHttpClient) CollectionManager(com.couchbase.client.java.manager.collection.CollectionManager) Cluster(com.couchbase.client.java.Cluster) SimpleCouchbaseClientFactory(org.springframework.data.couchbase.SimpleCouchbaseClientFactory) Config(org.springframework.data.couchbase.domain.Config) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) SearchQuery(com.couchbase.client.java.search.SearchQuery) Collections(java.util.Collections) Timeout(org.junit.jupiter.api.Timeout) CreatePrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions)

Aggregations

IndexExistsException (com.couchbase.client.core.error.IndexExistsException)2 QueryException (com.couchbase.client.core.error.QueryException)2 Mapper (com.couchbase.client.core.json.Mapper)2 ServiceType (com.couchbase.client.core.service.ServiceType)2 CbThrowables.hasCause (com.couchbase.client.core.util.CbThrowables.hasCause)2 CbThrowables.throwIfUnchecked (com.couchbase.client.core.util.CbThrowables.throwIfUnchecked)2 AsyncUtils.block (com.couchbase.client.java.AsyncUtils.block)2 JsonObject (com.couchbase.client.java.json.JsonObject)2 CollectionManager (com.couchbase.client.java.manager.collection.CollectionManager)2 CollectionSpec (com.couchbase.client.java.manager.collection.CollectionSpec)2 CreatePrimaryQueryIndexOptions (com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions)2 QueryOptions (com.couchbase.client.java.query.QueryOptions)2 QueryResult (com.couchbase.client.java.query.QueryResult)2 Duration (java.time.Duration)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Function (java.util.function.Function)2