|
8 | 8 |
|
9 | 9 | publicclassLmdbIterable<T>implementsIterable<KeyVal<T>>,AutoCloseable { |
10 | 10 |
|
| 11 | +privatefinalTxn<T>txn; |
11 | 12 | privatefinalCursor<T>cursor; |
12 | | -privatefinalIterator<KeyVal<T>>iterator; |
| 13 | +privatefinalComparator<T>comparator; |
| 14 | +privatefinalKeyRange<T>keyRange; |
| 15 | +privatebooleaniteratorReturned; |
13 | 16 |
|
14 | | -privateLmdbIterable(finalCursor<T>cursor,finalIterator<KeyVal<T>>iterator) { |
| 17 | +privateLmdbIterable( |
| 18 | +finalTxn<T>txn, |
| 19 | +finalCursor<T>cursor, |
| 20 | +finalComparator<T>comparator, |
| 21 | +finalKeyRange<T>keyRange) { |
| 22 | +this.txn =txn; |
15 | 23 | this.cursor =cursor; |
16 | | -this.iterator =iterator; |
| 24 | +this.comparator =comparator; |
| 25 | +this.keyRange =keyRange; |
17 | 26 | } |
18 | 27 |
|
19 | 28 | static <T>voiditerate(finalTxn<T>txn,finalDbi<T>dbi,finalEntryConsumer<T>consumer) { |
@@ -51,8 +60,7 @@ static <T> LmdbIterable<T> create( |
51 | 60 | finalKeyRange<T>keyRange) { |
52 | 61 | finalCursor<T>cursor =dbi.openCursor(txn); |
53 | 62 | try { |
54 | | -finalLmdbIterator<T>iterator =createIterator(cursor,txn.proxy,comparator,keyRange); |
55 | | -returnnewLmdbIterable<>(cursor,iterator); |
| 63 | +returnnewLmdbIterable<>(txn,cursor,comparator,keyRange); |
56 | 64 | }catch (finalError |RuntimeExceptione) { |
57 | 65 | cursor.close(); |
58 | 66 | throwe; |
@@ -103,7 +111,11 @@ private static <T> LmdbIterator<T> createIterator( |
103 | 111 |
|
104 | 112 | @Override |
105 | 113 | publicIterator<KeyVal<T>>iterator() { |
106 | | -returniterator; |
| 114 | +if (iteratorReturned) { |
| 115 | +thrownewIllegalStateException("Iterator can only be returned once"); |
| 116 | + } |
| 117 | +iteratorReturned =true; |
| 118 | +returncreateIterator(cursor,txn.proxy,comparator,keyRange); |
107 | 119 | } |
108 | 120 |
|
109 | 121 | @Override |
|