11package org .lmdbjava ;
22
33import java .nio .ByteBuffer ;
4- import java .util .Set ;
5-
6- import jnr .ffi .byref .IntByReference ;
7-
4+ import static java .nio .ByteBuffer .allocateDirect ;
85import static java .nio .ByteOrder .LITTLE_ENDIAN ;
96import static java .util .Objects .requireNonNull ;
10- import static org . lmdbjava . Library . lib ;
11-
7+ import java . util . Set ;
8+ import jnr . ffi . byref . IntByReference ;
129import jnr .ffi .byref .PointerByReference ;
1310import org .lmdbjava .Library .MDB_val ;
14-
11+ import static org . lmdbjava . Library . lib ;
1512import static org .lmdbjava .Library .runtime ;
13+ import static org .lmdbjava .MaskedFlag .mask ;
1614import static org .lmdbjava .MemoryAccess .createVal ;
1715import static org .lmdbjava .MemoryAccess .wrap ;
1816import 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}
0 commit comments