Skip to content

Commit 5aa1f74

Browse files
committed
LmdbException to RuntimeException
1 parent 62062bb commit 5aa1f74

7 files changed

Lines changed: 50 additions & 196 deletions

File tree

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

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import static org.lmdbjava.PutFlags.MDB_RESERVE;
2626
import static org.lmdbjava.ResultCodeMapper.checkRc;
2727
import org.lmdbjava.Txn.CommittedException;
28-
import org.lmdbjava.Txn.ReadOnlyRequiredException;
29-
import org.lmdbjava.Txn.ReadWriteRequiredException;
3028

3129
/**
3230
* A cursor handle.
@@ -51,12 +49,9 @@ public final class Cursor<T> implements AutoCloseable {
5149
* <p>
5250
* The cursor handle will be freed and must not be used again after this call.
5351
* Its transaction must still be live if it is a write-transaction.
54-
*
55-
* @throws CommittedException if the transaction was read-write and has
56-
* already been closed
5752
*/
5853
@Override
59-
public void close() throws CommittedException {
54+
public void close() {
6055
if (closed) {
6156
return;
6257
}
@@ -74,12 +69,8 @@ public void close() throws CommittedException {
7469
* items {@link DbiFlags#MDB_DUPSORT}.
7570
*
7671
* @return count of duplicates for current key
77-
* @throws LmdbNativeException if a native C error occurred
78-
* @throws CommittedException if the transaction was committed
79-
* @throws ClosedException if the cursor is already closed
8072
*/
81-
public long count() throws LmdbNativeException, CommittedException,
82-
ClosedException {
73+
public long count() {
8374
if (SHOULD_CHECK) {
8475
checkNotClosed();
8576
txn.checkNotCommitted();
@@ -95,14 +86,8 @@ public long count() throws LmdbNativeException, CommittedException,
9586
* This function deletes the key/data pair to which the cursor refers.
9687
*
9788
* @param f flags (either null or {@link PutFlags#MDB_NODUPDATA}
98-
* @throws LmdbNativeException if a native C error occurred
99-
* @throws CommittedException if the transaction was committed
100-
* @throws ClosedException if the cursor is already closed
101-
* @throws ReadWriteRequiredException if cursor using a read-only transaction
10289
*/
103-
public void delete(final PutFlags... f)
104-
throws LmdbNativeException, CommittedException, ClosedException,
105-
ReadWriteRequiredException {
90+
public void delete(final PutFlags... f) {
10691
if (SHOULD_CHECK) {
10792
checkNotClosed();
10893
txn.checkNotCommitted();
@@ -118,12 +103,8 @@ public void delete(final PutFlags... f)
118103
* @param key to search for
119104
* @param op options for this operation
120105
* @return false if key not found
121-
* @throws LmdbNativeException if a native C error occurred
122-
* @throws CommittedException if the transaction was committed
123-
* @throws ClosedException if the cursor is already closed
124106
*/
125-
public boolean get(final T key, final GetOp op)
126-
throws LmdbNativeException, CommittedException, ClosedException {
107+
public boolean get(final T key, final GetOp op) {
127108
if (SHOULD_CHECK) {
128109
requireNonNull(key);
129110
requireNonNull(op);
@@ -154,14 +135,8 @@ public boolean get(final T key, final GetOp op)
154135
* @param key key to store
155136
* @param val data to store
156137
* @param op options for this operation
157-
* @throws LmdbNativeException if a native C error occurred
158-
* @throws CommittedException if the transaction was committed
159-
* @throws ClosedException if the cursor is already closed
160-
* @throws ReadWriteRequiredException if cursor using a read-only transaction
161138
*/
162-
public void put(final T key, final T val, final PutFlags... op)
163-
throws LmdbNativeException, CommittedException, ClosedException,
164-
ReadWriteRequiredException {
139+
public void put(final T key, final T val, final PutFlags... op) {
165140
if (SHOULD_CHECK) {
166141
requireNonNull(key);
167142
requireNonNull(val);
@@ -188,14 +163,8 @@ public void put(final T key, final T val, final PutFlags... op)
188163
* dead.
189164
*
190165
* @param txn transaction handle
191-
* @throws LmdbNativeException if a native C error occurred
192-
* @throws ClosedException if the cursor is already closed
193-
* @throws CommittedException if the new transaction was committed
194-
* @throws ReadOnlyRequiredException if a R-W transaction was presented
195166
*/
196-
public void renew(final Txn<T> txn)
197-
throws LmdbNativeException, ClosedException, ReadOnlyRequiredException,
198-
CommittedException {
167+
public void renew(final Txn<T> txn) {
199168
if (SHOULD_CHECK) {
200169
requireNonNull(txn);
201170
checkNotClosed();
@@ -219,16 +188,8 @@ public void renew(final Txn<T> txn)
219188
*
220189
* @param key key to store in the database (not null)
221190
* @param val size of the value to be stored in the database (not null)
222-
* @throws CommittedException if already committed
223-
* @throws LmdbNativeException if a native C error occurred
224-
* @throws ClosedException if the cursor is already closed
225-
* @throws ReadWriteRequiredException if cursor using a read-only transaction
226191
*/
227-
public void reserve(final T key, final T val) throws
228-
LmdbNativeException,
229-
CommittedException,
230-
ClosedException,
231-
ReadWriteRequiredException {
192+
public void reserve(final T key, final T val) {
232193
if (SHOULD_CHECK) {
233194
requireNonNull(key);
234195
requireNonNull(val);
@@ -249,12 +210,8 @@ public void reserve(final T key, final T val) throws
249210
*
250211
* @param op options for this operation
251212
* @return false if requested position not found
252-
* @throws LmdbNativeException if a native C error occurred
253-
* @throws CommittedException if the transaction was committed
254-
* @throws ClosedException if the cursor is already closed
255213
*/
256-
public boolean seek(final SeekOp op)
257-
throws LmdbNativeException, CommittedException, ClosedException {
214+
public boolean seek(final SeekOp op) {
258215
if (SHOULD_CHECK) {
259216
requireNonNull(op);
260217
checkNotClosed();

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

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import jnr.ffi.Pointer;
2222
import jnr.ffi.byref.PointerByReference;
2323
import static org.lmdbjava.Dbi.KeyNotFoundException.MDB_NOTFOUND;
24-
import org.lmdbjava.Env.NotOpenException;
2524
import static org.lmdbjava.Env.SHOULD_CHECK;
2625
import static org.lmdbjava.Library.LIB;
2726
import static org.lmdbjava.Library.RUNTIME;
@@ -33,11 +32,6 @@
3332

3433
/**
3534
* LMDB Database.
36-
* <p>
37-
* All accessor and mutator methods on this class use <code>ByteBuffer</code>.
38-
* This is solely for end user convenience and use of these methods is strongly
39-
* discouraged. Instead use the more flexible buffer API and lower latency
40-
* operating modes available via {@link #openCursor(org.lmdbjava.Txn)}.
4135
*
4236
* @param <T> buffer type
4337
*/
@@ -66,15 +60,9 @@ public final class Dbi<T> {
6660
* Starts a new read-write transaction and deletes the key.
6761
*
6862
* @param key key to delete from the database (not null)
69-
* @throws CommittedException if already committed
70-
* @throws NotOpenException if the environment is not currently open
71-
* @throws LmdbNativeException if a native C error occurred
72-
* @throws ReadWriteRequiredException if a read-only transaction presented
73-
* @see #delete(Txn, ByteBuffer, ByteBuffer)
63+
* @see #delete(org.lmdbjava.Txn, java.lang.Object, java.lang.Object)
7464
*/
75-
public void delete(final T key) throws
76-
CommittedException, LmdbNativeException,
77-
NotOpenException, ReadWriteRequiredException {
65+
public void delete(final T key) {
7866
try (final Txn<T> txn = env.txnWrite()) {
7967
delete(txn, key);
8068
txn.commit();
@@ -86,14 +74,9 @@ public void delete(final T key) throws
8674
*
8775
* @param txn transaction handle (not null; not committed; must be R-W)
8876
* @param key key to delete from the database (not null)
89-
* @throws CommittedException if already committed
90-
* @throws LmdbNativeException if a native C error occurred
91-
* @throws ReadWriteRequiredException if a read-only transaction presented
92-
* @see #delete(Txn, ByteBuffer, ByteBuffer)
77+
* @see #delete(org.lmdbjava.Txn, java.lang.Object, java.lang.Object)
9378
*/
94-
public void delete(final Txn<T> txn, final T key) throws
95-
CommittedException, LmdbNativeException,
96-
ReadWriteRequiredException {
79+
public void delete(final Txn<T> txn, final T key) {
9780
delete(txn, key, null);
9881
}
9982

@@ -112,14 +95,8 @@ public void delete(final Txn<T> txn, final T key) throws
11295
* @param txn transaction handle (not null; not committed; must be R-W)
11396
* @param key key to delete from the database (not null)
11497
* @param val value to delete from the database (null permitted)
115-
* @throws CommittedException if already committed
116-
* @throws LmdbNativeException if a native C error occurred
117-
* @throws ReadWriteRequiredException if a read-only transaction presented
11898
*/
119-
public void delete(final Txn<T> txn, final T key, final T val)
120-
throws
121-
CommittedException, LmdbNativeException,
122-
ReadWriteRequiredException {
99+
public void delete(final Txn<T> txn, final T key, final T val) {
123100
if (SHOULD_CHECK) {
124101
requireNonNull(txn);
125102
requireNonNull(key);
@@ -150,12 +127,8 @@ public void delete(final Txn<T> txn, final T key, final T val)
150127
* @param txn transaction handle (not null; not committed)
151128
* @param key key to search for in the database (not null)
152129
* @return the data or null if not found
153-
* @throws CommittedException if already committed
154-
* @throws LmdbNativeException if a native C error occurred
155130
*/
156-
public T get(final Txn<T> txn, final T key)
157-
throws
158-
CommittedException, LmdbNativeException {
131+
public T get(final Txn<T> txn, final T key) {
159132
if (SHOULD_CHECK) {
160133
requireNonNull(txn);
161134
requireNonNull(key);
@@ -194,11 +167,8 @@ public String getName() {
194167
*
195168
* @param txn transaction handle (not null; not committed)
196169
* @return cursor handle
197-
* @throws LmdbNativeException if a native C error occurred
198-
* @throws CommittedException if already committed
199170
*/
200-
public Cursor<T> openCursor(final Txn<T> txn)
201-
throws LmdbNativeException, CommittedException {
171+
public Cursor<T> openCursor(final Txn<T> txn) {
202172
if (SHOULD_CHECK) {
203173
requireNonNull(txn);
204174
txn.checkNotCommitted();
@@ -213,15 +183,10 @@ public Cursor<T> openCursor(final Txn<T> txn)
213183
*
214184
* @param key key to store in the database (not null)
215185
* @param val value to store in the database (not null)
216-
* @throws CommittedException if already committed
217-
* @throws NotOpenException if the environment is not currently open
218-
* @throws LmdbNativeException if a native C error occurred
219-
* @throws ReadWriteRequiredException if a read-only transaction presented
220-
* @see Dbi#put(Txn, ByteBuffer, ByteBuffer, PutFlags...)
186+
* @see #put(org.lmdbjava.Txn, java.lang.Object, java.lang.Object,
187+
* org.lmdbjava.PutFlags...)
221188
*/
222-
public void put(final T key, final T val) throws
223-
CommittedException, LmdbNativeException,
224-
NotOpenException, ReadWriteRequiredException {
189+
public void put(final T key, final T val) {
225190
try (final Txn<T> txn = env.txnWrite()) {
226191
put(txn, key, val);
227192
txn.commit();
@@ -240,14 +205,9 @@ public void put(final T key, final T val) throws
240205
* @param key key to store in the database (not null)
241206
* @param val value to store in the database (not null)
242207
* @param flags Special options for this operation
243-
* @throws CommittedException if already committed
244-
* @throws LmdbNativeException if a native C error occurred
245-
* @throws ReadWriteRequiredException if a read-only transaction presented
246208
*/
247209
public void put(final Txn<T> txn, final T key, final T val,
248-
final PutFlags... flags)
249-
throws CommittedException, LmdbNativeException,
250-
ReadWriteRequiredException {
210+
final PutFlags... flags) {
251211
if (SHOULD_CHECK) {
252212
requireNonNull(txn);
253213
requireNonNull(key);
@@ -275,13 +235,8 @@ public void put(final Txn<T> txn, final T key, final T val,
275235
* @param txn transaction handle (not null; not committed; must be R-W)
276236
* @param key key to store in the database (not null)
277237
* @param val size of the value to be stored in the database (not null)
278-
* @throws CommittedException if already committed
279-
* @throws LmdbNativeException if a native C error occurred
280-
* @throws ReadWriteRequiredException if a read-only transaction presented
281238
*/
282-
public void reserve(Txn<T> txn, final T key, final T val)
283-
throws CommittedException, LmdbNativeException,
284-
ReadWriteRequiredException {
239+
public void reserve(Txn<T> txn, final T key, final T val) {
285240
if (SHOULD_CHECK) {
286241
requireNonNull(txn);
287242
requireNonNull(key);

0 commit comments

Comments
 (0)