Session s = openSession(); s.beginTransaction(); Set parents = new HashSet(); for (int i=0; i<5; i++) { Parent p = new Parent( String.valueOf( i ) ); Child child = new Child( "child" + i ); child.setParent( p ); p.getChildren().add( child ); s.save( p ); parents.add(p); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); int i = 0; for ( Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) { i++; if (i % 2 == 0) { s.flush(); s.clear(); } Parent p = (Parent) it.next(); assertEquals( 1, p.getChildren().size() ); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); for (Iterator it=parents.iterator(); it.hasNext(); ) { s.delete(it.next()); } s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); Set parents = new HashSet(); for (int i=0; i<5; i++) { Parent p = new Parent( String.valueOf( i + 100 ) ); Child child = new Child( "child" + i ); child.setParent( p ); p.getChildren().add( child ); s.save( p ); parents.add(p); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); Parent p = null; for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) { if ( p != null) { s.evict(p); } p = (Parent) it.next(); assertEquals( 1, p.getChildren().size() ); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); for (Iterator it=parents.iterator(); it.hasNext(); ) { s.delete(it.next()); } s.getTransaction().commit(); s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java
Method name: void testIterateWithClearTopOfLoop() Method name: void testIterateWithEvictTopOfLoop()
Number of AST nodes: 30 Number of AST nodes: 28
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		Set parents = new HashSet();
3
		Set parents = new HashSet();
4
		for (int i=0; i<5; i++) {
4
		for (int i=0; i<5; i++) {
5
			Parent p = new Parent( String.valueOf( i ) );
5
			Parent p = new Parent( String.valueOf( i + 100 ) );
6
			Child child = new Child( "child" + i );
6
			Child child = new Child( "child" + i );
7
			child.setParent( p );
7
			child.setParent( p );
8
			p.getChildren().add( child );
8
			p.getChildren().add( child );
9
			s.save( p );
9
			s.save( p );
10
			parents.add(p);
10
			parents.add(p);
11
		}
11
		}
12
		s.getTransaction().commit();
12
		s.getTransaction().commit();
13
		s.close();
13
		s.close();
14
		s = openSession();
14
		s = openSession();
15
		s.beginTransaction();
15
		s.beginTransaction();
16
		int i = 0;
16
		Parent p = null;
17
		for ( Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
17
		for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
18
			i++;
18
			i
19
			if (i % 2 == 0) {
20
				s.flush();
21
				s.clear();
22
			}
23
			Parent 
19
f ( p != null) { s.evict(p); }
24
p = (Parent) it.next();
20
			p = (Parent) it.next();
25
			assertEquals( 1, p.getChildren().size() );
21
			assertEquals( 1, p.getChildren().size() );
26
		}
22
		}
27
		s.getTransaction().commit();
23
		s.getTransaction().commit();
28
		s.close();
24
		s.close();
29
		s = openSession();
25
		s = openSession();
30
		s.beginTransaction();
26
		s.beginTransaction();
31
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
27
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
32
			s.delete(it.next());
28
			s.delete(it.next());
33
		}
29
		}
34
		s.getTransaction().commit();
30
		s.getTransaction().commit();
35
		s.close();
31
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.2
Clones locationClones are declared in the same class
Number of node comparisons94
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements22
    Number of unmapped statements in the first code fragment8
    Number of unmapped statements in the second code fragment6
    Time elapsed for statement mapping (ms)26.9
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    3
    Set parents = new HashSet();
    3
    Set parents = new HashSet();
    4
    for (int i = 0; i < 5; i++)
    4
    for (int i = 0; i < 5; i++)
    5
    Parent p = new Parent(String.valueOf(i));
    5
    Parent p = new Parent(String.valueOf(i));
    5
    Parent p = new Parent(String.valueOf(i + 100));
    Differences
    Expression1Expression2Difference
    ii + 100TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression i cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression i + 100 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5
    Parent p = new Parent(String.valueOf(i + 100));
    6
    Child child = new Child("child" + i);
    6
    Child child = new Child("child" + i);
    7
    child.setParent(p);
    7
    child.setParent(p);
    8
    p.getChildren().add(child);
    8
    p.getChildren().add(child);
    9
    s.save(p);
    9
    s.save(p);
    10
    parents.add(p);
    10
    parents.add(p);
    11
    s.getTransaction().commit();
    11
    s.getTransaction().commit();
    12
    s.close();
    12
    s.close();
    13
    s = openSession();
    13
    s = openSession();
    14
    s.beginTransaction();
    14
    s.beginTransaction();
                                        
    15
    Parent p = null;
    15
    int i = 0;
                            
                                                                                                                                                      
    16
    for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); )
    Preondition Violations
    Unmatched statement for(Iterator it=s.createQuery("from Parent").iterate(); it.hasNext()) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); )
                                      
    17
    if (p != null)
                                  
    18
    s.evict(p);
    Preondition Violations
    Unmatched statement s.evict(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18
    s.evict(p);
                                                    
    19
    p = (Parent)it.next();
                                                                                          
    20
    assertEquals(1, p.getChildren().size());
    16
    for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); )
    16
    for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); )
    Preondition Violations
    Unmatched statement for(Iterator it=s.createQuery("from Parent").iterate(); it.hasNext()) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                      
    17
    i++;
                    
    18
    if (i % 2 == 0)
                                        
    19
    s.flush();
    19
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
    20
    s.clear();
    20
    s.clear();
    Preondition Violations
    Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
    21
    Parent p = (Parent)it.next();
                                                                  
    22
    assertEquals(1, p.getChildren().size());
                                                                                          
    23
    s.getTransaction().commit();
    21
    s.getTransaction().commit();
    24
    s.close();
    22
    s.close();
    25
    s = openSession();
    23
    s = openSession();
    26
    s.beginTransaction();
    24
    s.beginTransaction();
    27
    for (Iterator it = parents.iterator(); it.hasNext(); )
    25
    for (Iterator it = parents.iterator(); it.hasNext(); )
    28
    s.delete(it.next());
    26
    s.delete(it.next());
    29
    s.getTransaction().commit();
    27
    s.getTransaction().commit();
    30
    s.close();
    28
    s.close();
    Precondition Violations (7)
    Row Violation
    1Expression i cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression i + 100 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement for(Iterator it=s.createQuery("from Parent").iterate(); it.hasNext()) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement s.evict(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement for(Iterator it=s.createQuery("from Parent").iterate(); it.hasNext()) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted