-
Notifications
You must be signed in to change notification settings - Fork 191
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
Scopes and collections for repositories #1149
Conversation
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
a58d95c
to
cabef91
Compare
src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
Show resolved
Hide resolved
.../java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java
Show resolved
Hide resolved
.../java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseOperations.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplateSupport.java
Show resolved
Hide resolved
...g/springframework/data/couchbase/repository/auditing/ReactiveCouchbaseAuditingRegistrar.java
Show resolved
Hide resolved
...main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryBase.java
Show resolved
Hide resolved
...a/org/springframework/data/couchbase/repository/support/CrudMethodMetadataPostProcessor.java
Show resolved
Hide resolved
throw ite.getCause(); | ||
} | ||
return result; | ||
} |
There was a problem hiding this comment.
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.
...org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java
Show resolved
Hide resolved
cabef91
to
948811b
Compare
src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/mapping/Expiry.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java
Show resolved
Hide resolved
@@ -43,4 +47,8 @@ | |||
@Override | |||
List<T> findAllById(Iterable<ID> iterable); | |||
|
|||
CouchbaseEntityInformation<T, String> getEntityInformation(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
948811b
to
39233d9
Compare
9eb6e9a
to
3aaeaa0
Compare
There was a problem hiding this 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)
...ain/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentEntity.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java
Show resolved
Hide resolved
...main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryBase.java
Show resolved
Hide resolved
} | ||
|
||
/** | ||
* Get the Scope from <br> |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
There was a problem hiding this comment.
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.
...a/org/springframework/data/couchbase/repository/support/CrudMethodMetadataPostProcessor.java
Show resolved
Hide resolved
...org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java
Show resolved
Hide resolved
3aaeaa0
to
eb2555c
Compare
This adds scope and collection support to repositories via the DynamicInvocationHandler and PseudoArgs. It also adds annotations for scopes and collections. Closes #963
eb2555c
to
4f6b678
Compare
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."); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
...a/org/springframework/data/couchbase/repository/support/CrudMethodMetadataPostProcessor.java
Show resolved
Hide resolved
* 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]>
This reverts commit 1581712.
This adds scope and collection support to repositories via the
DynamicInvocationHandler and PseudoArgs.
It also adds annotations for scopes and collections.
Closes #963