From 42b7fb3af862efd224df31b6317900cf861fea82 Mon Sep 17 00:00:00 2001
From: Michael Reiche <48999328+mikereiche@users.noreply.github.com>
Date: Wed, 2 Jun 2021 09:38:02 -0400
Subject: [PATCH] Scope and collection API for template. (#1133)
Scope and Collection API for template.
Closes #963.
Original pull request: #1071.
---
pom.xml | 28 +-
.../couchbase/core/CouchbaseTemplate.java | 16 +-
.../core/ExecutableExistsByIdOperation.java | 71 +-
.../ExecutableExistsByIdOperationSupport.java | 36 +-
.../ExecutableFindByAnalyticsOperation.java | 79 +-
...utableFindByAnalyticsOperationSupport.java | 61 +-
.../core/ExecutableFindByIdOperation.java | 75 +-
.../ExecutableFindByIdOperationSupport.java | 39 +-
.../core/ExecutableFindByQueryOperation.java | 115 ++-
...ExecutableFindByQueryOperationSupport.java | 70 +-
...ecutableFindFromReplicasByIdOperation.java | 91 ++-
...eFindFromReplicasByIdOperationSupport.java | 28 +-
.../core/ExecutableInsertByIdOperation.java | 91 ++-
.../ExecutableInsertByIdOperationSupport.java | 45 +-
.../core/ExecutableRemoveByIdOperation.java | 86 +-
.../ExecutableRemoveByIdOperationSupport.java | 54 +-
.../ExecutableRemoveByQueryOperation.java | 80 +-
...ecutableRemoveByQueryOperationSupport.java | 44 +-
.../core/ExecutableReplaceByIdOperation.java | 89 ++-
...ExecutableReplaceByIdOperationSupport.java | 55 +-
.../core/ExecutableUpsertByIdOperation.java | 90 ++-
.../ExecutableUpsertByIdOperationSupport.java | 47 +-
.../core/ReactiveCouchbaseOperations.java | 11 +-
.../core/ReactiveCouchbaseTemplate.java | 12 +-
.../core/ReactiveExistsByIdOperation.java | 63 +-
.../ReactiveExistsByIdOperationSupport.java | 42 +-
.../ReactiveFindByAnalyticsOperation.java | 82 +-
...activeFindByAnalyticsOperationSupport.java | 58 +-
.../core/ReactiveFindByIdOperation.java | 73 +-
.../ReactiveFindByIdOperationSupport.java | 52 +-
.../core/ReactiveFindByQueryOperation.java | 85 +-
.../ReactiveFindByQueryOperationSupport.java | 102 ++-
...ReactiveFindFromReplicasByIdOperation.java | 87 +-
...eFindFromReplicasByIdOperationSupport.java | 42 +-
.../core/ReactiveInsertByIdOperation.java | 90 ++-
.../ReactiveInsertByIdOperationSupport.java | 87 +-
.../core/ReactiveRemoveByIdOperation.java | 82 +-
.../ReactiveRemoveByIdOperationSupport.java | 71 +-
.../core/ReactiveRemoveByQueryOperation.java | 81 +-
...ReactiveRemoveByQueryOperationSupport.java | 63 +-
.../core/ReactiveReplaceByIdOperation.java | 88 ++-
.../ReactiveReplaceByIdOperationSupport.java | 80 +-
.../core/ReactiveUpsertByIdOperation.java | 93 ++-
.../ReactiveUpsertByIdOperationSupport.java | 78 +-
.../BasicCouchbasePersistentProperty.java | 18 +-
.../mapping/CouchbasePersistentProperty.java | 4 +-
.../couchbase/core/mapping/Expiration.java | 33 +
.../data/couchbase/core/query/Query.java | 16 +-
.../couchbase/core/support/InCollection.java | 31 +
.../{WithCollection.java => InScope.java} | 13 +-
.../couchbase/core/support/PseudoArgs.java | 117 +++
.../support/WithAnalyticsConsistency.java | 7 +-
.../core/support/WithAnalyticsOptions.java | 33 +
.../core/support/WithAnalyticsQuery.java | 7 +-
.../core/support/WithConsistency.java | 7 +-
.../couchbase/core/support/WithDistinct.java | 7 +-
.../core/support/WithExistsOptions.java | 33 +
.../support/WithGetAnyReplicaOptions.java | 33 +
.../core/support/WithGetOptions.java | 33 +
.../core/support/WithInsertOptions.java | 33 +
.../core/support/WithQueryOptions.java | 33 +
.../core/support/WithRemoveOptions.java | 28 +
.../core/support/WithReplaceOptions.java | 28 +
.../core/support/WithUpsertOptions.java | 28 +
.../query/AbstractCouchbaseQuery.java | 13 +-
.../query/AbstractCouchbaseQueryBase.java | 4 +-
.../query/AbstractReactiveCouchbaseQuery.java | 3 +-
.../query/CouchbaseQueryExecution.java | 13 +-
.../repository/query/N1qlQueryCreator.java | 20 +-
.../query/N1qlRepositoryQueryExecutor.java | 11 +-
.../SimpleReactiveCouchbaseRepository.java | 3 +-
...hbaseTemplateKeyValueIntegrationTests.java | 46 +-
...mplateQueryCollectionIntegrationTests.java | 448 ++++++++++-
...ouchbaseTemplateQueryIntegrationTests.java | 27 +-
.../core/query/QueryCriteriaTests.java | 4 +-
...mplateQueryCollectionIntegrationTests.java | 745 ++++++++++++++++++
.../data/couchbase/domain/Config.java | 15 +-
.../data/couchbase/domain/ConfigScoped.java | 42 -
.../CustomMappingCouchbaseConverter.java | 27 +-
.../data/couchbase/domain/FluxTest.java | 225 ++++++
.../data/couchbase/domain/Person.java | 4 +-
.../couchbase/domain/PersonRepository.java | 16 +-
.../domain/ReactiveAirportRepository.java | 13 +-
...chbaseRepositoryQueryIntegrationTests.java | 22 +-
...chbaseRepositoryQueryIntegrationTests.java | 41 +-
.../query/N1qlQueryCreatorTests.java | 27 +-
.../query/StringN1qlQueryCreatorTests.java | 4 +-
.../util/ClusterAwareIntegrationTests.java | 53 +-
.../util/CollectionAwareIntegrationTests.java | 34 +-
.../couchbase/util/JavaIntegrationTests.java | 40 +-
.../couchbase/util/UnmanagedTestCluster.java | 21 +-
src/test/resources/logback.xml | 4 +-
92 files changed, 4630 insertions(+), 749 deletions(-)
create mode 100644 src/main/java/org/springframework/data/couchbase/core/mapping/Expiration.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/InCollection.java
rename src/main/java/org/springframework/data/couchbase/core/support/{WithCollection.java => InScope.java} (80%)
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/PseudoArgs.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithAnalyticsOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithExistsOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithGetAnyReplicaOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithGetOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithInsertOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithQueryOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithRemoveOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithReplaceOptions.java
create mode 100644 src/main/java/org/springframework/data/couchbase/core/support/WithUpsertOptions.java
create mode 100644 src/test/java/org/springframework/data/couchbase/core/query/ReactiveCouchbaseTemplateQueryCollectionIntegrationTests.java
delete mode 100644 src/test/java/org/springframework/data/couchbase/domain/ConfigScoped.java
create mode 100644 src/test/java/org/springframework/data/couchbase/domain/FluxTest.java
diff --git a/pom.xml b/pom.xml
index e619cd0e..a919f4de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,16 +25,16 @@
-
-
- org.testcontainers
- testcontainers-bom
- ${testcontainers}
- pom
- import
-
-
-
+
+
+ org.testcontainers
+ testcontainers-bom
+ ${testcontainers}
+ pom
+ import
+
+
+
@@ -88,7 +88,7 @@
io.projectreactor
reactor-test
- 3.1.0.RELEASE
+ 3.4.6
test
@@ -170,12 +170,6 @@
test
-
- io.projectreactor
- reactor-test
- test
-
-
org.jetbrains.kotlin
diff --git a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
index 29829d9b..2f1354dc 100644
--- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
+++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
@@ -28,6 +28,7 @@ import org.springframework.data.couchbase.core.index.CouchbasePersistentEntityIn
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
+import org.springframework.data.couchbase.core.support.PseudoArgs;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.lang.Nullable;
@@ -60,14 +61,14 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex
this.converter = converter;
this.templateSupport = new CouchbaseTemplateSupport(converter, translationService);
this.reactiveCouchbaseTemplate = new ReactiveCouchbaseTemplate(clientFactory, converter, translationService);
-
+
this.mappingContext = this.converter.getMappingContext();
- if (mappingContext instanceof CouchbaseMappingContext) {
- CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
- if (cmc.isAutoIndexCreation()) {
- indexCreator = new CouchbasePersistentEntityIndexCreator(cmc, this);
- }
- }
+ if (mappingContext instanceof CouchbaseMappingContext) {
+ CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
+ if (cmc.isAutoIndexCreation()) {
+ indexCreator = new CouchbasePersistentEntityIndexCreator(cmc, this);
+ }
+ }
}
@Override
@@ -184,4 +185,5 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex
TemplateSupport support() {
return templateSupport;
}
+
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperation.java
index 75185f52..357ba500 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperation.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,19 @@ package org.springframework.data.couchbase.core;
import java.util.Collection;
import java.util.Map;
+import org.springframework.data.couchbase.core.support.InCollection;
+import org.springframework.data.couchbase.core.support.InScope;
import org.springframework.data.couchbase.core.support.OneAndAllExists;
-import org.springframework.data.couchbase.core.support.WithCollection;
+import org.springframework.data.couchbase.core.support.WithExistsOptions;
+import com.couchbase.client.java.kv.ExistsOptions;
+
+/**
+ * Insert Operations
+ *
+ * @author Christoph Strobl
+ * @since 2.0
+ */
public interface ExecutableExistsByIdOperation {
/**
@@ -28,6 +38,9 @@ public interface ExecutableExistsByIdOperation {
*/
ExecutableExistsById existsById();
+ /**
+ * Terminating operations invoking the actual execution.
+ */
interface TerminatingExistsById extends OneAndAllExists {
/**
@@ -36,6 +49,7 @@ public interface ExecutableExistsByIdOperation {
* @param id the ID to perform the operation on.
* @return true if the document exists, false otherwise.
*/
+ @Override
boolean one(String id);
/**
@@ -44,20 +58,59 @@ public interface ExecutableExistsByIdOperation {
* @param ids the ids to check.
* @return a map consisting of the document IDs as the keys and if they exist as the value.
*/
+ @Override
Map all(Collection ids);
-
}
- interface ExistsByIdWithCollection extends TerminatingExistsById, WithCollection {
-
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface ExistsByIdWithOptions extends TerminatingExistsById, WithExistsOptions {
/**
- * Allows to specify a different collection than the default one configured.
+ * Fluent method to specify options to use for execution
*
- * @param collection the collection to use in this scope.
+ * @param options options to use for execution
*/
- TerminatingExistsById inCollection(String collection);
+ @Override
+ TerminatingExistsById withOptions(ExistsOptions options);
}
- interface ExecutableExistsById extends ExistsByIdWithCollection {}
+ /**
+ *
+ * Fluent method to specify the collection.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface ExistsByIdInCollection extends ExistsByIdWithOptions, InCollection {
+ /**
+ * With a different collection
+ *
+ * @param collection the collection to use.
+ */
+ @Override
+ ExistsByIdWithOptions inCollection(String collection);
+ }
+
+ /**
+ * Fluent method to specify the scope.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface ExistsByIdInScope extends ExistsByIdInCollection, InScope {
+ /**
+ * With a different scope
+ *
+ * @param scope the scope to use.
+ */
+ @Override
+ ExistsByIdInCollection inScope(String scope);
+ }
+
+ /**
+ * Provides methods for constructing KV exists operations in a fluent way.
+ */
+ interface ExecutableExistsById extends ExistsByIdInScope {}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java
index 3841fa64..5484d9ab 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,13 +15,14 @@
*/
package org.springframework.data.couchbase.core;
-import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
-
import java.util.Collection;
import java.util.Map;
+import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
import org.springframework.util.Assert;
+import com.couchbase.client.java.kv.ExistsOptions;
+
public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByIdOperation {
private final CouchbaseTemplate template;
@@ -32,17 +33,25 @@ public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI
@Override
public ExecutableExistsById existsById() {
- return new ExecutableExistsByIdSupport(template, null);
+ return new ExecutableExistsByIdSupport(template, null, null, null);
}
static class ExecutableExistsByIdSupport implements ExecutableExistsById {
private final CouchbaseTemplate template;
+ private final String scope;
+ private final String collection;
+ private final ExistsOptions options;
+
private final ReactiveExistsByIdSupport reactiveSupport;
- ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String collection) {
+ ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String scope, final String collection,
+ final ExistsOptions options) {
this.template = template;
- this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), collection);
+ this.scope = scope;
+ this.collection = collection;
+ this.options = options;
+ this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), scope, collection, options);
}
@Override
@@ -56,11 +65,22 @@ public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI
}
@Override
- public TerminatingExistsById inCollection(final String collection) {
+ public ExistsByIdWithOptions inCollection(final String collection) {
Assert.hasText(collection, "Collection must not be null nor empty.");
- return new ExecutableExistsByIdSupport(template, collection);
+ return new ExecutableExistsByIdSupport(template, scope, collection, options);
}
+ @Override
+ public TerminatingExistsById withOptions(final ExistsOptions options) {
+ Assert.notNull(options, "Options must not be null.");
+ return new ExecutableExistsByIdSupport(template, scope, collection, options);
+ }
+
+ @Override
+ public ExistsByIdInCollection inScope(final String scope) {
+ Assert.hasText(scope, "Scope must not be null nor empty.");
+ return new ExecutableExistsByIdSupport(template, scope, collection, options);
+ }
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperation.java
index 20962172..2aed295f 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperation.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +21,23 @@ import java.util.stream.Stream;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
+import org.springframework.data.couchbase.core.support.InCollection;
+import org.springframework.data.couchbase.core.support.InScope;
import org.springframework.data.couchbase.core.support.OneAndAll;
import org.springframework.data.couchbase.core.support.WithAnalyticsConsistency;
+import org.springframework.data.couchbase.core.support.WithAnalyticsOptions;
import org.springframework.data.couchbase.core.support.WithAnalyticsQuery;
import org.springframework.lang.Nullable;
+import com.couchbase.client.java.analytics.AnalyticsOptions;
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
-public interface ExecutableFindByAnalyticsOperation {
+/**
+ * FindByAnalytics Operations
+ *
+ * @author Christoph Strobl
+ * @since 2.0
+ */public interface ExecutableFindByAnalyticsOperation {
/**
* Queries the analytics service.
@@ -117,8 +126,53 @@ public interface ExecutableFindByAnalyticsOperation {
}
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use.
+ */
+ interface FindByAnalyticsWithOptions extends FindByAnalyticsWithQuery, WithAnalyticsOptions {
+ /**
+ * Fluent method to specify options to use for execution
+ *
+ * @param options to use for execution
+ */
+ @Override
+ FindByAnalyticsWithQuery withOptions(AnalyticsOptions options);
+ }
+
+ /**
+ * Fluent method to specify the collection.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByAnalyticsInCollection extends FindByAnalyticsWithOptions, InCollection {
+ /**
+ * With a different collection
+ *
+ * @param collection the collection to use.
+ */
+ @Override
+ FindByAnalyticsWithOptions inCollection(String collection);
+ }
+
+ /**
+ * Fluent method to specify the scope.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByAnalyticsInScope extends FindByAnalyticsInCollection, InScope {
+ /**
+ * With a different scope
+ *
+ * @param scope the scope to use.
+ */
+ @Override
+ FindByAnalyticsInCollection inScope(String scope);
+ }
+
@Deprecated
- interface FindByAnalyticsConsistentWith extends FindByAnalyticsWithQuery {
+ interface FindByAnalyticsConsistentWith extends FindByAnalyticsInScope {
/**
* Allows to override the default scan consistency.
@@ -138,9 +192,24 @@ public interface ExecutableFindByAnalyticsOperation {
* @param scanConsistency the custom scan consistency to use for this analytics query.
*/
FindByAnalyticsConsistentWith withConsistency(AnalyticsScanConsistency scanConsistency);
-
}
- interface ExecutableFindByAnalytics extends FindByAnalyticsWithConsistency {}
+ /**
+ * Result type override (Optional).
+ */
+ interface FindByAnalyticsWithProjection extends FindByAnalyticsWithConsistency {
+
+ /**
+ * Define the target type fields should be mapped to.
+ * Skip this step if you are anyway only interested in the original domain type.
+ *
+ * @param returnType must not be {@literal null}.
+ * @return new instance of {@link FindByAnalyticsWithConsistency}.
+ * @throws IllegalArgumentException if returnType is {@literal null}.
+ */
+ FindByAnalyticsWithConsistency as(Class returnType);
+ }
+
+ interface ExecutableFindByAnalytics extends FindByAnalyticsWithProjection {}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java
index 4c430fca..54924a80 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java
@@ -20,7 +20,9 @@ import java.util.stream.Stream;
import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport;
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
+import org.springframework.util.Assert;
+import com.couchbase.client.java.analytics.AnalyticsOptions;
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
public class ExecutableFindByAnalyticsOperationSupport implements ExecutableFindByAnalyticsOperation {
@@ -35,26 +37,34 @@ public class ExecutableFindByAnalyticsOperationSupport implements ExecutableFind
@Override
public ExecutableFindByAnalytics findByAnalytics(final Class domainType) {
- return new ExecutableFindByAnalyticsSupport<>(template, domainType, ALL_QUERY,
- AnalyticsScanConsistency.NOT_BOUNDED);
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null);
}
static class ExecutableFindByAnalyticsSupport implements ExecutableFindByAnalytics {
private final CouchbaseTemplate template;
- private final Class domainType;
+ private final Class> domainType;
+ private final Class returnType;
private final ReactiveFindByAnalyticsSupport reactiveSupport;
private final AnalyticsQuery query;
private final AnalyticsScanConsistency scanConsistency;
+ private final String scope;
+ private final String collection;
+ private final AnalyticsOptions options;
- ExecutableFindByAnalyticsSupport(final CouchbaseTemplate template, final Class domainType,
- final AnalyticsQuery query, final AnalyticsScanConsistency scanConsistency) {
+ ExecutableFindByAnalyticsSupport(final CouchbaseTemplate template, final Class> domainType,
+ final Class returnType, final AnalyticsQuery query, final AnalyticsScanConsistency scanConsistency,
+ final String scope, final String collection, final AnalyticsOptions options) {
this.template = template;
this.domainType = domainType;
+ this.returnType = returnType;
this.query = query;
- this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, query,
- scanConsistency, new NonReactiveSupportWrapper(template.support()));
+ this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, returnType, query,
+ scanConsistency, scope, collection, options, new NonReactiveSupportWrapper(template.support()));
this.scanConsistency = scanConsistency;
+ this.scope = scope;
+ this.collection = collection;
+ this.options = options;
}
@Override
@@ -74,18 +84,49 @@ public class ExecutableFindByAnalyticsOperationSupport implements ExecutableFind
@Override
public TerminatingFindByAnalytics matching(final AnalyticsQuery query) {
- return new ExecutableFindByAnalyticsSupport<>(template, domainType, query, scanConsistency);
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
+ }
+
+ @Override
+ public FindByAnalyticsWithQuery withOptions(final AnalyticsOptions options) {
+ Assert.notNull(options, "Options must not be null.");
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
+ }
+
+ @Override
+ public FindByAnalyticsInCollection inScope(final String scope) {
+ Assert.hasText(scope, "Scope must not be null nor empty.");
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
+ }
+
+ @Override
+ public FindByAnalyticsWithConsistency inCollection(final String collection) {
+ Assert.hasText(collection, "Collection must not be null nor empty.");
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
}
@Override
@Deprecated
public FindByAnalyticsWithQuery consistentWith(final AnalyticsScanConsistency scanConsistency) {
- return new ExecutableFindByAnalyticsSupport<>(template, domainType, query, scanConsistency);
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
}
@Override
public FindByAnalyticsWithConsistency withConsistency(final AnalyticsScanConsistency scanConsistency) {
- return new ExecutableFindByAnalyticsSupport<>(template, domainType, query, scanConsistency);
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
+ }
+
+ @Override
+ public FindByAnalyticsWithConsistency as(final Class returnType) {
+ Assert.notNull(returnType, "returnType must not be null!");
+ return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options);
}
@Override
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperation.java
index ba6fee1f..b2ce5dfd 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperation.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,9 +18,19 @@ package org.springframework.data.couchbase.core;
import java.util.Collection;
import org.springframework.data.couchbase.core.support.OneAndAllId;
-import org.springframework.data.couchbase.core.support.WithCollection;
+import org.springframework.data.couchbase.core.support.InCollection;
+import org.springframework.data.couchbase.core.support.WithGetOptions;
import org.springframework.data.couchbase.core.support.WithProjectionId;
+import org.springframework.data.couchbase.core.support.InScope;
+import com.couchbase.client.java.kv.GetOptions;
+
+/**
+ * Get Operations
+ *
+ * @author Christoph Strobl
+ * @since 2.0
+ */
public interface ExecutableFindByIdOperation {
/**
@@ -30,6 +40,11 @@ public interface ExecutableFindByIdOperation {
*/
ExecutableFindById findById(Class domainType);
+ /**
+ * Terminating operations invoking the actual execution.
+ *
+ * @param the entity type to use for the results.
+ */
interface TerminatingFindById extends OneAndAllId {
/**
@@ -50,28 +65,66 @@ public interface ExecutableFindByIdOperation {
}
- interface FindByIdWithCollection extends TerminatingFindById, WithCollection {
-
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByIdWithOptions extends TerminatingFindById, WithGetOptions {
/**
- * Allows to specify a different collection than the default one configured.
+ * Fluent method to specify options to use for execution
*
- * @param collection the collection to use in this scope.
+ * @param options options to use for execution
*/
- TerminatingFindById inCollection(String collection);
-
+ @Override
+ TerminatingFindById withOptions(GetOptions options);
}
- interface FindByIdWithProjection extends FindByIdWithCollection, WithProjectionId {
+ /**
+ * Fluent method to specify the collection.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByIdInCollection extends FindByIdWithOptions, InCollection {
+ /**
+ * With a different collection
+ *
+ * @param collection the collection to use.
+ */
+ @Override
+ FindByIdWithOptions inCollection(String collection);
+ }
+ /**
+ * Fluent method to specify the scope.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByIdInScope extends FindByIdInCollection, InScope {
+ /**
+ * With a different scope
+ *
+ * @param scope the scope to use.
+ */
+ @Override
+ FindByIdInCollection inScope(String scope);
+ }
+
+ interface FindByIdWithProjection extends FindByIdInScope, WithProjectionId {
/**
* Load only certain fields for the document.
*
* @param fields the projected fields to load.
*/
- FindByIdWithCollection project(String... fields);
-
+ @Override
+ FindByIdInScope project(String... fields);
}
+ /**
+ * Provides methods for constructing query operations in a fluent way.
+ *
+ * @param the entity type to use for the results
+ */
interface ExecutableFindById extends FindByIdWithProjection {}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java
index 5948c806..b1d07be5 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java
@@ -22,6 +22,8 @@ import java.util.List;
import org.springframework.data.couchbase.core.ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport;
import org.springframework.util.Assert;
+import com.couchbase.client.java.kv.GetOptions;
+
public class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOperation {
private final CouchbaseTemplate template;
@@ -32,23 +34,29 @@ public class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOpe
@Override
public ExecutableFindById findById(Class domainType) {
- return new ExecutableFindByIdSupport<>(template, domainType, null, null);
+ return new ExecutableFindByIdSupport<>(template, domainType, null, null, null, null);
}
static class ExecutableFindByIdSupport implements ExecutableFindById {
private final CouchbaseTemplate template;
private final Class domainType;
+ private final String scope;
private final String collection;
+ private final GetOptions options;
private final List fields;
private final ReactiveFindByIdSupport reactiveSupport;
- ExecutableFindByIdSupport(CouchbaseTemplate template, Class domainType, String collection, List fields) {
+ ExecutableFindByIdSupport(CouchbaseTemplate template, Class domainType, String scope, String collection,
+ GetOptions options, List fields) {
this.template = template;
this.domainType = domainType;
+ this.scope = scope;
this.collection = collection;
+ this.options = options;
this.fields = fields;
- this.reactiveSupport = new ReactiveFindByIdSupport<>(template.reactive(), domainType, collection, fields, new NonReactiveSupportWrapper(template.support()));
+ this.reactiveSupport = new ReactiveFindByIdSupport<>(template.reactive(), domainType, scope, collection, options,
+ fields, new NonReactiveSupportWrapper(template.support()));
}
@Override
@@ -62,16 +70,29 @@ public class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOpe
}
@Override
- public TerminatingFindById inCollection(final String collection) {
- Assert.hasText(collection, "Collection must not be null nor empty.");
- return new ExecutableFindByIdSupport<>(template, domainType, collection, fields);
+ public TerminatingFindById withOptions(final GetOptions options) {
+ Assert.notNull(options, "Options must not be null.");
+ return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
}
@Override
- public FindByIdWithCollection project(String... fields) {
- Assert.notEmpty(fields, "Fields must not be null nor empty.");
- return new ExecutableFindByIdSupport<>(template, domainType, collection, Arrays.asList(fields));
+ public FindByIdWithOptions inCollection(final String collection) {
+ Assert.hasText(collection, "Collection must not be null nor empty.");
+ return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
}
+
+ @Override
+ public FindByIdInCollection inScope(final String scope) {
+ Assert.hasText(scope, "Scope must not be null nor empty.");
+ return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
+ }
+
+ @Override
+ public FindByIdInScope project(String... fields) {
+ Assert.notEmpty(fields, "Fields must not be null nor empty.");
+ return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, Arrays.asList(fields));
+ }
+
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperation.java
index 39e6c990..8e6e603a 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperation.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,16 +22,24 @@ import java.util.stream.Stream;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.data.couchbase.core.query.QueryCriteriaDefinition;
+import org.springframework.data.couchbase.core.support.InCollection;
+import org.springframework.data.couchbase.core.support.InScope;
import org.springframework.data.couchbase.core.support.OneAndAll;
-import org.springframework.data.couchbase.core.support.WithCollection;
import org.springframework.data.couchbase.core.support.WithConsistency;
import org.springframework.data.couchbase.core.support.WithDistinct;
-import org.springframework.data.couchbase.core.support.WithProjection;
import org.springframework.data.couchbase.core.support.WithQuery;
+import org.springframework.data.couchbase.core.support.WithQueryOptions;
import org.springframework.lang.Nullable;
+import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryScanConsistency;
+/**
+ * Query Operations
+ *
+ * @author Christoph Strobl
+ * @since 2.0
+ */
public interface ExecutableFindByQueryOperation {
/**
@@ -41,13 +49,18 @@ public interface ExecutableFindByQueryOperation {
*/
ExecutableFindByQuery findByQuery(Class domainType);
+ /**
+ * Terminating operations invoking the actual execution.
+ */
interface TerminatingFindByQuery extends OneAndAll {
+
/**
* Get exactly zero or one result.
*
* @return {@link Optional#empty()} if no match found.
* @throws IncorrectResultSizeDataAccessException if more than one match found.
*/
+ @Override
default Optional one() {
return Optional.ofNullable(oneValue());
}
@@ -59,6 +72,7 @@ public interface ExecutableFindByQueryOperation {
* @throws IncorrectResultSizeDataAccessException if more than one match found.
*/
@Nullable
+ @Override
T oneValue();
/**
@@ -66,6 +80,7 @@ public interface ExecutableFindByQueryOperation {
*
* @return {@link Optional#empty()} if no match found.
*/
+ @Override
default Optional first() {
return Optional.ofNullable(firstValue());
}
@@ -76,13 +91,15 @@ public interface ExecutableFindByQueryOperation {
* @return {@literal null} if no match found.
*/
@Nullable
+ @Override
T firstValue();
/**
- * Get all matching elements.
+ * Get all matching documents.
*
* @return never {@literal null}.
*/
+ @Override
List all();
/**
@@ -90,6 +107,7 @@ public interface ExecutableFindByQueryOperation {
*
* @return a {@link Stream} of results. Never {@literal null}.
*/
+ @Override
Stream stream();
/**
@@ -97,6 +115,7 @@ public interface ExecutableFindByQueryOperation {
*
* @return total number of matching elements.
*/
+ @Override
long count();
/**
@@ -104,15 +123,15 @@ public interface ExecutableFindByQueryOperation {
*
* @return {@literal true} if at least one matching element exists.
*/
+ @Override
boolean exists();
}
/**
- * Terminating operations invoking the actual query execution.
+ * Fluent methods to specify the query
*
- * @author Christoph Strobl
- * @since 2.0
+ * @param the entity type to use for the results.
*/
interface FindByQueryWithQuery extends TerminatingFindByQuery, WithQuery {
@@ -122,6 +141,7 @@ public interface ExecutableFindByQueryOperation {
* @param query must not be {@literal null}.
* @throws IllegalArgumentException if query is {@literal null}.
*/
+ @Override
TerminatingFindByQuery matching(Query query);
/**
@@ -131,25 +151,65 @@ public interface ExecutableFindByQueryOperation {
* @return new instance of {@link ExecutableFindByQuery}.
* @throws IllegalArgumentException if criteria is {@literal null}.
*/
+ @Override
default TerminatingFindByQuery matching(QueryCriteriaDefinition criteria) {
return matching(Query.query(criteria));
}
}
- interface FindByQueryInCollection extends FindByQueryWithQuery, WithCollection {
-
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByQueryWithOptions extends FindByQueryWithQuery, WithQueryOptions {
/**
- * Allows to override the default scan consistency.
+ * Fluent method to specify options to use for execution
*
- * @param collection the collection to use for this query.
+ * @param options to use for execution
*/
- FindByQueryWithQuery inCollection(String collection);
-
+ @Override
+ TerminatingFindByQuery withOptions(QueryOptions options);
}
+ /**
+ * Fluent method to specify the collection.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByQueryInCollection extends FindByQueryWithOptions, InCollection {
+ /**
+ * With a different collection
+ *
+ * @param collection the collection to use.
+ */
+ @Override
+ FindByQueryWithOptions inCollection(String collection);
+ }
+
+ /**
+ * Fluent method to specify the scope.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindByQueryInScope extends FindByQueryInCollection, InScope {
+ /**
+ * With a different scope
+ *
+ * @param scope the scope to use.
+ */
+ @Override
+ FindByQueryInCollection inScope(String scope);
+ }
+
+ /**
+ * To be removed at the next major release. use WithConsistency instead
+ *
+ * @param the entity type to use for the results.
+ */
@Deprecated
- interface FindByQueryConsistentWith extends FindByQueryInCollection {
+ interface FindByQueryConsistentWith extends FindByQueryInScope {
/**
* Allows to override the default scan consistency.
@@ -157,10 +217,14 @@ public interface ExecutableFindByQueryOperation {
* @param scanConsistency the custom scan consistency to use for this query.
*/
@Deprecated
- FindByQueryInCollection consistentWith(QueryScanConsistency scanConsistency);
-
+ FindByQueryInScope consistentWith(QueryScanConsistency scanConsistency);
}
+ /**
+ * Fluent method to specify scan consistency. Scan consistency may also come from an annotation.
+ *
+ * @param the entity type to use for the results.
+ */
interface FindByQueryWithConsistency extends FindByQueryConsistentWith, WithConsistency {
/**
@@ -168,18 +232,20 @@ public interface ExecutableFindByQueryOperation {
*
* @param scanConsistency the custom scan consistency to use for this query.
*/
+ @Override
FindByQueryConsistentWith withConsistency(QueryScanConsistency scanConsistency);
-
}
/**
- * Result type override (Optional).
+ * Fluent method to specify a return type different than the the entity type to use for the results.
+ *
+ * @param the entity type to use for the results.
*/
interface FindByQueryWithProjection extends FindByQueryWithConsistency {
/**
* Define the target type fields should be mapped to.
- * Skip this step if you are anyway only interested in the original domain type.
+ * Skip this step if you are only interested in the original the entity type to use for the results.
*
* @param returnType must not be {@literal null}.
* @return new instance of {@link FindByQueryWithProjection}.
@@ -189,7 +255,9 @@ public interface ExecutableFindByQueryOperation {
}
/**
- * Distinct Find support.
+ * Fluent method to specify DISTINCT fields
+ *
+ * @param the entity type to use for the results.
*/
interface FindByQueryWithDistinct extends FindByQueryWithProjection, WithDistinct {
@@ -200,14 +268,15 @@ public interface ExecutableFindByQueryOperation {
* @return new instance of {@link ExecutableFindByQuery}.
* @throws IllegalArgumentException if field is {@literal null}.
*/
+ @Override
FindByQueryWithProjection distinct(String[] distinctFields);
-
}
/**
- * {@link ExecutableFindByQuery} provides methods for constructing lookup operations in a fluent way.
+ * Provides methods for constructing query operations in a fluent way.
+ *
+ * @param the entity type to use for the results
*/
-
interface ExecutableFindByQuery extends FindByQueryWithDistinct {}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java
index 7e95be43..86cb5880 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java
@@ -22,6 +22,7 @@ import org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSuppo
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.util.Assert;
+import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryScanConsistency;
/**
@@ -42,8 +43,8 @@ public class ExecutableFindByQueryOperationSupport implements ExecutableFindByQu
@Override
public ExecutableFindByQuery findByQuery(final Class domainType) {
- return new ExecutableFindByQuerySupport(template, domainType, domainType, ALL_QUERY,
- QueryScanConsistency.NOT_BOUNDED, null, null);
+ return new ExecutableFindByQuerySupport(template, domainType, domainType, ALL_QUERY, null, null, null, null,
+ null);
}
static class ExecutableFindByQuerySupport implements ExecutableFindByQuery {
@@ -54,20 +55,24 @@ public class ExecutableFindByQueryOperationSupport implements ExecutableFindByQu
private final Query query;
private final ReactiveFindByQuerySupport reactiveSupport;
private final QueryScanConsistency scanConsistency;
+ private final String scope;
private final String collection;
+ private final QueryOptions options;
private final String[] distinctFields;
ExecutableFindByQuerySupport(final CouchbaseTemplate template, final Class> domainType, final Class returnType,
- final Query query, final QueryScanConsistency scanConsistency, final String collection,
- final String[] distinctFields) {
+ final Query query, final QueryScanConsistency scanConsistency, final String scope, final String collection,
+ final QueryOptions options, final String[] distinctFields) {
this.template = template;
this.domainType = domainType;
this.returnType = returnType;
this.query = query;
this.reactiveSupport = new ReactiveFindByQuerySupport(template.reactive(), domainType, returnType, query,
- scanConsistency, collection, distinctFields, new NonReactiveSupportWrapper(template.support()));
+ scanConsistency, scope, collection, options, distinctFields, new NonReactiveSupportWrapper(template.support()));
this.scanConsistency = scanConsistency;
+ this.scope = scope;
this.collection = collection;
+ this.options = options;
this.distinctFields = distinctFields;
}
@@ -94,42 +99,35 @@ public class ExecutableFindByQueryOperationSupport implements ExecutableFindByQu
} else {
scanCons = scanConsistency;
}
- return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanCons, collection,
- distinctFields);
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanCons, scope, collection,
+ options, distinctFields);
}
@Override
@Deprecated
- public FindByQueryInCollection consistentWith(final QueryScanConsistency scanConsistency) {
- return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, collection,
- distinctFields);
+ public FindByQueryInScope consistentWith(final QueryScanConsistency scanConsistency) {
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
}
@Override
public FindByQueryConsistentWith withConsistency(final QueryScanConsistency scanConsistency) {
- return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, collection,
- distinctFields);
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
}
@Override
- public FindByQueryWithConsistency inCollection(final String collection) {
- Assert.hasText(collection, "Collection must not be null nor empty.");
- return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, collection,
- distinctFields);
- }
-
- @Override
- public FindByQueryWithConsistency as(final Class resturnType) {
- Assert.notNull(resturnType, "returnType must not be null!");
- return new ExecutableFindByQuerySupport<>(template, domainType, resturnType, query, scanConsistency, collection,
- distinctFields);
+ public FindByQueryWithConsistency as(final Class returnType) {
+ Assert.notNull(returnType, "returnType must not be null!");
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
}
@Override
public FindByQueryWithProjection distinct(final String[] distinctFields) {
Assert.notNull(distinctFields, "distinctFields must not be null!");
- return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, collection,
- distinctFields);
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
}
@Override
@@ -146,6 +144,28 @@ public class ExecutableFindByQueryOperationSupport implements ExecutableFindByQu
public boolean exists() {
return count() > 0;
}
+
+ @Override
+ public TerminatingFindByQuery withOptions(final QueryOptions options) {
+ Assert.notNull(options, "Options must not be null.");
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
+ }
+
+ @Override
+ public FindByQueryInCollection inScope(final String scope) {
+ Assert.hasText(scope, "Scope must not be null nor empty.");
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
+ }
+
+ @Override
+ public FindByQueryWithConsistency inCollection(final String collection) {
+ Assert.hasText(collection, "Collection must not be null nor empty.");
+ return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
+ collection, options, distinctFields);
+ }
+
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperation.java
index bc744bce..7a7b13de 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperation.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,25 +18,100 @@ package org.springframework.data.couchbase.core;
import java.util.Collection;
import org.springframework.data.couchbase.core.support.AnyId;
-import org.springframework.data.couchbase.core.support.WithCollection;
+import org.springframework.data.couchbase.core.support.InCollection;
+import org.springframework.data.couchbase.core.support.InScope;
+import org.springframework.data.couchbase.core.support.WithGetAnyReplicaOptions;
+import com.couchbase.client.java.kv.GetAnyReplicaOptions;
+
+/**
+ * Query Operations
+ *
+ * @author Christoph Strobl
+ * @since 2.0
+ */
public interface ExecutableFindFromReplicasByIdOperation {
+ /**
+ * Loads a document from a replica.
+ *
+ * @param domainType the entity type to use for the results.
+ */
ExecutableFindFromReplicasById findFromReplicasById(Class domainType);
+ /**
+ * Terminating operations invoking the actual get execution.
+ */
interface TerminatingFindFromReplicasById extends AnyId {
-
+ /**
+ * Finds one document based on the given ID.
+ *
+ * @param id the document ID.
+ * @return the entity if found.
+ */
+ @Override
T any(String id);
-
+ /**
+ * Finds a list of documents based on the given IDs.
+ *
+ * @param ids the document ID ids.
+ * @return the list of found entities.
+ */
+ @Override
Collection extends T> any(Collection ids);
}
- interface FindFromReplicasByIdWithCollection extends TerminatingFindFromReplicasById, WithCollection {
-
- TerminatingFindFromReplicasById inCollection(String collection);
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindFromReplicasByIdWithOptions extends TerminatingFindFromReplicasById, WithGetAnyReplicaOptions {
+ /**
+ * Fluent method to specify options to use for execution
+ *
+ * @param options options to use for execution
+ */
+ @Override
+ TerminatingFindFromReplicasById withOptions(GetAnyReplicaOptions options);
}
- interface ExecutableFindFromReplicasById extends FindFromReplicasByIdWithCollection {}
+ /**
+ * Fluent method to specify the collection.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindFromReplicasByIdInCollection extends FindFromReplicasByIdWithOptions, InCollection {
+ /**
+ * With a different collection
+ *
+ * @param collection the collection to use.
+ */
+ @Override
+ FindFromReplicasByIdWithOptions inCollection(String collection);
+ }
+
+ /**
+ * Fluent method to specify the scope.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindFromReplicasByIdInScope extends FindFromReplicasByIdInCollection, InScope {
+ /**
+ * With a different scope
+ *
+ * @param scope the scope to use.
+ */
+ @Override
+ FindFromReplicasByIdInCollection inScope(String scope);
+ }
+
+ /**
+ * Provides methods for constructing get operations in a fluent way.
+ *
+ * @param the entity type to use for the results
+ */
+ interface ExecutableFindFromReplicasById extends FindFromReplicasByIdInScope {}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java
index fa81cf63..5ef12b54 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java
@@ -18,6 +18,8 @@ package org.springframework.data.couchbase.core;
import java.util.Collection;
import org.springframework.data.couchbase.core.ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport;
+
+import com.couchbase.client.java.kv.GetAnyReplicaOptions;
import org.springframework.util.Assert;
public class ExecutableFindFromReplicasByIdOperationSupport implements ExecutableFindFromReplicasByIdOperation {
@@ -30,7 +32,7 @@ public class ExecutableFindFromReplicasByIdOperationSupport implements Executabl
@Override
public ExecutableFindFromReplicasById findFromReplicasById(Class domainType) {
- return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType, null);
+ return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType, null, null, null);
}
static class ExecutableFindFromReplicasByIdSupport implements ExecutableFindFromReplicasById {
@@ -38,17 +40,21 @@ public class ExecutableFindFromReplicasByIdOperationSupport implements Executabl
private final CouchbaseTemplate template;
private final Class> domainType;
private final Class returnType;
+ private final String scope;
private final String collection;
+ private final GetAnyReplicaOptions options;
private final ReactiveFindFromReplicasByIdSupport reactiveSupport;
ExecutableFindFromReplicasByIdSupport(CouchbaseTemplate template, Class> domainType, Class returnType,
- String collection) {
+ String scope, String collection, GetAnyReplicaOptions options) {
this.template = template;
this.domainType = domainType;
+ this.scope = scope;
this.collection = collection;
+ this.options = options;
this.returnType = returnType;
this.reactiveSupport = new ReactiveFindFromReplicasByIdSupport<>(template.reactive(), domainType, returnType,
- collection, new NonReactiveSupportWrapper(template.support()));
+ scope, collection, options, new NonReactiveSupportWrapper(template.support()));
}
@Override
@@ -62,9 +68,21 @@ public class ExecutableFindFromReplicasByIdOperationSupport implements Executabl
}
@Override
- public TerminatingFindFromReplicasById inCollection(final String collection) {
+ public TerminatingFindFromReplicasById withOptions(final GetAnyReplicaOptions options) {
+ Assert.notNull(options, "Options must not be null.");
+ return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
+ }
+
+ @Override
+ public FindFromReplicasByIdWithOptions inCollection(final String collection) {
Assert.hasText(collection, "Collection must not be null nor empty.");
- return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, collection);
+ return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
+ }
+
+ @Override
+ public FindFromReplicasByIdInCollection inScope(final String scope) {
+ Assert.hasText(scope, "Scope must not be null nor empty.");
+ return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
}
}
diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java
index 7451b631..0c28fc4d 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors
+ * Copyright 2012-2021 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,37 +18,107 @@ package org.springframework.data.couchbase.core;
import java.time.Duration;
import java.util.Collection;
+import org.springframework.data.couchbase.core.support.InCollection;
+import org.springframework.data.couchbase.core.support.InScope;
import org.springframework.data.couchbase.core.support.OneAndAllEntity;
-import org.springframework.data.couchbase.core.support.WithCollection;
+import org.springframework.data.couchbase.core.support.WithInsertOptions;
import com.couchbase.client.core.msg.kv.DurabilityLevel;
+import com.couchbase.client.java.kv.InsertOptions;
import com.couchbase.client.java.kv.PersistTo;
import com.couchbase.client.java.kv.ReplicateTo;
+/**
+ * Insert Operations
+ *
+ * @author Christoph Strobl
+ * @since 2.0
+ */
public interface ExecutableInsertByIdOperation {
+ /**
+ * Insert using the KV service.
+ *
+ * @param domainType the entity type to insert.
+ */
ExecutableInsertById insertById(Class domainType);
+ /**
+ * Terminating operations invoking the actual execution.
+ */
interface TerminatingInsertById extends OneAndAllEntity {
+ /**
+ * Insert one entity.
+ *
+ * @return Inserted entity.
+ */
@Override
T one(T object);
+ /**
+ * Insert a collection of entities.
+ *
+ * @return Inserted entities
+ */
@Override
Collection extends T> all(Collection extends T> objects);
}
- interface InsertByIdWithCollection extends TerminatingInsertById, WithCollection {
-
- TerminatingInsertById inCollection(String collection);
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use.
+ */
+ interface InsertByIdWithOptions
+ extends TerminatingInsertById, WithInsertOptions