TableHiLoGeneratorpublic class TableHiLoGenerator extends TableGenerator hilo
An IdentifierGenerator that returns a Long, constructed using
a hi/lo algorithm. The hi value MUST be fetched in a seperate 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 |
Fields Summary |
---|
public static final String | MAX_LOThe max_lo parameter | private long | hi | private int | lo | private int | maxLo | private Class | returnClass | private static final Log | log |
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, Short.MAX_VALUE);
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);
log.debug("new hi value: " + hival);
}
return IdentifierGeneratorFactory.createNumber( hi + lo++, returnClass );
|
|