Skip to content

Commit f342238

Browse files
committed
Apply static field naming convention to Library
1 parent 4be773f commit f342238

File tree

8 files changed

+49
-48
lines changed

8 files changed

+49
-48
lines changed

src/main/java/org/lmdbjava/Cursor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static java.util.Objects.requireNonNull;
2020
import jnr.ffi.Pointer;
2121
import jnr.ffi.byref.NativeLongByReference;
22-
import static org.lmdbjava.Library.lib;
22+
import static org.lmdbjava.Library.LIB;
2323
import org.lmdbjava.LmdbException.BufferNotDirectException;
2424
import static org.lmdbjava.MaskedFlag.mask;
2525
import static org.lmdbjava.ResultCodeMapper.checkRc;
@@ -63,7 +63,7 @@ public void close() throws CommittedException {
6363
if (!tx.isReadOnly() && tx.isCommitted()) {
6464
throw new CommittedException();
6565
}
66-
lib.mdb_cursor_close(ptr);
66+
LIB.mdb_cursor_close(ptr);
6767
closed = true;
6868
}
6969

@@ -83,7 +83,7 @@ public long count() throws LmdbNativeException, CommittedException,
8383
checkNotClosed();
8484
tx.checkNotCommitted();
8585
final NativeLongByReference longByReference = new NativeLongByReference();
86-
checkRc(lib.mdb_cursor_count(ptr, longByReference));
86+
checkRc(LIB.mdb_cursor_count(ptr, longByReference));
8787
return longByReference.longValue();
8888
}
8989

@@ -102,7 +102,7 @@ public void delete() throws LmdbNativeException, CommittedException,
102102
checkNotClosed();
103103
tx.checkNotCommitted();
104104
tx.checkWritesAllowed();
105-
checkRc(lib.mdb_cursor_del(ptr, 0));
105+
checkRc(LIB.mdb_cursor_del(ptr, 0));
106106
}
107107

