Skip to content

DATACOUCH-963 - Scope and collection api. #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
Expand Down Expand Up @@ -173,6 +173,7 @@
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.1.0.RELEASE</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -216,11 +217,11 @@
<id>sonatype-snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>jitpack.io</id>
Expand Down Expand Up @@ -284,6 +285,14 @@
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -180,4 +181,12 @@ private void prepareIndexCreator(final ApplicationContext context) {
}
}
}

/**
* {@inheritDoc}
*/
public void setThreadLocalArgs(PseudoArgs pseudoArgs) {
reactiveCouchbaseTemplate.setThreadLocalArgs(pseudoArgs);
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,16 +18,29 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy/paste?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - I tried to fill in some of the missing javadoc. From looking at javadoc on other classes that would have been created at the same time, I assumed the same author.

* @since 2.0
*/
public interface ExecutableExistsByIdOperation {

/**
* Checks if the document exists in the bucket.
*/
ExecutableExistsById existsById();

/**
* Terminating operations invoking the actual execution.
*/
interface TerminatingExistsById extends OneAndAllExists {

/**
Expand All @@ -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);

/**
Expand All @@ -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<String, Boolean> all(Collection<String> ids);
}

/**
* Fluent method to specify options.
*
* @param <T> the entity type to use for the results.
*/
interface ExistsByIdWithOptions<T> extends TerminatingExistsById, WithExistsOptions<T> {
/**
* 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 <T> the entity type to use for the results.
*/
interface ExistsByIdInCollection<T> extends ExistsByIdWithOptions<T>, InCollection<T> {
/**
* With a different collection
*
* @param collection the collection to use.
*/
@Override
ExistsByIdWithOptions<T> inCollection(String collection);
}

/**
* Fluent method to specify the scope.
*
* @param <T> the entity type to use for the results.
*/
interface ExistsByIdInScope<T> extends ExistsByIdInCollection<T>, InScope<T> {
/**
* 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<T> inScope(String scope);
}

interface ExecutableExistsById extends ExistsByIdWithCollection {}
/**
* Provides methods for constructing KV exists operations in a fluent way.
*/
interface ExecutableExistsById extends ExistsByIdInScope {}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -56,11 +65,22 @@ public Map<String, Boolean> all(final Collection<String> 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was the assertion removed by accident? I wonder if it makes sense to validate those as well (also inScope)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At one point I removed the assertion to allow just calling without checking if the caller was using collections or not. That said - I put the assertion back in and all the tests pass - so it seems I'm not doing that anymore. I'll put it back for scope and collection.

}

@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);
}
}

}
Loading