@@ -63,6 +63,8 @@ static class ReactiveFindByIdSupport<T> implements ReactiveFindById<T> {
63
63
private final ReactiveTemplateSupport support ;
64
64
private final Duration expiry ;
65
65
66
+ private Duration expiryToUse ;
67
+
66
68
ReactiveFindByIdSupport (ReactiveCouchbaseTemplate template , Class <T > domainType , String scope , String collection ,
67
69
CommonOptions <?> options , List <String > fields , Duration expiry , ReactiveTemplateSupport support ) {
68
70
this .template = template ;
@@ -86,7 +88,7 @@ public Mono<T> one(final String id) {
86
88
ReactiveCollection reactive = template .getCouchbaseClientFactory ().withScope (pArgs .getScope ())
87
89
.getCollection (pArgs .getCollection ()).reactive ();
88
90
if (pArgs .getOptions () instanceof GetAndTouchOptions ) {
89
- return reactive .getAndTouch (docId , expiryToUse () , (GetAndTouchOptions ) pArgs .getOptions ());
91
+ return reactive .getAndTouch (docId , expiryToUse , (GetAndTouchOptions ) pArgs .getOptions ());
90
92
} else {
91
93
return reactive .get (docId , (GetOptions ) pArgs .getOptions ());
92
94
}
@@ -142,7 +144,18 @@ public FindByIdWithProjection<T> withExpiry(final Duration expiry) {
142
144
143
145
private CommonOptions <?> initGetOptions () {
144
146
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
+ }
146
159
GetAndTouchOptions gOptions = options != null ? (GetAndTouchOptions ) options : getAndTouchOptions ();
147
160
if (gOptions .build ().transcoder () == null ) {
148
161
gOptions .transcoder (RawJsonTranscoder .INSTANCE );
@@ -160,18 +173,7 @@ private CommonOptions<?> initGetOptions() {
160
173
}
161
174
return getOptions ;
162
175
}
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
+
175
177
}
176
178
177
179
}
0 commit comments