/
CoreKvOps.java
417 lines (371 loc) · 11.1 KB
/
CoreKvOps.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
* Copyright 2023 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.client.core.api.kv;
import com.couchbase.client.core.annotation.Stability;
import com.couchbase.client.core.endpoint.http.CoreCommonOptions;
import com.couchbase.client.core.error.InvalidArgumentException;
import com.couchbase.client.core.kv.CoreRangeScanItem;
import com.couchbase.client.core.kv.CoreScanOptions;
import com.couchbase.client.core.kv.CoreScanType;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.stream.Stream;
@Stability.Internal
public interface CoreKvOps {
CoreAsyncResponse<CoreGetResult> getAsync(
CoreCommonOptions common,
String key,
List<String> projections,
boolean withExpiry
);
default CoreGetResult getBlocking(
CoreCommonOptions common,
String key,
List<String> projections,
boolean withExpiry
) {
return getAsync(common, key, projections, withExpiry).toBlocking();
}
default Mono<CoreGetResult> getReactive(
CoreCommonOptions common,
String key,
List<String> projections,
boolean withExpiry
) {
return Mono.defer(() -> getAsync(common, key, projections, withExpiry).toMono());
}
default void checkProjectionLimits(
List<String> projections,
boolean withExpiry
) {
if (withExpiry) {
if (projections.size() > 15) {
throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be "
+ "projected per request due to a server limitation (includes the expiration macro as one field).");
}
} else if (projections.size() > 16) {
throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be "
+ "projected per request due to a server limitation.");
}
}
CoreAsyncResponse<CoreGetResult> getAndLockAsync(
CoreCommonOptions common,
String key,
Duration lockTime
);
default CoreGetResult getAndLockBlocking(
CoreCommonOptions common,
String key,
Duration lockTime
) {
return getAndLockAsync(common, key, lockTime).toBlocking();
}
default Mono<CoreGetResult> getAndLockReactive(
CoreCommonOptions common,
String key,
Duration lockTime
) {
return Mono.defer(() -> getAndLockAsync(common, key, lockTime).toMono());
}
CoreAsyncResponse<CoreGetResult> getAndTouchAsync(
CoreCommonOptions common,
String key,
CoreExpiry expiry
);
default CoreGetResult getAndTouchBlocking(
CoreCommonOptions common,
String key,
CoreExpiry expiry
) {
return getAndTouchAsync(common, key, expiry).toBlocking();
}
default Mono<CoreGetResult> getAndTouchReactive(
CoreCommonOptions common,
String key,
CoreExpiry expiry
) {
return Mono.defer(() -> getAndTouchAsync(common, key, expiry).toMono());
}
CoreAsyncResponse<CoreMutationResult> insertAsync(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
CoreDurability durability,
CoreExpiry expiry
);
default CoreMutationResult insertBlocking(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
CoreDurability durability,
CoreExpiry expiry
) {
return insertAsync(common, key, content, durability, expiry).toBlocking();
}
default Mono<CoreMutationResult> insertReactive(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
CoreDurability durability,
CoreExpiry expiry
) {
return Mono.defer(() -> insertAsync(common, key, content, durability, expiry).toMono());
}
CoreAsyncResponse<CoreMutationResult> upsertAsync(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry
);
default CoreMutationResult upsertBlocking(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry
) {
return upsertAsync(common, key, content, durability, expiry, preserveExpiry).toBlocking();
}
default Mono<CoreMutationResult> upsertReactive(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry
) {
return Mono.defer(() -> upsertAsync(common, key, content, durability, expiry, preserveExpiry).toMono());
}
CoreAsyncResponse<CoreMutationResult> replaceAsync(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
long cas,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry
);
default CoreMutationResult replaceBlocking(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
long cas,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry
) {
return replaceAsync(common, key, content, cas, durability, expiry, preserveExpiry).toBlocking();
}
default Mono<CoreMutationResult> replaceReactive(
CoreCommonOptions common,
String key,
Supplier<CoreEncodedContent> content,
long cas,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry
) {
return Mono.defer(() -> replaceAsync(common, key, content, cas, durability, expiry, preserveExpiry).toMono());
}
CoreAsyncResponse<CoreMutationResult> removeAsync(
CoreCommonOptions common,
String key,
long cas,
CoreDurability durability
);
default CoreMutationResult removeBlocking(
CoreCommonOptions common,
String key,
long cas,
CoreDurability durability
) {
return removeAsync(common, key, cas, durability).toBlocking();
}
default Mono<CoreMutationResult> removeReactive(
CoreCommonOptions common,
String key,
long cas,
CoreDurability durability
) {
return Mono.defer(() -> removeAsync(common, key, cas, durability).toMono());
}
CoreAsyncResponse<CoreExistsResult> existsAsync(
CoreCommonOptions common,
String key
);
default CoreExistsResult existsBlocking(
CoreCommonOptions common,
String key
) {
return existsAsync(common, key).toBlocking();
}
default Mono<CoreExistsResult> existsReactive(
CoreCommonOptions common,
String key
) {
return Mono.defer(() -> existsAsync(common, key).toMono());
}
CoreAsyncResponse<CoreMutationResult> touchAsync(
CoreCommonOptions common,
String key,
CoreExpiry expiry
);
default CoreMutationResult touchBlocking(
CoreCommonOptions common,
String key,
CoreExpiry expiry
) {
return touchAsync(common, key, expiry).toBlocking();
}
default Mono<CoreMutationResult> touchReactive(
CoreCommonOptions common,
String key,
CoreExpiry expiry
) {
return Mono.defer(() -> touchAsync(common, key, expiry).toMono());
}
CoreAsyncResponse<Void> unlockAsync(
CoreCommonOptions common,
String key,
long cas
);
default void unlockBlocking(
CoreCommonOptions common,
String key,
long cas
) {
unlockAsync(common, key, cas).toBlocking();
}
default Mono<Void> unlockReactive(
CoreCommonOptions common,
String key,
long cas
) {
return Mono.defer(() -> unlockAsync(common, key, cas).toMono());
}
CoreAsyncResponse<CoreSubdocGetResult> subdocGetAsync(
CoreCommonOptions common,
String key,
List<CoreSubdocGetCommand> commands,
boolean accessDeleted
);
default CoreSubdocGetResult subdocGetBlocking(
CoreCommonOptions common,
String key,
List<CoreSubdocGetCommand> commands,
boolean accessDeleted
) {
return subdocGetAsync(common, key, commands, accessDeleted).toBlocking();
}
default Mono<CoreSubdocGetResult> subdocGetReactive(
CoreCommonOptions common,
String key,
List<CoreSubdocGetCommand> commands,
boolean accessDeleted
) {
return Mono.defer(() -> subdocGetReactive(common, key, commands, accessDeleted));
}
Flux<CoreGetResult> getAllReplicasReactive(
CoreCommonOptions common,
String key
);
Mono<CoreGetResult> getAnyReplicaReactive(
CoreCommonOptions common,
String key
);
CoreAsyncResponse<CoreSubdocMutateResult> subdocMutateAsync(
CoreCommonOptions common,
String key,
Supplier<List<CoreSubdocMutateCommand>> commands,
CoreStoreSemantics storeSemantics,
long cas,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry,
boolean accessDeleted,
boolean createAsDeleted
);
default CoreSubdocMutateResult subdocMutateBlocking(
CoreCommonOptions common,
String key,
Supplier<List<CoreSubdocMutateCommand>> commands,
CoreStoreSemantics storeSemantics,
long cas,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry,
boolean accessDeleted,
boolean createAsDeleted
) {
return subdocMutateAsync(
common,
key,
commands,
storeSemantics,
cas,
durability,
expiry,
preserveExpiry,
accessDeleted,
createAsDeleted
).toBlocking();
}
default Mono<CoreSubdocMutateResult> subdocMutateReactive(
CoreCommonOptions common,
String key,
Supplier<List<CoreSubdocMutateCommand>> commands,
CoreStoreSemantics storeSemantics,
long cas,
CoreDurability durability,
CoreExpiry expiry,
boolean preserveExpiry,
boolean accessDeleted,
boolean createAsDeleted
) {
return Mono.defer(() -> subdocMutateAsync(
common,
key,
commands,
storeSemantics,
cas,
durability,
expiry,
preserveExpiry,
accessDeleted,
createAsDeleted
).toMono());
}
Flux<CoreRangeScanItem> scanRequestReactive(
CoreScanType scanType,
CoreScanOptions options);
default CompletableFuture<List<CoreRangeScanItem>> scanRequestAsync(
CoreScanType coreScanType,
CoreScanOptions coreScanOptions) {
return scanRequestReactive(coreScanType, coreScanOptions).collectList().toFuture();
}
default Stream<CoreRangeScanItem> scanRequestBlocking(
CoreScanType coreScanType,
CoreScanOptions coreScanOptions) {
return scanRequestReactive(coreScanType, coreScanOptions).toStream();
}
}