108108
/**
@@ -132,7 +132,7 @@ public void get(final ByteBuffer key, final ByteBuffer val, final CursorOp op)
132132
setPointerToBuffer(key, k);
133133
}
134134

135-
checkRc(lib.mdb_cursor_get(ptr, k, v, op.getCode()));
135+
checkRc(LIB.mdb_cursor_get(ptr, k, v, op.getCode()));
136136
setBufferToPointer(k, key);
137137
setBufferToPointer(v, val);
138138
}
@@ -164,7 +164,7 @@ public void put(final ByteBuffer key, final ByteBuffer val,
164164
setPointerToBuffer(key, k);
165165
setPointerToBuffer(val, v);
166166
final int flags = mask(op);
167-
checkRc(lib.mdb_cursor_put(ptr, k, v, flags));
167+
checkRc(LIB.mdb_cursor_put(ptr, k, v, flags));
168168
}
169169

170170
/**
@@ -193,7 +193,7 @@ public void renew(final Txn tx)
193193
tx.checkReadOnly(); // new
194194
tx.checkNotCommitted(); // new
195195
this.tx = tx;
196-
checkRc(lib.mdb_cursor_renew(tx.ptr, ptr));
196+
checkRc(LIB.mdb_cursor_renew(tx.ptr, ptr));
197197
}
198198

199199
private void checkNotClosed() throws ClosedException {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import jnr.ffi.byref.IntByReference;
2323
import jnr.ffi.byref.PointerByReference;
2424
import org.lmdbjava.Env.NotOpenException;
25-
import static org.lmdbjava.Library.lib;
25+
import static org.lmdbjava.Library.LIB;
2626
import org.lmdbjava.LmdbException.BufferNotDirectException;
2727
import static org.lmdbjava.MaskedFlag.mask;
2828
import static org.lmdbjava.ResultCodeMapper.checkRc;
@@ -64,7 +64,7 @@ public Dbi(final Txn tx, final String name, final DbiFlags... flags)
6464
this.name = name;
6565
final int flagsMask = mask(flags);
6666
final IntByReference dbiPtr = new IntByReference();
67-
checkRc(lib.mdb_dbi_open(tx.ptr, name, flagsMask, dbiPtr));
67+
checkRc(LIB.mdb_dbi_open(tx.ptr, name, flagsMask, dbiPtr));
6868
dbi = dbiPtr.intValue();
6969
}
7070

@@ -137,7 +137,7 @@ public void delete(final Txn tx, final ByteBuffer key, final ByteBuffer val)
137137
tx.checkWritesAllowed();
138138
final Pointer k = allocateMdbVal(key);
139139
final Pointer v = allocateMdbVal(val);
140-
checkRc(lib.mdb_del(tx.ptr, dbi, k, v));
140+
checkRc(LIB.mdb_del(tx.ptr, dbi, k, v));
141141
}
142142

143143
/**
@@ -213,7 +213,7 @@ public void get(final Txn tx, final ByteBuffer key, final ByteBuffer val)
213213
tx.checkNotCommitted();
214214
final Pointer k = allocateMdbVal(key);
215215
final Pointer v = allocateMdbVal();
216-
checkRc(lib.mdb_get(tx.ptr, dbi, k, v));
216+
checkRc(LIB.mdb_get(tx.ptr, dbi, k, v));
217217
setBufferToPointer(v, val);
218218
}
219219

@@ -248,7 +248,7 @@ public Cursor openCursor(final Txn tx) throws LmdbNativeException,
248248
requireNonNull(tx);
249249
tx.checkNotCommitted();
250250
final PointerByReference ptr = new PointerByReference();
251-
checkRc(lib.mdb_cursor_open(tx.ptr, dbi, ptr));
251+
checkRc(LIB.mdb_cursor_open(tx.ptr, dbi, ptr));
252252
return new Cursor(ptr.getValue(), tx);
253253
}
254254

@@ -304,7 +304,7 @@ public void put(final Txn tx, final ByteBuffer key, final ByteBuffer val,
304304
final Pointer k = allocateMdbVal(key);
305305
final Pointer v = allocateMdbVal(val);
306306
int mask = mask(flags);
307-
checkRc(lib.mdb_put(tx.ptr, dbi, k, v, mask));
307+
checkRc(LIB.mdb_put(tx.ptr, dbi, k, v, mask));
308308
}
309309

310310
/**

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import static java.util.Objects.requireNonNull;
2020
import jnr.ffi.Pointer;
2121
import jnr.ffi.byref.PointerByReference;
22+
import static org.lmdbjava.Library.LIB;
2223
import org.lmdbjava.Library.MDB_envinfo;
2324
import org.lmdbjava.Library.MDB_stat;
24-
import static org.lmdbjava.Library.lib;
25-
import static org.lmdbjava.Library.runtime;
25+
import static org.lmdbjava.Library.RUNTIME;
2626
import static org.lmdbjava.MaskedFlag.mask;
2727
import static org.lmdbjava.ResultCodeMapper.checkRc;
2828

@@ -42,7 +42,7 @@ public final class Env implements AutoCloseable {
4242
*/
4343
public Env() throws LmdbNativeException {
4444
final PointerByReference envPtr = new PointerByReference();
45-
checkRc(lib.mdb_env_create(envPtr));
45+
checkRc(LIB.mdb_env_create(envPtr));
4646
ptr = envPtr.getValue();
4747
}
4848

@@ -60,7 +60,7 @@ public void close() {
6060
if (!open) {
6161
return;
6262
}
63-
lib.mdb_env_close(ptr);
63+
LIB.mdb_env_close(ptr);
6464
}
6565

