if ( !collection.wasInitialized() && ce.getLoadedPersister() == collectionPersister ) { if ( checkForEnd && i == end ) { return keys; //the first key found after the given key } //if ( end == -1 && count > batchSize*10 ) return keys; //try out ten batches, max final boolean isEqual = collectionPersister.getKeyType().isEqual( id, ce.getLoadedKey(), entityMode, collectionPersister.getFactory() ); if ( isEqual ) { end = i; //checkForEnd = false; } else if ( !isCached( ce.getLoadedKey(), collectionPersister, entityMode ) ) { keys[i++] = ce.getLoadedKey(); //count++; } if ( i == batchSize ) { i = 1; //end of array, start filling again from start if ( end != -1 ) { checkForEnd = true; } } }
EntityKey key = (EntityKey) iter.next(); if ( key.getEntityName().equals( persister.getEntityName() ) ) { //TODO: this needn't exclude subclasses... if ( checkForEnd && i == end ) { //the first id found after the given id return ids; } if ( persister.getIdentifierType().isEqual( id, key.getIdentifier(), entityMode ) ) { end = i; } else { if ( !isCached( key, persister, entityMode ) ) { ids[i++] = key.getIdentifier(); } } if ( i == batchSize ) { i = 1; //end of array, start filling again from start if (end!=-1) checkForEnd = true; } }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/engine/BatchFetchQueue.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/engine/BatchFetchQueue.java
Method name: Serializable[] getCollectionBatch(CollectionPersister, Serializable, int, EntityMode) Method name: Serializable[] getEntityBatch(EntityPersister, Serializable, int, EntityMode)
Number of AST nodes: 12 Number of AST nodes: 12
1
if ( !collection.wasInitialized() && ce.getLoadedPersister() == collectionPersister ) {
1
EntityKey key = (EntityKey) iter.next();
2
			if ( key.getEntityName().equals( persister.getEntityName() ) ) { //TODO: this needn't exclude subclasses...
2
				if ( checkForEnd && i == end ) {
3
				if ( checkForEnd && i == end ) {
3
					return keys; //the first key found after the given key
4
					//the first id found after the given id
4
				}
5
				
5
				//if ( end == -1 && count > batchSize*10 ) return keys; //try out ten batches, max
6
				final boolean isEqual = collectionP
6
	return ids;
7
				}
7
ersister.getKeyType().isEqual(
8
				if ( persister.getIdentifierType().isEqual(
8
						id,
9
						ce.getLoadedKey(),
10
						entityMode,
11
						collectionPersister.getFactory()
12
				);
13
				if ( isEqual ) {
14
					end = i;
15
					//checkForEnd = false
9
 id, key.getIdentifier(), entityMode ) ) {
16
;
10
					end = i;
17
				}
11
				}
18
				else 
12
				else {
19
if ( !isCached( ce.getLoadedKey(), collectionPersister, entityMode ) ) {
13
					if ( !isCached( key, persister, entityMode ) ) {
20
					keys[i++] = ce.getLoadedKey();
14
						ids[i++] = key.get
21
					//count++;
15
Identifier();
16
					}
22
				}
17
				}
23
				if ( i == batchSize ) {
18
				if ( i == batchSize ) {
24
					i = 1; //end of array, start filling again from start
19
					i = 1; //end of array, start filling again from start
25
					if ( end != -1 ) {
20
					if (end!=-1) 
26
						checkForEnd = true;
21
checkForEnd = true;
27
					}
22
				
28
				}
23
}
29
			}
24
			}
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.7
Clones locationClones are declared in the same class
Number of node comparisons22
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)21.5
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    12
    if (checkForEnd && i == end)
    10
    if (checkForEnd && i == end)
    13
    return keys;
    13
    return keys;
    11
    return ids;
    Differences
    Expression1Expression2Difference
    keysidsVARIABLE_NAME_MISMATCH
    11
    return ids;
    14
    final boolean isEqual = collectionPersister.getKeyType().isEqual(id, ce.getLoadedKey(), entityMode, collectionPersister.getFactory());
    14
    final boolean isEqual = collectionPersister.getKeyType().isEqual(id, ce.getLoadedKey(), entityMode, collectionPersister.getFactory());
    Preondition Violations
    Unmatched statement final boolean isEqual=collectionPersister.getKeyType().isEqual(id,ce.getLoadedKey(),entityMode,collectionPersister.getFactory()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                                                              
    15
    if (isEqual)
    15
    if (isEqual)
    12
    if (persister.getIdentifierType().isEqual(id, key.getIdentifier(), entityMode))
    Differences
    Expression1Expression2Difference
    isEqualpersister.getIdentifierType().isEqual(id,key.getIdentifier(),entityMode)TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression isEqual cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12
    if (persister.getIdentifierType().isEqual(id, key.getIdentifier(), entityMode))
    16
    end = i;
    13
    end = i;
                                                                                          
    14
    if (!isCached(key, persister, entityMode))
    Preondition Violations
    Unmatched statement if(!isCached(key,persister,entityMode)) cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    14
    if (!isCached(key, persister, entityMode))
                                                                      
    15
    ids[i++] = key.getIdentifier();
    Preondition Violations
    Unmatched statement ids[i++]=key.getIdentifier(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    ids[i++] = key.getIdentifier();
    17
    else if (!isCached(ce.getLoadedKey(), collectionPersister, entityMode))
                                                                                                                                          
    18
    keys[i++] = ce.getLoadedKey();
    18
    keys[i++] = ce.getLoadedKey();
    Preondition Violations
    Unmatched statement keys[i++]=ce.getLoadedKey(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                    
    19
    if (i == batchSize)
    16
    if (i == batchSize)
    20
    i = 1;
    17
    i = 1;
    21
    if (end != -1)
    18
    if (end != -1)
    22
    checkForEnd = true;
    19
    checkForEnd = true;
    Precondition Violations (7)
    Row Violation
    1Unmatched statement final boolean isEqual=collectionPersister.getKeyType().isEqual(id,ce.getLoadedKey(),entityMode,collectionPersister.getFactory()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression isEqual cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement if(!isCached(key,persister,entityMode)) cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement ids[i++]=key.getIdentifier(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement keys[i++]=ce.getLoadedKey(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Clone fragment #1 returns variables i, end, checkForEnd , while Clone fragment #2 returns variables i, end, checkForEnd
    7Not all possible execution flows end in a return statement