public class SequenceHiLoGenerator extends SequenceGenerator { public static final String MAX_LO = "max_lo"; private static final Logger log = LoggerFactory.getLogger(SequenceHiLoGenerator.class); private int maxLo; private int lo; private long hi; private Class returnClass; public void configure(Type type, Properties params, Dialect d) throws MappingException { 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 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 ); if ( log.isDebugEnabled() ) log.debug("new hi value: " + hival); } return IdentifierGeneratorFactory.createNumber( hi + lo++, returnClass )
public class TableHiLoGenerator extends TableGenerator { /** * The max_lo parameter */ public static final String MAX_LO = "max_lo"; private long hi; private int lo; private int maxLo; private Class returnClass; private static final Logger log = LoggerFactory.getLogger(TableHiLoGenerator.class); 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 )
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/id/SequenceHiLoGenerator.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/id/TableHiLoGenerator.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class SequenceHiLoGenerator extends SequenceGenerator {
1
public class TableHiLoGenerator extends TableGenerator {
2
	/**
3
	 * The max_lo parameter
4
	 */
2
	public static final String MAX_LO = "max_lo";
5
	public static final String MAX_LO = "max_lo";
3
	private static final Logger log = LoggerFactory.getLogger(SequenceHiLoGenerator.class);
6
	private 
7
long hi;
4
	private int maxLo;
8
	private int lo;
5
	private int lo;
9
	private int maxLo;
6
	private long hi;
10
	private 
7
	private Class returnC
11
Class returnClass;
8
lass;
12
	private static final Logger log = LoggerFactory.getLogger(TableHiLoGenerator.class);
9
	public void configure(Type type, Properties params, Dialect d) throws MappingException {
13
	public void configure(Type type, Properties params, Dialect d) {
10
		super.configure(type, params, d);
14
		super.configure(type, params, d);
11
		maxLo = PropertiesHelper.getInt(MAX_LO, params, 9);
15
		maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
12
		lo = maxLo + 1; // so we "clock over" on the first invocation
16
		lo = maxLo + 1; // so we "clock over" on the first invocation
13
		returnClass = type.getReturnedClass();
17
		returnClass = type.getReturnedClass();
14
	}
18
	}
15
	public synchronized Serializable generate(SessionImplementor session, Object obj) 
19
	public synchronized Serializable generate(SessionImplementor session, Object obj) 
16
	throws HibernateException {
20
	throws HibernateException {
17
		if (maxLo < 1) {
21
        if (maxLo < 1) {
18
			//keep the behavior consistent even for boundary usages
22
			//keep the behavior consistent even for boundary usages
19
			long val = ( (Number) super.generate(session, obj) ).longValue();
23
			long val = ( (Number) super.generate(session, obj) ).longValue();
20
			if (val == 0) val = ( (Number) super.generate(session, obj) ).longValue();
24
			if (val == 0) val = ( (Number) super.generate(session, obj) ).longValue();
21
			return IdentifierGeneratorFactory.createNumber( val, returnClass );
25
			return IdentifierGeneratorFactory.createNumber( val, returnClass );
22
		}
26
		}
23
		if ( lo>maxLo ) {
27
		if (lo>maxLo) {
24
			long hival = ( (Number) super.generate(session, obj) ).longValue();
28
			long hival = ( (Number) super.generate(session, obj) ).longValue();
25
			lo = (hival == 0) ? 1 : 0;
29
			lo = (hival == 0) ? 1 : 0;
26
			hi = hival * ( maxLo+1 );
30
			hi = hival * (maxLo+1);
27
			if ( log.isDebugEnabled() )
31
			
28
				log.debug("new hi value: " + hival);
32
log.debug("new hi value: " + hival);
29
		}
33
		}
30
		return IdentifierGeneratorFactory.createNumber( hi + lo++, returnClass )
34
		return IdentifierGeneratorFactory.createNumber( hi + lo++, returnClass )
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0