OPENDJ-1116 Introduce abstraction for the changelog DB
DBCursor.java:
Added usage example to the javadocs.
DraftCNDB.java:
Replaced catch (Exception) by catch (DatabaseException), or removed them altogether where unapplicable.
In next(), first wiped the current record + reverted the if condition and clauses.
| | |
| | | * Generic cursor interface into the changelog database. Once it is not used |
| | | * anymore, a cursor must be closed to release all the resources into the |
| | | * database. |
| | | * <p> |
| | | * Here is a typical usage pattern: |
| | | * |
| | | * <pre> |
| | | * DBCursor<T> cursor = ...; // obtain a new cursor, |
| | | * // already initialized |
| | | * T record1 = cursor.getRecord(); // get the first record |
| | | * while (cursor.next()) { // advance to the next record |
| | | * T record = cursor.getRecord(); // get the next record |
| | | * ... // etc. |
| | | * } |
| | | * </pre> |
| | | * |
| | | * @param <T> |
| | | * type of the record being returned |
| | |
| | | |
| | | return db.count(); |
| | | } |
| | | catch (Exception e) |
| | | catch (DatabaseException e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | try |
| | | { |
| | | return record; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Go to the next record on the cursor. |
| | |
| | | */ |
| | | public boolean next() throws ChangelogException |
| | | { |
| | | // first wipe old entry |
| | | record = null; |
| | | if (isClosed) |
| | | { |
| | | return false; |
| | |
| | | |
| | | try { |
| | | OperationStatus status = cursor.getNext(key, entry, LockMode.DEFAULT); |
| | | if (status != OperationStatus.SUCCESS) |
| | | if (status == OperationStatus.SUCCESS) |
| | | { |
| | | record = null; |
| | | record = newCNIndexRecord(this.key, entry); |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | record = newCNIndexRecord(this.key, entry); |
| | | } |
| | | catch(Exception e) |
| | | catch (DatabaseException e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | throw new ChangelogException(e); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |