| | |
| | | |
| | | import com.sleepycat.je.DatabaseEntry; |
| | | |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | |
| | | /** |
| | | * An integer identifier assigned to each entry in the JE backend. |
| | | * An entry ID is implemented by this class as a long. |
| | |
| | | public class EntryID implements Comparable<EntryID> |
| | | { |
| | | /** |
| | | * The cached value of the next identifier to be assigned. |
| | | */ |
| | | private static AtomicLong nextid = new AtomicLong(1); |
| | | |
| | | /** |
| | | * The identifier integer value. |
| | | */ |
| | | private final Long id; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Initialize the next ID counter from the previous highest value. |
| | | * @param highestID The previous highest entry ID. |
| | | */ |
| | | public static void initialize(EntryID highestID) |
| | | { |
| | | nextid = new AtomicLong(highestID.id + 1); |
| | | } |
| | | |
| | | /** |
| | | * Assign the next entry ID. |
| | | * @return The assigned entry ID. |
| | | */ |
| | | public static EntryID assignNext() |
| | | { |
| | | return new EntryID(nextid.getAndIncrement()); |
| | | } |
| | | |
| | | /** |
| | | * Return the lowest entry ID assigned. |
| | | * @return The lowest entry ID assigned. |
| | | */ |
| | | public static Long getLowest() |
| | | { |
| | | return 1L; |
| | | } |
| | | |
| | | /** |
| | | * Return the highest entry ID assigned. |
| | | * @return The highest entry ID assigned. |
| | | */ |
| | | public static Long getHighest() |
| | | { |
| | | return (nextid.get() - 1); |
| | | } |
| | | |
| | | /** |
| | | * Compares this object with the specified object for order. Returns a |
| | | * negative integer, zero, or a positive integer as this object is less |
| | | * than, equal to, or greater than the specified object.<p> |