Class TableGenerator

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

public final class TableGenerator extends org.datanucleus.store.valuegenerator.AbstractConnectedGenerator<Long>
Identity generator for RDBMS databases that generates ids using a table in the database. This generator is coupled to core and can't be used in standalone mode.

The following properties define the name of the sequence being generated. If "sequence-name" is specified then it is used. Otherwise the name of the sequence will either be based on the table name or the class name (for what we are generating the ids).

  • sequence-name - Name for the sequence
  • sequence-table-basis - Basic for the sequence name (if "sequence-name" not provided). This can be "table" or "class".

The following properties define the table where the identities are generated.

  • sequence-catalog-name - the catalog name for the table (defaults to the default catalog)
  • sequence-schema-name - the schema name for the table (defaults to the default schema)
  • sequence-table-name - the table name for the table (defaults to SEQUENCE_TABLE)
  • sequence-name-column-name - the name for the column that represent sequence names
  • sequence-nextval-column-name - the name for the column that represent incrementing sequence values

The following properties control the initial value, and the number of ids that are cached (generated) in each call.

  • key-initial-value - start value (if we have no current value). If not specified and we have no current value then we do a "SELECT max(column-name) FROM table-name" for the column being incremented
  • key-cache-size - number of unique identifiers to cache (defaults to 5)

The following properties are used when finding the starting point for the identities generated.

  • table-name - name of the table whose column we are generating the value for
  • column-name - name of the column that we are generating the value for
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.
    static final String
    Default name for the column storing the next value of the sequence.
    static final String
    Default name for the column storing the name of the sequence.
    static final String
    Default name for the datastore table storing the sequence values.
    protected boolean
    Flag for whether we know that the repository exists.
    private final String
    Name of the sequence that we are storing values under in the SequenceTable.
    Table where we store the identities for each table.

    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
    TableGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Method to create the repository for ids to be stored.
    static Class
    Accessor for the storage class for values generated with this generator.
    Convenience accessor for the table being used.
    protected void
    Method to initialise the sequence table used for storing the sequence values.
    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.
    org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long>
    reserveBlock(long size)
    Method to reserve a block of "size" identities.

    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.
    • sequenceTable

      private SequenceTable sequenceTable
      Table where we store the identities for each table.
    • sequenceName

      private final String sequenceName
      Name of the sequence that we are storing values under in the SequenceTable.
    • DEFAULT_TABLE_NAME

      public static final String DEFAULT_TABLE_NAME
      Default name for the datastore table storing the sequence values. Defaults to SEQUENCE_TABLE
      See Also:
    • DEFAULT_SEQUENCE_COLUMN_NAME

      public static final String DEFAULT_SEQUENCE_COLUMN_NAME
      Default name for the column storing the name of the sequence.
      See Also:
    • DEFAULT_NEXTVALUE_COLUMN_NAME

      public static final String DEFAULT_NEXTVALUE_COLUMN_NAME
      Default name for the column storing the next value of the sequence.
      See Also:
  • Constructor Details

    • TableGenerator

      public TableGenerator(org.datanucleus.store.StoreManager storeMgr, String name, Properties props)
      Constructor.
      Parameters:
      storeMgr - StoreManager
      name - Symbolic name for this generator
      props - Properties defining the behaviour of this 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)
    • getTable

      public SequenceTable getTable()
      Convenience accessor for the table being used.
      Returns:
      The table
    • reserveBlock

      public org.datanucleus.store.valuegenerator.ValueGenerationBlock<Long> reserveBlock(long size)
      Method to reserve a block of "size" identities.
      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 repository for ids to be stored.
      Returns:
      Whether it was created successfully.
    • initialiseSequenceTable

      protected void initialiseSequenceTable()
      Method to initialise the sequence table used for storing the sequence values.
    • 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