Skip to content

Commit 77a3494

Browse files
committed
Fix failing test
1 parent ad75cb2 commit 77a3494

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

src/main/java/org/lmdbjava/Cursor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ public void delete(final PutFlags... flags) {
110110
}
111111

112112
/**
113-
* @deprecated Instead use {@link Cursor#delete(PutFlagSet)}.
114-
* <hr>
115113
* Delete current key/data pair.
116114
*
117115
* <p>This function deletes the key/data pair to which the cursor refers.

src/main/java/org/lmdbjava/Dbi.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
*/
5050
public final class Dbi<T> {
5151

52+
@SuppressWarnings("FieldCanBeLocal") // Needs to be instance variable for FFI
53+
private final ComparatorCallback callbackComparator;
5254
private boolean cleaned;
5355
// Used for CursorIterable KeyRange testing and/or native callbacks
5456
private final Comparator<T> comparator;
@@ -90,26 +92,24 @@ public final class Dbi<T> {
9092
final Pointer dbiPtr = allocateDirect(RUNTIME, ADDRESS);
9193
checkRc(LIB.mdb_dbi_open(txn.pointer(), name, this.dbiFlagSet.getMask(), dbiPtr));
9294
ptr = dbiPtr.getPointer(0);
93-
ComparatorCallback callbackComparator;
9495
if (nativeCb) {
9596
// LMDB will call back to this comparator for insertion/iteration order
96-
callbackComparator = createCallbackComparator(proxy);
97+
this.callbackComparator = createCallbackComparator(proxy);
9798
LIB.mdb_set_compare(txn.pointer(), ptr, callbackComparator);
99+
} else {
100+
callbackComparator = null;
98101
}
99102
}
100103

101-
private ComparatorCallback createCallbackComparator(BufferProxy<T> proxy) {
102-
ComparatorCallback callbackComparator;
103-
callbackComparator =
104-
(keyA, keyB) -> {
105-
final T compKeyA = proxy.out(proxy.allocate(), keyA);
106-
final T compKeyB = proxy.out(proxy.allocate(), keyB);
107-
final int result = this.comparator.compare(compKeyA, compKeyB);
108-
proxy.deallocate(compKeyA);
109-
proxy.deallocate(compKeyB);
110-
return result;
111-
};
112-
return callbackComparator;
104+
private ComparatorCallback createCallbackComparator(final BufferProxy<T> proxy) {
105+
return (keyA, keyB) -> {
106+
final T compKeyA = proxy.out(proxy.allocate(), keyA);
107+
final T compKeyB = proxy.out(proxy.allocate(), keyB);
108+
final int result = this.comparator.compare(compKeyA, compKeyB);
109+
proxy.deallocate(compKeyA);
110+
proxy.deallocate(compKeyB);
111+
return result;
112+
};
113113
}
114114

115115
Pointer pointer() {

src/main/java/org/lmdbjava/DbiBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,8 @@ private Comparator<T> getComparator(final DbiBuilder<T> dbiBuilder,
420420
break;
421421
case CALLBACK:
422422
case ITERATOR:
423-
comparator = Objects.requireNonNull(
424-
dbiBuilderStage2.comparatorFactory.create(dbiFlagSet),
425-
() -> "comparatorFactory returned null");
423+
comparator = dbiBuilderStage2.comparatorFactory.create(dbiFlagSet);
424+
Objects.requireNonNull(comparator, "comparatorFactory returned null");
426425
break;
427426
case NATIVE:
428427
break;

src/test/java/org/lmdbjava/CursorIterableIntegerKeyTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,16 @@ public void testIntegerKeyKeySize() {
234234
db.put(txn, bbNative(Long.MAX_VALUE), bb("val_" + ++val));
235235
txn.commit();
236236
}
237-
238-
try (Txn<ByteBuffer> txn = env.txnRead()) {
239-
try (CursorIterable<ByteBuffer> iterable = db.iterate(txn)) {
240-
for (KeyVal<ByteBuffer> keyVal : iterable) {
241-
final String val = getString(keyVal.val());
242-
final long key = getNativeLong(keyVal.key());
243-
final int remaining = keyVal.key().remaining();
237+
// try (Txn<ByteBuffer> txn = env.txnRead()) {
238+
// try (CursorIterable<ByteBuffer> iterable = db.iterate(txn)) {
239+
// for (KeyVal<ByteBuffer> keyVal : iterable) {
240+
// final String val = getString(keyVal.val());
241+
// final long key = getNativeLong(keyVal.key());
242+
// final int remaining = keyVal.key().remaining();
244243
// System.out.println("key: " + key + ", val: " + val + ", remaining: " + remaining);
245-
}
246-
}
247-
}
248-
244+
// }
245+
// }
246+
// }
249247
}
250248

251249
@Test

0 commit comments

Comments
 (0)