@@ -72,6 +72,8 @@ static class ReactiveFindByIdSupport<T> implements ReactiveFindById<T> {
7272 private final ReactiveTemplateSupport support ;
7373 private final Duration expiry ;
7474
75+ private Duration expiryToUse ;
76+
7577 ReactiveFindByIdSupport (ReactiveCouchbaseTemplate template , Class <T > domainType , String scope , String collection ,
7678 CommonOptions <?> options , List <String > fields , Duration expiry , ReactiveTemplateSupport support ) {
7779 this .template = template ;
@@ -98,7 +100,7 @@ public Mono<T> one(final Object id) {
98100 Mono <T > reactiveEntity = TransactionalSupport .checkForTransactionInThreadLocalStorage ().flatMap (ctxOpt -> {
99101 if (!ctxOpt .isPresent ()) {
100102 if (pArgs .getOptions () instanceof GetAndTouchOptions ) {
101- return rc .getAndTouch (id .toString (), expiryToUse () , (GetAndTouchOptions ) pArgs .getOptions ())
103+ return rc .getAndTouch (id .toString (), expiryToUse , (GetAndTouchOptions ) pArgs .getOptions ())
102104 .flatMap (result -> support .decodeEntity (id , result .contentAs (String .class ), result .cas (), domainType ,
103105 pArgs .getScope (), pArgs .getCollection (), null , null ));
104106 } else {
@@ -110,8 +112,7 @@ public Mono<T> one(final Object id) {
110112 rejectInvalidTransactionalOptions ();
111113 return ctxOpt .get ().getCore ().get (makeCollectionIdentifier (rc .async ()), id .toString ())
112114 .flatMap (result -> support .decodeEntity (id , new String (result .contentAsBytes (), StandardCharsets .UTF_8 ),
113- result .cas (), domainType , pArgs .getScope (), pArgs .getCollection (),
114- null , null ));
115+ result .cas (), domainType , pArgs .getScope (), pArgs .getCollection (), null , null ));
115116 }
116117 });
117118
@@ -179,7 +180,18 @@ public FindByIdWithProjection<T> withExpiry(final Duration expiry) {
179180
180181 private CommonOptions <?> initGetOptions () {
181182 CommonOptions <?> getOptions ;
182- if (expiry != null || options instanceof GetAndTouchOptions ) {
183+ final CouchbasePersistentEntity <?> entity = template .getConverter ().getMappingContext ()
184+ .getRequiredPersistentEntity (domainType );
185+ Duration entityExpiryAnnotation = entity .getExpiryDuration ();
186+ if (expiry != null || entityExpiryAnnotation == null || !entityExpiryAnnotation .isZero ()
187+ || options instanceof GetAndTouchOptions ) {
188+ if (expiry != null ) {
189+ expiryToUse = expiry ;
190+ } else if (entityExpiryAnnotation == null || !entityExpiryAnnotation .isZero ()) {
191+ expiryToUse = entityExpiryAnnotation ;
192+ } else {
193+ expiryToUse = Duration .ZERO ;
194+ }
183195 GetAndTouchOptions gOptions = options != null ? (GetAndTouchOptions ) options : getAndTouchOptions ();
184196 if (gOptions .build ().transcoder () == null ) {
185197 gOptions .transcoder (RawJsonTranscoder .INSTANCE );
@@ -197,19 +209,7 @@ private CommonOptions<?> initGetOptions() {
197209 }
198210 return getOptions ;
199211 }
200-
201- private Duration expiryToUse () {
202- Duration expiryToUse = expiry ;
203- if (expiryToUse != null || options instanceof GetAndTouchOptions ) {
204- if (expiryToUse == null ) { // GetAndTouchOptions without specifying expiry -> get expiry from annoation
205- final CouchbasePersistentEntity <?> entity = template .getConverter ().getMappingContext ()
206- .getRequiredPersistentEntity (domainType );
207- expiryToUse = entity .getExpiryDuration ();
208- }
209- }
210- return expiryToUse ;
211- }
212-
212+
213213 }
214214
215215}
0 commit comments