@@ -88,6 +88,11 @@ B applyLimit(B builder, Long newLimit) {
88
88
return this .limitSetter .apply (builder , newLimit );
89
89
}
90
90
91
+ B removeOptsForSubsequentPage (O options , B builder ) {
92
+ // Default is a no-op
93
+ return builder ;
94
+ }
95
+
91
96
Long getPageSizeFromOptionsLimit (O opts ) {
92
97
return Optional .ofNullable (this .limitGetter .apply (opts )).orElse (MAX_LIMIT );
93
98
}
@@ -172,15 +177,17 @@ private abstract static class KeyOptionsHandler<B, O, K> extends OptionsHandler<
172
177
173
178
protected final Function <O , K > keyGetter ;
174
179
private final Function <O , List <K >> keysGetter ;
180
+ protected final Function <O , Long > skipGetter ;
175
181
private final String keyErrorMsg =
176
182
keyErrorMessage (new StringBuilder ("when using pagination. " ));
177
183
178
184
protected KeyOptionsHandler (Function <B , O > builderToOptions , Function <O , B > optionsToBuilder ,
179
185
Function <O , Long > limitGetter , BiFunction <B , Long , B > limitSetter , Function <O , K > keyGetter ,
180
- Function <O , List <K >> keysGetter ) {
186
+ Function <O , List <K >> keysGetter , Function < O , Long > skipGetter ) {
181
187
super (builderToOptions , optionsToBuilder , limitGetter , limitSetter );
182
188
this .keyGetter = keyGetter ;
183
189
this .keysGetter = keysGetter ;
190
+ this .skipGetter = skipGetter ;
184
191
}
185
192
186
193
protected String keyErrorMessage (StringBuilder baseMessage ) {
@@ -201,14 +208,27 @@ protected void validate(O options) {
201
208
this .keyErrorMsg );
202
209
super .validate (options );
203
210
}
211
+
212
+ @ Override
213
+ B removeOptsForSubsequentPage (O options , B builder ) {
214
+ // Unset the skip option if necessary
215
+ if (optionIsPresent (options , this .skipGetter )) {
216
+ builder = this .builderFromOptions (replaceOpts (builder ));
217
+ }
218
+ return super .removeOptsForSubsequentPage (options , builder );
219
+ }
220
+
221
+ protected abstract O replaceOpts (B builder );
204
222
}
205
223
206
224
private abstract static class ViewsOptionsHandler <B , O > extends KeyOptionsHandler <B , O , Object > {
207
225
208
226
protected ViewsOptionsHandler (Function <B , O > builderToOptions , Function <O , B > optionsToBuilder ,
209
227
Function <O , Long > limitGetter , BiFunction <B , Long , B > limitSetter ,
210
- Function <O , Object > keyGetter , Function <O , List <Object >> keysGetter ) {
211
- super (builderToOptions , optionsToBuilder , limitGetter , limitSetter , keyGetter , keysGetter );
228
+ Function <O , Object > keyGetter , Function <O , List <Object >> keysGetter ,
229
+ Function <O , Long > skipGetter ) {
230
+ super (builderToOptions , optionsToBuilder , limitGetter , limitSetter , keyGetter , keysGetter ,
231
+ skipGetter );
212
232
}
213
233
214
234
@ Override
@@ -233,7 +253,17 @@ private static final class AllDocsOptionsHandler
233
253
private AllDocsOptionsHandler () {
234
254
super (PostAllDocsOptions .Builder ::build , PostAllDocsOptions ::newBuilder ,
235
255
PostAllDocsOptions ::limit , PostAllDocsOptions .Builder ::limit , PostAllDocsOptions ::key ,
236
- PostAllDocsOptions ::keys );
256
+ PostAllDocsOptions ::keys , PostAllDocsOptions ::skip );
257
+ }
258
+
259
+ @ Override
260
+ protected PostAllDocsOptions replaceOpts (PostAllDocsOptions .Builder builder ) {
261
+ return new PostAllDocsOptions (builder ) {
262
+ PostAllDocsOptions unsetOpts () {
263
+ this .skip = null ;
264
+ return this ;
265
+ }
266
+ }.unsetOpts ();
237
267
}
238
268
239
269
}
@@ -244,19 +274,45 @@ private static final class DesignDocsOptionsHandler
244
274
private DesignDocsOptionsHandler () {
245
275
super (PostDesignDocsOptions .Builder ::build , PostDesignDocsOptions ::newBuilder ,
246
276
PostDesignDocsOptions ::limit , PostDesignDocsOptions .Builder ::limit ,
247
- PostDesignDocsOptions ::key , PostDesignDocsOptions ::keys );
277
+ PostDesignDocsOptions ::key , PostDesignDocsOptions ::keys , PostDesignDocsOptions ::skip );
278
+ }
279
+
280
+ @ Override
281
+ protected PostDesignDocsOptions replaceOpts (PostDesignDocsOptions .Builder builder ) {
282
+ return new PostDesignDocsOptions (builder ) {
283
+ PostDesignDocsOptions unsetOpts () {
284
+ this .skip = null ;
285
+ return this ;
286
+ }
287
+ }.unsetOpts ();
248
288
}
249
289
250
290
}
251
291
252
292
private static final class FindOptionsHandler
253
293
extends BookmarkOptionsHandler <PostFindOptions .Builder , PostFindOptions > {
254
294
295
+ private final Function <PostFindOptions , Long > skipGetter = PostFindOptions ::skip ;
296
+
255
297
private FindOptionsHandler () {
256
298
super (PostFindOptions .Builder ::build , PostFindOptions ::newBuilder , PostFindOptions ::limit ,
257
299
PostFindOptions .Builder ::limit );
258
300
}
259
301
302
+ @ Override
303
+ PostFindOptions .Builder removeOptsForSubsequentPage (PostFindOptions options ,
304
+ PostFindOptions .Builder builder ) {
305
+ if (optionIsPresent (options , this .skipGetter )) {
306
+ return new PostFindOptions (builder ) {
307
+ PostFindOptions unsetOpts () {
308
+ this .skip = null ;
309
+ return this ;
310
+ }
311
+ }.unsetOpts ().newBuilder ();
312
+ }
313
+ return builder ;
314
+ }
315
+
260
316
}
261
317
262
318
private static final class PartitionAllDocsOptionsHandler extends
@@ -265,19 +321,47 @@ private static final class PartitionAllDocsOptionsHandler extends
265
321
private PartitionAllDocsOptionsHandler () {
266
322
super (PostPartitionAllDocsOptions .Builder ::build , PostPartitionAllDocsOptions ::newBuilder ,
267
323
PostPartitionAllDocsOptions ::limit , PostPartitionAllDocsOptions .Builder ::limit ,
268
- PostPartitionAllDocsOptions ::key , PostPartitionAllDocsOptions ::keys );
324
+ PostPartitionAllDocsOptions ::key , PostPartitionAllDocsOptions ::keys ,
325
+ PostPartitionAllDocsOptions ::skip );
326
+ }
327
+
328
+ @ Override
329
+ protected PostPartitionAllDocsOptions replaceOpts (PostPartitionAllDocsOptions .Builder builder ) {
330
+ return new PostPartitionAllDocsOptions (builder ) {
331
+ PostPartitionAllDocsOptions unsetOpts () {
332
+ this .skip = null ;
333
+ return this ;
334
+ }
335
+ }.unsetOpts ();
269
336
}
270
337
271
338
}
272
339
273
340
private static final class PartitionFindOptionsHandler
274
341
extends BookmarkOptionsHandler <PostPartitionFindOptions .Builder , PostPartitionFindOptions > {
275
342
343
+ private final Function <PostPartitionFindOptions , Long > skipGetter =
344
+ PostPartitionFindOptions ::skip ;
345
+
276
346
private PartitionFindOptionsHandler () {
277
347
super (PostPartitionFindOptions .Builder ::build , PostPartitionFindOptions ::newBuilder ,
278
348
PostPartitionFindOptions ::limit , PostPartitionFindOptions .Builder ::limit );
279
349
}
280
350
351
+ @ Override
352
+ PostPartitionFindOptions .Builder removeOptsForSubsequentPage (PostPartitionFindOptions options ,
353
+ PostPartitionFindOptions .Builder builder ) {
354
+ if (optionIsPresent (options , this .skipGetter )) {
355
+ return new PostPartitionFindOptions (builder ) {
356
+ PostPartitionFindOptions unsetOpts () {
357
+ this .skip = null ;
358
+ return this ;
359
+ }
360
+ }.unsetOpts ().newBuilder ();
361
+ }
362
+ return builder ;
363
+ }
364
+
281
365
}
282
366
283
367
private static final class PartitionSearchOptionsHandler extends
@@ -296,7 +380,18 @@ private static final class PartitionViewOptionsHandler
296
380
private PartitionViewOptionsHandler () {
297
381
super (PostPartitionViewOptions .Builder ::build , PostPartitionViewOptions ::newBuilder ,
298
382
PostPartitionViewOptions ::limit , PostPartitionViewOptions .Builder ::limit ,
299
- PostPartitionViewOptions ::key , PostPartitionViewOptions ::keys );
383
+ PostPartitionViewOptions ::key , PostPartitionViewOptions ::keys ,
384
+ PostPartitionViewOptions ::skip );
385
+ }
386
+
387
+ @ Override
388
+ protected PostPartitionViewOptions replaceOpts (PostPartitionViewOptions .Builder builder ) {
389
+ return new PostPartitionViewOptions (builder ) {
390
+ PostPartitionViewOptions unsetOpts () {
391
+ this .skip = null ;
392
+ return this ;
393
+ }
394
+ }.unsetOpts ();
300
395
}
301
396
302
397
}
@@ -328,7 +423,18 @@ private static final class ViewOptionsHandler
328
423
329
424
private ViewOptionsHandler () {
330
425
super (PostViewOptions .Builder ::build , PostViewOptions ::newBuilder , PostViewOptions ::limit ,
331
- PostViewOptions .Builder ::limit , PostViewOptions ::key , PostViewOptions ::keys );
426
+ PostViewOptions .Builder ::limit , PostViewOptions ::key , PostViewOptions ::keys ,
427
+ PostViewOptions ::skip );
428
+ }
429
+
430
+ @ Override
431
+ protected PostViewOptions replaceOpts (PostViewOptions .Builder builder ) {
432
+ return new PostViewOptions (builder ) {
433
+ PostViewOptions unsetOpts () {
434
+ this .skip = null ;
435
+ return this ;
436
+ }
437
+ }.unsetOpts ();
332
438
}
333
439
334
440
}
0 commit comments