Skip to content

Scope and collection API for template. #1133

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

Merged
merged 16 commits into from
Jun 2, 2021

Conversation

mikereiche
Copy link
Collaborator

Scope and collection API for template.

Closes #963.
Original pull request: #1071.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

…name.

Queries on field annotated properties have original name.

They should use getFieldName() which will use the annotated if it exists.
@mikereiche mikereiche force-pushed the datacouch_963_scope_and_collection_api_main branch from a11a3ff to bb8e690 Compare April 26, 2021 21:38
Scope and Collection API for template.

Closes #963.
Original pull request: #1071.
@mikereiche mikereiche force-pushed the datacouch_963_scope_and_collection_api_main branch from bb8e690 to 46072dc Compare April 26, 2021 21:56
if (cmc.isAutoIndexCreation()) {
indexCreator = new CouchbasePersistentEntityIndexCreator(cmc, this);
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just formatting changes

*
* @author Christoph Strobl
* @since 2.0
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm just adding javadoc that was missing. As near as I can figure, the original author was Christoph

return new ExecutableFindByQuerySupport<T>(template, domainType, domainType, ALL_QUERY,
QueryScanConsistency.NOT_BOUNDED, null, null);
return new ExecutableFindByQuerySupport<T>(template, domainType, domainType, ALL_QUERY, null, null, null, null,
null);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

replace the default QueryScanConsistency.NOT_BOUNDED with null.
If it is not null, it will override the scanConsistency on the QueryOptions, if provided.

.getCollection(pArgs.getCollection()).reactive()
.replace(converted.getId(), converted.export(), buildReplaceOptions(pArgs.getOptions(), object, converted))
.flatMap(result -> support.applyUpdatedId(object, converted.getId())
.flatMap(replacedObject -> (Mono<T>) support.applyUpdatedCas(replacedObject, result.cas())))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The cast to Mono is necessary here because support (ReactiveTemplateSupport) is not parameterized with the entity type, the method just returns an Object. One day I will fix that.

.append('`').toString();
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know why this appears after rebasing. It should have already been in master (?????)

@@ -72,7 +76,7 @@ void shouldSaveAndFindAll() {
Airport vie = null;
Airport jfk = null;
try {
vie = new Airport("airports::vie", "vie", "loww");
vie = new Airport("airports::vie", "vie", "low1");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After running tests, I found some "vie", "loww" Airport records. So I made them unique to figure out what test was creating them and not deleting them.

@@ -59,7 +59,7 @@ ClusterType type() {

@Override
TestClusterConfig _start() throws Exception {
bucketname = UUID.randomUUID().toString();
bucketname = "my_bucket"; // UUID.randomUUID().toString();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reuse "my_bucket" if it already exists. Creating the indexes, scopes and collections takes time.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you do that, you also remove the natural isolation of each test, since indexes and/or data might be left behind or still on there. If you take that into account it is fine, just wanted to mention it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are some tests that don't delete everything they've inserted. So I will remove this change from the changeset and leave it for later when I have had time to verify that all the tests clean up after themselves.

mikereiche and others added 2 commits May 4, 2021 07:25
@daschl daschl self-requested a review May 6, 2021 14:07
Copy link
Contributor

@daschl daschl left a comment

Choose a reason for hiding this comment

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

This change looks veeery solid already, most of my comments are nits and small changes -- should be able to merge afterwards

pom.xml Outdated
@@ -173,6 +173,7 @@
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.1.0.RELEASE</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

latest one is 3.4.6, might cause issues with testing when using such an old version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to 3.4.6. Seems ok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed one instance and removed the other (duplicate).

/**
* {@inheritDoc}
*/
public void setThreadLocalArgs(PseudoArgs pseudoArgs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is something internal, can it 1) be package private or 2) if not, add a comment that it is internal?

Copy link
Collaborator Author

@mikereiche mikereiche May 17, 2021

Choose a reason for hiding this comment

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

Changed to package private.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unused. Removed.

import com.couchbase.client.java.kv.ReplicateTo;

/**
* Insert Operations
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 error ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed. For real, this time.
I'm not sure what happened to the things that are marked "fixed". Either I just marked them "fixed" without actually fixing them, or a pull/rebase un-fixed them.

/**
* @param pseudoArgs - the metaArgs to set on the ThreadLocal field of the CouchbaseOperations
*/
void setThreadLocalArgs(PseudoArgs<?> pseudoArgs);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should also be named getPseudoArgs and setPseudoArgs? the thread local would be an implementation detail

void setThreadLocalArgs(PseudoArgs<?> pseudoArgs);

/**
* @@return the metaArgs from the ThreadLocal field of the CouchbaseOperations
Copy link
Contributor

Choose a reason for hiding this comment

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

two @

*
* @author Michael Reiche
* @param <T> - the entity class
*/
public interface WithCollection<T> {
Object inCollection(String collectionName);
public interface InScope<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't T unused?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's not used. Ideally, the methods in all these With* interfaces would return a parameterized interface as in the Override and implementation. However, there is no common interface for all the different operations. So I just define it to return Object, and T is not used. I would like to leave the parameter there, in hopes that I eventually figure out how to define it properly.

interface FindByQueryInScope<T> extends FindByQueryInCollection<T>, InScope<T> {
	/**
	 * With a different scope
	 *
	 * @param scope the scope to use.
	 */
	@Override
	FindByQueryInCollection<T> inScope(String scope);
}

@@ -18,11 +18,16 @@
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;

/**
* A common interface for all of Insert, Replace, Upsert that take consistency
* Interface for operations that take AnalyticsScanConsistency
*
* @author Michael Reiche
* @param <T> - the entity class
*/
public interface WithAnalyticsConsistency<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

unused T?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's not used. Ideally, the methods in all these With* interfaces would return a parameterized interface as in the Override and implementation. However, there is no common interface for all the different operations. So I just define it to return Object, and T is not used. I would like to leave the parameter there, in hopes that I eventually figure out how to define it properly.

* @author Michael Reiche
* @param <T> - the entity class
*/
public interface WithAnalyticsOptions<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

unused T ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it's unused. But inCollection() should return an operation, and I was hoping to figure out how to achieve that eventually.

Object inCollection(String collection);

@@ -18,11 +18,16 @@
import org.springframework.data.couchbase.core.query.AnalyticsQuery;

/**
* A common interface for all of Insert, Replace, Upsert that take Query
* Interface for operations that take AnalyticsQuery
*
* @author Michael Reiche
* @param <T> - the entity class
*/
public interface WithAnalyticsQuery<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll stop with the T unused comment, please look through the others if valid too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's not used. Ideally, the methods in all these With* interfaces would return a parameterized interface as in the Override and implementation. However, there is no common interface for all the different operations. So I just define it to return Object, and T is not used. I would like to leave the parameter there, in hopes that I eventually figure out how to define it properly.

@@ -86,7 +87,8 @@ protected Object doExecute(CouchbaseQueryMethod method, ResultProcessor processo
ExecutableFindByQuery<?> find = typeToRead == null ? findOperationWithProjection //
: findOperationWithProjection; // not yet implemented in core .as(typeToRead);

String collection = "_default._default";// method.getEntityInformation().getCollectionName(); // not yet implemented
// TODO (maybe) // method.getEntityInformation().getCollectionName(); // not yet implemented
Copy link
Contributor

Choose a reason for hiding this comment

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

should a ticket be filed for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is irrelevant now. This _default._default is ignored.

…name.

Queries on field annotated properties have original name.

They should use getFieldName() which will use the annotated if it exists.
Scope and Collection API for template.

Closes #963.
Original pull request: #1071.
…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
pom.xml Outdated
@@ -173,6 +173,7 @@
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<version>3.1.0.RELEASE</version>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed one instance and removed the other (duplicate).

pom.xml Outdated
<source>8</source>
<target>8</target>
</configuration>
</plugin>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed. Shouldn't need this.

/**
* {@inheritDoc}
*/
public void setThreadLocalArgs(PseudoArgs pseudoArgs) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unused. Removed.

return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, collection,
distinctFields);
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
collection, options, distinctFields);
}

@Override
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

InCollection (below) got moved to the end. It is not missing.

import com.couchbase.client.java.kv.ReplicateTo;

/**
* Insert Operations
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed. For real, this time.
I'm not sure what happened to the things that are marked "fixed". Either I just marked them "fixed" without actually fixing them, or a pull/rebase un-fixed them.


/**
* Insert Operations
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

@@ -31,4 +31,6 @@
* The field name can be different from the actual property name by using a custom annotation.
*/
String getFieldName();

Boolean isExpirationProperty();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to unboxed boolean.
But leaving as "is..." to be consistent with isIdProperty() and isVersionProperty() from PersistentProperty.

boolean isIdProperty();
boolean isVersionProperty();

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
public @interface Expiration {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It represents META().expiration so I named it Expiration. Did you still want it renamed? I could go either way.

* @author Michael Reiche
* @param <T> - the entity class
*/
public interface InCollection<T> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it's unused. But inCollection() should return an operation, and I was hoping to figure out how to achieve that eventually.

Object inCollection(String collection);

* @author Michael Reiche
* @param <T> - the entity class
*/
public interface WithAnalyticsOptions<T> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it's unused. But inCollection() should return an operation, and I was hoping to figure out how to achieve that eventually.

Object inCollection(String collection);

…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
…com:spring-projects/spring-data-couchbase into datacouch_963_scope_and_collection_api_main
@mikereiche mikereiche merged commit 43889e6 into main Jun 2, 2021
mikereiche added a commit that referenced this pull request Aug 9, 2021
Scope and Collection API for template.

Closes #963.
Original pull request: #1071.
@mikereiche mikereiche deleted the datacouch_963_scope_and_collection_api_main branch August 11, 2021 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Scope and Collection API Changes [DATACOUCH-655]
4 participants