Skip to content

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

Closed

Conversation

mikereiche
Copy link
Collaborator

@mikereiche mikereiche commented Dec 11, 2020

  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.

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

@mikereiche mikereiche requested a review from daschl December 11, 2020 03:44
@mikereiche mikereiche force-pushed the datacouch_645_support_expiryExpression_annotation branch 2 times, most recently from 1656820 to 7815522 Compare December 11, 2020 03:53
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.
@mikereiche mikereiche force-pushed the datacouch_645_support_expiryExpression_annotation branch from 7815522 to d531dbd Compare December 11, 2020 03:56
* @param <T> - the entity class
*/
public interface InCollection<T> {
Object inCollection(String collection);
Copy link
Member

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?

Copy link
Collaborator Author

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);
Copy link
Member

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)?

Copy link
Collaborator Author

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()));
		}

@mikereiche mikereiche closed this Dec 11, 2020
@mikereiche mikereiche deleted the datacouch_645_support_expiryExpression_annotation branch December 11, 2020 19: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.

2 participants