@@ -93,13 +93,9 @@ public static Env<ByteBuffer> open(
9393 }
9494
9595 private boolean closed = false ;
96- private boolean open = false ;
9796 private final BufferProxy <T > proxy ;
9897 final Pointer ptr ;
9998
100- /**
101- * Creates a new environment handle.
102- */
10399 private Env (final BufferProxy <T > proxy ) {
104100 requireNonNull (proxy );
105101 this .proxy = proxy ;
@@ -119,9 +115,6 @@ public void close() {
119115 return ;
120116 }
121117 closed = true ;
122- if (!open ) {
123- return ;
124- }
125118 LIB .mdb_env_close (ptr );
126119 }
127120
@@ -162,9 +155,6 @@ public EnvInfo info() {
162155 if (closed ) {
163156 throw new AlreadyClosedException ();
164157 }
165- if (!open ) {
166- throw new NotOpenException ();
167- }
168158 final MDB_envinfo info = new MDB_envinfo (RUNTIME );
169159 checkRc (LIB .mdb_env_info (ptr , info ));
170160
@@ -193,15 +183,6 @@ public boolean isClosed() {
193183 return closed ;
194184 }
195185
196- /**
197- * Indicates whether this environment has been opened.
198- *
199- * @return true if opened
200- */
201- public boolean isOpen () {
202- return open ;
203- }
204-
205186 /**
206187 * Open the {@link Dbi}.
207188 *
@@ -228,9 +209,6 @@ public EnvStat stat() {
228209 if (closed ) {
229210 throw new AlreadyClosedException ();
230211 }
231- if (!open ) {
232- throw new NotOpenException ();
233- }
234212 final MDB_stat stat = new MDB_stat (RUNTIME );
235213 checkRc (LIB .mdb_env_stat (ptr , stat ));
236214 return new EnvStat (
@@ -253,9 +231,6 @@ public void sync(final boolean force) {
253231 if (closed ) {
254232 throw new AlreadyClosedException ();
255233 }
256- if (!open ) {
257- throw new NotOpenException ();
258- }
259234 final int f = force ? 1 : 0 ;
260235 checkRc (LIB .mdb_env_sync (ptr , f ));
261236 }
@@ -326,7 +301,8 @@ public AlreadyOpenException() {
326301 */
327302 public static final class Builder <T > {
328303
329- Env <T > env ;
304+ private final Env <T > env ;
305+ private boolean opened = false ;
330306
331307 private Builder (Env <T > env ) {
332308 this .env = env ;
@@ -346,12 +322,12 @@ public Env<T> open(final File path, final int mode,
346322 if (env .closed ) {
347323 throw new AlreadyClosedException ();
348324 }
349- if (env . open ) {
325+ if (opened ) {
350326 throw new AlreadyOpenException ();
351327 }
352328 final int flagsMask = mask (flags );
353329 checkRc (LIB .mdb_env_open (env .ptr , path .getAbsolutePath (), flagsMask , mode ));
354- this . env . open = true ;
330+ opened = true ;
355331 return this .env ;
356332 }
357333
@@ -373,12 +349,9 @@ public Env<T> open(final File path, final EnvFlags... flags) {
373349 * @return the builder
374350 */
375351 public Builder <T > setMapSize (final long mapSize ) {
376- if (env . open ) {
352+ if (opened ) {
377353 throw new AlreadyOpenException ();
378354 }
379- if (env .closed ) {
380- throw new AlreadyClosedException ();
381- }
382355 checkRc (LIB .mdb_env_set_mapsize (env .ptr , mapSize ));
383356 return this ;
384357 }
@@ -401,12 +374,9 @@ public Builder<T> setMapSize(final int size, ByteUnit unit) {
401374 * @return the builder
402375 */
403376 public Builder <T > setMaxDbs (final int dbs ) {
404- if (env . open ) {
377+ if (opened ) {
405378 throw new AlreadyOpenException ();
406379 }
407- if (env .closed ) {
408- throw new AlreadyClosedException ();
409- }
410380 checkRc (LIB .mdb_env_set_maxdbs (env .ptr , dbs ));
411381 return this ;
412382 }
@@ -418,12 +388,9 @@ public Builder<T> setMaxDbs(final int dbs) {
418388 * @return the builder
419389 */
420390 public Builder <T > setMaxReaders (final int readers ) {
421- if (env . open ) {
391+ if (opened ) {
422392 throw new AlreadyOpenException ();
423393 }
424- if (env .closed ) {
425- throw new AlreadyClosedException ();
426- }
427394 checkRc (LIB .mdb_env_set_maxreaders (env .ptr , readers ));
428395 return this ;
429396 }
@@ -472,21 +439,6 @@ public static final class MapFullException extends LmdbNativeException {
472439 }
473440 }
474441
475- /**
476- * Object has is not open (eg never opened, or since closed).
477- */
478- public static class NotOpenException extends LmdbException {
479-
480- private static final long serialVersionUID = 1L ;
481-
482- /**
483- * Creates a new instance.
484- */
485- public NotOpenException () {
486- super ("Environment is not open" );
487- }
488- }
489-
490442 /**
491443 * Environment maxreaders reached.
492444 */
0 commit comments