2121import static java .util .Objects .requireNonNull ;
2222import jnr .ffi .Pointer ;
2323import jnr .ffi .byref .PointerByReference ;
24- import static org .lmdbjava .ByteBufferProxy .PROXY_OPTIMAL ;
2524import static org .lmdbjava .Library .LIB ;
2625import org .lmdbjava .Library .MDB_envinfo ;
2726import org .lmdbjava .Library .MDB_stat ;
2827import static org .lmdbjava .Library .RUNTIME ;
2928import static org .lmdbjava .MaskedFlag .mask ;
3029import static org .lmdbjava .ResultCodeMapper .checkRc ;
3130import org .lmdbjava .Txn .CommittedException ;
31+ import static org .lmdbjava .TxnFlags .MDB_RDONLY ;
3232
3333/**
3434 * LMDB environment.
35+ *
36+ * @param <T>
3537 */
3638public final class Env <T > implements AutoCloseable {
3739
@@ -48,23 +50,10 @@ public final class Env<T> implements AutoCloseable {
4850 */
4951 public static final boolean SHOULD_CHECK = !getBoolean (DISABLE_CHECKS_PROP );
5052
51- private boolean closed = false ;
52- private boolean open = false ;
53- final Pointer ptr ;
54- final BufferProxyFactory <T > factory ;
55-
5653 /**
57- * Creates a new environment handle.
5854 *
59- * @throws LmdbNativeException if a native C error occurred
55+ * @return @ throws LmdbNativeException
6056 */
61- Env (BufferProxyFactory <T > factory ) throws LmdbNativeException {
62- final PointerByReference envPtr = new PointerByReference ();
63- checkRc (LIB .mdb_env_create (envPtr ));
64- ptr = envPtr .getValue ();
65- this .factory = factory ;
66- }
67-
6857 public static Env <ByteBuffer > create () throws LmdbNativeException {
6958 return new Env <>(new BufferProxyFactory <ByteBuffer >() {
7059 @ Override
@@ -78,11 +67,34 @@ public void deallocate(BufferProxy<ByteBuffer> proxy) {
7867 });
7968 }
8069
81- public static <T > Env <T > create (BufferProxyFactory <T > factory )
82- throws LmdbNativeException {
70+ /**
71+ *
72+ * @param <T>
73+ * @param factory
74+ * @return
75+ * @throws LmdbNativeException
76+ */
77+ public static <T > Env <T > create (BufferProxyFactory <T > factory ) throws
78+ LmdbNativeException {
8379 return new Env <>(factory );
8480 }
8581
82+ private boolean closed = false ;
83+ private boolean open = false ;
84+ final BufferProxyFactory <T > factory ;
85+ final Pointer ptr ;
86+
87+ /**
88+ * Creates a new environment handle.
89+ *
90+ * @throws LmdbNativeException if a native C error occurred
91+ */
92+ Env (BufferProxyFactory <T > factory ) throws LmdbNativeException {
93+ final PointerByReference envPtr = new PointerByReference ();
94+ checkRc (LIB .mdb_env_create (envPtr ));
95+ ptr = envPtr .getValue ();
96+ this .factory = factory ;
97+ }
8698
8799 /**
88100 * Close the handle.
@@ -274,7 +286,6 @@ public void open(final File path, final int mode, final EnvFlags... flags)
274286 *
275287 * @param <T> buffer type that used by {@link Dbi} and its {@link Cursor}s
276288 * @param name name of the database (or null if no name is required)
277- * @param proxy the proxy to use for buffer management
278289 * @param flags to open the database with
279290 * @return a database that is ready to use
280291 * @throws NotOpenException
@@ -291,14 +302,6 @@ public <T> Dbi<T> openDbi(String name, DbiFlags... flags)
291302 }
292303 }
293304
294- public Txn txnWrite () throws NotOpenException , LmdbNativeException {
295- return new Txn (this , factory , null );
296- }
297-
298- public Txn txnRead () throws NotOpenException , LmdbNativeException {
299- return new Txn (this , factory , null , TxnFlags .MDB_RDONLY );
300- }
301-
302305 /**
303306 * Return statistics about this environment.
304307 *
@@ -349,6 +352,25 @@ public void sync(final boolean force) throws AlreadyClosedException,
349352 checkRc (LIB .mdb_env_sync (ptr , f ));
350353 }
351354
355+ /**
356+ *
357+ * @return @throws NotOpenException
358+ * @throws LmdbNativeException
359+ */
360+ public Txn txnRead () throws NotOpenException , LmdbNativeException {
361+ return new Txn (this , factory , null , MDB_RDONLY );
362+ }
363+
364+ /**
365+ *
366+ * @return @throws NotOpenException
367+ * @throws LmdbNativeException
368+ */
369+ public Txn txnWrite () throws NotOpenException ,
370+ LmdbNativeException {
371+ return new Txn (this , factory , null );
372+ }
373+
352374 /**
353375 * Object has already been closed and the operation is therefore prohibited.
354376 */
0 commit comments