SequenceHiLoGeneratorpublic class SequenceHiLoGenerator extends SequenceGenerator seqhilo
An IdentifierGenerator that combines a hi/lo algorithm with an underlying
oracle-style sequence that generates hi values. The user may specify a
maximum lo value to determine how often new hi values are fetched.
If sequences are not available, TableHiLoGenerator might be an
alternative.
Mapping parameters supported: sequence, max_lo, parameters. |
Fields Summary |
---|
public static final String | MAX_LO | private static final Log | log | private int | maxLo | private int | lo | private long | hi | private Class | returnClass |
Methods Summary |
---|
public void | configure(org.hibernate.type.Type type, java.util.Properties params, org.hibernate.dialect.Dialect d)
super.configure(type, params, d);
maxLo = PropertiesHelper.getInt(MAX_LO, params, 9);
lo = maxLo + 1; // so we "clock over" on the first invocation
returnClass = type.getReturnedClass();
| public synchronized java.io.Serializable | generate(org.hibernate.engine.SessionImplementor session, java.lang.Object obj)
if (maxLo < 1) {
//keep the behavior consistent even for boundary usages
long val = ( (Number) super.generate(session, obj) ).longValue();
if (val == 0) val = ( (Number) super.generate(session, obj) ).longValue();
return IdentifierGeneratorFactory.createNumber( val, returnClass );
}
if ( lo>maxLo ) {
long hival = ( (Number) super.generate(session, obj) ).longValue();
lo = (hival == 0) ? 1 : 0;
hi = hival * ( maxLo+1 );
if ( log.isDebugEnabled() )
log.debug("new hi value: " + hival);
}
return IdentifierGeneratorFactory.createNumber( hi + lo++, returnClass );
|
|