-
Notifications
You must be signed in to change notification settings - Fork 192
Change method visibility CouchbaseTemplate#support & ReactiveCouchbaseTemplate#support #1210
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
Comments
Why? How would that be configured? maintained? debugged? |
@jorgerod to clarify, the template support classes were never intended to be used publicly, that's why they are package private. If you could describe what feature you need we can see how that fits onto the public API and will also help other users along the way - thank you! |
Hello, thank you for your answers I would like to extend template with new operations. For this, it is necessary that the support is protected to be able to use it and thus to maintain the conversion of objects in the same point. I will give an example for better understanding: I want to add the public class CustomReactiveCouchbaseTemplate extends ReactiveCouchbaseTemplate {
public CustomReactiveCouchbaseTemplate(CouchbaseClientFactory clientFactory,
CouchbaseConverter converter,
TranslationService translationService) {
super(clientFactory, converter, translationService);
...
}
public <T> ReactiveFindById<T> getAndTouch(final Class<T> domainType) {
return new ReactiveGetAndTouchOperationSupport(this).getAndTouch(domainType);
}
} and I will create a support class to execute that operation. I will make the request to the database and on return I would want to use the same decodeEntity that is being used for the other operations but there is no access to the support method. public class ReactiveGetAndTouchOperationSupport {
private final CustomReactiveCouchbaseTemplate myTemplate;
public ReactiveGetAndTouchOperationSupport(CustomReactiveCouchbaseTemplate myTemplate) {
this.myTemplate= myTemplate;
}
public <T> ReactiveFindById<T> getAndTouch(Class<T> domainType) {
return new ReactiveFindByIdSupport<>(this.myTemplate, domainType, null,
null, null, null, this.myTemplate.support()); //Not compile. No visibility to the ReactiveTemplate#support
}
static class ReactiveGetAndTouchSupport<T> {
private final CustomReactiveCouchbaseTemplate myTemplate;
private ReactiveTemplateSupport support;
private final Class<T> domainType;
private final String scope;
private final String collection;
private final GetOptions options;
private final List<String> fields;
public <T> ReactiveGetAndTouchSupport(final CustomReactiveCouchbaseTemplate myTemplate, final Class<T> domainType,
final String scope, final String collection, final GetOptions options, final List<String> fields,
final ReactiveTemplateSupport support) {
this.myTemplate= myTemplate;
this.domainType = domainType;
this.scope = scope;
this.collection = collection;
this.options = options;
this.fields = fields;
this.support = support;
}
@Override
public Mono<T> one(final String id) {
return Mono.just(id).flatMap(docId -> {
final Mono<GetResult> getResultMono;
if (isTouchOnRead()) {
doGetAndTouch();
} else {
doGet();
}
return getResultMono;
})
.flatMap(result -> this.support.decodeEntity(id, result.contentAs(String.class), result.cas(),
this.domainType)) //I need ReactiveTemplateSupport for decode entity
.onErrorResume(throwable -> {
return doErrorResume();
})
.onErrorMap(throwable -> {
if (throwable instanceof RuntimeException) {
return this.template.potentiallyConvertRuntimeException((RuntimeException) throwable);
} else {
return throwable;
}
});
}
}
}
Apparently yes, because a template can be extended to add more functionality with respect to the driver. Thank you in advance |
GetAndTouch will be available tomorrow in 4.3.0-M3. #982 |
Hi @mikereiche |
Edit: If you just want to create your own CustomReactiveCouchbaseTemplate, it would need to be in the same package (or the visibility of template.support() would need to be changed). ReactiveCouchbaseTemplate and CouchbaseTemplate are not final, so it's possible - it's just that I cannot find anyone doing that.
Assuming that there was no GetAndTouch available, let's do that. Let's look at an existing operation. FindById (since you would like to create something like FindByIdAndTouch.
You will need to create four new classes:
Just copy/rename the classes we found earlier (better yet, sub-class them). Then add the withExpiry() method to them.
Then add some test cases. |
Hi
We have the need to extend the functionality of
CouchbaseTemplate
andReactiveCouchbaseTemplate
.For this, we would also need to use a custom
CouchbaseTemplateSupport
andReactiveCouchbaseTemplateSupport
but it is not possible because the support() method only has visibility.spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java
Line 196 in edaf11e
spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplate.java
Line 150 in edaf11e
It would be possible to add this method as protected or public?
Thank you very much, best regards
The text was updated successfully, but these errors were encountered: