Class TableIdGenerator

java.lang.Object
org.fastnate.generator.context.IdGenerator
org.fastnate.generator.context.TableIdGenerator

public class TableIdGenerator extends IdGenerator
Saves the current value for a TableGenerator. The content of the value column is interpreted like nextValue of a sequence, which means the maximum allocated value is allways at most value column value - allocationSize.
Author:
Tobias Liefke
  • Constructor Details

    • TableIdGenerator

      public TableIdGenerator(String tableName, jakarta.persistence.TableGenerator generator, GeneratorContext context)
      Creates a new instance of SequenceIdGenerator.
      Parameters:
      tableName - the name of the current table
      generator - the annotation that contains our settings
      context - the current context
  • Method Details

    • addNextValue

      public void addNextValue(TableStatement statement, GeneratorColumn column, Number value)
      Description copied from class: IdGenerator
      Adds the generated value to the given statement. Depending on the generator this may add the value itself or a reference to the value.
      Specified by:
      addNextValue in class IdGenerator
      Parameters:
      statement - the current insert statement
      column - the ID column of the current table
      value - the current value of the column, previously generated with IdGenerator.createNextValue()
    • alignNextValue

      public void alignNextValue(StatementsWriter writer) throws IOException
      Description copied from class: IdGenerator
      Creates all statements that are necessary to set the next value created from the database is currentValue + 1.
      Specified by:
      alignNextValue in class IdGenerator
      Parameters:
      writer - the target of the created statements
      Throws:
      IOException - if the writer throws one
    • createNextValue

      public long createNextValue()
      Description copied from class: IdGenerator
      Resolves the next value of this generator.
      Specified by:
      createNextValue in class IdGenerator
      Returns:
      the generated value
    • createPreInsertStatements

      public void createPreInsertStatements(StatementsWriter writer) throws IOException
      Description copied from class: IdGenerator
      Creates the statements that are needed in the output before IdGenerator.addNextValue(TableStatement, GeneratorColumn, Number).
      Overrides:
      createPreInsertStatements in class IdGenerator
      Parameters:
      writer - target for the created statements
      Throws:
      IOException - if the writer throws one
    • derive

      public IdGenerator derive(GeneratorTable currentTable)
      Description copied from class: IdGenerator
      Some implementations (like the Hibernate table generator) create a different generator, depending on the table name.
      Overrides:
      derive in class IdGenerator
      Parameters:
      currentTable - the current entity table
      Returns:
      the generator
    • getCurrentValue

      public long getCurrentValue()
      Description copied from class: IdGenerator
      The last value returned by IdGenerator.createNextValue(Class).
      Specified by:
      getCurrentValue in class IdGenerator
      Returns:
      the current value
    • getExpression

      public ColumnExpression getExpression(GeneratorTable table, GeneratorColumn column, Number targetId, boolean whereExpression)
      Description copied from class: IdGenerator
      Builds the reference to another entity that has the given ID.
      Specified by:
      getExpression in class IdGenerator
      Parameters:
      table - the main table of the entity
      column - the name of the column of the ID
      targetId - the current value of the ID
      whereExpression - indicates if this expression is needed for a "SELECT ... WHERE ..." - some dialects behave differently in this situation
      Returns:
      the expression for selecting the ID
    • isPostIncrement

      public boolean isPostIncrement()
      Description copied from class: IdGenerator
      Indicates that IdGenerator.createNextValue(Class) should be called after the entity was written - as the value is not available before.
      Specified by:
      isPostIncrement in class IdGenerator
      Returns:
      true if the database increments the value _after_ the insert statement was executed, true if it is incremented before or during the execution
    • setCurrentValue

      public void setCurrentValue(long currentValue)
      Description copied from class: IdGenerator
      Sets a new start value.
      Specified by:
      setCurrentValue in class IdGenerator
      Parameters:
      currentValue - the current value - most likely as extracted from the target database
    • getContext

      public GeneratorContext getContext()
    • isRelativeIds

      public boolean isRelativeIds()
    • getGeneratorTable

      public GeneratorTable getGeneratorTable()
    • getPkColumn

      public GeneratorColumn getPkColumn()
    • getPkColumnValue

      public ColumnExpression getPkColumnValue()
    • getValueColumn

      public GeneratorColumn getValueColumn()
    • getAllocationSize

      public int getAllocationSize()
    • getInitialValue

      public long getInitialValue()
    • getNextValue

      public long getNextValue()
    • getMaxAllocatedValue

      public long getMaxAllocatedValue()
      The maximum allocated value. The value column value in the table is at any time by allocationSize greater.