Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
480e984
gh-249 Remove MDB_UNSIGNEDKEY, let CursorIterable call mdb_cmp
at055612 Mar 6, 2025
46f8d08
gh-249 Remove non-J8 features, use indent size 2
at055612 Mar 6, 2025
f92012e
gh-249 Fix indents
at055612 Mar 6, 2025
e1756d6
gh-249 Tidy code and refactor RangeComparator impls
at055612 Mar 6, 2025
9509f6b
gh-249 Remove commented code
at055612 Mar 6, 2025
67e2df1
gh-249 Add CursorIterableIntegerKeyTest
at055612 Mar 7, 2025
620a89f
gh-249 Remove MaskedFlag.isPropagatedToLmdb, add DbiBuilder WIP
at055612 Jun 5, 2025
75d87d0
Merge branch 'master' into mdb_cmp
at055612 Oct 26, 2025
47b4c4f
Merge branch 'master' into mdb_cmp
at055612 Oct 26, 2025
bfbf223
Add FlagSet, DbiFlagSet, PutFlagSet
at055612 Oct 27, 2025
0f66aaf
Rename FlagSet to AbstractFlagSet
at055612 Oct 27, 2025
aa000a1
Add remaining FlagSet impls
at055612 Oct 27, 2025
667dab3
Fix Javadoc
at055612 Oct 27, 2025
b46c916
Add more cursor tests to protect against future regression
stroomdev66 Oct 28, 2025
0234d32
Replace get(Uns|S)ignedComparator with getComparator(DbiFlagSet)
at055612 Oct 28, 2025
ef0c852
Add missing txn commit in DbiBuilder
at055612 Oct 28, 2025
1b3f94d
Change CursorIterableTest to use Parameterized
at055612 Oct 28, 2025
c0bbe73
Deprecate methods using varargs flags
at055612 Oct 28, 2025
4fd89ff
Add int key compare method to (Direct|Byte)BufferProxy
at055612 Oct 29, 2025
916b441
Merge branch 'master' of github.com:lmdbjava/lmdbjava into more-curso…
stroomdev66 Oct 29, 2025
58dcc6e
Tidy code
at055612 Oct 29, 2025
26665ba
Fix byte order issues with compareAsIntegerKeys
at055612 Oct 29, 2025
dc0b96b
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Oct 29, 2025
9db91a5
Merge branch 'master' of github.com:lmdbjava/lmdbjava into gh-267
stroomdev66 Oct 30, 2025
c427801
Add/refactor tests
at055612 Nov 4, 2025
f606e7e
Merge branch 'master' into mdb_cmp
at055612 Nov 4, 2025
e2be6bf
Add integer key comparator tests
at055612 Nov 5, 2025
7374fde
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
79c0df6
Merge branch 'master' of github.com:lmdbjava/lmdbjava into gh-267
stroomdev66 Nov 5, 2025
787d6d3
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
c289763
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
1acd971
Add ComparatorFactory
at055612 Nov 5, 2025
69eb5b7
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
915edce
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
dea7975
Merge branch 'master' into mdb_cmp
at055612 Nov 5, 2025
5a62965
Merged new comparator code
stroomdev66 Nov 5, 2025
484a772
Merged new comparator code
stroomdev66 Nov 5, 2025
ad75cb2
Fix CodeQL issues, add setMapSizeXx methods
at055612 Nov 5, 2025
77a3494
Fix failing test
at055612 Nov 5, 2025
1d46e0b
Refactor deprecated method calls
at055612 Nov 6, 2025
577062f
Fix compile issue
at055612 Nov 6, 2025
12a9679
Improve FlagSet tests
at055612 Nov 6, 2025
7a6910b
Add licence header
at055612 Nov 6, 2025
167cdad
Rename buildDbi to createDbi to be consistent with Env.create()
at055612 Nov 6, 2025
d47694e
Remove ByteUnits dep, add ByteUnit enum, add setMapSize() overload
at055612 Nov 6, 2025
fb08779
Fix compile errors
at055612 Nov 6, 2025
a82d7f2
Add more test coverage
at055612 Nov 6, 2025
534b76b
Fix codeQL issue
at055612 Nov 6, 2025
e9f9ac4
Add test coverage on FlagSet
at055612 Nov 6, 2025
b0112bb
Add tests
at055612 Nov 6, 2025
c25a7d2
Run format plugin
at055612 Nov 7, 2025
cf3a11e
Remove class separators
at055612 Nov 7, 2025
0c97cf4
Run format plugin
at055612 Nov 7, 2025
72d4e3f
Remove binaries accidentally added, fix test
at055612 Nov 7, 2025
18013fb
Merged new comparator code
stroomdev66 Nov 7, 2025
6b40d0b
Merge branch 'gh-267_plus_new_comparators' into gh-249-remove-unsigne…
at055612 Nov 7, 2025
48aa0fd
Fix javadoc warnings and class visibility, fix licence warnings
at055612 Nov 7, 2025
72b5234
Auto-format
at055612 Nov 7, 2025
dd95dea
Add error handling for parse(Int|Long)
at055612 Nov 7, 2025
b53378a
Remove unused code
at055612 Nov 7, 2025
deb1f1b
Remove unused code
at055612 Nov 7, 2025
2bfe07c
Remove unused hashCode methods
at055612 Nov 7, 2025
a84ceaa
Change CursorIterableRangeTest to do default+native modes
at055612 Nov 9, 2025
a5e4cf2
Remove separator comments
at055612 Nov 9, 2025
f8e6e07
Add more tests to CursorIterableRangeTest
at055612 Nov 9, 2025
6982aca
Remove unused test, auto format
at055612 Nov 9, 2025
6740e2b
Add tests to stop CodeQL warnings
at055612 Nov 12, 2025
0103f13
Auto format
at055612 Nov 12, 2025
4249566
Fix typo in javadoc
at055612 Nov 12, 2025
35b0a9d
Tidy code
at055612 Nov 12, 2025
9a35718
Add in test classes for deprecated methods
at055612 Nov 14, 2025
8c19bf4
Add test coverage
at055612 Nov 14, 2025
496e5ea
Add test coverage
at055612 Nov 14, 2025
7bd3332
Auto format
at055612 Nov 14, 2025
06523f9
Add more tests
at055612 Nov 14, 2025
fe41338
Add test coverage
at055612 Nov 14, 2025
38eac0d
Add ByteBufProxyTest, refactor some test classes
at055612 Nov 14, 2025
53ac34d
Add missing licences
at055612 Nov 14, 2025
5ad4f0c
Add test assert
at055612 Nov 14, 2025
a0503d3
Add TxnDeprecatedTest for more coverage
at055612 Nov 17, 2025
29d5ba2
Auto format
at055612 Nov 17, 2025
1312e10
Add tests for XxxFlags.isSet
at055612 Nov 17, 2025
0216c92
Add more test coverage
at055612 Nov 17, 2025
8b60f29
Change FlagSet args to be requireNonNull
at055612 Nov 17, 2025
e53956d
Add requireNonNull checks to Dbi
at055612 Nov 17, 2025
654a5bc
Add more coverage
at055612 Nov 17, 2025
850c4e2
Add DirectBufferProxyTest
at055612 Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Deprecate methods using varargs flags
  • Loading branch information
