@@ -63,6 +63,8 @@ static class ReactiveFindByIdSupport<T> implements ReactiveFindById<T> {
6363 private final ReactiveTemplateSupport support ;
6464 private final Duration expiry ;
6565
66+ private Duration expiryToUse ;
67+
6668 ReactiveFindByIdSupport (ReactiveCouchbaseTemplate template , Class <T > domainType , String scope , String collection ,
6769 CommonOptions <?> options , List <String > fields , Duration expiry , ReactiveTemplateSupport support ) {
6870 this .template = template ;
@@ -86,7 +88,7 @@ public Mono<T> one(final String id) {
8688 ReactiveCollection reactive = template .getCouchbaseClientFactory ().withScope (pArgs .getScope ())
8789 .getCollection (pArgs .getCollection ()).reactive ();
8890 if (pArgs .getOptions () instanceof GetAndTouchOptions ) {
89- return reactive .getAndTouch (docId , expiryToUse () , (GetAndTouchOptions ) pArgs .getOptions ());
91+ return reactive .getAndTouch (docId , expiryToUse , (GetAndTouchOptions ) pArgs .getOptions ());
9092 } else {
9193 return reactive .get (docId , (GetOptions ) pArgs .getOptions ());
9294 }
@@ -142,7 +144,18 @@ public FindByIdWithProjection<T> withExpiry(final Duration expiry) {
142144
143145 private CommonOptions <?> initGetOptions () {
144146 CommonOptions <?> getOptions ;
145- if (expiry != null || options instanceof GetAndTouchOptions ) {
147+ final CouchbasePersistentEntity <?> entity = template .getConverter ().getMappingContext ()
148+ .getRequiredPersistentEntity (domainType );
149+ Duration entityExpiryAnnotation = entity .getExpiryDuration ();
150+ if (expiry != null || entityExpiryAnnotation == null || !entityExpiryAnnotation .isZero ()
151+ || options instanceof GetAndTouchOptions ) {
152+ if (expiry != null ) {
153+ expiryToUse = expiry ;
154+ } else if (entityExpiryAnnotation == null || !entityExpiryAnnotation .isZero ()) {
155+ expiryToUse = entityExpiryAnnotation ;
156+ } else {
157+ expiryToUse = Duration .ZERO ;
158+ }
146159 GetAndTouchOptions gOptions = options != null ? (GetAndTouchOptions ) options : getAndTouchOptions ();
147160 if (gOptions .build ().transcoder () == null ) {
148161 gOptions .transcoder (RawJsonTranscoder .INSTANCE );
@@ -160,18 +173,7 @@ private CommonOptions<?> initGetOptions() {
160173 }
161174 return getOptions ;
162175 }
163-
164- private Duration expiryToUse () {
165- Duration expiryToUse = expiry ;
166- if (expiryToUse != null || options instanceof GetAndTouchOptions ) {
167- if (expiryToUse == null ) { // GetAndTouchOptions without specifying expiry -> get expiry from annoation
168- final CouchbasePersistentEntity <?> entity = template .getConverter ().getMappingContext ()
169- .getRequiredPersistentEntity (domainType );
170- expiryToUse = entity .getExpiryDuration ();
171- }
172- }
173- return expiryToUse ;
174- }
176+
175177 }
176178
177179}
0 commit comments