Skip to content

Commit dd18470

Browse files
committed
Rename Database -> Dbi
1 parent 5ab3c50 commit dd18470

File tree

7 files changed

+55
-54
lines changed

7 files changed

+55
-54
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* LMDB Database.
2323
*/
24-
public final class Database {
24+
public final class Dbi {
2525

2626
private final String name;
2727
final int dbi;
@@ -39,7 +39,7 @@ public final class Database {
3939
* @throws CommittedException if already committed
4040
* @throws LmdbNativeException if a native C error occurred
4141
*/
42-
public Database(Txn tx, String name, DatabaseFlags... flags)
42+
public Dbi(Txn tx, String name, DbiFlags... flags)
4343
throws CommittedException, LmdbNativeException {
4444
requireNonNull(tx);
4545
if (tx.isCommitted()) {
@@ -85,7 +85,7 @@ public void delete(Txn tx, ByteBuffer key) throws
8585
* Removes key/data pairs from the database.
8686
* </p>
8787
* If the database does not support sorted duplicate data items
88-
* ({@link org.lmdbjava.DatabaseFlags#MDB_DUPSORT}) the value parameter is
88+
* ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}) the value parameter is
8989
* ignored. If the database supports sorted duplicates and the data parameter
9090
* is NULL, all of the duplicate data items for the key will be deleted.
9191
* Otherwise, if the data parameter is non-NULL only the matching data item
@@ -131,7 +131,7 @@ public ByteBuffer get(ByteBuffer key) throws
131131
* This function retrieves key/data pairs from the database. The address and
132132
* length of the data associated with the specified \b key are returned in the
133133
* structure to which \b data refers. If the database supports duplicate keys
134-
* ({@link org.lmdbjava.DatabaseFlags#MDB_DUPSORT}) then the first data item
134+
* ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}) then the first data item
135135
* for the key will be returned. Retrieval of other items requires the use of
136136
* #mdb_cursor_get().
137137
*
@@ -217,7 +217,7 @@ public void put(ByteBuffer key, ByteBuffer val) throws
217217
* This function stores key/data pairs in the database. The default behavior
218218
* is to enter the new key/data pair, replacing any previously existing key if
219219
* duplicates are disallowed, or adding a duplicate data item if duplicates
220-
* are allowed ({@link org.lmdbjava.DatabaseFlags#MDB_DUPSORT}).
220+
* are allowed ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}).
221221
*
222222
* @param tx transaction handle
223223
* @param key The key to store in the database
@@ -226,7 +226,7 @@ public void put(ByteBuffer key, ByteBuffer val) throws
226226
* @throws CommittedException if already committed
227227
* @throws LmdbNativeException if a native C error occurred
228228
*/
229-
public void put(Txn tx, ByteBuffer key, ByteBuffer val, DatabaseFlags... flags)
229+
public void put(Txn tx, ByteBuffer key, ByteBuffer val, DbiFlags... flags)
230230
throws
231231
CommittedException, LmdbNativeException {
232232

src/main/java/org/lmdbjava/DatabaseFlags.java renamed to src/main/java/org/lmdbjava/DbiFlags.java

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

1818
/**
19-
* Flags for use when opening a {@link Database}.
19+
* Flags for use when opening a {@link Dbi}.
2020
*/
21-
public enum DatabaseFlags implements MaskedFlag {
21+
public enum DbiFlags implements MaskedFlag {
2222

2323
/**
2424
* use reverse string keys
@@ -52,7 +52,7 @@ public enum DatabaseFlags implements MaskedFlag {
5252

5353
private final int mask;
5454

55-
DatabaseFlags(final int mask) {
55+
DbiFlags(final int mask) {
5656
this.mask = mask;
5757
}
5858

src/main/java/org/lmdbjava/ResultCodeMapper.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import jnr.constants.ConstantSet;
2020
import static jnr.constants.ConstantSet.getConstantSet;
2121
import static org.lmdbjava.Cursor.FullException.MDB_CURSOR_FULL;
22-
import static org.lmdbjava.Database.BadDbiException.MDB_BAD_DBI;
23-
import static org.lmdbjava.Database.BadValueSizeException.MDB_BAD_VALSIZE;
24-
import static org.lmdbjava.Database.DbFullException.MDB_DBS_FULL;
25-
import static org.lmdbjava.Database.IncompatibleException.MDB_INCOMPATIBLE;
26-
import static org.lmdbjava.Database.KeyExistsException.MDB_KEYEXIST;
27-
import static org.lmdbjava.Database.KeyNotFoundException.MDB_NOTFOUND;
28-
import static org.lmdbjava.Database.MapResizedException.MDB_MAP_RESIZED;
22+
import static org.lmdbjava.Dbi.BadDbiException.MDB_BAD_DBI;
23+
import static org.lmdbjava.Dbi.BadValueSizeException.MDB_BAD_VALSIZE;
24+
import static org.lmdbjava.Dbi.DbFullException.MDB_DBS_FULL;
25+
import static org.lmdbjava.Dbi.IncompatibleException.MDB_INCOMPATIBLE;
26+
import static org.lmdbjava.Dbi.KeyExistsException.MDB_KEYEXIST;
27+
import static org.lmdbjava.Dbi.KeyNotFoundException.MDB_NOTFOUND;
28+
import static org.lmdbjava.Dbi.MapResizedException.MDB_MAP_RESIZED;
2929
import static org.lmdbjava.Env.FileInvalidException.MDB_INVALID;
3030
import static org.lmdbjava.Env.MapFullException.MDB_MAP_FULL;
3131
import static org.lmdbjava.Env.ReadersFullException.MDB_READERS_FULL;
@@ -102,31 +102,31 @@ static LmdbNativeException rcException(final int rc) throws
102102

103103
switch (rc) {
104104
case MDB_BAD_DBI:
105-
return new Database.BadDbiException();
105+
return new Dbi.BadDbiException();
106106
case MDB_BAD_RSLOT:
107107
return new BadReaderLockException();
108108
case MDB_BAD_TXN:
109109
return new BadException();
110110
case MDB_BAD_VALSIZE:
111-
return new Database.BadValueSizeException();
111+
return new Dbi.BadValueSizeException();
112112
case MDB_CORRUPTED:
113113
return new LmdbNativeException.PageCorruptedException();
114114
case MDB_CURSOR_FULL:
115115
return new Cursor.FullException();
116116
case MDB_DBS_FULL:
117-
return new Database.DbFullException();
117+
return new Dbi.DbFullException();
118118
case MDB_INCOMPATIBLE:
119-
return new Database.IncompatibleException();
119+
return new Dbi.IncompatibleException();
120120
case MDB_INVALID:
121121
return new Env.FileInvalidException();
122122
case MDB_KEYEXIST:
123-
return new Database.KeyExistsException();
123+
return new Dbi.KeyExistsException();
124124
case MDB_MAP_FULL:
125125
return new Env.MapFullException();
126126
case MDB_MAP_RESIZED:
127-
return new Database.MapResizedException();
127+
return new Dbi.MapResizedException();
128128
case MDB_NOTFOUND:
129-
return new Database.KeyNotFoundException();
129+
return new Dbi.KeyNotFoundException();
130130
case MDB_PAGE_FULL:
131131
return new LmdbNativeException.PageFullException();
132132
case MDB_PAGE_NOTFOUND:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import static org.lmdbjava.CursorOp.MDB_SET;
1717
import static org.lmdbjava.CursorOp.MDB_SET_KEY;
1818
import static org.lmdbjava.CursorOp.MDB_SET_RANGE;
19-
import org.lmdbjava.Database.KeyNotFoundException;
20-
import static org.lmdbjava.DatabaseFlags.MDB_CREATE;
21-
import static org.lmdbjava.DatabaseFlags.MDB_DUPSORT;
19+
import org.lmdbjava.Dbi.KeyNotFoundException;
20+
import static org.lmdbjava.DbiFlags.MDB_CREATE;
21+
import static org.lmdbjava.DbiFlags.MDB_DUPSORT;
2222
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
2323
import static org.lmdbjava.PutFlags.MDB_APPENDDUP;
2424
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;
@@ -32,7 +32,7 @@ public class CursorTest {
3232

3333
@Rule
3434
public final TemporaryFolder tmp = new TemporaryFolder();
35-
private Database db;
35+
private Dbi db;
3636
private Env env;
3737
private Txn tx;
3838

@@ -45,13 +45,13 @@ public void before() throws Exception {
4545
env.setMaxReaders(1);
4646
env.open(path, POSIX_MODE, MDB_NOSUBDIR);
4747
tx = new Txn(env);
48-
db = new Database(tx, DB_1, MDB_CREATE, MDB_DUPSORT);
48+
db = new Dbi(tx, DB_1, MDB_CREATE, MDB_DUPSORT);
4949
}
5050

5151
@Test(expected = IllegalArgumentException.class)
5252
public void closeCursor() throws LmdbNativeException,
5353
CommittedException {
54-
db = new Database(tx, DB_1, MDB_CREATE);
54+
db = new Dbi(tx, DB_1, MDB_CREATE);
5555
Cursor cursor = db.openCursor(tx);
5656
cursor.close();
5757
ByteBuffer k = createBb(1);

src/test/java/org/lmdbjava/DatabaseTest.java renamed to src/test/java/org/lmdbjava/DbiTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import org.junit.Rule;
1212
import org.junit.Test;
1313
import org.junit.rules.TemporaryFolder;
14-
import org.lmdbjava.Database.DbFullException;
15-
import org.lmdbjava.Database.KeyNotFoundException;
16-
import static org.lmdbjava.DatabaseFlags.MDB_CREATE;
14+
import org.lmdbjava.Dbi.DbFullException;
15+
import org.lmdbjava.Dbi.KeyNotFoundException;
16+
import static org.lmdbjava.DbiFlags.MDB_CREATE;
1717
import org.lmdbjava.Env.NotOpenException;
1818
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
1919
import org.lmdbjava.LmdbNativeException.ConstantDerviedException;
@@ -22,11 +22,11 @@
2222
import static org.lmdbjava.TestUtils.createBb;
2323
import org.lmdbjava.Txn.CommittedException;
2424

25-
public class DatabaseTest {
25+
public class DbiTest {
2626

2727
@Rule
2828
public final TemporaryFolder tmp = new TemporaryFolder();
29-
private Database db;
29+
private Dbi dbi;
3030
private Env env;
3131
private Txn tx;
3232

@@ -41,23 +41,24 @@ public void before() throws Exception {
4141
env.open(path, POSIX_MODE, MDB_NOSUBDIR);
4242

4343
tx = new Txn(env);
44-
db = new Database(tx, DB_1, MDB_CREATE);
44+
dbi = new Dbi(tx, DB_1, MDB_CREATE);
4545
}
4646

4747
@Test(expected = DbFullException.class)
48+
@SuppressWarnings("ResultOfObjectAllocationIgnored")
4849
public void dbOpenMaxDatabases() throws Exception {
49-
new Database(tx, "another", MDB_CREATE);
50+
new Dbi(tx, "another", MDB_CREATE);
5051
}
5152

5253
@Test
5354
public void putAbortGet() throws Exception {
54-
Database db = new Database(tx, DB_1, MDB_CREATE);
55+
Dbi db = new Dbi(tx, DB_1, MDB_CREATE);
5556

5657
db.put(tx, createBb(5), createBb(5));
5758
tx.abort();
5859

59-
try (Txn tx = new Txn(env)) {
60-
db.get(tx, createBb(5));
60+
try (Txn tx2 = new Txn(env)) {
61+
db.get(tx2, createBb(5));
6162
fail("key does not exist");
6263
} catch (ConstantDerviedException e) {
6364
assertThat(e.getResultCode(), is(22));
@@ -66,7 +67,7 @@ public void putAbortGet() throws Exception {
6667

6768
@Test
6869
public void putAndGetAndDeleteWithInternalTx() throws Exception {
69-
Database db = new Database(tx, DB_1, MDB_CREATE);
70+
Dbi db = new Dbi(tx, DB_1, MDB_CREATE);
7071
tx.commit();
7172
db.put(createBb(5), createBb(5));
7273
ByteBuffer val = db.get(createBb(5));
@@ -81,20 +82,20 @@ public void putAndGetAndDeleteWithInternalTx() throws Exception {
8182

8283
@Test
8384
public void putCommitGet() throws Exception {
84-
Database db = new Database(tx, DB_1, MDB_CREATE);
85+
Dbi db = new Dbi(tx, DB_1, MDB_CREATE);
8586

8687
db.put(tx, createBb(5), createBb(5));
8788
tx.commit();
8889

89-
try (Txn tx = new Txn(env)) {
90-
ByteBuffer result = db.get(tx, createBb(5));
90+
try (Txn tx2 = new Txn(env)) {
91+
ByteBuffer result = db.get(tx2, createBb(5));
9192
assertThat(result.getInt(), is(5));
9293
}
9394
}
9495

9596
@Test
9697
public void putDelete() throws Exception {
97-
Database db = new Database(tx, DB_1, MDB_CREATE);
98+
Dbi db = new Dbi(tx, DB_1, MDB_CREATE);
9899

99100
db.put(tx, createBb(5), createBb(5));
100101
db.delete(tx, createBb(5));
@@ -116,7 +117,7 @@ public void testParallelWritesStress() throws Exception {
116117
Random random = new Random();
117118
for (int i = 0; i < 15_000; i++) {
118119
try {
119-
db.put(createBb(random.nextInt()), createBb(random.nextInt()));
120+
dbi.put(createBb(random.nextInt()), createBb(random.nextInt()));
120121
} catch (CommittedException | LmdbNativeException | NotOpenException e) {
121122
throw new RuntimeException(e);
122123
}

src/test/java/org/lmdbjava/ResultCodeMapperTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import org.junit.Test;
1111
import org.lmdbjava.Cursor.FullException;
1212
import static org.lmdbjava.Cursor.FullException.MDB_CURSOR_FULL;
13-
import org.lmdbjava.Database.BadDbiException;
14-
import org.lmdbjava.Database.BadValueSizeException;
15-
import org.lmdbjava.Database.DbFullException;
16-
import org.lmdbjava.Database.IncompatibleException;
17-
import org.lmdbjava.Database.KeyExistsException;
18-
import org.lmdbjava.Database.KeyNotFoundException;
19-
import org.lmdbjava.Database.MapResizedException;
13+
import org.lmdbjava.Dbi.BadDbiException;
14+
import org.lmdbjava.Dbi.BadValueSizeException;
15+
import org.lmdbjava.Dbi.DbFullException;
16+
import org.lmdbjava.Dbi.IncompatibleException;
17+
import org.lmdbjava.Dbi.KeyExistsException;
18+
import org.lmdbjava.Dbi.KeyNotFoundException;
19+
import org.lmdbjava.Dbi.MapResizedException;
2020
import org.lmdbjava.Env.FileInvalidException;
2121
import org.lmdbjava.Env.MapFullException;
2222
import org.lmdbjava.Env.ReadersFullException;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.junit.Rule;
1212
import org.junit.Test;
1313
import org.junit.rules.TemporaryFolder;
14-
import static org.lmdbjava.DatabaseFlags.MDB_CREATE;
14+
import static org.lmdbjava.DbiFlags.MDB_CREATE;
1515
import org.lmdbjava.Env.NotOpenException;
1616
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
1717
import static org.lmdbjava.TestUtils.DB_1;
@@ -45,7 +45,7 @@ public void before() throws Exception {
4545
@Ignore
4646
public void testGetId() throws Exception {
4747
Txn tx = new Txn(env);
48-
Database db = new Database(tx, DB_1, MDB_CREATE);
48+
Dbi db = new Dbi(tx, DB_1, MDB_CREATE);
4949
tx.commit();
5050

5151
final AtomicLong txId1 = new AtomicLong();

0 commit comments

Comments
 (0)