Skip to content

Scopes and collections for repositories #1149

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

Conversation

mikereiche
Copy link
Collaborator

This adds scope and collection support to repositories via the
DynamicInvocationHandler and PseudoArgs.
It also adds annotations for scopes and collections.

Closes #963

  • 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).

Adds DynamicProxyable and DynamicInvocationHandler to
set scope/collection/options on PseudoArgs when calling
operations via repository interfaces.

Closes #963.
This adds scope and collection support to repositories via the
DynamicInvocationHandler and PseudoArgs.
It also adds annotations for scopes and collections.

Closes #963
@mikereiche mikereiche requested a review from daschl June 17, 2021 22:30
@mikereiche mikereiche force-pushed the datacouch_963_scopes_and_collections_for_repositories branch 2 times, most recently from a58d95c to cabef91 Compare June 21, 2021 23:48
throw ite.getCause();
}
return result;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

similar to CrudMethodMetadataPostProcessor - there is no need to reset the thread-local data after the call as this is in the same thread.

@mikereiche mikereiche force-pushed the datacouch_963_scopes_and_collections_for_repositories branch from cabef91 to 948811b Compare June 22, 2021 03:55
@@ -43,4 +47,8 @@
@Override
List<T> findAllById(Iterable<ID> iterable);

CouchbaseEntityInformation<T, String> getEntityInformation();
Copy link
Contributor

@daschl daschl Jun 23, 2021

Choose a reason for hiding this comment

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

is it ok to add this here @mp911de ?

[Mike Reiche] - This is no longer necessary since I refactored it into CouchbaseRepositoryBase.

Copy link
Contributor

@daschl daschl Jul 15, 2021

Choose a reason for hiding this comment

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

@mikereiche based on your comment this needs to be removed then from this PR

Copy link
Collaborator Author

@mikereiche mikereiche Jul 23, 2021

Choose a reason for hiding this comment

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

Yes. I will move it to SimpleCouchbaseRepository and SimpleReactiveCouchbaseRepository.

Edit: I will leave this here - I tried moving it to SimpleCouchbaseRepository, but casting the 'target' in DynamicInvocationHandler to a SimpleCouchbaseRepository results in a ClassCastException due to being loaded in a different class loader.

@mikereiche mikereiche force-pushed the datacouch_963_scopes_and_collections_for_repositories branch from 948811b to 39233d9 Compare June 23, 2021 19:36
@mikereiche mikereiche force-pushed the datacouch_963_scopes_and_collections_for_repositories branch 2 times, most recently from 9eb6e9a to 3aaeaa0 Compare July 9, 2021 05:27
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 is getting close -- a couple comments/nits, but the big one is still that the interfaces should not get the new public signatures I think (it's in the comments)

}

/**
* Get the Scope from <br>
Copy link
Contributor

Choose a reason for hiding this comment

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

dangling comment block?

@@ -161,10 +166,10 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
try {
return invocation.proceed();
} finally {
TransactionSynchronizationManager.unbindResource(method);
// TransactionSynchronizationManager.unbindResource(method);
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover?

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 original CrudMethodMetadataPostProcessor - copied from the JPA project - included code to bind/unbind the 'method' and push/pop the 'invocation'. The problem with unbinding/popping is that for reactive methods, that might take place before the information is consumed in the calling method. The unbinding/popping does not seem necessary as this all occurs in the same thread.

When I brought up the issue of the unbind/pop being done before the reactive methods consumed the data, the proposed solution was to capture the data in those methods before the reactive code, and pass it as an additional argument to the reactive code - which would require replicating every repository method with another one with an additional argument - which is what I proposed in the beginning - and which was rejected - and. I was told to use this mechanism instead.

@mikereiche mikereiche force-pushed the datacouch_963_scopes_and_collections_for_repositories branch from 3aaeaa0 to eb2555c Compare July 16, 2021 00:18
This adds scope and collection support to repositories via the
DynamicInvocationHandler and PseudoArgs.
It also adds annotations for scopes and collections.

Closes #963
@mikereiche mikereiche force-pushed the datacouch_963_scopes_and_collections_for_repositories branch from eb2555c to 4f6b678 Compare July 23, 2021 20:48
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
}

@Override
public FindByIdInScope<T> project(String... fields) {
Assert.notEmpty(fields, "Fields must not be null nor empty.");
Assert.notEmpty(fields, "Fields must not be 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.

Empty list means do not use the project option.

@@ -126,8 +127,9 @@ public T firstValue() {
@Override
public FindByQueryWithProjection<T> distinct(final String[] distinctFields) {
Assert.notNull(distinctFields, "distinctFields must not be null!");
String[] dFields = distinctFields.length == 1 && "-".equals(distinctFields[0]) ? null : distinctFields;
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Coming from an annotation, this cannot be null.
But a non-null but empty distinctFields means distinct on all fields
So to indicate do not use distinct, we use {"-"} from the annotation, and here we change it to null.

@@ -161,10 +166,10 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
try {
return invocation.proceed();
} finally {
TransactionSynchronizationManager.unbindResource(method);
// TransactionSynchronizationManager.unbindResource(method);
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 original CrudMethodMetadataPostProcessor - copied from the JPA project - included code to bind/unbind the 'method' and push/pop the 'invocation'. The problem with unbinding/popping is that for reactive methods, that might take place before the information is consumed in the calling method. The unbinding/popping does not seem necessary as this all occurs in the same thread.

When I brought up the issue of the unbind/pop being done before the reactive methods consumed the data, the proposed solution was to capture the data in those methods before the reactive code, and pass it as an additional argument to the reactive code - which would require replicating every repository method with another one with an additional argument - which is what I proposed in the beginning - and which was rejected - and. I was told to use this mechanism instead.

@mikereiche mikereiche merged commit 7cde6b9 into main Aug 9, 2021
mikereiche added a commit that referenced this pull request Aug 9, 2021
* Add support for scopes and collections for repositories.

Adds DynamicProxyable and DynamicInvocationHandler to
set scope/collection/options on PseudoArgs when calling
operations via repository interfaces.

Closes #963.

Co-authored-by: mikereiche <[email protected]>
mikereiche added a commit that referenced this pull request Aug 11, 2021
@mikereiche mikereiche deleted the datacouch_963_scopes_and_collections_for_repositories branch August 11, 2021 22:07
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]
2 participants