use of com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions.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);
}
Aggregations