]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/TransactionLogIterator.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / TransactionLogIterator.java
1 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 package org.rocksdb;
3
4 /**
5 * <p>A TransactionLogIterator is used to iterate over the transactions in a db.
6 * One run of the iterator is continuous, i.e. the iterator will stop at the
7 * beginning of any gap in sequences.</p>
8 */
9 public class TransactionLogIterator extends RocksObject {
10
11 /**
12 * <p>An iterator is either positioned at a WriteBatch
13 * or not valid. This method returns true if the iterator
14 * is valid. Can read data from a valid iterator.</p>
15 *
16 * @return true if iterator position is valid.
17 */
18 public boolean isValid() {
19 return isValid(nativeHandle_);
20 }
21
22 /**
23 * <p>Moves the iterator to the next WriteBatch.
24 * <strong>REQUIRES</strong>: Valid() to be true.</p>
25 */
26 public void next() {
27 next(nativeHandle_);
28 }
29
30 /**
31 * <p>Throws RocksDBException if something went wrong.</p>
32 *
33 * @throws org.rocksdb.RocksDBException if something went
34 * wrong in the underlying C++ code.
35 */
36 public void status() throws RocksDBException {
37 status(nativeHandle_);
38 }
39
40 /**
41 * <p>If iterator position is valid, return the current
42 * write_batch and the sequence number of the earliest
43 * transaction contained in the batch.</p>
44 *
45 * <p>ONLY use if Valid() is true and status() is OK.</p>
46 *
47 * @return {@link org.rocksdb.TransactionLogIterator.BatchResult}
48 * instance.
49 */
50 public BatchResult getBatch() {
51 assert(isValid());
52 return getBatch(nativeHandle_);
53 }
54
55 /**
56 * <p>TransactionLogIterator constructor.</p>
57 *
58 * @param nativeHandle address to native address.
59 */
60 TransactionLogIterator(final long nativeHandle) {
61 super(nativeHandle);
62 }
63
64 /**
65 * <p>BatchResult represents a data structure returned
66 * by a TransactionLogIterator containing a sequence
67 * number and a {@link WriteBatch} instance.</p>
68 */
69 public static final class BatchResult {
70 /**
71 * <p>Constructor of BatchResult class.</p>
72 *
73 * @param sequenceNumber related to this BatchResult instance.
74 * @param nativeHandle to {@link org.rocksdb.WriteBatch}
75 * native instance.
76 */
77 public BatchResult(final long sequenceNumber,
78 final long nativeHandle) {
79 sequenceNumber_ = sequenceNumber;
80 writeBatch_ = new WriteBatch(nativeHandle, true);
81 }
82
83 /**
84 * <p>Return sequence number related to this BatchResult.</p>
85 *
86 * @return Sequence number.
87 */
88 public long sequenceNumber() {
89 return sequenceNumber_;
90 }
91
92 /**
93 * <p>Return contained {@link org.rocksdb.WriteBatch}
94 * instance</p>
95 *
96 * @return {@link org.rocksdb.WriteBatch} instance.
97 */
98 public WriteBatch writeBatch() {
99 return writeBatch_;
100 }
101
102 private final long sequenceNumber_;
103 private final WriteBatch writeBatch_;
104 }
105
106 @Override protected final native void disposeInternal(final long handle);
107 private native boolean isValid(long handle);
108 private native void next(long handle);
109 private native void status(long handle)
110 throws RocksDBException;
111 private native BatchResult getBatch(long handle);
112 }