Skip to content

Commit 134359f

Browse files
committed
Revert "builder methods for byteBuffer and byteArray on Env"
This reverts commit c1fb4d5.
1 parent 374793c commit 134359f

9 files changed

Lines changed: 46 additions & 54 deletions

File tree

src/main/java/org/lmdbjava/ByteArrayProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* Byte array proxy.
3030
*
31-
* {@link Env#byteArray()}
31+
* {@link Env#create(org.lmdbjava.BufferProxy)}.
3232
*/
3333
public class ByteArrayProxy extends BufferProxy<byte[]> {
3434
/**

src/main/java/org/lmdbjava/ByteBufferProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* <p>
4444
* Users nominate which implementation they prefer by referencing the
4545
* {@link #PROXY_OPTIMAL} or {@link #PROXY_SAFE} field when invoking
46-
* {@link Env#byteBuffer()}.
46+
* {@link Env#create(org.lmdbjava.BufferProxy)}.
4747
*/
4848
public final class ByteBufferProxy {
4949

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import static java.util.Objects.requireNonNull;
2727
import jnr.ffi.Pointer;
2828
import jnr.ffi.byref.PointerByReference;
29-
30-
import static org.lmdbjava.ByteArrayProxy.PROXY_BA;
3129
import static org.lmdbjava.ByteBufferProxy.PROXY_OPTIMAL;
3230
import static org.lmdbjava.EnvFlags.MDB_RDONLY_ENV;
3331
import static org.lmdbjava.Library.LIB;
@@ -79,19 +77,10 @@ private Env(final BufferProxy<T> proxy, final Pointer ptr,
7977
*
8078
* @return the environment (never null)
8179
*/
82-
public static Builder<ByteBuffer> byteBuffer() {
80+
public static Builder<ByteBuffer> create() {
8381
return new Builder<>(PROXY_OPTIMAL);
8482
}
8583

86-
/**
87-
* Create an {@link Env} using the {@link ByteArrayProxy#PROXY_BA}.
88-
*
89-
* @return the environment (never null)
90-
*/
91-
public static Builder<byte[]> byteArray() {
92-
return new Builder<>(PROXY_BA);
93-
}
94-
9584
/**
9685
* Create an {@link Env} using the passed {@link BufferProxy}.
9786
*

src/test/java/org/lmdbjava/ByteBufferProxyTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.lmdbjava.ByteBufferProxy.PROXY_OPTIMAL;
4444
import static org.lmdbjava.ByteBufferProxy.PROXY_SAFE;
4545
import static org.lmdbjava.DbiFlags.MDB_CREATE;
46+
import static org.lmdbjava.Env.create;
4647
import static org.lmdbjava.Library.RUNTIME;
4748
import static org.lmdbjava.TestUtils.DB_1;
4849
import static org.lmdbjava.TestUtils.invokePrivateConstructor;
@@ -61,7 +62,7 @@ public final class ByteBufferProxyTest {
6162
@Test(expected = BufferMustBeDirectException.class)
6263
public void buffersMustBeDirect() throws IOException {
6364
final File path = tmp.newFolder();
64-
try (final Env<ByteBuffer> env = Env.byteBuffer().open(path)) {
65+
try (final Env<ByteBuffer> env = create().open(path)) {
6566
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
6667
final ByteBuffer key = allocate(100);
6768
key.putInt(1).flip();

src/test/java/org/lmdbjava/CursorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.lmdbjava.DbiFlags.MDB_CREATE;
4444
import static org.lmdbjava.DbiFlags.MDB_DUPSORT;
4545
import static org.lmdbjava.DirectBufferProxy.PROXY_DB;
46+
import static org.lmdbjava.Env.create;
4647
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
4748
import static org.lmdbjava.GetOp.MDB_SET_KEY;
4849
import static org.lmdbjava.GetOp.MDB_SET_RANGE;
@@ -443,7 +444,7 @@ private void cursorByteBuffer(final BufferProxy<ByteBuffer> buffType) {
443444
private <T> Env<T> makeEnv(final BufferProxy<T> proxy) {
444445
try {
445446
final File path = tmp.newFile();
446-
final Env<T> env = Env.create(proxy)
447+
final Env<T> env = create(proxy)
447448
.setMapSize(KIBIBYTES.toBytes(1_024))
448449
.setMaxReaders(1)
449450
.setMaxDbs(1)

src/test/java/org/lmdbjava/DbiTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
import static org.lmdbjava.DbiFlags.MDB_CREATE;
4848
import static org.lmdbjava.DbiFlags.MDB_DUPSORT;
4949
import org.lmdbjava.Env.MapFullException;
50-
51-
import static org.lmdbjava.Env.byteBuffer;
50+
import static org.lmdbjava.Env.create;
5251
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
5352
import static org.lmdbjava.GetOp.MDB_SET_KEY;
5453
import org.lmdbjava.LmdbNativeException.ConstantDerviedException;
@@ -69,7 +68,7 @@ public final class DbiTest {
6968
@Before
7069
public void before() throws IOException {
7170
final File path = tmp.newFile();
72-
env = byteBuffer()
71+
env = create()
7372
.setMapSize(MEBIBYTES.toBytes(1_024))
7473
.setMaxReaders(1)
7574
.setMaxDbs(2)
@@ -187,19 +186,19 @@ public void putDelete() {
187186
@Test
188187
public void putCommitGetByteArray() throws IOException {
189188
final File path = tmp.newFile();
190-
final Env<byte[]> byteArrayEnv = Env.byteArray()
191-
.setMapSize(MEBIBYTES.toBytes(1_024))
192-
.setMaxReaders(1)
193-
.setMaxDbs(2)
194-
.open(path, MDB_NOSUBDIR);
195-
196-
final Dbi<byte[]> db = byteArrayEnv.openDbi(DB_1, MDB_CREATE);
197-
try (final Txn<byte[]> txn = byteArrayEnv.txnWrite()) {
189+
Env<byte[]> env = create(new ByteArrayProxy())
190+
.setMapSize(MEBIBYTES.toBytes(1_024))
191+
.setMaxReaders(1)
192+
.setMaxDbs(2)
193+
.open(path, MDB_NOSUBDIR);
194+
195+
final Dbi<byte[]> db = env.openDbi(DB_1, MDB_CREATE);
196+
try (final Txn<byte[]> txn = env.txnWrite()) {
198197
db.put(txn, ba(5), ba(5));
199198
txn.commit();
200199
}
201200

202-
try (final Txn<byte[]> txn = byteArrayEnv.txnWrite()) {
201+
try (final Txn<byte[]> txn = env.txnWrite()) {
203202
final byte[] found = db.get(txn, ba(5));
204203
assertNotNull(found);
205204
assertThat(new UnsafeBuffer(txn.val()).getInt(0), is(5));

src/test/java/org/lmdbjava/EnvTest.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.lmdbjava.Env.Builder;
4040
import org.lmdbjava.Env.InvalidCopyDestination;
4141
import org.lmdbjava.Env.MapFullException;
42+
import static org.lmdbjava.Env.create;
4243
import static org.lmdbjava.Env.open;
4344
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
4445
import static org.lmdbjava.EnvFlags.MDB_RDONLY_ENV;
@@ -56,7 +57,7 @@ public final class EnvTest {
5657
@Test
5758
public void byteUnit() throws IOException {
5859
final File path = tmp.newFile();
59-
final Env<ByteBuffer> env = Env.byteBuffer().setMapSize(MEBIBYTES.toBytes(1)).open(
60+
final Env<ByteBuffer> env = create().setMapSize(MEBIBYTES.toBytes(1)).open(
6061
path, MDB_NOSUBDIR);
6162
final EnvInfo info = env.info();
6263
assertThat(info.mapSize, is(MEBIBYTES.toBytes(1)));
@@ -65,31 +66,31 @@ public void byteUnit() throws IOException {
6566
@Test(expected = AlreadyOpenException.class)
6667
public void cannotChangeMapSizeAfterOpen() throws IOException {
6768
final File path = tmp.newFile();
68-
final Builder<ByteBuffer> builder = Env.byteBuffer();
69+
final Builder<ByteBuffer> builder = create();
6970
builder.open(path, MDB_NOSUBDIR);
7071
builder.setMapSize(1);
7172
}
7273

7374
@Test(expected = AlreadyOpenException.class)
7475
public void cannotChangeMaxDbsAfterOpen() throws IOException {
7576
final File path = tmp.newFile();
76-
final Builder<ByteBuffer> builder = Env.byteBuffer();
77+
final Builder<ByteBuffer> builder = create();
7778
builder.open(path, MDB_NOSUBDIR);
7879
builder.setMaxDbs(1);
7980
}
8081

8182
@Test(expected = AlreadyOpenException.class)
8283
public void cannotChangeMaxReadersAfterOpen() throws IOException {
8384
final File path = tmp.newFile();
84-
final Builder<ByteBuffer> builder = Env.byteBuffer();
85+
final Builder<ByteBuffer> builder = create();
8586
builder.open(path, MDB_NOSUBDIR);
8687
builder.setMaxReaders(1);
8788
}
8889

8990
@Test(expected = AlreadyClosedException.class)
9091
public void cannotInfoOnceClosed() throws IOException {
9192
final File path = tmp.newFile();
92-
final Env<ByteBuffer> env = Env.byteBuffer()
93+
final Env<ByteBuffer> env = create()
9394
.open(path, MDB_NOSUBDIR);
9495
env.close();
9596
env.info();
@@ -98,14 +99,14 @@ public void cannotInfoOnceClosed() throws IOException {
9899
@Test(expected = AlreadyOpenException.class)
99100
public void cannotOpenTwice() throws IOException {
100101
final File path = tmp.newFile();
101-
final Builder<ByteBuffer> builder = Env.byteBuffer();
102+
final Builder<ByteBuffer> builder = create();
102103
builder.open(path, MDB_NOSUBDIR);
103104
builder.open(path, MDB_NOSUBDIR);
104105
}
105106

106107
@Test(expected = IllegalArgumentException.class)
107108
public void cannotOverflowMapSize() {
108-
final Builder<ByteBuffer> builder = Env.byteBuffer();
109+
final Builder<ByteBuffer> builder = create();
109110
final int mb = 1_024 * 1_024;
110111
final int size = mb * 2_048; // as per issue 18
111112
builder.setMapSize(size);
@@ -114,7 +115,7 @@ public void cannotOverflowMapSize() {
114115
@Test(expected = AlreadyClosedException.class)
115116
public void cannotStatOnceClosed() throws IOException {
116117
final File path = tmp.newFile();
117-
final Env<ByteBuffer> env = Env.byteBuffer()
118+
final Env<ByteBuffer> env = create()
118119
.open(path, MDB_NOSUBDIR);
119120
env.close();
120121
env.stat();
@@ -123,7 +124,7 @@ public void cannotStatOnceClosed() throws IOException {
123124
@Test(expected = AlreadyClosedException.class)
124125
public void cannotSyncOnceClosed() throws IOException {
125126
final File path = tmp.newFile();
126-
final Env<ByteBuffer> env = Env.byteBuffer()
127+
final Env<ByteBuffer> env = create()
127128
.open(path, MDB_NOSUBDIR);
128129
env.close();
129130
env.sync(false);
@@ -136,7 +137,7 @@ public void copy() throws IOException {
136137
assertThat(dest.isDirectory(), is(true));
137138
assertThat(dest.list().length, is(0));
138139
final File src = tmp.newFolder();
139-
try (final Env<ByteBuffer> env = Env.byteBuffer().open(src)) {
140+
try (final Env<ByteBuffer> env = create().open(src)) {
140141
env.copy(dest, MDB_CP_COMPACT);
141142
assertThat(dest.list().length, is(1));
142143
}
@@ -146,7 +147,7 @@ public void copy() throws IOException {
146147
public void copyRejectsFileDestination() throws IOException {
147148
final File dest = tmp.newFile();
148149
final File src = tmp.newFolder();
149-
try (final Env<ByteBuffer> env = Env.byteBuffer().open(src)) {
150+
try (final Env<ByteBuffer> env = create().open(src)) {
150151
env.copy(dest, MDB_CP_COMPACT);
151152
}
152153
}
@@ -156,7 +157,7 @@ public void copyRejectsMissingDestination() throws IOException {
156157
final File dest = tmp.newFolder();
157158
assertThat(dest.delete(), is(true));
158159
final File src = tmp.newFolder();
159-
try (final Env<ByteBuffer> env = Env.byteBuffer().open(src)) {
160+
try (final Env<ByteBuffer> env = create().open(src)) {
160161
env.copy(dest, MDB_CP_COMPACT);
161162
}
162163
}
@@ -167,15 +168,15 @@ public void copyRejectsNonEmptyDestination() throws IOException {
167168
final File subDir = new File(dest, "hello");
168169
assertThat(subDir.mkdir(), is(true));
169170
final File src = tmp.newFolder();
170-
try (final Env<ByteBuffer> env = Env.byteBuffer().open(src)) {
171+
try (final Env<ByteBuffer> env = create().open(src)) {
171172
env.copy(dest, MDB_CP_COMPACT);
172173
}
173174
}
174175

175176
@Test
176177
public void createAsDirectory() throws IOException {
177178
final File path = tmp.newFolder();
178-
final Env<ByteBuffer> env = Env.byteBuffer().open(path);
179+
final Env<ByteBuffer> env = create().open(path);
179180
assertThat(path.isDirectory(), is(true));
180181
env.sync(false);
181182
env.close();
@@ -186,7 +187,7 @@ public void createAsDirectory() throws IOException {
186187
@Test
187188
public void createAsFile() throws IOException {
188189
final File path = tmp.newFile();
189-
try (final Env<ByteBuffer> env = Env.byteBuffer()
190+
try (final Env<ByteBuffer> env = create()
190191
.setMapSize(1_024 * 1_024)
191192
.setMaxDbs(1)
192193
.setMaxReaders(1)
@@ -199,7 +200,7 @@ public void createAsFile() throws IOException {
199200
@Test
200201
public void info() throws IOException {
201202
final File path = tmp.newFile();
202-
final Env<ByteBuffer> env = Env.byteBuffer()
203+
final Env<ByteBuffer> env = create()
203204
.setMaxReaders(4)
204205
.setMapSize(123_456)
205206
.open(path, MDB_NOSUBDIR);
@@ -222,7 +223,7 @@ public void mapFull() throws IOException {
222223
final ByteBuffer key = allocateDirect(500);
223224
final ByteBuffer val = allocateDirect(1_024);
224225
final Random rnd = new Random();
225-
try (final Env<ByteBuffer> env = Env.byteBuffer().setMapSize(MEBIBYTES.toBytes(8))
226+
try (final Env<ByteBuffer> env = create().setMapSize(MEBIBYTES.toBytes(8))
226227
.setMaxDbs(1).open(path)) {
227228
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
228229
for (;;) {
@@ -238,11 +239,11 @@ public void mapFull() throws IOException {
238239
@Test
239240
public void readOnlySupported() throws IOException {
240241
final File path = tmp.newFolder();
241-
try (final Env<ByteBuffer> rwEnv = Env.byteBuffer().open(path)) {
242+
try (final Env<ByteBuffer> rwEnv = create().open(path)) {
242243
final Dbi<ByteBuffer> rwDb = rwEnv.openDbi(DB_1, MDB_CREATE);
243244
rwDb.put(bb(1), bb(42));
244245
}
245-
final Env<ByteBuffer> roEnv = Env.byteBuffer().open(path, MDB_RDONLY_ENV);
246+
final Env<ByteBuffer> roEnv = create().open(path, MDB_RDONLY_ENV);
246247
final Dbi<ByteBuffer> roDb = roEnv.openDbi(DB_1);
247248
try (final Txn<ByteBuffer> roTxn = roEnv.txnRead()) {
248249
assertThat(roDb.get(roTxn, bb(1)), notNullValue());
@@ -252,7 +253,7 @@ public void readOnlySupported() throws IOException {
252253
@Test
253254
public void stats() throws IOException {
254255
final File path = tmp.newFile();
255-
final Env<ByteBuffer> env = Env.byteBuffer()
256+
final Env<ByteBuffer> env = create()
256257
.open(path, MDB_NOSUBDIR);
257258
final Stat stat = env.stat();
258259
assertThat(stat, is(notNullValue()));

src/test/java/org/lmdbjava/TutorialTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import static org.lmdbjava.DbiFlags.MDB_CREATE;
4545
import static org.lmdbjava.DbiFlags.MDB_DUPSORT;
4646
import static org.lmdbjava.DirectBufferProxy.PROXY_DB;
47-
import static org.lmdbjava.Env.byteBuffer;
47+
import static org.lmdbjava.Env.create;
4848
import static org.lmdbjava.Env.open;
4949
import static org.lmdbjava.GetOp.MDB_SET;
5050
import static org.lmdbjava.SeekOp.MDB_FIRST;
@@ -83,7 +83,7 @@ public void tutorial1() throws IOException {
8383

8484
// We always need an Env. An Env owns a physical on-disk storage file. One
8585
// Env can store many different databases (ie sorted maps).
86-
final Env<ByteBuffer> env = byteBuffer()
86+
final Env<ByteBuffer> env = create()
8787
// LMDB also needs to know how large our DB might be. Over-estimating is OK.
8888
.setMapSize(MEBIBYTES.toBytes(10))
8989
// LMDB also needs to know how many DBs (Dbi) we want to store in this Env.
@@ -400,7 +400,7 @@ public void tutorial6() throws IOException {
400400
// There's also a PROXY_SAFE if you want to stop ByteBuffer's Unsafe use.
401401
// Aside from that and a different type argument, it's the same as usual...
402402
final File path = tmp.newFolder();
403-
final Env<DirectBuffer> env = Env.create(PROXY_DB)
403+
final Env<DirectBuffer> env = create(PROXY_DB)
404404
.setMapSize(MEBIBYTES.toBytes(10))
405405
.setMaxDbs(1)
406406
.open(path);

src/test/java/org/lmdbjava/TxnTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.junit.rules.TemporaryFolder;
3838
import static org.lmdbjava.DbiFlags.MDB_CREATE;
3939
import org.lmdbjava.Env.AlreadyClosedException;
40+
import static org.lmdbjava.Env.create;
4041
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
4142
import static org.lmdbjava.EnvFlags.MDB_RDONLY_ENV;
4243
import static org.lmdbjava.TestUtils.DB_1;
@@ -73,7 +74,7 @@ public void after() {
7374
@Before
7475
public void before() throws IOException {
7576
path = tmp.newFile();
76-
env = Env.byteBuffer()
77+
env = create()
7778
.setMapSize(KIBIBYTES.toBytes(100))
7879
.setMaxReaders(1)
7980
.setMaxDbs(2)
@@ -83,7 +84,7 @@ public void before() throws IOException {
8384
@Test
8485
public void readOnlyTxnAllowedInReadOnlyEnv() {
8586
env.openDbi(DB_1, MDB_CREATE);
86-
final Env<ByteBuffer> roEnv = Env.byteBuffer().open(path, MDB_NOSUBDIR,
87+
final Env<ByteBuffer> roEnv = create().open(path, MDB_NOSUBDIR,
8788
MDB_RDONLY_ENV);
8889
assertThat(roEnv.txnRead(), is(notNullValue()));
8990
}
@@ -92,7 +93,7 @@ public void readOnlyTxnAllowedInReadOnlyEnv() {
9293
public void readWriteTxnDeniedInReadOnlyEnv() {
9394
env.openDbi(DB_1, MDB_CREATE);
9495
env.close();
95-
final Env<ByteBuffer> roEnv = Env.byteBuffer().open(path, MDB_NOSUBDIR,
96+
final Env<ByteBuffer> roEnv = create().open(path, MDB_NOSUBDIR,
9697
MDB_RDONLY_ENV);
9798
roEnv.txnWrite(); // error
9899
}

0 commit comments

Comments
 (0)