From a3b61beb275534993ce885573f2f7abb246d9987 Mon Sep 17 00:00:00 2001 From: Sergio Vega Date: Tue, 24 Jul 2018 16:19:09 -0500 Subject: [PATCH] add cursor seek for MDB_GET_BOTH --- src/main/java/org/lmdbjava/Cursor.java | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/lmdbjava/Cursor.java b/src/main/java/org/lmdbjava/Cursor.java index 9950cde5..c0293a08 100644 --- a/src/main/java/org/lmdbjava/Cursor.java +++ b/src/main/java/org/lmdbjava/Cursor.java @@ -125,6 +125,37 @@ public boolean first() { return seek(MDB_FIRST); } + /** + * Reposition the key/value buffers based on the passed key and operation. + * + * @param key to search for + * @param data to search for + * @param op options for this operation + * @return false if key not found + */ + public boolean get(final T key, final T data, final SeekOp op) { + if (SHOULD_CHECK) { + requireNonNull(key); + requireNonNull(op); + checkNotClosed(); + txn.checkReady(); + } + kv.keyIn(key); + kv.valIn(data); + + final int rc = LIB.mdb_cursor_get(ptrCursor, kv.pointerKey(), kv + .pointerVal(), op.getCode()); + + if (rc == MDB_NOTFOUND) { + return false; + } + + checkRc(rc); + kv.keyOut(); + kv.valOut(); + return true; + } + /** * Reposition the key/value buffers based on the passed key and operation. *