Class SequenceGenerator

java.lang.Object
org.datanucleus.store.valuegenerator.AbstractGenerator<Long>
org.datanucleus.store.valuegenerator.AbstractConnectedGenerator<Long>
org.datanucleus.store.rdbms.valuegenerator.SequenceGenerator
All Implemented Interfaces:
org.datanucleus.store.valuegenerator.ValueGenerator<Long>

public final class SequenceGenerator extends org.datanucleus.store.valuegenerator.AbstractConnectedGenerator<Long>
ValueGenerator utilising datastore (RDBMS) sequences. It uses a statement like
"select {sequence}.nextval from dual"
to get the next value in the sequence. It is datastore-dependent since there is no RDBMS-independent statement. SequenceGenerator works with Longs, so clients using this generator must cast the ID to Long.

Optional user properties

  • sequence-catalog-name - catalog for the sequence
  • sequence-schema-name - schema for the sequence
  • key-initial-value - the initial value for the sequence
  • key-cache-size - number of unique identifiers to cache
  • key-min-value - determines the minimum value a sequence can generate
  • key-max-value - determines the maximum value a sequence can generate
  • key-database-cache-size - specifies how many sequence numbers are to be preallocated and stored in memory for faster access
TODO Change structure to not override obtainGenerationBlock so we can follow the superclass process and commonise more code.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator

    org.datanucleus.store.valuegenerator.AbstractConnectedGenerator.ConnectionPreference
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.datanucleus.store.connection.ManagedConnection
    Connection to the datastore.
    protected boolean
    Flag for whether we know that the repository exists.
    protected String
    Name of the sequence that we are creating values for

    Fields inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator

    connectionProvider, properties

    Fields inherited from class org.datanucleus.store.valuegenerator.AbstractGenerator

    allocationSize, block, initialValue, name, storeMgr

    Fields inherited from interface org.datanucleus.store.valuegenerator.ValueGenerator

    PROPERTY_CATALOG_NAME, PROPERTY_CLASS_NAME, PROPERTY_COLUMN_NAME, PROPERTY_FIELD_NAME, PROPERTY_KEY_CACHE_SIZE, PROPERTY_KEY_DATABASE_CACHE_SIZE, PROPERTY_KEY_INITIAL_VALUE, PROPERTY_KEY_MAX_VALUE, PROPERTY_KEY_MIN_VALUE, PROPERTY_ROOT_CLASS_NAME, PROPERTY_SCHEMA_NAME, PROPERTY_SEQUENCE_NAME, PROPERTY_SEQUENCETABLE_CATALOG, PROPERTY_SEQUENCETABLE_NAME_COLUMN, PROPERTY_SEQUENCETABLE_NEXTVAL_COLUMN, PROPERTY_SEQUENCETABLE_SCHEMA, PROPERTY_SEQUENCETABLE_TABLE, PROPERTY_TABLE_NAME
  • Constructor Summary

    Constructors
    Constructor
    Description
    SequenceGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Method to create the sequence.
    static Class
    Accessor for the storage class for values generated with this generator.
    protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long>
    Get a new ValueGenerationBlock with the specified number of ids.
    protected boolean
    Method to return if the repository already exists.
    protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long>
    reserveBlock(long size)
    Reserve a block of ids.

    Methods inherited from class org.datanucleus.store.valuegenerator.AbstractConnectedGenerator

    getConnectionPreference, setConnectionProvider

    Methods inherited from class org.datanucleus.store.valuegenerator.AbstractGenerator

    allocate, current, currentValue, getName, next, nextValue, obtainGenerationBlock, reserveBlock

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • connection

      protected org.datanucleus.store.connection.ManagedConnection connection
      Connection to the datastore.
    • repositoryExists

      protected boolean repositoryExists
      Flag for whether we know that the repository exists.
    • sequenceName

      protected String sequenceName
      Name of the sequence that we are creating values for
  • Constructor Details

    • SequenceGenerator

      public SequenceGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props)
      Constructor.
      Parameters:
      storeMgr - StoreManager
      name - Symbolic name for the generator
      props - Properties controlling the behaviour of the generator
  • Method Details

    • getStorageClass

      public static Class getStorageClass()
      Accessor for the storage class for values generated with this generator.
      Returns:
      Storage class (in this case Long.class)
    • reserveBlock

      protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> reserveBlock(long size)
      Reserve a block of ids.
      Specified by:
      reserveBlock in class org.datanucleus.store.valuegenerator.AbstractGenerator<Long>
      Parameters:
      size - Block size
      Returns:
      The reserved block
    • repositoryExists

      protected boolean repositoryExists()
      Method to return if the repository already exists.
      Returns:
      Whether the repository exists
    • createRepository

      protected boolean createRepository()
      Method to create the sequence.
      Returns:
      Whether it was created successfully.
    • obtainGenerationBlock

      protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> obtainGenerationBlock(int number)
      Get a new ValueGenerationBlock with the specified number of ids.
      Overrides:
      obtainGenerationBlock in class org.datanucleus.store.valuegenerator.AbstractGenerator<Long>
      Parameters:
      number - The number of additional ids required
      Returns:
      the ValueGenerationBlock