Skip to content

Commit 2bdf460

Browse files
committed
Formatting only
1 parent bcdd318 commit 2bdf460

File tree

8 files changed

+115
-154
lines changed

8 files changed

+115
-154
lines changed
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,41 @@
11
package org.lmdbjava;
22

3-
import jnr.ffi.Pointer;
4-
import org.lmdbjava.Library.MDB_val;
5-
63
import java.nio.ByteBuffer;
7-
84
import static java.util.Objects.requireNonNull;
5+
import jnr.ffi.Pointer;
6+
import org.lmdbjava.Library.MDB_val;
97
import static org.lmdbjava.Library.lib;
108
import static org.lmdbjava.Library.runtime;
119
import static org.lmdbjava.MemoryAccess.createVal;
1210
import static org.lmdbjava.MemoryAccess.wrap;
11+
import static org.lmdbjava.PutFlags.ZERO;
1312
import static org.lmdbjava.ResultCodeMapper.checkRc;
1413

15-
1614
public class Cursor {
15+
1716
private ByteBuffer buffer;
17+
private boolean closed;
1818
private final Pointer ptr;
1919
private final Transaction tx;
20-
private boolean closed;
2120

2221
Cursor(Pointer ptr, Transaction tx) {
2322
this.ptr = ptr;
2423
this.tx = tx;
2524
}
2625

27-
public void put(ByteBuffer key, ByteBuffer val)
28-
throws LmdbNativeException {
29-
put(key, val, PutFlags.ZERO);
26+
public void close() {
27+
if (!closed) {
28+
lib.mdb_cursor_close(ptr);
29+
closed = true;
30+
}
3031
}
3132

32-
public void put(ByteBuffer key, ByteBuffer val, PutFlags op)
33-
throws LmdbNativeException {
34-
requireNonNull(key);
35-
requireNonNull(val);
36-
requireNonNull(op);
37-
if (tx.isCommitted()) {
38-
throw new IllegalArgumentException("transaction already committed");
39-
}
40-
if (closed) {
41-
throw new IllegalArgumentException("cursor closed");
42-
}
43-
final MDB_val k = createVal(key);
44-
final MDB_val v = createVal(val);
45-
checkRc(lib.mdb_cursor_put(ptr, k, v, op.getMask()));
33+
public void count() {
34+
4635
}
4736

4837
public void get(ByteBuffer key, ByteBuffer val, CursorOp op)
49-
throws LmdbNativeException {
38+
throws LmdbNativeException {
5039
requireNonNull(key);
5140
requireNonNull(val);
5241
requireNonNull(op);
@@ -69,19 +58,29 @@ public void get(ByteBuffer key, ByteBuffer val, CursorOp op)
6958
wrap(val, v);
7059
}
7160

72-
public void count() {
61+
public void put(ByteBuffer key, ByteBuffer val) throws LmdbNativeException {
62+
put(key, val, ZERO);
7363

7464
}
7565

76-
public void renew(Transaction tx) throws LmdbNativeException {
77-
checkRc(lib.mdb_cursor_renew(tx.ptr, ptr));
66+
public void put(ByteBuffer key, ByteBuffer val, PutFlags op)
67+
throws LmdbNativeException {
68+
requireNonNull(key);
69+
requireNonNull(val);
70+
requireNonNull(op);
71+
if (tx.isCommitted()) {
72+
throw new IllegalArgumentException("transaction already committed");
73+
}
74+
if (closed) {
75+
throw new IllegalArgumentException("cursor closed");
76+
}
77+
final MDB_val k = createVal(key);
78+
final MDB_val v = createVal(val);
79+
checkRc(lib.mdb_cursor_put(ptr, k, v, op.getMask()));
7880
}
7981

80-
public void close() {
81-
if (!closed) {
82-
lib.mdb_cursor_close(ptr);
83-
closed = true;
84-
}
82+
public void renew(Transaction tx) throws LmdbNativeException {
83+
checkRc(lib.mdb_cursor_renew(tx.ptr, ptr));
8584
}
8685

8786
}
Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package org.lmdbjava;
22

33
import java.nio.ByteBuffer;
4-
import java.util.Set;
5-
6-
import jnr.ffi.byref.IntByReference;
7-
4+
import static java.nio.ByteBuffer.allocateDirect;
85
import static java.nio.ByteOrder.LITTLE_ENDIAN;
96
import static java.util.Objects.requireNonNull;
10-
import static org.lmdbjava.Library.lib;
11-
7+
import java.util.Set;
8+
import jnr.ffi.byref.IntByReference;
129
import jnr.ffi.byref.PointerByReference;
1310
import org.lmdbjava.Library.MDB_val;
14-
11+
import static org.lmdbjava.Library.lib;
1512
import static org.lmdbjava.Library.runtime;
13+
import static org.lmdbjava.MaskedFlag.mask;
1614
import static org.lmdbjava.MemoryAccess.createVal;
1715
import static org.lmdbjava.MemoryAccess.wrap;
1816
import static org.lmdbjava.ResultCodeMapper.checkRc;
@@ -26,8 +24,9 @@ public final class Database {
2624
final int dbi;
2725
final Env env;
2826

29-
Database(Env env, Transaction tx, String name, Set<DatabaseFlags> flags) throws
30-
AlreadyCommittedException, LmdbNativeException {
27+
Database(Env env, Transaction tx, String name, Set<DatabaseFlags> flags)
28+
throws
29+
AlreadyCommittedException, LmdbNativeException {
3130
requireNonNull(env);
3231
requireNonNull(tx);
3332
requireNonNull(flags);
@@ -40,40 +39,22 @@ public final class Database {
4039
}
4140
this.env = env;
4241
this.name = name;
43-
final int flagsMask = MaskedFlag.mask(flags);
42+
final int flagsMask = mask(flags);
4443
final IntByReference dbiPtr = new IntByReference();
4544
checkRc(lib.mdb_dbi_open(tx.ptr, name, flagsMask, dbiPtr));
4645
dbi = dbiPtr.intValue();
4746
}
4847

49-
/**
50-
* Obtains the name of this database.
51-
*
52-
* @return the name (never null or empty)
53-
*/
54-
public String getName() {
55-
return name;
56-
}
57-
58-
public void put(Transaction tx, ByteBuffer key, ByteBuffer val) throws
59-
AlreadyCommittedException, LmdbNativeException {
60-
61-
final MDB_val k = createVal(key);
62-
final MDB_val v = createVal(val);
63-
64-
checkRc(lib.mdb_put(tx.ptr, dbi, k, v, 0));
65-
}
66-
6748
public void delete(Transaction tx, ByteBuffer key) throws
68-
AlreadyCommittedException, LmdbNativeException {
49+
AlreadyCommittedException, LmdbNativeException {
6950

7051
final MDB_val k = createVal(key);
7152

7253
checkRc(lib.mdb_del(tx.ptr, dbi, k, null));
7354
}
7455

7556
public ByteBuffer get(Transaction tx, ByteBuffer key) throws
76-
AlreadyCommittedException, LmdbNativeException {
57+
AlreadyCommittedException, LmdbNativeException {
7758
assert key.isDirect();
7859

7960
final MDB_val k = createVal(key);
@@ -82,14 +63,32 @@ public ByteBuffer get(Transaction tx, ByteBuffer key) throws
8263
checkRc(lib.mdb_get(tx.ptr, dbi, k, v));
8364

8465
// inefficient as we create a BB
85-
ByteBuffer bb = ByteBuffer.allocateDirect(1).order(LITTLE_ENDIAN);
66+
ByteBuffer bb = allocateDirect(1).order(LITTLE_ENDIAN);
8667
wrap(bb, v);
8768
return bb;
8869
}
8970

71+
/**
72+
* Obtains the name of this database.
73+
*
74+
* @return the name (never null or empty)
75+
*/
76+
public String getName() {
77+
return name;
78+
}
79+
9080
public Cursor openCursor(Transaction tx) throws LmdbNativeException {
9181
PointerByReference ptr = new PointerByReference();
9282
checkRc(lib.mdb_cursor_open(tx.ptr, dbi, ptr));
9383
return new Cursor(ptr.getValue(), tx);
9484
}
85+
86+
public void put(Transaction tx, ByteBuffer key, ByteBuffer val) throws
87+
AlreadyCommittedException, LmdbNativeException {
88+
89+
final MDB_val k = createVal(key);
90+
final MDB_val v = createVal(val);
91+
92+
checkRc(lib.mdb_put(tx.ptr, dbi, k, v, 0));
93+
}
9594
}

src/main/java/org/lmdbjava/Env.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import java.io.File;
44
import java.util.HashSet;
5+
import static java.util.Objects.requireNonNull;
56
import java.util.Set;
67
import jnr.ffi.Pointer;
78
import jnr.ffi.byref.PointerByReference;
8-
9-
import static java.util.Objects.requireNonNull;
109
import static org.lmdbjava.Library.lib;
11-
import static org.lmdbjava.TransactionFlags.MDB_RDONLY;
10+
import static org.lmdbjava.MaskedFlag.mask;
1211
import static org.lmdbjava.ResultCodeMapper.checkRc;
12+
import static org.lmdbjava.TransactionFlags.MDB_RDONLY;
1313

1414
/**
1515
* LMDB environment.
@@ -109,7 +109,7 @@ public void open(final File path,
109109
if (open) {
110110
throw new AlreadyOpenException(Env.class.getSimpleName());
111111
}
112-
final int flagsMask = MaskedFlag.mask(flags);
112+
final int flagsMask = mask(flags);
113113
checkRc(lib.mdb_env_open(ptr, path.getAbsolutePath(), flagsMask, mode));
114114
this.open = true;
115115
}

0 commit comments

Comments
 (0)