Class SequenceTable

  • All Implemented Interfaces:
    Table, org.datanucleus.store.schema.table.Table

    public class SequenceTable
    extends TableImpl
    Class defining a table for storing generated values for use with TableGenerator. The table has 2 columns : a primary key String, and a value Long.
    • Field Detail

      • sequenceNameMapping

        private JavaTypeMapping sequenceNameMapping
        Mapping for the sequence name column.
      • nextValMapping

        private JavaTypeMapping nextValMapping
        Mapping for the next value column
      • insertStmt

        private java.lang.String insertStmt
      • incrementByStmt

        private java.lang.String incrementByStmt
      • fetchStmt

        private java.lang.String fetchStmt
      • sequenceNameColumnName

        private java.lang.String sequenceNameColumnName
        the sequence column name
      • nextValColumnName

        private java.lang.String nextValColumnName
        the next value column name
    • Constructor Detail

      • SequenceTable

        public SequenceTable​(DatastoreIdentifier identifier,
                             RDBMSStoreManager storeMgr,
                             java.lang.String seqNameColName,
                             java.lang.String nextValColName)
        Constructor
        Parameters:
        identifier - Datastore identifier for this table
        storeMgr - The RDBMSManager for this datastore
        seqNameColName - Name for the "sequence name" column
        nextValColName - Name for the "next value" column
    • Method Detail

      • initialize

        public void initialize​(org.datanucleus.ClassLoaderResolver clr)
        Method to initialise the table.
        Parameters:
        clr - The ClassLoaderResolver
      • getIdMapping

        public JavaTypeMapping getIdMapping()
        Accessor for a mapping for the ID (persistable) for this table.
        Returns:
        The (persistable) ID mapping.
      • getNextVal

        public java.lang.Long getNextVal​(java.lang.String sequenceName,
                                         org.datanucleus.store.connection.ManagedConnection conn,
                                         int incrementBy,
                                         DatastoreIdentifier tableIdentifier,
                                         java.lang.String columnName,
                                         int initialValue)
                                  throws java.sql.SQLException
        Accessor for the nextval of a sequence
        Parameters:
        conn - Connection for this datastore.
        sequenceName - The sequence name (the key)
        incrementBy - The amount to increment (from the current value)
        tableIdentifier - Identifier for the table being incremented (used when there is no current value)
        columnName - Name of the column being incremented (used when there is no current value)
        initialValue - Initial value (if not using tableIdentifier/columnName to find the initial value)
        Returns:
        The next value that should be used
        Throws:
        java.sql.SQLException - Thrown when an error occurs in the process.
      • incrementSequence

        private void incrementSequence​(java.lang.String sequenceName,
                                       long incrementBy,
                                       org.datanucleus.store.connection.ManagedConnection conn)
                                throws java.sql.SQLException
        Method to increment a sequence
        Parameters:
        conn - Connection to the datastore
        Throws:
        java.sql.SQLException - Thrown when an error occurs incrementing the sequence.
      • addSequence

        private void addSequence​(java.lang.String sequenceName,
                                 java.lang.Long nextVal,
                                 org.datanucleus.store.connection.ManagedConnection conn)
                          throws java.sql.SQLException
        Method to insert a row in the SequenceTable
        Parameters:
        conn - Connection to the datastore
        Throws:
        java.sql.SQLException - Thrown when an error occurs inserting the sequence.
      • getMemberMapping

        public JavaTypeMapping getMemberMapping​(org.datanucleus.metadata.AbstractMemberMetaData mmd)
        Accessor the for the mapping for a field stored in this table
        Parameters:
        mmd - MetaData for the field whose mapping we want
        Returns:
        The mapping