at055612 committed Oct 28, 2025
commit c0bbe73cb1d128ebb04baf842b9ed98b941a8e7f
181 changes: 160 additions & 21 deletions src/main/java/org/lmdbjava/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import static org.lmdbjava.Dbi.KeyNotFoundException.MDB_NOTFOUND;
import static org.lmdbjava.Env.SHOULD_CHECK;
import static org.lmdbjava.Library.LIB;
import static org.lmdbjava.MaskedFlag.isSet;
import static org.lmdbjava.MaskedFlag.mask;
import static org.lmdbjava.PutFlags.MDB_MULTIPLE;
import static org.lmdbjava.PutFlags.MDB_NODUPDATA;
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;
Expand Down Expand Up @@ -97,23 +95,49 @@ public long count() {
checkRc(LIB.mdb_cursor_count(ptrCursor, longByReference));
return longByReference.longValue();
}
/**
* @deprecated Instead use {@link Cursor#delete(PutFlagSet)}.
* <hr>
* Delete current key/data pair.
*
* <p>This function deletes the key/data pair to which the cursor refers.
*
* @param flags flags (either null or {@link PutFlags#MDB_NODUPDATA}
*/
@Deprecated
public void delete(final PutFlags... flags) {
delete(PutFlagSet.of(flags));
}

/**
* @deprecated Instead use {@link Cursor#delete(PutFlagSet)}.
* <hr>
* Delete current key/data pair.
*
* <p>This function deletes the key/data pair to which the cursor refers.
*/
public void delete() {
delete(PutFlagSet.EMPTY);
}

