org.hibernate.id
public class: TableHiLoGenerator [javadoc |
source]
java.lang.Object
org.hibernate.engine.TransactionHelper
org.hibernate.id.TableGenerator
org.hibernate.id.TableHiLoGenerator
All Implemented Interfaces:
Configurable, PersistentIdentifierGenerator
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
| Field Summary |
|---|
| public static final String | MAX_LO | The max_lo parameter |
| Method from org.hibernate.id.TableHiLoGenerator Detail: |
public void configure(Type type,
Properties params,
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 Serializable generate(SessionImplementor session,
Object obj) throws HibernateException {
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 );
}
|