Package com.helger.commons.id.factory
Class FileIntIDFactory
java.lang.Object
com.helger.commons.id.factory.AbstractPersistingIntIDFactory
com.helger.commons.id.factory.FileIntIDFactory
- All Implemented Interfaces:
IBaseIDFactory,IIntIDFactory
File based persisting IIntIDFactory 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.AbstractPersistingIntIDFactory
m_aLock -
Constructor Summary
ConstructorsConstructorDescriptionFileIntIDFactory(File aFile) FileIntIDFactory(File aFile, int nReserveCount) -
Method Summary
Methods inherited from class com.helger.commons.id.factory.AbstractPersistingIntIDFactory
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
-
FileIntIDFactory
-
FileIntIDFactory
-
-
Method Details
-
getFile
- Returns:
- The
Fileto write to, as provided in the constructor. Nevernull.
-
readAndUpdateIDCounter
Description copied from class:AbstractPersistingIntIDFactoryRead 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 int readAndUpdateIDCounter (int nReserveCount) { final int nRead = FileIO.read (file); FileIO.write (file, nRead + nReserveCount); return nRead; }- Specified by:
readAndUpdateIDCounterin classAbstractPersistingIntIDFactory- 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_UINTin case of an error.
-
equals
- Overrides:
equalsin classAbstractPersistingIntIDFactory
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractPersistingIntIDFactory
-
toString
- Overrides:
toStringin classAbstractPersistingIntIDFactory
-