/**
* Delete current key/data pair.
*
* <p>This function deletes the key/data pair to which the cursor refers.
*
* @param f flags (either null or {@link PutFlags#MDB_NODUPDATA}
* @param flags flags (either null or {@link PutFlags#MDB_NODUPDATA}
*/
public void delete(final PutFlags... f) {
public void delete(final PutFlagSet flags) {
if (SHOULD_CHECK) {
env.checkNotClosed();
checkNotClosed();
txn.checkReady();
txn.checkWritesAllowed();
}
final int flags = mask(f);
checkRc(LIB.mdb_cursor_del(ptrCursor, flags));
final PutFlagSet putFlagSet = flags != null
? flags
: PutFlagSet.EMPTY;
checkRc(LIB.mdb_cursor_del(ptrCursor, putFlagSet.getMask()));
}

/**
Expand Down Expand Up @@ -235,17 +259,49 @@ public boolean prev() {
}

/**
* @deprecated Use {@link Cursor#put(Object, Object, PutFlagSet)} instead.
* <hr>
* Store by cursor.
*
* <p>This function stores key/data pairs into the database.
*
* @param key key to store
* @param val data to store
* @param op options for this operation
* @param flags options for this operation
* @return true if the value was put, false if MDB_NOOVERWRITE or MDB_NODUPDATA were set and the
* key/value existed already.
*/
@Deprecated
public boolean put(final T key, final T val, final PutFlags... flags) {
return put(key, val, PutFlagSet.of(flags));
}

/**
* Store by cursor.
*
* <p>This function stores key/data pairs into the database.
*
* @param key key to store
* @param val data to store
* @return true if the value was put, false if MDB_NOOVERWRITE or MDB_NODUPDATA were set and the
* key/value existed already.
*/
public boolean put(final T key, final T val) {
return put(key, val, PutFlagSet.EMPTY);
}

/**
* Store by cursor.
*
* <p>This function stores key/data pairs into the database.
*
* @param key key to store
* @param val data to store
* @param flags options for this operation
* @return true if the value was put, false if MDB_NOOVERWRITE or MDB_NODUPDATA were set and the
* key/value existed already.
*/
public boolean put(final T key, final T val, final PutFlags... op) {
public boolean put(final T key, final T val, final PutFlagSet flags) {
if (SHOULD_CHECK) {
requireNonNull(key);
requireNonNull(val);
Expand All @@ -256,12 +312,14 @@ public boolean put(final T key, final T val, final PutFlags... op) {
}
final Pointer transientKey = kv.keyIn(key);
final Pointer transientVal = kv.valIn(val);
final int mask = mask(op);
final int rc = LIB.mdb_cursor_put(ptrCursor, kv.pointerKey(), kv.pointerVal(), mask);
final PutFlagSet putFlagSet = flags != null
? flags
: PutFlagSet.EMPTY;
final int rc = LIB.mdb_cursor_put(ptrCursor, kv.pointerKey(), kv.pointerVal(), putFlagSet.getMask());
if (rc == MDB_KEYEXIST) {
if (isSet(mask, MDB_NOOVERWRITE)) {
if (putFlagSet.isSet(MDB_NOOVERWRITE)) {
kv.valOut(); // marked as in,out in LMDB C docs
} else if (!isSet(mask, MDB_NODUPDATA)) {
} else if (!putFlagSet.isSet(MDB_NODUPDATA)) {
checkRc(rc);
}
return false;
Expand All @@ -274,6 +332,42 @@ public boolean put(final T key, final T val, final PutFlags... op) {
return true;
}

/**
* @deprecated Use {@link Cursor#put(Object, Object, PutFlagSet)} instead.
* <hr>
* Put multiple values into the database in one <code>MDB_MULTIPLE</code> operation.
*
* <p>The database must have been opened with {@link DbiFlags#MDB_DUPFIXED}. The buffer must
* contain fixed-sized values to be inserted. The size of each element is calculated from the
* buffer's size divided by the given element count. For example, to populate 10 X 4 byte integers
* at once, present a buffer of 40 bytes and specify the element as 10.
*
* @param key key to store in the database (not null)
* @param val value to store in the database (not null)
* @param elements number of elements contained in the passed value buffer
* @param flags options for operation (must set <code>MDB_MULTIPLE</code>)
*/
@Deprecated
public void putMultiple(final T key, final T val, final int elements, final PutFlags... flags) {
putMultiple(key, val, elements, PutFlagSet.of(flags));
}

/**
* Put multiple values into the database in one <code>MDB_MULTIPLE</code> operation.
*
* <p>The database must have been opened with {@link DbiFlags#MDB_DUPFIXED}. The buffer must
* contain fixed-sized values to be inserted. The size of each element is calculated from the
* buffer's size divided by the given element count. For example, to populate 10 X 4 byte integers
* at once, present a buffer of 40 bytes and specify the element as 10.
*
* @param key key to store in the database (not null)
* @param val value to store in the database (not null)
* @param elements number of elements contained in the passed value buffer
*/
public void putMultiple(final T key, final T val, final int elements) {
putMultiple(key, val, elements, PutFlagSet.EMPTY);
}

/**
* Put multiple values into the database in one <code>MDB_MULTIPLE</code> operation.
*
Expand All @@ -285,9 +379,10 @@ public boolean put(final T key, final T val, final PutFlags... op) {
* @param key key to store in the database (not null)
* @param val value to store in the database (not null)
* @param elements number of elements contained in the passed value buffer
* @param op options for operation (must set <code>MDB_MULTIPLE</code>)
* @param flags options for operation (must set <code>MDB_MULTIPLE</code>)
* Either a {@link PutFlagSet} or a single {@link PutFlags}.
*/
public void putMultiple(final T key, final T val, final int elements, final PutFlags... op) {
public void putMultiple(final T key, final T val, final int elements, final PutFlagSet flags) {
if (SHOULD_CHECK) {
requireNonNull(txn);
requireNonNull(key);
Expand All @@ -296,13 +391,15 @@ public void putMultiple(final T key, final T val, final int elements, final PutF
txn.checkReady();
txn.checkWritesAllowed();
}
final int mask = mask(op);
if (SHOULD_CHECK && !isSet(mask, MDB_MULTIPLE)) {
final PutFlagSet putFlagSet = flags != null
? flags
: PutFlagSet.EMPTY;
if (SHOULD_CHECK && !putFlagSet.isSet(MDB_MULTIPLE)) {
throw new IllegalArgumentException("Must set " + MDB_MULTIPLE + " flag");
}
final Pointer transientKey = txn.kv().keyIn(key);
final Pointer dataPtr = txn.kv().valInMulti(val, elements);
final int rc = LIB.mdb_cursor_put(ptrCursor, txn.kv().pointerKey(), dataPtr, mask);
final int rc = LIB.mdb_cursor_put(ptrCursor, txn.kv().pointerKey(), dataPtr, putFlagSet.getMask());
checkRc(rc);
ReferenceUtil.reachabilityFence0(transientKey);
ReferenceUtil.reachabilityFence0(dataPtr);
Expand Down Expand Up @@ -334,6 +431,8 @@ public void renew(final Txn<T> newTxn) {
}

/**
* @deprecated Use {@link Cursor#reserve(Object, int, PutFlagSet)} instead.
* <hr>
* Reserve space for data of the given size, but don't copy the given val. Instead, return a
* pointer to the reserved space, which the caller can fill in later - before the next update
* operation or the transaction ends. This saves an extra memcpy if the data is being generated
Expand All @@ -344,10 +443,46 @@ public void renew(final Txn<T> newTxn) {
*
* @param key key to store in the database (not null)
* @param size size of the value to be stored in the database (not null)
* @param op options for this operation
* @param flags options for this operation
* @return a buffer that can be used to modify the value
*/
@Deprecated
public T reserve(final T key, final int size, final PutFlags... flags) {
return reserve(key, size, PutFlagSet.of(flags));
}

/**
* Reserve space for data of the given size, but don't copy the given val. Instead, return a
* pointer to the reserved space, which the caller can fill in later - before the next update
* operation or the transaction ends. This saves an extra {@code memcpy} if the data is being generated
* later. LMDB does nothing else with this memory, the caller is expected to modify all the
* space requested.
*
* <p>This flag must not be specified if the database was opened with MDB_DUPSORT
*
* @param key key to store in the database (not null)
* @param size size of the value to be stored in the database (not null)
* @return a buffer that can be used to modify the value
*/
public T reserve(final T key, final int size) {
return reserve(key, size, PutFlagSet.EMPTY);
}

/**
* Reserve space for data of the given size, but don't copy the given val. Instead, return a
* pointer to the reserved space, which the caller can fill in later - before the next update
* operation or the transaction ends. This saves an extra memcpy if the data is being generated
* later. LMDB does nothing else with this memory, the caller is expected to modify all of the
* space requested.
*
* <p>This flag must not be specified if the database was opened with MDB_DUPSORT
*
* @param key key to store in the database (not null)
* @param size size of the value to be stored in the database (not null)
* @param flags options for this operation
* @return a buffer that can be used to modify the value
*/
public T reserve(final T key, final int size, final PutFlags... op) {
public T reserve(final T key, final int size, final PutFlagSet flags) {
if (SHOULD_CHECK) {
requireNonNull(key);
env.checkNotClosed();
Expand All @@ -357,8 +492,12 @@ public T reserve(final T key, final int size, final PutFlags... op) {
}
final Pointer transientKey = kv.keyIn(key);
final Pointer transientVal = kv.valIn(size);
final int flags = mask(op) | MDB_RESERVE.getMask();
checkRc(LIB.mdb_cursor_put(ptrCursor, kv.pointerKey(), kv.pointerVal(), flags));
final PutFlagSet putFlagSet = flags != null
? flags
: PutFlagSet.EMPTY;
// This is inconsistent with putMultiple which require MDB_MULTIPLE to be in the set.
final int flagsMask = putFlagSet.getMaskWith(MDB_RESERVE);
checkRc(LIB.mdb_cursor_put(ptrCursor, kv.pointerKey(), kv.pointerVal(), flagsMask));
kv.valOut();
ReferenceUtil.reachabilityFence0(transientKey);
ReferenceUtil.reachabilityFence0(transientVal);
Expand Down
Loading
Loading