/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2002,2008 Oracle. All rights reserved. * * $Id: ForwardCursor.java,v 1.1 2008/02/07 17:12:26 mark Exp $ */ package com.sleepycat.persist; import java.util.Iterator; import com.sleepycat.db.DatabaseException; import com.sleepycat.db.LockMode; /** * Cursor operations limited to traversing forward. See {@link EntityCursor} * for general information on cursors. * *

{@code ForwardCursor} objects are not thread-safe. Cursors * should be opened, used and closed by a single thread.

* *

WARNING: Cursors must always be closed to prevent resource leaks * which could lead to the index becoming unusable or cause an * OutOfMemoryError. To ensure that a cursor is closed in the * face of exceptions, close it in a finally block.

* * @author Mark Hayes */ public interface ForwardCursor extends Iterable { /** * Moves the cursor to the next value and returns it, or returns null * if there are no more values in the cursor range. If the cursor is * uninitialized, this method returns the first value. * *

{@link LockMode#DEFAULT} is used implicitly.

* * @return the next value, or null if there are no more values in the * cursor range. */ V next() throws DatabaseException; /** * Moves the cursor to the next value and returns it, or returns null * if there are no more values in the cursor range. If the cursor is * uninitialized, this method returns the first value. * * @param lockMode the lock mode to use for this operation, or null to * use {@link LockMode#DEFAULT}. * * @return the next value, or null if there are no more values in the * cursor range. */ V next(LockMode lockMode) throws DatabaseException; /** * Returns an iterator over the key range, starting with the value * following the current position or at the first value if the cursor is * uninitialized. * *

{@link LockMode#DEFAULT} is used implicitly.

* * @return the iterator. */ Iterator iterator(); /** * Returns an iterator over the key range, starting with the value * following the current position or at the first value if the cursor is * uninitialized. * * @param lockMode the lock mode to use for all operations performed * using the iterator, or null to use {@link LockMode#DEFAULT}. * * @return the iterator. */ Iterator iterator(LockMode lockMode); /** * Closes the cursor. */ void close() throws DatabaseException; }