Package com.helger.commons.id.factory
Class FileLongIDFactory
java.lang.Object
com.helger.commons.id.factory.AbstractPersistingLongIDFactory
com.helger.commons.id.factory.FileLongIDFactory
- All Implemented Interfaces:
IBaseIDFactory,ILongIDFactory
File based persisting ILongIDFactory implementation.- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetThe charset to use for writing the filestatic final intThe default number of values to reserve with a single IO actionFields inherited from class com.helger.commons.id.factory.AbstractPersistingLongIDFactory
m_aLock -
Constructor Summary
ConstructorsConstructorDescriptionFileLongIDFactory(File aFile) FileLongIDFactory(File aFile, int nReserveCount) -
Method Summary
Methods inherited from class com.helger.commons.id.factory.AbstractPersistingLongIDFactory
getNewID, getReserveCount
-
Field Details
-
CHARSET_TO_USE
The charset to use for writing the file -
DEFAULT_RESERVE_COUNT
public static final int DEFAULT_RESERVE_COUNTThe default number of values to reserve with a single IO action- See Also:
-
-
Constructor Details
-
FileLongIDFactory
-
FileLongIDFactory
-
-
Method Details
-
getFile
- Returns:
- The
Fileto write to, as provided in the constructor. Nevernull.
-
readAndUpdateIDCounter
Description copied from class:AbstractPersistingLongIDFactoryRead the current ID from the device. In case the method is called for a non-initialized device, 0 should be returned.
The update should write the read value plus the passed reserve count back to the device. This method should perform an atomic read and update to avoid that ID can be reused.
Pseudo code:protected long readAndUpdateIDCounter (int nReserveCount) { final long nRead = FileIO.read (file); FileIO.write (file, nRead + nReserveCount); return nRead; }- Specified by:
readAndUpdateIDCounterin classAbstractPersistingLongIDFactory- Parameters:
nReserveCount- the number that should be added to the read value. Always > 0.- Returns:
- 0 if this method is called for a non-initialized device, the value
read from the device otherwise or
CGlobal.ILLEGAL_ULONGin case of an error.
-
equals
- Overrides:
equalsin classAbstractPersistingLongIDFactory
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractPersistingLongIDFactory
-
toString
- Overrides:
toStringin classAbstractPersistingLongIDFactory
-