-
Notifications
You must be signed in to change notification settings - Fork 192
DATACOUCH-645 - Support Document(expiryExpression) annotation. #292
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
DATACOUCH-645 - Support Document(expiryExpression) annotation. #292
Conversation
1656820
to
7815522
Compare
1) get the expiryExpression from the converted CouchbaseDocument. 2) added interfaces for apis on core objects which are common among many objects. For instance withExpiry and withExpirty on all the insert/replace/upsert/remove objects. The definition of an interface simplyfies testing of all the possible combinations - instead of having four (or eight, counting Reactive), there is one interface to test them all.
7815522
to
d531dbd
Compare
* @param <T> - the entity class | ||
*/ | ||
public interface InCollection<T> { | ||
Object inCollection(String collection); |
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.
Mind the formatting. What's the reason for extracting all these interfaces into top-level ones? From a usage perspective, calling code would not mix replace and e.g. remove operations by reusing the same interface, would it?
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.
fixed the formatting in this and the other interfaces.
From a usage perspective, the interfaces are not helpful. However, from a testing perspective, they allow testing all the implementers of those interfaces more easily. For testing withExpiry(), @document( expiry), and @document(@expiryExpression) (which require three different entity classes) across insert, replace and upsert, that would take 3 X 3 = 9 test cases. By having insert, replace and upsert implement OneAndAll and WithExpiry, all these tests can be done in a loop as in withExpiryAndExpiryAnnotation()
https://github.com/spring-projects/spring-data-couchbase/blob/7815522d682fceb0f55082ff825e6dabbd8a9343/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java
(I was not able to figure out how to define an interface that would be also satisfied by the one() and all() of Remove)
I did promise @daschl that I would split this into two branches - one for the interfaces followed by a second for expiry - but it's hard to explain the interfaces without showing how they would be used.
* @param <T> - the entity class | ||
*/ | ||
public interface WithExpiry<T> { | ||
Object withExpiry(Duration expiry); |
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.
How would you express that a default expiry should be overridden to persistent (i.e. no expiry)?
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.
Thats's a good point. It's not possible as an expiry of Zero gets ignored, resulting in the annotation being used.
The semantics could be changed to mean an expiry of Zero means to use zero as the expiry (to the server, this means no expiry). The 'expiry == null' meaning "don't use this, use the annotation instead" could be left as-is. The construction would need to be changed to be created with a null expiry instead of a Zero expiry.
if (expiry != null && !expiry.isZero()) {
options.expiry(expiry);
} else if (doc.getExpiration() != 0) {
options.expiry(Duration.ofSeconds(doc.getExpiration()));
}
get the expiryExpression from the converted CouchbaseDocument.
added interfaces for apis on core objects which are common among
many objects. For instance withExpiry and withExpirty on all the
insert/replace/upsert/remove objects. The definition of an interface
simplyfies testing of all the possible combinations - instead of having
four (or eight, counting Reactive), there is one interface to test
them all.