diff --git a/pom.xml b/pom.xml
index a53a6a403..734eaad1e 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
+
+
+
@@ -173,6 +173,7 @@
io.projectreactor
reactor-test
+ 3.1.0.RELEASE
test
@@ -216,11 +217,11 @@
sonatype-snapshot
https://oss.sonatype.org/content/repositories/snapshots
- true
-
+ true
+
- false
-
+ false
+
jitpack.io
@@ -284,6 +285,14 @@
org.asciidoctor
asciidoctor-maven-plugin
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 9
+ 9
+
+
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 9fc59eb3a..6ba21ac05 100644
--- a/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
+++ b/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.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.
@@ -28,6 +28,7 @@
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 CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final Couch
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
@@ -180,4 +181,12 @@ private void prepareIndexCreator(final ApplicationContext context) {
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setThreadLocalArgs(PseudoArgs pseudoArgs) {
+ reactiveCouchbaseTemplate.setThreadLocalArgs(pseudoArgs);
+ }
+
}
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 75185f521..357ba500b 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 @@
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 @@ interface TerminatingExistsById extends OneAndAllExists {
* @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 @@ interface TerminatingExistsById extends OneAndAllExists {
* @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);
+ }
+ /**
+ * Fluent method to specify options.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface ExistsByIdWithOptions extends TerminatingExistsById, WithExistsOptions {
+ /**
+ * Fluent method to specify options to use for execution
+ *
+ * @param options options to use for execution
+ */
+ @Override
+ TerminatingExistsById withOptions(ExistsOptions options);
}
- interface ExistsByIdWithCollection extends TerminatingExistsById, WithCollection {
+ /**
+ *
+ * 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 {
/**
- * Allows to specify a different collection than the default one configured.
+ * With a different scope
*
- * @param collection the collection to use in this scope.
+ * @param scope the scope to use.
*/
- TerminatingExistsById inCollection(String collection);
+ @Override
+ ExistsByIdInCollection inScope(String scope);
}
- interface ExecutableExistsById extends ExistsByIdWithCollection {}
+ /**
+ * 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 3841fa647..5484d9ab5 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 Map all(final Collection ids) {
}
@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 20962172a..2aed295fb 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 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 @@ interface FindByAnalyticsWithQuery extends TerminatingFindByAnalytics, Wit
}
+ /**
+ * 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 @@ interface FindByAnalyticsWithConsistency extends FindByAnalyticsConsistentWit
* @param scanConsistency the custom scan consistency to use for this analytics query.
*/
FindByAnalyticsConsistentWith withConsistency(AnalyticsScanConsistency scanConsistency);
+ }
+
+ /**
+ * 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 FindByAnalyticsWithConsistency {}
+ 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 d0e517136..8ba268c4a 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.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,7 +21,9 @@
import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport;
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
+import com.couchbase.client.java.analytics.AnalyticsOptions;
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
+import org.springframework.util.Assert;
public class ExecutableFindByAnalyticsOperationSupport implements ExecutableFindByAnalyticsOperation {
@@ -35,26 +37,34 @@ public ExecutableFindByAnalyticsOperationSupport(final CouchbaseTemplate templat
@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);
+ this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, returnType, query,
+ scanConsistency, scope, collection, options);
this.scanConsistency = scanConsistency;
+ this.scope = scope;
+ this.collection = collection;
+ this.options = options;
}
@Override
@@ -74,18 +84,49 @@ public List all() {
@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 ba6fee1fd..b2ce5dfda 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 @@
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 @@ interface TerminatingFindById extends OneAndAllId {
}
- 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);
+ }
+ /**
+ * 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);
}
- interface FindByIdWithProjection extends FindByIdWithCollection, WithProjectionId {
+ /**
+ * 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 caaa7c928..9fae1a790 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.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,6 +22,8 @@
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);
+ this.reactiveSupport = new ReactiveFindByIdSupport<>(template.reactive(), domainType, scope, collection, options,
+ fields);
}
@Override
@@ -62,16 +70,29 @@ public Collection extends T> all(final Collection ids) {
}
@Override
- public TerminatingFindById inCollection(final String collection) {
+ 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 FindByIdWithOptions inCollection(final String collection) {
Assert.hasText(collection, "Collection must not be null nor empty.");
- return new ExecutableFindByIdSupport<>(template, domainType, collection, fields);
+ return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
}
@Override
- public FindByIdWithCollection project(String... fields) {
+ 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, collection, Arrays.asList(fields));
+ 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 39e6c990e..8e6e603ab 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 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 @@ default Optional one() {
* @throws IncorrectResultSizeDataAccessException if more than one match found.
*/
@Nullable
+ @Override
T oneValue();
/**
@@ -66,6 +80,7 @@ default Optional one() {
*
* @return {@link Optional#empty()} if no match found.
*/
+ @Override
default Optional first() {
return Optional.ofNullable(firstValue());
}
@@ -76,13 +91,15 @@ default Optional first() {
* @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 @@ default Optional first() {
*
* @return a {@link Stream} of results. Never {@literal null}.
*/
+ @Override
Stream stream();
/**
@@ -97,6 +115,7 @@ default Optional first() {
*
* @return total number of matching elements.
*/
+ @Override
long count();
/**
@@ -104,15 +123,15 @@ default Optional first() {
*
* @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 @@ interface FindByQueryWithQuery extends TerminatingFindByQuery, WithQuery matching(Query query);
/**
@@ -131,25 +151,65 @@ interface FindByQueryWithQuery extends TerminatingFindByQuery, WithQuery 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 {
+ /**
+ * Fluent method to specify options to use for execution
+ *
+ * @param options to use for execution
+ */
+ @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 {
/**
- * Allows to override the default scan consistency.
+ * With a different collection
*
- * @param collection the collection to use for this query.
+ * @param collection the collection to use.
*/
- FindByQueryWithQuery inCollection(String collection);
+ @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 @@ interface FindByQueryConsistentWith extends FindByQueryInCollection {
* @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 @@ interface FindByQueryWithConsistency extends FindByQueryConsistentWith, Wi
*
* @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 @@ interface FindByQueryWithProjection extends FindByQueryWithConsistency {
}
/**
- * 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 @@ interface FindByQueryWithDistinct extends FindByQueryWithProjection, WithD
* @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 ee4908984..3889543d7 100644
--- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java
+++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.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,6 +22,7 @@
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 ExecutableFindByQueryOperationSupport(final CouchbaseTemplate template) {
@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 @@ static class ExecutableFindByQuerySupport implements ExecutableFindByQuery
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);
+ scanConsistency, scope, collection, options, distinctFields);
this.scanConsistency = scanConsistency;
+ this.scope = scope;
this.collection = collection;
+ this.options = options;
this.distinctFields = distinctFields;
}
@@ -94,42 +99,35 @@ public TerminatingFindByQuery matching(final Query query) {
} 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 long count() {
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 bc744bceb..7a7b13dea 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 @@
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 {
+ /**
+ * 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);
+ }
+
+ /**
+ * 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);
+ }
- TerminatingFindFromReplicasById inCollection(String collection);
+ /**
+ * Fluent method to specify the scope.
+ *
+ * @param the entity type to use for the results.
+ */
+ interface FindFromReplicasByIdInScope extends FindFromReplicasByIdInCollection, InScope