Class 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
      Connection to the datastore.
      protected boolean repositoryExists
      Flag for whether we know that the repository exists.
      protected String sequenceName
      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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean createRepository()
      Method to create the sequence.
      static Class getStorageClass()
      Accessor for the storage class for values generated with this generator.
      protected org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> obtainGenerationBlock​(int number)
      Get a new ValueGenerationBlock with the specified number of ids.
      protected boolean repositoryExists()
      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
    • Field Detail

      • 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 Detail

      • 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 Detail

      • 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