@@ -72,6 +72,8 @@ static class ReactiveFindByIdSupport<T> implements ReactiveFindById<T> {
72
72
private final ReactiveTemplateSupport support ;
73
73
private final Duration expiry ;
74
74
75
+ private Duration expiryToUse ;
76
+
75
77
ReactiveFindByIdSupport (ReactiveCouchbaseTemplate template , Class <T > domainType , String scope , String collection ,
76
78
CommonOptions <?> options , List <String > fields , Duration expiry , ReactiveTemplateSupport support ) {
77
79
this .template = template ;
@@ -98,7 +100,7 @@ public Mono<T> one(final Object id) {
98
100
Mono <T > reactiveEntity = TransactionalSupport .checkForTransactionInThreadLocalStorage ().flatMap (ctxOpt -> {
99
101
if (!ctxOpt .isPresent ()) {
100
102
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 ())
102
104
.flatMap (result -> support .decodeEntity (id , result .contentAs (String .class ), result .cas (), domainType ,
103
105
pArgs .getScope (), pArgs .getCollection (), null , null ));
104
106
} else {
@@ -110,8 +112,7 @@ public Mono<T> one(final Object id) {
110
112
rejectInvalidTransactionalOptions ();
111
113
return ctxOpt .get ().getCore ().get (makeCollectionIdentifier (rc .async ()), id .toString ())
112
114
.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 ));
115
116
}
116
117
});
117
118
@@ -179,7 +180,18 @@ public FindByIdWithProjection<T> withExpiry(final Duration expiry) {
179
180
180
181
private CommonOptions <?> initGetOptions () {
181
182
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
+ }
183
195
GetAndTouchOptions gOptions = options != null ? (GetAndTouchOptions ) options : getAndTouchOptions ();
184
196
if (gOptions .build ().transcoder () == null ) {
185
197
gOptions .transcoder (RawJsonTranscoder .INSTANCE );
@@ -197,19 +209,7 @@ private CommonOptions<?> initGetOptions() {
197
209
}
198
210
return getOptions ;
199
211
}
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
+
213
213
}
214
214
215
215
}
0 commit comments