-
Notifications
You must be signed in to change notification settings - Fork 192
Never call getAndTouch in ReactiveFindByIdOperationSupport #1634
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
Can you show the call you are making? This is the test case for getAndTouch() being used when an expiry is specified. Line 95 in d994eb7
|
Hi @mikereiche Sorry I couldn't answer you before, but I've been busy. As I understand it, to do According to the javadoc of the
And Spring Data Couchbase is not taking this property into account. In fact, reviewing Spring Data Couchbase 3x, this property is taken into account (spring-data-couchbase 3.2.9-RELEASE. (Couchbase.java): ): @Override
public <T> T findById(final String id, Class<T> entityClass) {
final CouchbasePersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(entityClass);
RawJsonDocument result = execute(new BucketCallback<RawJsonDocument>() {
@Override
public RawJsonDocument doInBucket() {
if (entity.isTouchOnRead()) {
return client.getAndTouch(id, entity.getExpiry(), RawJsonDocument.class);
} else {
return client.get(id, RawJsonDocument.class);
}
}
});
return mapToEntity(id, result, entityClass);
} Thank you very much |
Edit: it seems that relying solely on @expiry annotation would not work. "options are never initialized" It doesn't need to be initialized. from initGetOptions()
We can go back and forth with you saying that it doesn't work, and me pointing to the test that shows that it does work. The value comes from expiryToUse() in ReactiveFindByIdOperationSupport.
|
Sorry, maybe I didn't make myself clear. I'm going with an example as you asked me. Let's suppose we have the following code: package com.jorge.couchbase.reactive.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository;
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
import org.springframework.stereotype.Repository;
@Repository
interface UserWithEnableTouchOnReadRepository extends ReactiveCouchbaseRepository<UserWithEnableTouchOnRead, String> {}
@Repository
interface UserWithDisableTouchOnReadRepository extends ReactiveCouchbaseRepository<UserWithDisableTouchOnRead, String> {}
@Document(touchOnRead = true, expiry = 1000)
class UserWithEnableTouchOnRead {
String id;
String name;
public UserWithEnableTouchOnRead(String id, String name) {
this.id = id;
this.name = name;
}
}
@Document(touchOnRead = false, expiry = 1000)
class UserWithDisableTouchOnRead {
String id;
String name;
public UserWithDisableTouchOnRead(String id, String name) {
this.id = id;
this.name = name;
}
}
@SpringBootApplication
@EnableReactiveCouchbaseRepositories
public class DemoApplication implements ApplicationRunner {
@Autowired
public UserWithEnableTouchOnReadRepository userWithEnableTouchOnReadRepository;
@Autowired
public UserWithDisableTouchOnReadRepository userWithDisableTouchOnReadRepository;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
UserWithEnableTouchOnRead userWithEnableTouchOnRead = new UserWithEnableTouchOnRead("1", "1");
UserWithDisableTouchOnRead userWithDisableTouchOnRead = new UserWithDisableTouchOnRead("2", "2");
// Executes getAndTouch method
userWithEnableTouchOnReadRepository.findById(userWithEnableTouchOnRead.id);
// It executes getAndTouch method and I think it should NOT execute it.
userWithDisableTouchOnReadRepository.findById(userWithDisableTouchOnRead.id);
}
} According to the javadoc, only UserWithEnableTouchOnRead document should be executed as getAndTouch. Currently, the two documents would be consulted as getAndTouch. @mikereiche How do you see him? With the current behaviour, what is the Thank you very much for your answers and the time you are dedicating to it |
Why should it not be called?
Ignored. I was unaware of such an annotation. |
Hello
I'm trying to do a getAndTouch in the
spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java
Lines 88 to 90 in d994eb7
method and I think there is a bug.
The options are never initialized so the get method is always executed.
Related issue: #1196
Thank you very much
The text was updated successfully, but these errors were encountered: