void addQuerySpaces(Serializable[] spaces) { for ( int i = 0; i < spaces.length; i++ ) { querySpaces.add( spaces[i] ); } if ( superQuery != null ) superQuery.addQuerySpaces( spaces ); }
private void renderSQL() throws QueryException, MappingException { final int rtsize; if ( returnedTypes.size() == 0 && scalarTypes.size() == 0 ) { //ie no select clause in HQL returnedTypes = fromTypes; rtsize = returnedTypes.size(); } else { rtsize = returnedTypes.size(); Iterator iter = entitiesToFetch.iterator(); while ( iter.hasNext() ) { returnedTypes.add( iter.next() ); } } int size = returnedTypes.size(); persisters = new Queryable[size]; names = new String[size]; owners = new int[size]; ownerAssociationTypes = new EntityType[size]; suffixes = new String[size]; includeInSelect = new boolean[size]; for ( int i = 0; i < size; i++ ) { String name = ( String ) returnedTypes.get( i ); //if ( !isName(name) ) throw new QueryException("unknown type: " + name); persisters[i] = getEntityPersisterForName( name ); // TODO: cannot use generateSuffixes() - it handles the initial suffix differently. suffixes[i] = ( size == 1 ) ? "" : Integer.toString( i ) + '_'; names[i] = name; includeInSelect[i] = !entitiesToFetch.contains( name ); if ( includeInSelect[i] ) selectLength++; if ( name.equals( collectionOwnerName ) ) collectionOwnerColumn = i; String oneToOneOwner = ( String ) oneToOneOwnerNames.get( name ); owners[i] = ( oneToOneOwner == null ) ? -1 : returnedTypes.indexOf( oneToOneOwner ); ownerAssociationTypes[i] = (EntityType) uniqueKeyOwnerReferences.get( name ); } if ( ArrayHelper.isAllNegative( owners ) ) owners = null; String scalarSelect = renderScalarSelect(); //Must be done here because of side-effect! yuck... int scalarSize = scalarTypes.size(); hasScalars = scalarTypes.size() != rtsize; returnTypes = new Type[scalarSize]; for ( int i = 0; i < scalarSize; i++ ) { returnTypes[i] = ( Type ) scalarTypes.get( i ); } QuerySelect sql = new QuerySelect( getFactory().getDialect() ); sql.setDistinct( distinct ); if ( !shallowQuery ) { renderIdentifierSelect( sql ); renderPropertiesSelect( sql ); } if ( collectionPersister != null ) { sql.addSelectFragmentString( collectionPersister.selectFragment( fetchName, "__" ) ); } if ( hasScalars || shallowQuery ) sql.addSelectFragmentString( scalarSelect ); //TODO: for some dialects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings mergeJoins( sql.getJoinFragment() ); sql.setWhereTokens( whereTokens.iterator() ); sql.setGroupByTokens( groupByTokens.iterator() ); sql.setHavingTokens( havingTokens.iterator() ); sql.setOrderByTokens( orderByTokens.iterator() ); if ( collectionPersister != null && collectionPersister.hasOrdering() ) { sql.addOrderBy( collectionPersister.getSQLOrderByString( fetchName ) ); } scalarColumnNames = NameGenerator.generateColumnNames( returnTypes, getFactory() ); // initialize the Set of queried identifier spaces (ie. tables) Iterator iter = collections.values().iterator(); while ( iter.hasNext() ) { CollectionPersister p = getCollectionPersister( ( String ) iter.next() ); addQuerySpaces( p.getCollectionSpaces() ); } iter = typeMap.keySet().iterator(); while ( iter.hasNext() ) { Queryable p = getEntityPersisterForName( ( String ) iter.next() ); addQuerySpaces( p.getQuerySpaces() ); } sqlString = sql.toQueryString(); if ( holderClass != null ) holderConstructor = ReflectHelper.getConstructor( holderClass, returnTypes ); if ( hasScalars ) { actualReturnTypes = returnTypes; } else { actualReturnTypes = new Type[selectLength]; int j = 0; for ( int i = 0; i < persisters.length; i++ ) { if ( includeInSelect[i] ) { actualReturnTypes[j++] = TypeFactory.manyToOne( persisters[i].getEntityName(), shallowQuery ); } } } }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java
Method name: void addQuerySpaces(Serializable[]) Method name: void renderSQL()
Number of AST nodes: 2 Number of AST nodes: 2
1
void addQuerySpaces(Serializable[] spaces) {
1
private void renderSQL() throws QueryException, MappingException {
2
		for ( int i = 0; i < spaces.length; i++ ) {
2
3
			querySpaces.add( spaces[i] );
3
		final int rtsize;
4
		}
4
		if ( returnedTypes.size() == 0 && scalarTypes.size() == 0 ) {
5
		if ( superQuery != null ) superQuery.addQuerySpaces( spaces );
5
			//ie no select clause in HQL
6
	}
6
			returnedTypes = fromTypes;
7
			rtsize = returnedTypes.size();
8
		}
9
		else {
10
			rtsize = returnedTypes.size();
11
			Iterator iter = entitiesToFetch.iterator();
12
			while ( iter.hasNext() ) {
13
				returnedTypes.add( iter.next() );
14
			}
15
		}
16
		int size = returnedTypes.size();
17
		persisters = new Queryable[size];
18
		names = new String[size];
19
		owners = new int[size];
20
		ownerAssociationTypes = new EntityType[size];
21
		suffixes = new String[size];
22
		includeInSelect = new boolean[size];
23
		for ( int i = 0; i < size; i++ ) {
24
			String name = ( String ) returnedTypes.get( i );
25
			//if ( !isName(name) ) throw new QueryException("unknown type: " + name);
26
			persisters[i] = getEntityPersisterForName( name );
27
			// TODO: cannot use generateSuffixes() - it handles the initial suffix differently.
28
			suffixes[i] = ( size == 1 ) ? "" : Integer.toString( i ) + '_';
29
			names[i] = name;
30
			includeInSelect[i] = !entitiesToFetch.contains( name );
31
			if ( includeInSelect[i] ) selectLength++;
32
			if ( name.equals( collectionOwnerName ) ) collectionOwnerColumn = i;
33
			String oneToOneOwner = ( String ) oneToOneOwnerNames.get( name );
34
			owners[i] = ( oneToOneOwner == null ) ? -1 : returnedTypes.indexOf( oneToOneOwner );
35
			ownerAssociationTypes[i] = (EntityType) uniqueKeyOwnerReferences.get( name );
36
		}
37
38
		if ( ArrayHelper.isAllNegative( owners ) ) owners = null;
39
40
		String scalarSelect = renderScalarSelect(); //Must be done here because of side-effect! yuck...
41
42
		int scalarSize = scalarTypes.size();
43
		hasScalars = scalarTypes.size() != rtsize;
44
45
		returnTypes = new Type[scalarSize];
46
		for ( int i = 0; i < scalarSize; i++ ) {
47
			returnTypes[i] = ( Type ) scalarTypes.get( i );
48
		}
49
50
		QuerySelect sql = new QuerySelect( getFactory().getDialect() );
51
		sql.setDistinct( distinct );
52
53
		if ( !shallowQuery ) {
54
			renderIdentifierSelect( sql );
55
			renderPropertiesSelect( sql );
56
		}
57
58
		if ( collectionPersister != null ) {
59
			sql.addSelectFragmentString( collectionPersister.selectFragment( fetchName, "__" ) );
60
		}
61
62
		if ( hasScalars || shallowQuery ) sql.addSelectFragmentString( scalarSelect );
63
64
		//TODO: for some dialects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings
65
		mergeJoins( sql.getJoinFragment() );
66
67
		sql.setWhereTokens( whereTokens.iterator() );
68
69
		sql.setGroupByTokens( groupByTokens.iterator() );
70
		sql.setHavingTokens( havingTokens.iterator() );
71
		sql.setOrderByTokens( orderByTokens.iterator() );
72
73
		if ( collectionPersister != null && collectionPersister.hasOrdering() ) {
74
			sql.addOrderBy( collectionPersister.getSQLOrderByString( fetchName ) );
75
		}
76
77
		scalarColumnNames = NameGenerator.generateColumnNames( returnTypes, getFactory() );
78
79
		// initialize the Set of queried identifier spaces (ie. tables)
80
		Iterator iter = collections.values().iterator();
81
		while ( iter.hasNext() ) {
82
			CollectionPersister p = getCollectionPersister( ( String ) iter.next() );
83
			addQuerySpaces( p.getCollectionSpaces() );
84
		}
85
		iter = typeMap.keySet().iterator();
86
		while ( iter.hasNext() ) {
87
			Queryable p = getEntityPersisterForName( ( String ) iter.next() );
88
			addQuerySpaces( p.getQuerySpaces() );
89
		}
90
91
		sqlString = sql.toQueryString();
92
93
		if ( holderClass != null ) holderConstructor = ReflectHelper.getConstructor( holderClass, returnTypes );
94
95
		if ( hasScalars ) {
96
			actualReturnTypes = returnTypes;
97
		}
98
		else {
99
			actualReturnTypes = new Type[selectLength];
100
			int j = 0;
101
			for ( int i = 0; i < persisters.length; i++ ) {
102
				if ( includeInSelect[i] ) {
103
					actualReturnTypes[j++] = TypeFactory.manyToOne( persisters[i].getEntityName(), shallowQuery );
104
				}
105
			}
106
		}
107
108
	}
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.500
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    for (int i = 0; i < spaces.length; i++)
    1
    for (int i = 0; i < spaces.length; i++)
    7
    while (iter.hasNext())
    Differences
    Expression1Expression2Difference
    i < spaces.lengthiter.hasNext()TYPE_COMPATIBLE_REPLACEMENT
    java.io.Serializable[]java.util.SetVARIABLE_TYPE_MISMATCH
    java.io.Serializable[]java.util.SetVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.io.Serializable[] of variable spaces does not match with type java.util.Set of variable entitiesToFetch
    • Make classes java.io.Serializable[] and java.util.Set extend a common superclass
    Type java.io.Serializable[] of variable spaces does not match with type java.util.Set of variable entitiesToFetch
    • Make classes java.io.Serializable[] and java.util.Set extend a common superclass
    7
    while (iter.hasNext())
    2
    querySpaces.add(spaces[i]);
    2
    querySpaces.add(spaces[i]);
    Preondition Violations
    Unmatched statement querySpaces.add(spaces[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                
                                                                        
    8
    returnedTypes.add(iter.next());
    Precondition Violations (4)
    Row Violation
    1Type java.io.Serializable[] of variable spaces does not match with type java.util.Set of variable entitiesToFetch
    2Type java.io.Serializable[] of variable spaces does not match with type java.util.Set of variable entitiesToFetch
    3Unmatched statement querySpaces.add(spaces[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Clone fragment #1 returns variables i , while Clone fragment #2 returns variables