Class AbstractGenerator<T>

java.lang.Object
org.datanucleus.store.valuegenerator.AbstractGenerator<T>
All Implemented Interfaces:
ValueGenerator<T>
Direct Known Subclasses:
AbstractConnectedGenerator, AbstractUUIDGenerator, AUIDGenerator, TimestampGenerator, TimestampValueGenerator, UUIDGenerator, UUIDObjectGenerator

public abstract class AbstractGenerator<T> extends Object implements ValueGenerator<T>
Abstract value generator.
  • Field Details

    • storeMgr

      protected StoreManager storeMgr
    • name

      protected String name
      Symbolic name for the value generator.
    • allocationSize

      protected int allocationSize
      Allocation size
    • initialValue

      protected int initialValue
      Initial value (of the first id).
    • block

      protected ValueGenerationBlock<T> block
      The current block of values that have been reserved.
  • Constructor Details

    • AbstractGenerator

      public AbstractGenerator(StoreManager storeMgr, String name)
      Constructor.
      Parameters:
      storeMgr - Store Manager
      name - Symbolic name for this generator
  • Method Details

    • getName

      public String getName()
      Accessor for the symbolic name for this generator.
      Returns:
      Symbolic name for the generator.
    • next

      public T next()
      Get next value from the reserved block of values.
      Specified by:
      next in interface ValueGenerator<T>
      Returns:
      The next value
    • current

      public T current()
      Accessor for the current value allocated. Returns null if none are allocated
      Specified by:
      current in interface ValueGenerator<T>
      Returns:
      The current value
    • nextValue

      public long nextValue()
      Accessor for the next element as a long.
      Specified by:
      nextValue in interface ValueGenerator<T>
      Returns:
      The next element
      Throws:
      NucleusDataStoreException - Thrown if not numeric
    • currentValue

      public long currentValue()
      Accessor for the current element as a long.
      Specified by:
      currentValue in interface ValueGenerator<T>
      Returns:
      The current element
      Throws:
      NucleusDataStoreException - Thrown if not numeric
    • getLongValueForObject

      private long getLongValueForObject(Object oid)
      Convenience method to convert a value into a long. Throws NucleusDataStoreException if the value is not numeric.
      Parameters:
      oid - The id
      Returns:
      The long value
      Throws:
      NucleusDataStoreException - Thrown if not numeric
    • allocate

      public void allocate(int additional)
      Method to allocate a number of values into the block. If the block already exists and has remaining values, the additional values are added to the block.
      Specified by:
      allocate in interface ValueGenerator<T>
      Parameters:
      additional - The number to allocate
    • obtainGenerationBlock

      protected ValueGenerationBlock<T> obtainGenerationBlock()
      Get a new block with the default number of ids.
      Returns:
      the block
    • obtainGenerationBlock

      protected ValueGenerationBlock<T> obtainGenerationBlock(int number)
      Get a new block with the specified number of ids.
      Parameters:
      number - The number of additional ids required
      Returns:
      the block
    • reserveBlock

      protected ValueGenerationBlock<T> reserveBlock()
      Method to reserve a default sized block of values.
      Returns:
      The reserved block
    • reserveBlock

      protected abstract ValueGenerationBlock<T> reserveBlock(long size)
      Method to reserve a block of "size" values.
      Parameters:
      size - Number of values to reserve
      Returns:
      The allocated block