@ThreadSafe public abstract class AbstractPersistingIntIDFactory extends Object implements IIntIDFactory
IIntIDFactory reads IDs from a device. It does
it by reserving a range of n IDs so that not each ID reservation
requires IO. If only 1 ID is effectively used, the other n-1 IDs are
lost and will never be assigned to any object again.| Modifier and Type | Field and Description |
|---|---|
protected SimpleLock |
m_aLock |
| Constructor and Description |
|---|
AbstractPersistingIntIDFactory(int nReserveCount)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
int |
getNewID()
Create a new unique integer ID.
|
int |
getReserveCount() |
int |
hashCode() |
protected abstract int |
readAndUpdateIDCounter(int nReserveCount)
Read the current ID from the device.
|
String |
toString() |
protected final SimpleLock m_aLock
public AbstractPersistingIntIDFactory(@Nonnegative int nReserveCount)
nReserveCount - The number of IDs to reserve per persistence layer access. Must be
> 0.@Nonnegative public final int getReserveCount()
@IsLocked(value=WRITE) protected abstract int readAndUpdateIDCounter(@Nonnegative int nReserveCount)
protected int readAndUpdateIDCounter (int nReserveCount)
{
final int nRead = FileIO.read (file);
FileIO.write (file, nRead + nReserveCount);
return nRead;
}
nReserveCount - the number that should be added to the read value. Always > 0.CGlobal.ILLEGAL_UINT in case of an
error.public final int getNewID()
IIntIDFactorygetNewID in interface IIntIDFactoryCopyright © 2014–2022 Philip Helger. All rights reserved.