Class ResettableTableHiLoGenerator

java.lang.Object
org.hibernate.id.enhanced.SequenceStyleGenerator
com.atlassian.confluence.impl.hibernate.ResettableTableHiLoGenerator
All Implemented Interfaces:
BulkIdGenerator, org.hibernate.boot.model.relational.ExportableProducer, org.hibernate.id.BulkInsertionCapableIdentifierGenerator, org.hibernate.id.Configurable, org.hibernate.id.IdentifierGenerator, org.hibernate.id.PersistentIdentifierGenerator
Direct Known Subclasses:
ResettableTableHiLoGeneratorV5

public class ResettableTableHiLoGenerator extends org.hibernate.id.enhanced.SequenceStyleGenerator implements BulkIdGenerator
An implementation of a resettable hi/lo IdentifierGenerator which is compatible with Hibernate 5.2.
hilo

An IdentifierGenerator that returns a Long, constructed using a hi/lo algorithm. The hi value MUST be fetched in a separate transaction to the Session transaction so the generator must be able to obtain a new connection and commit it. Hence this implementation may not be used when the user is supplying connections. In this case a SequenceHiLoGenerator would be a better choice (where supported).

Mapping parameters supported: table, column, max_lo
Note : This class is copied as it is from hibernate atlassian-hibernate5.2-extras (Except a couple of minor changes to replace public synchronization with a private lock. Refactor to make it unit testable)
Since:
7.17
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The max_lo parameter

    Fields inherited from class org.hibernate.id.enhanced.SequenceStyleGenerator

    CONFIG_PREFER_SEQUENCE_PER_ENTITY, CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, DEF_SEQUENCE_NAME, DEF_SEQUENCE_SUFFIX, DEF_VALUE_COLUMN, DEFAULT_INCREMENT_SIZE, DEFAULT_INITIAL_VALUE, FORCE_TBL_PARAM, INCREMENT_PARAM, INITIAL_PARAM, OPT_PARAM, SEQUENCE_PARAM, VALUE_COLUMN_PARAM

    Fields inherited from interface org.hibernate.id.IdentifierGenerator

    ENTITY_NAME, GENERATOR_NAME, JPA_ENTITY_NAME

    Fields inherited from interface org.hibernate.id.PersistentIdentifierGenerator

    CATALOG, IDENTIFIER_NORMALIZER, PK, SCHEMA, TABLE, TABLES
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    configure(org.hibernate.type.Type type, Properties params, org.hibernate.service.ServiceRegistry serviceRegistry)
     
    generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object obj)
     
    generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object fakeHibernateObject, int count)
    Generate a collection of ids.
    int
    Get the max_lo value, so that we can calculate a valid value for the next_hi DB value, given the ids already allocated in the database.
    void
    Set the lo value to more than maxLo to force a reset of the hi value.

    Methods inherited from class org.hibernate.id.enhanced.SequenceStyleGenerator

    buildDatabaseStructure, buildSequenceStructure, buildTableStructure, determineAdjustedIncrementSize, determineBulkInsertionIdentifierGenerationSelectFragment, determineIncrementSize, determineInitialValue, determineOptimizationStrategy, determineSequenceName, determineValueColumnName, generatorKey, getDatabaseStructure, getIdentifierType, getOptimizer, initialize, isPhysicalSequence, registerExportables, supportsBulkInsertionIdentifierGeneration

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.hibernate.id.BulkInsertionCapableIdentifierGenerator

    determineBulkInsertionIdentifierGenerationSelectFragment

    Methods inherited from interface org.hibernate.id.IdentifierGenerator

    supportsJdbcBatchInserts
  • Field Details

  • Constructor Details

    • ResettableTableHiLoGenerator

      public ResettableTableHiLoGenerator()
  • Method Details

    • configure

      public void configure(org.hibernate.type.Type type, Properties params, org.hibernate.service.ServiceRegistry serviceRegistry)
      Specified by:
      configure in interface org.hibernate.id.Configurable
      Specified by:
      configure in interface org.hibernate.id.IdentifierGenerator
      Overrides:
      configure in class org.hibernate.id.enhanced.SequenceStyleGenerator
    • generate

      public Serializable generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object obj) throws org.hibernate.HibernateException
      Specified by:
      generate in interface org.hibernate.id.IdentifierGenerator
      Overrides:
      generate in class org.hibernate.id.enhanced.SequenceStyleGenerator
      Throws:
      org.hibernate.HibernateException
    • generate

      public Collection<Serializable> generate(org.hibernate.engine.spi.SharedSessionContractImplementor session, Object fakeHibernateObject, int count)
      Generate a collection of ids.
      Specified by:
      generate in interface BulkIdGenerator
      Parameters:
      session - session
      fakeHibernateObject - an example of the hibernate object. The object itself is not used. It is only needed to understand the types of ids to generate (ints, longs, string, etc.)
      count - number of ids to generate
      Returns:
      collection of ids
    • getMaxLo

      public int getMaxLo()
      Get the max_lo value, so that we can calculate a valid value for the next_hi DB value, given the ids already allocated in the database.
    • reset

      public void reset()
      Set the lo value to more than maxLo to force a reset of the hi value.