Skip to content

Commit 0da45e9

Browse files
committed
Minor auto-formatting and test coverage following merge of lmdbjava#67
1 parent 388e15a commit 0da45e9

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
*/
5555
public final class Dbi<T> {
5656

57+
private boolean cleaned;
5758
private final Comparator<T> compFunc;
5859
private final T compKeyA;
5960
private final T compKeyB;
@@ -62,8 +63,6 @@ public final class Dbi<T> {
6263
private final BufferProxy<T> proxy;
6364
private final Pointer ptr;
6465

65-
private boolean isClean;
66-
6766
Dbi(final Env<T> env, final Txn<T> txn, final byte[] name,
6867
final Comparator<T> comparator, final DbiFlags... flags) {
6968
this.env = env;
@@ -107,17 +106,6 @@ public void close() {
107106
LIB.mdb_dbi_close(env.pointer(), ptr);
108107
}
109108

110-
private void clean() {
111-
if (isClean) {
112-
return;
113-
}
114-
isClean = true;
115-
if (compKeyA != null) {
116-
proxy.deallocate(compKeyA);
117-
proxy.deallocate(compKeyB);
118-
}
119-
}
120-
121109
/**
122110
* Starts a new read-write transaction and deletes the key.
123111
*
@@ -201,10 +189,10 @@ public void drop(final Txn<T> txn) {
201189

202190
/**
203191
* Drops the database. If delete is set to true, the database will be deleted
204-
* and handle will be closed. See {@link #close()} for implication of handle close.
205-
* Otherwise, only the data in this database will be dropped.
192+
* and handle will be closed. See {@link #close()} for implication of handle
193+
* close. Otherwise, only the data in this database will be dropped.
206194
*
207-
* @param txn transaction handle (not null; not committed; must be R-W)
195+
* @param txn transaction handle (not null; not committed; must be R-W)
208196
* @param delete whether database should be deleted.
209197
*/
210198
public void drop(final Txn<T> txn, final boolean delete) {
@@ -500,6 +488,17 @@ public Stat stat(final Txn<T> txn) {
500488
stat.f5_ms_entries.longValue());
501489
}
502490

491+
private void clean() {
492+
if (cleaned) {
493+
return;
494+
}
495+
cleaned = true;
496+
if (compKeyA != null) {
497+
proxy.deallocate(compKeyA);
498+
proxy.deallocate(compKeyB);
499+
}
500+
}
501+
503502
/**
504503
* The specified DBI was changed unexpectedly.
505504
*/

src/test/java/org/lmdbjava/DbiTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import static java.nio.ByteBuffer.allocateDirect;
3030
import static java.nio.charset.StandardCharsets.UTF_8;
3131
import static java.util.Collections.nCopies;
32-
3332
import java.util.Comparator;
3433
import java.util.List;
3534
import java.util.Random;
@@ -176,6 +175,8 @@ public void dropAndDeleteAnonymousDb() {
176175
assertThat(nameDb.get(txn, dbNameBuffer), is(nullValue()));
177176
txn.commit();
178177
}
178+
179+
nameDb.close(); // explicit close after drop is OK
179180
}
180181

181182
@Test

0 commit comments

Comments
 (0)