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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
package com.sleepycat.db;
import com.sleepycat.db.internal.DbConstants;
import com.sleepycat.db.internal.Dbc;
/**
A database cursor. Cursors are used for operating on collections of
records, for iterating over a database, and for saving handles to
individual records, so that they can be modified after they have been
read.
<p>
Cursors may be used by multiple threads, but only serially. That is,
the application must serialize access to the handle.
<p>
If the cursor is to be used to perform operations on behalf of a
transaction, the cursor must be opened and closed within the context of
that single transaction.
<p>
If you do not close the cursor before closing the database handle or the
transaction handle that owns this cursor, then, closing a database
handle or a transaction handle closes these open cursors.
Once the cursor close method has been called, the handle may not be
accessed again, regardless of the close method's success or failure.
<p>
To obtain a cursor with default attributes:
<blockquote><pre>
Cursor cursor = myDatabase.openCursor(txn, null);
</pre></blockquote>
To customize the attributes of a cursor, use a CursorConfig object.
<blockquote><pre>
CursorConfig config = new CursorConfig();
config.setDirtyRead(true);
Cursor cursor = myDatabase.openCursor(txn, config);
</pre></blockquote>
<p>
Modifications to the database during a sequential scan will be reflected
in the scan; that is, records inserted behind a cursor will not be
returned while records inserted in front of a cursor will be returned.
In Queue and Recno databases, missing entries (that is, entries that
were never explicitly created or that were created and then deleted)
will be ignored during a sequential scan.
*/
public class Cursor {
/* package */ Dbc dbc;
/* package */ Database database;
/* package */ CursorConfig config;
// Constructor needed by Java RPC server
protected Cursor(final Database database, final CursorConfig config) {
this.database = database;
this.config = config;
}
Cursor(final Database database, final Dbc dbc, final CursorConfig config)
throws DatabaseException {
this.database = database;
this.dbc = dbc;
this.config = config;
}
/**
Discard the cursor.
<p>
After the close method has been called, you cannot use the cursor handle
again.
<p>
It is not required to close the cursor explicitly before closing the
database handle or the transaction handle that owns this cursor because
closing a database handle or transaction handle closes those open cursor.
<p>
However, it is recommended that you always close all cursor handles
immediately after their use to promote concurrency and to release resources
such as page locks.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock. If the application is already intending to abort the transaction,
this exception should be ignored, and the application should proceed.
<p>
@throws DatabaseException if a failure occurs.
*/
public synchronized void close()
throws DatabaseException {
if (dbc != null) {
try {
dbc.close();
} finally {
dbc = null;
}
}
}
/**
Creates a new cursor that uses the same transaction and locker ID as the
original cursor.
<p>
This is useful when an application is using locking and requires two
or more cursors in the same thread of control.
<p>
@param samePosition
If true, the newly created cursor is initialized to refer to the
same position in the database as the original cursor (if any) and
hold the same locks (if any). If false, or the original cursor does
not hold a database position and locks, the returned cursor is
uninitialized and will behave like a newly created cursor.
<p>
@return
A new cursor with the same transaction and locker ID as the original
cursor.
<p>
<p>
@throws DatabaseException if a failure occurs.
*/
public Cursor dup(final boolean samePosition)
throws DatabaseException {
return new Cursor(database,
dbc.dup(samePosition ? DbConstants.DB_POSITION : 0), config);
}
/**
Return this cursor's configuration.
<p>
This may differ from the configuration used to open this object if
the cursor existed previously.
<p>
@return
This cursor's configuration.
<p>
<p>
@throws DatabaseException if a failure occurs.
*/
public CursorConfig getConfig() {
return config;
}
/**
Return the Database handle associated with this Cursor.
<p>
@return
The Database handle associated with this Cursor.
<p>
*/
public Database getDatabase() {
return database;
}
/**
Return a comparison of the two cursors. Two cursors are
equal if and only if they are positioned
on the same item in the same database.
<p>
@return
An integer representing the result of the
comparison between this cursor and OtherCursor (another
cursor handle used as the comparator). 0 indicates that this cursor and
OtherCursor are positioned on the same item, 1
indicates this cursor is greater than OtherCursor, -1 indicates that
OtherCursor is greater than this cursor.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws DatabaseException if a failure occurs.
*/
public int compare(Cursor OtherCursor)
throws DatabaseException {
return dbc.cmp(OtherCursor.dbc, 0);
}
/**
Return a count of the number of data items for the key to which the
cursor refers.
<p>
@return
A count of the number of data items for the key to which the cursor
refers.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws DatabaseException if a failure occurs.
*/
public int count()
throws DatabaseException {
return dbc.count(0);
}
/**
Delete the key/data pair to which the cursor refers.
<p>
When called on a cursor opened on a database that has been made into a
secondary index, this method deletes the key/data pair from the primary database
and all secondary indices.
<p>
The cursor position is unchanged after a delete, and subsequent calls
to cursor functions expecting the cursor to refer to an existing key
will fail.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus delete()
throws DatabaseException {
return OperationStatus.fromInt(dbc.del(0));
}
/**
Returns the key/data pair to which the cursor refers.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the key/pair at the cursor
position has been deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getCurrent(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_CURRENT |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the first key/data pair of the database, and return
that pair. If the first key has duplicate values, the first data item
in the set of duplicates is returned.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getFirst(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_FIRST |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the last key/data pair of the database, and return
that pair. If the last key has duplicate values, the last data item in
the set of duplicates is returned.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Its byte array does not need to be initialized by the
caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getLast(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_LAST |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the next key/data pair and return that pair. If
the matching key has duplicate values, the first data item in the set
of duplicates is returned.
<p>
If the cursor is not yet initialized, move the cursor to the first
key/data pair of the database, and return that pair. Otherwise, the
cursor is moved to the next key/data pair of the database, and that pair
is returned. In the presence of duplicate key values, the value of the
key may not change.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getNext(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_NEXT |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
If the next key/data pair of the database is a duplicate data record for
the current key/data pair, move the cursor to the next key/data pair
of the database and return that pair.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getNextDup(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_NEXT_DUP |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the next non-duplicate key/data pair and return
that pair. If the matching key has duplicate values, the first data
item in the set of duplicates is returned.
<p>
If the cursor is not yet initialized, move the cursor to the first
key/data pair of the database, and return that pair. Otherwise, the
cursor is moved to the next non-duplicate key of the database, and that
key/data pair is returned.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getNextNoDup(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_NEXT_NODUP |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the previous key/data pair and return that pair.
If the matching key has duplicate values, the last data item in the set
of duplicates is returned.
<p>
If the cursor is not yet initialized, move the cursor to the last
key/data pair of the database, and return that pair. Otherwise, the
cursor is moved to the previous key/data pair of the database, and that
pair is returned. In the presence of duplicate key values, the value of
the key may not change.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Its byte array does not need to be initialized by the
caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getPrev(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_PREV |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
If the previous key/data pair of the database is a duplicate data record
for the current key/data pair, move the cursor to the previous key/data
pair of the database and return that pair.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Its byte array does not need to be initialized by the
caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getPrevDup(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_PREV_DUP |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the previous non-duplicate key/data pair and return
that pair. If the matching key has duplicate values, the last data item
in the set of duplicates is returned.
<p>
If the cursor is not yet initialized, move the cursor to the last
key/data pair of the database, and return that pair. Otherwise, the
cursor is moved to the previous non-duplicate key of the database, and
that key/data pair is returned.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Its byte array does not need to be initialized by the
caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getPrevNoDup(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_PREV_NODUP |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Return the record number associated with the cursor. The record number
will be returned in the data parameter.
<p>
For this method to be called, the underlying database must be of type
Btree, and it must have been configured to support record numbers.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param data the data
returned as output. Its byte array does not need to be initialized by the
caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getRecordNumber(final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(DatabaseEntry.IGNORE, data,
DbConstants.DB_GET_RECNO |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the given key of the database, and return the datum
associated with the given key. If the matching key has duplicate
values, the first data item in the set of duplicates is returned.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
used as input. It must be initialized with a non-null byte array by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getSearchKey(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_SET |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the closest matching key of the database, and return
the data item associated with the matching key. If the matching key has
duplicate values, the first data item in the set of duplicates is returned.
<p>
The returned key/data pair is for the smallest key greater than or equal
to the specified key (as determined by the key comparison function),
permitting partial key matches and range searches.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
used as input and returned as output. It must be initialized with a non-null
byte array by the caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getSearchKeyRange(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_SET_RANGE |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the specified key/data pair, where both the key and
data items must match.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
used as input. It must be initialized with a non-null byte array by the
caller.
@param data the data
used as input. It must be initialized with a non-null byte array by the
caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getSearchBoth(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_GET_BOTH |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the specified key and matching data item of the database.
<p>
In the case of any database supporting sorted duplicate sets, the returned
key/data pair is for the smallest data item greater than or equal to the
specified data item (as determined by the duplicate comparison function),
permitting partial matches and range searches in duplicate data sets.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
used as input and returned as output. It must be initialized with a non-null
byte array by the caller.
@param data the data
used as input and returned as output. It must be initialized with a non-null
byte array by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getSearchBothRange(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_GET_BOTH_RANGE |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Move the cursor to the specific numbered record of the database, and
return the associated key/data pair.
<p>
The data field of the specified key must be a byte array containing a
record number, as described in {@link com.sleepycat.db.DatabaseEntry DatabaseEntry}. This determines
the record to be retrieved.
<p>
For this method to be called, the underlying database must be of type
Btree, and it must have been configured to support record numbers.
<p>
If this method fails for any reason, the position of the cursor will be
unchanged.
@throws NullPointerException if a DatabaseEntry parameter is null or
does not contain a required non-null byte array.
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
<p>
@param key the key
returned as output. Its byte array does not need to be initialized by the
caller.
@param data the data
returned as output. Multiple results can be retrieved by passing an object
that is a subclass of {@link com.sleepycat.db.MultipleEntry MultipleEntry}, otherwise its byte array does not
need to be initialized by the caller.
@param lockMode the locking attributes; if null, default attributes are used.
@return {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} if no matching key/data pair is
found; {@link com.sleepycat.db.OperationStatus#KEYEMPTY OperationStatus.KEYEMPTY} if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted; otherwise, {@link com.sleepycat.db.OperationStatus#SUCCESS OperationStatus.SUCCESS}.
*/
public OperationStatus getSearchRecordNumber(final DatabaseEntry key,
final DatabaseEntry data,
LockMode lockMode)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.get(key, data, DbConstants.DB_SET_RECNO |
LockMode.getFlag(lockMode) |
((data == null) ? 0 : data.getMultiFlag())));
}
/**
Store a key/data pair into the database.
<p>
If the put method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the put method fails for any reason, the
state of the cursor will be unchanged.
<p>
If the key already appears in the database and duplicates are supported,
the new data value is inserted at the correct sorted location. If the
key already appears in the database and duplicates are not supported,
the existing key/data pair will be replaced.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus put(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_KEYLAST));
}
/**
Store a key/data pair into the database.
<p>
If the putAfter method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the putAfter method fails for any reason, the
state of the cursor will be unchanged.
<p>
In the case of the Btree and Hash access methods, insert the data
element as a duplicate element of the key to which the cursor refers.
The new element appears immediately
after
the current cursor position. It is an error to call this method if the
underlying Btree or Hash database does not support duplicate data items.
The key parameter is ignored.
<p>
In the case of the Hash access method, the putAfter method will fail and
throw an exception if the current cursor record has already been deleted.
<p>
In the case of the Recno access method, it is an error to call this
method if the underlying Recno database was not configured to have
mutable record numbers. A new key is created, all records after the
inserted item are automatically renumbered, and the key of the new
record is returned in the key parameter. The initial value of the key
parameter is ignored.
<p>
The putAfter method may not be called for the Queue access method.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus putAfter(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_AFTER));
}
/**
Store a key/data pair into the database.
<p>
If the putBefore method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the putBefore method fails for any reason, the
state of the cursor will be unchanged.
<p>
In the case of the Btree and Hash access methods, insert the data
element as a duplicate element of the key to which the cursor refers.
The new element appears immediately
before
the current cursor position. It is an error to call this method if the
underlying Btree or Hash database does not support duplicate data items.
The key parameter is ignored.
<p>
In the case of the Hash access method, the putBefore method will fail and
throw an exception if the current cursor record has already been deleted.
<p>
In the case of the Recno access method, it is an error to call this
method if the underlying Recno database was not configured to have
mutable record numbers. A new key is created, all records after the
inserted item are automatically renumbered, and the key of the new
record is returned in the key parameter. The initial value of the key
parameter is ignored.
<p>
The putBefore method may not be called for the Queue access method.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus putBefore(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_BEFORE));
}
/**
Store a key/data pair into the database.
<p>
If the putNoOverwrite method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the putNoOverwrite method fails for any reason, the
state of the cursor will be unchanged.
<p>
If the key already appears in the database, putNoOverwrite will return
{@link com.sleepycat.db.OperationStatus#KEYEXIST OperationStatus.KEYEXIST}.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus putNoOverwrite(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
/*
* The tricks here are making sure the cursor doesn't move on error and
* noticing that if the key exists, that's an error and we don't want
* to return the data.
*/
Dbc tempDbc = dbc.dup(0);
try {
int errCode = tempDbc.get(key, DatabaseEntry.IGNORE,
DbConstants.DB_SET | database.rmwFlag);
if (errCode == 0)
return OperationStatus.KEYEXIST;
else if (errCode != DbConstants.DB_NOTFOUND &&
errCode != DbConstants.DB_KEYEMPTY)
return OperationStatus.fromInt(errCode);
else {
Dbc tdbc = dbc;
dbc = tempDbc;
tempDbc = tdbc;
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_KEYLAST));
}
} finally {
tempDbc.close();
}
}
/**
Store a key/data pair into the database.
<p>
If the putKeyFirst method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the putKeyFirst method fails for any reason, the
state of the cursor will be unchanged.
<p>
In the case of the Btree and Hash access methods, insert the specified
key/data pair into the database.
<p>
If the underlying database supports duplicate data items, and if the
key already exists in the database and a duplicate sort function has
been specified, the inserted data item is added in its sorted location.
If the key already exists in the database and no duplicate sort function
has been specified, the inserted data item is added as the
first
of the data items for that key.
<p>
The putKeyFirst method may not be called for the Queue or Recno access methods.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus putKeyFirst(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_KEYFIRST));
}
/**
Store a key/data pair into the database.
<p>
If the putKeyLast method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the putKeyLast method fails for any reason, the
state of the cursor will be unchanged.
<p>
In the case of the Btree and Hash access methods, insert the specified
key/data pair into the database.
<p>
If the underlying database supports duplicate data items, and if the
key already exists in the database and a duplicate sort function has
been specified, the inserted data item is added in its sorted location.
If the key already exists in the database and no duplicate sort function
has been specified, the inserted data item is added as the
last
of the data items for that key.
<p>
The putKeyLast method may not be called for the Queue or Recno access methods.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus putKeyLast(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_KEYLAST));
}
/**
Store a key/data pair into the database.
<p>
If the putNoDupData method succeeds, the cursor is always positioned to refer to
the newly inserted item. If the putNoDupData method fails for any reason, the
state of the cursor will be unchanged.
<p>
In the case of the Btree and Hash access methods, insert
the specified key/data pair into the database, unless a key/data pair
comparing equally to it already exists in the database. If a matching
key/data pair already exists in the database, {@link com.sleepycat.db.OperationStatus#KEYEXIST OperationStatus.KEYEXIST} is returned.
<p>
This method may only be called if the underlying database has been
configured to support sorted duplicate data items.
<p>
This method may not be called for the Queue or Recno access methods.
<p>
@param key the key {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} operated on.
<p>
@param data the data {@link com.sleepycat.db.DatabaseEntry DatabaseEntry} stored.
<p>
<p>
@throws DeadlockException if the operation was selected to resolve a
deadlock.
<p>
@throws IllegalArgumentException if an invalid parameter was specified.
<p>
@throws DatabaseException if a failure occurs.
*/
public OperationStatus putNoDupData(final DatabaseEntry key,
final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(key, data, DbConstants.DB_NODUPDATA));
}
/**
Replaces the data in the key/data pair at the current cursor position.
<p>
Whether the putCurrent method succeeds or fails for any reason, the state
of the cursor will be unchanged.
<p>
Overwrite the data of the key/data pair to which the cursor refers with the
specified data item. This method will return OperationStatus.NOTFOUND if
the cursor currently refers to an already-deleted key/data pair.
<p>
For a database that does not support duplicates, the data may be changed by
this method. If duplicates are supported, the data may be changed only if
a custom partial comparator is configured and the comparator considers the
old and new data to be equal (that is, the comparator returns zero). For
more information on partial comparators see {@link
DatabaseConfig#setDuplicateComparator}.
<p>
If the old and new data are unequal according to the comparator, a {@code
DatabaseException} is thrown. Changing the data in this case would change
the sort order of the record, which would change the cursor position, and
this is not allowed. To change the sort order of a record, delete it and
then re-insert it.
<p>
@param data the data DatabaseEntry stored.
<br>
@throws DeadlockException - if the operation was selected to resolve a
deadlock.
<br>
@throws IllegalArgumentException - if an invalid parameter was specified.
<br>
@throws DatabaseException - if the old and new data are not equal according
to the configured duplicate comparator or default comparator, or if a
failure occurs.
<br>
*/
public OperationStatus putCurrent(final DatabaseEntry data)
throws DatabaseException {
return OperationStatus.fromInt(
dbc.put(DatabaseEntry.UNUSED, data, DbConstants.DB_CURRENT));
}
/**
Get the cache priority for pages referenced by the cursor.
<p>
This method may be called at any time during the life of the application.
<p>
<p>
@throws DatabaseException if a failure occurs.
*/
public CacheFilePriority getPriority()
throws DatabaseException {
return CacheFilePriority.fromFlag(dbc.get_priority());
}
/**
Set the cache priority for pages referenced by the DBC handle.
<p>
The priority of a page biases the replacement algorithm to be more or less
likely to discard a page when space is needed in the buffer pool. The bias
is temporary, and pages will eventually be discarded if they are not
referenced again. The setPriority method is only advisory, and
does not guarantee pages will be treated in a specific way.
<p>
This method may be called at any time during the life of the application.
<p>
@throws DatabaseException if a failure occurs.
*/
public void setPriority(final CacheFilePriority priority)
throws DatabaseException {
dbc.set_priority(priority.getFlag());
}
/**
Return a database stream pointing to a key/data pair where the data item
is a blob.
<p>
@param config
The database stream attributes. If null, default attributes are used.
<p>
@return
A database stream.
<p>
@throws DatabaseException if the data item is not a blob.
*/
public DatabaseStream openDatabaseStream(DatabaseStreamConfig config)
throws DatabaseException {
return new DatabaseStream(this, DatabaseStreamConfig.checkNull(
config).openDatabaseStream(dbc), config);
}
}
|