6666
/**
@@ -91,7 +91,7 @@ public void copy(final File path, final CopyFlags... flags) throws
9191
throw new InvalidCopyDestination("Path must contain no files");
9292
}
9393
final int flagsMask = mask(flags);
94-
checkRc(lib.mdb_env_copy2(ptr, path.getAbsolutePath(), flagsMask));
94+
checkRc(LIB.mdb_env_copy2(ptr, path.getAbsolutePath(), flagsMask));
9595
}
9696

9797
/**
@@ -111,7 +111,7 @@ public void setMapSize(final int mapSize) throws AlreadyOpenException,
111111
if (closed) {
112112
throw new AlreadyClosedException();
113113
}
114-
checkRc(lib.mdb_env_set_mapsize(ptr, mapSize));
114+
checkRc(LIB.mdb_env_set_mapsize(ptr, mapSize));
115115
}
116116

117117
/**
@@ -131,7 +131,7 @@ public void setMaxDbs(final int dbs) throws AlreadyOpenException,
131131
if (closed) {
132132
throw new AlreadyClosedException();
133133
}
134-
checkRc(lib.mdb_env_set_maxdbs(ptr, dbs));
134+
checkRc(LIB.mdb_env_set_maxdbs(ptr, dbs));
135135
}
136136

137137
/**
@@ -151,7 +151,7 @@ public void setMaxReaders(final int readers) throws AlreadyOpenException,
151151
if (closed) {
152152
throw new AlreadyClosedException();
153153
}
154-
checkRc(lib.mdb_env_set_maxreaders(ptr, readers));
154+
checkRc(LIB.mdb_env_set_maxreaders(ptr, readers));
155155
}
156156

157157
/**
@@ -165,8 +165,8 @@ public EnvInfo info() throws NotOpenException, LmdbNativeException {
165165
if (!open) {
166166
throw new NotOpenException();
167167
}
168-
final MDB_envinfo info = new MDB_envinfo(runtime);
169-
checkRc(lib.mdb_env_info(ptr, info));
168+
final MDB_envinfo info = new MDB_envinfo(RUNTIME);
169+
checkRc(LIB.mdb_env_info(ptr, info));
170170

171171
final long mapAddress;
172172
if (info.me_mapaddr.get() == null) {
@@ -222,7 +222,7 @@ public void open(final File path, final int mode, final EnvFlags... flags)
222222
throw new AlreadyClosedException();
223223
}
224224
final int flagsMask = mask(flags);
225-
checkRc(lib.mdb_env_open(ptr, path.getAbsolutePath(), flagsMask, mode));
225+
checkRc(LIB.mdb_env_open(ptr, path.getAbsolutePath(), flagsMask, mode));
226226
this.open = true;
227227
}
228228

@@ -237,8 +237,8 @@ public EnvStat stat() throws NotOpenException, LmdbNativeException {
237237
if (!open) {
238238
throw new NotOpenException();
239239
}
240-
final MDB_stat stat = new MDB_stat(runtime);
241-
checkRc(lib.mdb_env_stat(ptr, stat));
240+
final MDB_stat stat = new MDB_stat(RUNTIME);
241+
checkRc(LIB.mdb_env_stat(ptr, stat));
242242
return new EnvStat(
243243
stat.ms_psize.intValue(),
244244
stat.ms_depth.intValue(),
@@ -258,7 +258,7 @@ public EnvStat stat() throws NotOpenException, LmdbNativeException {
258258
*/
259259
public void sync(final boolean force) throws LmdbNativeException {
260260
final int f = force ? 1 : 0;
261-
checkRc(lib.mdb_env_sync(ptr, f));
261+
checkRc(LIB.mdb_env_sync(ptr, f));
262262
}
263263

