FileDocCategorySizeDatePackage
SequenceHiLoGenerator.javaAPI DocHibernate 3.2.52272Thu Mar 30 18:11:54 BST 2006org.hibernate.id

SequenceHiLoGenerator

public 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.
see
TableHiLoGenerator
author
Gavin King

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
Constructors Summary
Methods Summary
public voidconfigure(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.Serializablegenerate(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 );