Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 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
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
58dcc6e
Tidy code
at055612 Oct 29, 2025
26665ba
Fix byte order issues with compareAsIntegerKeys
at055612 Oct 29, 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
1acd971
Add ComparatorFactory
at055612 Nov 5, 2025
dea7975
Merge branch 'master' into mdb_cmp
at055612 Nov 5, 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
Merge branch 'master' into mdb_cmp
  • Loading branch information
at055612 committed Nov 4, 2025
commit f606e7ee85bd5511a58e172940225a93a20d4bb3
3 changes: 3 additions & 0 deletions src/main/java/org/lmdbjava/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
*/
public List<byte[]> getDbiNames() {
final List<byte[]> result = new ArrayList<>();
final Dbi<T> names = openDbi((byte[]) null);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Env.openDbi
should be avoided because it has been deprecated.
try (Txn<T> txn = txnRead();
Cursor<T> cursor = names.openCursor(txn)) {
if (!cursor.first()) {
Expand Down Expand Up @@ -508,7 +508,7 @@
return new Txn<>(this, parent, proxy, flag);
}

/**
* Obtain a transaction with the requested parent and flags.
*
* @param parent parent transaction (may be null if no parent)
Expand Down Expand Up @@ -644,6 +644,8 @@
* @return an environment ready for use
*/
public Env<T> open(final File path, final int mode, final EnvFlags... flags) {
// TODO Use EnvFlagSet and deprecate
// TODO Make setUnixPermissions(int) method on builder.
requireNonNull(path);
if (opened) {
throw new AlreadyOpenException();
Expand Down Expand Up @@ -675,6 +677,7 @@
* @return an environment ready for use
*/
public Env<T> open(final File path, final EnvFlags... flags) {
// TODO make constant
return open(path, 0664, flags);
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/lmdbjava/MaskedFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,20 @@ static <M extends MaskedFlag> int mask(final M... flags) {
}
}

/**
* Combine the two masks into a single mask value, i.e. when combining two {@link FlagSet}s.
*/
static <M extends MaskedFlag> int mask(final int mask1, final int mask2) {
return mask1 | mask2;
}

/**
* Fetch the integer mask for the presented flags.
*
* @param <M> flag type
* @param flags to mask (null or empty returns zero)
* @return the integer mask for use in C
*/
static <M extends MaskedFlag> int mask(final Collection<M> flags) {
if (flags == null || flags.isEmpty()) {
return EMPTY_MASK;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/lmdbjava/ReferenceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ private ReferenceUtil() {}
* Vladimir Ivanov on reachabilityFence implementation</a>
*/
public static void reachabilityFence0(final Object ref) {
if (ref != null) {
//noinspection EmptySynchronizedStatement
synchronized (ref) {
// Empty synchronized is ok: https://stackoverflow.com/a/31933260/1151521
}
}
// Empty method body is intentional - the method call itself at bytecode level
// extends the object's live range per HotSpot JIT behavior
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 25 additions & 22 deletions src/test/java/org/lmdbjava/ByteBufferProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@
import java.util.Set;
import jnr.ffi.Pointer;
import jnr.ffi.provider.MemoryManager;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.lmdbjava.ByteBufferProxy.BufferMustBeDirectException;
import org.lmdbjava.Env.ReadersFullException;

Expand All @@ -61,20 +59,23 @@

static final MemoryManager MEM_MGR = RUNTIME.getMemoryManager();

@Rule
public final TemporaryFolder tmp = new TemporaryFolder();

@Test(expected = BufferMustBeDirectException.class)
public void buffersMustBeDirect() throws IOException {
final File path = tmp.newFolder();
try (Env<ByteBuffer> env = create().setMaxReaders(1).open(path)) {
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
final ByteBuffer key = allocate(100);
key.putInt(1).flip();
final ByteBuffer val = allocate(100);
val.putInt(1).flip();
db.put(key, val); // error
}
@Test
void buffersMustBeDirect() {
assertThatThrownBy(
() -> {
FileUtil.useTempDir(
dir -> {
try (Env<ByteBuffer> env = create().setMaxReaders(1).open(dir.toFile())) {
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
Comment thread Fixed
final ByteBuffer key = allocate(100);
key.putInt(1).flip();
final ByteBuffer val = allocate(100);
val.putInt(1).flip();
db.put(key, val); // error
}
});
})
.isInstanceOf(BufferMustBeDirectException.class);
}

@Test
Expand All @@ -98,9 +99,9 @@
@Test
void fieldNeverFound() {
assertThatThrownBy(
() -> {
findField(Exception.class, "notARealField");
})
() -> {
findField(Exception.class, "notARealField");
})
.isInstanceOf(LmdbException.class);
}

Expand Down Expand Up @@ -157,7 +158,7 @@
final long[] values = random.longs(5_000_000).toArray();

Instant time = Instant.now();
int x = 0;

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'int x' is never read.
for (int rounds = 0; rounds < 100; rounds++) {
for (int i = 1; i < values.length; i++) {
buffer1.order(ByteOrder.nativeOrder())
Expand Down Expand Up @@ -234,7 +235,9 @@
});

if (uniqueResults.size() != 1) {
Assert.fail("Comparator mismatch for values: " + val1 + " and " + val2 + ". Results: " + results);
Assertions.fail("Comparator mismatch for values: "
+ val1 + " and "
+ val2 + ". Results: " + results);
}
}
}
Expand Down
64 changes: 20 additions & 44 deletions src/test/java/org/lmdbjava/CopyFlagSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,44 @@
*/
package org.lmdbjava;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;
import java.util.HashSet;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CopyFlagSetTest {

@Test
public void testEmpty() {
final CopyFlagSet copyFlagSet = CopyFlagSet.empty();
assertThat(
copyFlagSet.getMask(),
is(0));
assertThat(
copyFlagSet.size(),
is(0));
assertThat(
copyFlagSet.isEmpty(),
is(true));
assertThat(
copyFlagSet.isSet(CopyFlags.MDB_CP_COMPACT),
is(false));
assertThat(copyFlagSet.getMask()).isEqualTo(0);
assertThat(copyFlagSet.size()).isEqualTo(0);
assertThat(copyFlagSet.isEmpty()).isEqualTo(true);
assertThat(copyFlagSet.isSet(CopyFlags.MDB_CP_COMPACT)).isEqualTo(false);
final CopyFlagSet copyFlagSet2 = CopyFlagSet.builder()
.build();
assertThat(copyFlagSet, is(copyFlagSet2));
assertThat(copyFlagSet, not(CopyFlagSet.of(CopyFlags.MDB_CP_COMPACT)));
assertThat(copyFlagSet, not(CopyFlagSet.builder()
assertThat(copyFlagSet).isEqualTo(copyFlagSet2);
assertThat(copyFlagSet).isNotEqualTo(CopyFlagSet.of(CopyFlags.MDB_CP_COMPACT));
assertThat(copyFlagSet).isNotEqualTo(CopyFlagSet.builder()
.setFlag(CopyFlags.MDB_CP_COMPACT)
.build()));
.build());
}

@Test
public void testOf() {
final CopyFlags copyFlag = CopyFlags.MDB_CP_COMPACT;
final CopyFlagSet copyFlagSet = CopyFlagSet.of(copyFlag);
assertThat(
copyFlagSet.getMask(),
is(MaskedFlag.mask(copyFlag)));
assertThat(
copyFlagSet.size(),
is(1));
assertThat(copyFlagSet.getMask()).isEqualTo(MaskedFlag.mask(copyFlag));
assertThat(copyFlagSet.size()).isEqualTo(1);
for (CopyFlags flag : copyFlagSet) {
assertThat(
copyFlagSet.isSet(flag),
is(true));
assertThat(copyFlagSet.isSet(flag)).isEqualTo(true);
}

final CopyFlagSet copyFlagSet2 = CopyFlagSet.builder()
.setFlag(copyFlag)
.build();
assertThat(copyFlagSet, is(copyFlagSet2));
assertThat(copyFlagSet).isEqualTo(copyFlagSet2);
}

@Test
Expand All @@ -77,27 +61,19 @@ public void testBuilder() {
final CopyFlagSet copyFlagSet = CopyFlagSet.builder()
.setFlag(copyFlag1)
.build();
assertThat(
copyFlagSet.getMask(),
is(MaskedFlag.mask(copyFlag1)));
assertThat(
copyFlagSet.size(),
is(1));
assertThat(
copyFlagSet.isSet(CopyFlags.MDB_CP_COMPACT),
is(true));
assertThat(copyFlagSet.getMask()).isEqualTo(MaskedFlag.mask(copyFlag1));
assertThat(copyFlagSet.size()).isEqualTo(1);
assertThat(copyFlagSet.isSet(CopyFlags.MDB_CP_COMPACT)).isEqualTo(true);
for (CopyFlags flag : copyFlagSet) {
assertThat(
copyFlagSet.isSet(flag),
is(true));
assertThat(copyFlagSet.isSet(flag)).isEqualTo(true);
}
final CopyFlagSet copyFlagSet2 = CopyFlagSet.builder()
.withFlags(copyFlag1)
.build();
final CopyFlagSet copyFlagSet3 = CopyFlagSet.builder()
.withFlags(new HashSet<>(Collections.singletonList(copyFlag1)))
.build();
assertThat(copyFlagSet, is(copyFlagSet2));
assertThat(copyFlagSet, is(copyFlagSet3));
assertThat(copyFlagSet).isEqualTo(copyFlagSet2);
assertThat(copyFlagSet).isEqualTo(copyFlagSet3);
}
}
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.