Class FileIntIDFactory

All Implemented Interfaces:
IBaseIDFactory, IIntIDFactory

@ThreadSafe public class FileIntIDFactory extends AbstractPersistingIntIDFactory
File based persisting IIntIDFactory implementation.
Author:
Philip Helger
  • Field Details

    • CHARSET_TO_USE

      public static final Charset CHARSET_TO_USE
      The charset to use for writing the file
    • DEFAULT_RESERVE_COUNT

      public static final int DEFAULT_RESERVE_COUNT
      The default number of values to reserve with a single IO action
      See Also:
  • Constructor Details

  • Method Details

    • getFile

      @Nonnull public final File getFile()
      Returns:
      The File to write to, as provided in the constructor. Never null.
    • readAndUpdateIDCounter

      @MustBeLocked(WRITE) protected final int readAndUpdateIDCounter(@Nonnegative int nReserveCount)
      Description copied from class: AbstractPersistingIntIDFactory
      Read 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:
      readAndUpdateIDCounter in class AbstractPersistingIntIDFactory
      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_UINT in case of an error.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class AbstractPersistingIntIDFactory
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractPersistingIntIDFactory
    • toString

      public String toString()
      Overrides:
      toString in class AbstractPersistingIntIDFactory