264264
/**

src/main/java/org/lmdbjava/Library.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
*/
3535
final class Library {
3636

37-
static final Lmdb lib;
38-
static final jnr.ffi.Runtime runtime;
37+
private static final String LIB_NAME = "lmdb";
38+
static final Lmdb LIB;
39+
static final jnr.ffi.Runtime RUNTIME;
3940

4041
static {
41-
lib = create(Lmdb.class).load("lmdb");
42-
runtime = getRuntime(lib);
42+
LIB = create(Lmdb.class).load(LIB_NAME);
43+
RUNTIME = getRuntime(LIB);
4344
}
4445

4546
private Library() {

src/main/java/org/lmdbjava/Meta.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.lmdbjava;
1717

1818
import jnr.ffi.byref.IntByReference;
19-
import static org.lmdbjava.Library.lib;
19+
import static org.lmdbjava.Library.LIB;
2020

2121
/**
2222
* LMDB metadata functions.
@@ -36,7 +36,7 @@ public final class Meta {
3636
* @return the description
3737
*/
3838
public static String error(final int err) {
39-
return lib.mdb_strerror(err);
39+
return LIB.mdb_strerror(err);
4040
}
4141

4242
/**
@@ -49,7 +49,7 @@ public static Version version() {
4949
final IntByReference minor = new IntByReference();
5050
final IntByReference patch = new IntByReference();
5151

52-
lib.mdb_version(major, minor, patch);
52+
LIB.mdb_version(major, minor, patch);
5353

5454
return new Version(major.intValue(), minor.intValue(), patch.
5555
intValue());

src/main/java/org/lmdbjava/Txn.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import static jnr.ffi.NativeType.ADDRESS;
2121
import jnr.ffi.Pointer;
2222
import org.lmdbjava.Env.NotOpenException;
23-
import static org.lmdbjava.Library.lib;
24-
import static org.lmdbjava.Library.runtime;
23+
import static org.lmdbjava.Library.LIB;
24+
import static org.lmdbjava.Library.RUNTIME;
2525
import static org.lmdbjava.MaskedFlag.isSet;
2626
import static org.lmdbjava.MaskedFlag.mask;
2727
import static org.lmdbjava.ResultCodeMapper.checkRc;
@@ -67,9 +67,9 @@ public Txn(final Env env, final Txn parent,
6767
final int flagsMask = mask(flags);
6868
this.readOnly = isSet(flagsMask, MDB_RDONLY);
6969
this.parent = parent;
70-
final Pointer txnPtr = allocateDirect(runtime, ADDRESS);
70+
final Pointer txnPtr = allocateDirect(RUNTIME, ADDRESS);
7171
final Pointer txnParentPtr = parent == null ? null : parent.ptr;
72-
checkRc(lib.mdb_txn_begin(env.ptr, txnParentPtr, flagsMask, txnPtr));
72+
checkRc(LIB.mdb_txn_begin(env.ptr, txnParentPtr, flagsMask, txnPtr));
7373
ptr = txnPtr.getPointer(0);
7474
}
7575

@@ -107,7 +107,7 @@ public void abort() throws CommittedException {
107107
if (committed) {
108108
throw new CommittedException();
109109
}
110-
lib.mdb_txn_abort(ptr);
110+
LIB.mdb_txn_abort(ptr);
111111
committed = true;
112112
}
113113

@@ -119,7 +119,7 @@ public void close() {
119119
if (committed) {
120120
return;
121121
}
122-
lib.mdb_txn_abort(ptr);
122+
LIB.mdb_txn_abort(ptr);
123123
committed = true;
124124
}
125125

@@ -133,7 +133,7 @@ public void commit() throws CommittedException, LmdbNativeException {
133133
if (committed) {
134134
throw new CommittedException();
135135
}
136-
checkRc(lib.mdb_txn_commit(ptr));
136+
checkRc(LIB.mdb_txn_commit(ptr));
137137
committed = true;
138138
}
139139

@@ -143,7 +143,7 @@ public void commit() throws CommittedException, LmdbNativeException {
143143
* @return A transaction ID, valid if input is an active transaction
144144
*/
145145
public long getId() {
146-
return lib.mdb_txn_id(ptr);
146+
return LIB.mdb_txn_id(ptr);
147147
}
148148

149149
/**
@@ -193,7 +193,7 @@ public void renew() throws NotResetException, LmdbNativeException {
193193
throw new NotResetException();
194194
}
195195
reset = false;
196-
checkRc(lib.mdb_txn_renew(ptr));
196+
checkRc(LIB.mdb_txn_renew(ptr));
197197
}
198198

199199
/**
@@ -210,7 +210,7 @@ public void reset() throws ReadOnlyRequiredException, ResetException {
210210
if (reset) {
211211
throw new ResetException();
212212
}
213-
lib.mdb_txn_reset(ptr);
213+
LIB.mdb_txn_reset(ptr);
214214
reset = true;
215215
}
216216

src/main/java/org/lmdbjava/ValueBuffers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import jnr.ffi.Pointer;
2424
import static org.lmdbjava.BufferMutators.MUTATOR;
2525
import static org.lmdbjava.BufferMutators.requireDirectBuffer;
26-
import static org.lmdbjava.Library.runtime;
26+
import static org.lmdbjava.Library.RUNTIME;
2727
import org.lmdbjava.LmdbException.BufferNotDirectException;
2828

2929
/**
@@ -48,7 +48,7 @@ final class ValueBuffers {
4848
* @return the allocated location
4949
*/
5050
static Pointer allocateMdbVal() {
51-
return allocateDirect(runtime, MDB_VAL_STRUCT_SIZE, true);
51+
return allocateDirect(RUNTIME, MDB_VAL_STRUCT_SIZE, true);
5252
}
5353

5454
static Pointer allocateMdbVal(final Buffer src) throws

src/test/java/org/lmdbjava/LibraryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.hamcrest.MatcherAssert.assertThat;
2121
import org.junit.Test;
2222
import org.lmdbjava.Library.MDB_envinfo;
23-
import static org.lmdbjava.Library.runtime;
23+
import static org.lmdbjava.Library.RUNTIME;
2424
import static org.lmdbjava.TestUtils.invokePrivateConstructor;
2525

2626
public class LibraryTest {
@@ -32,7 +32,7 @@ public void coverPrivateConstructors() throws Exception {
3232

3333
@Test
3434
public void structureFieldOrder() throws Exception {
35-
MDB_envinfo v = new MDB_envinfo(runtime);
35+
MDB_envinfo v = new MDB_envinfo(RUNTIME);
3636
assertThat(v.me_mapaddr.offset(), is(0L));
3737
assertThat(v.me_mapsize.offset(), is((long) BYTES));
3838
}

0 commit comments

Comments
 (0)