com.atlassian.hibernate
Class ResettableTableHiLoGenerator

java.lang.Object
  extended by net.sf.hibernate.id.TableGenerator
      extended by com.atlassian.hibernate.ResettableTableHiLoGenerator
All Implemented Interfaces:
net.sf.hibernate.id.Configurable, net.sf.hibernate.id.IdentifierGenerator, net.sf.hibernate.id.PersistentIdentifierGenerator

public class ResettableTableHiLoGenerator
extends net.sf.hibernate.id.TableGenerator

A variant on Hibernate's HiLoGenerator that allows us to force a reload of the HI value. This is necessary because after an import or restore, the hi value in the generator may overlap with IDs already assigned in the database.

Note: calling reset() does not ensure that the hi value that we get from the database is correct. If you've imported data with pre-set IDs you'll need something like Confluence's HiLoIdRepairUpgradeTask to set the hi value to a sane value before resetting the generator.


Field Summary
static String MAX_LO
          The max_lo parameter
 
Fields inherited from class net.sf.hibernate.id.TableGenerator
COLUMN, TABLE
 
Fields inherited from interface net.sf.hibernate.id.PersistentIdentifierGenerator
PK, SCHEMA
 
Constructor Summary
ResettableTableHiLoGenerator()
           
 
Method Summary
 void configure(net.sf.hibernate.type.Type type, Properties params, net.sf.hibernate.dialect.Dialect d)
           
 Serializable generate(net.sf.hibernate.engine.SessionImplementor session, Object obj)
           
 int getMaxLo()
          Get the max_lo value, so that we can calculate a vaid value for the next_hi DB value, given the ids already allocated in the databse.
 void reset()
          set the lo value to more than maxLo to force a reset of hival
 
Methods inherited from class net.sf.hibernate.id.TableGenerator
generatorKey, sqlCreateStrings, sqlDropString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_LO

public static final String MAX_LO
The max_lo parameter

See Also:
Constant Field Values
Constructor Detail

ResettableTableHiLoGenerator

public ResettableTableHiLoGenerator()
Method Detail

configure

public void configure(net.sf.hibernate.type.Type type,
                      Properties params,
                      net.sf.hibernate.dialect.Dialect d)
Specified by:
configure in interface net.sf.hibernate.id.Configurable
Overrides:
configure in class net.sf.hibernate.id.TableGenerator

getMaxLo

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


generate

public Serializable generate(net.sf.hibernate.engine.SessionImplementor session,
                             Object obj)
                      throws SQLException,
                             net.sf.hibernate.HibernateException
Specified by:
generate in interface net.sf.hibernate.id.IdentifierGenerator
Overrides:
generate in class net.sf.hibernate.id.TableGenerator
Throws:
SQLException
net.sf.hibernate.HibernateException

reset

public void reset()
set the lo value to more than maxLo to force a reset of hival



Copyright © 2003-2012 Atlassian. All Rights Reserved.