public void testBatchOrdering() { Session s = openSession(); s.beginTransaction(); int iterations = 12; for ( int i = 0; i < iterations; i++ ) { User user = new User( "user-" + i ); Group group = new Group( "group-" + i ); s.save( user ); s.save( group ); user.addMembership( group ); } StatsBatcher.reset(); s.getTransaction().commit(); s.close(); assertEquals( 6, StatsBatcher.batchSizes.size() ); // 2 batches of each insert statement s = openSession(); s.beginTransaction(); Iterator users = s.createQuery( "from User u left join fetch u.memberships m left join fetch m.group" ).list().iterator(); while ( users.hasNext() ) { s.delete( users.next() ); } s.getTransaction().commit(); s.close(); }
public void testIterateWithEvictBottomOfLoop() { 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(); for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) { Parent p = (Parent) it.next(); assertEquals( 1, p.getChildren().size() ); s.evict(p); } 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/insertordering/InsertOrderingTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java
Method name: void testBatchOrdering() Method name: void testIterateWithEvictBottomOfLoop()
Number of AST nodes: 2 Number of AST nodes: 2
1
public void testBatchOrdering() {
1
public void testIterateWithEvictBottomOfLoop() {
2
		Session s = openSession();
2
		Session s = openSession();
3
		s.beginTransaction();
3
		s.beginTransaction();
4
		int iterations = 12;
4
		Set parents = new HashSet();
5
		for ( int i = 0; i < iterations; i++ ) {
5
		for (int i=0; i<5; i++) {
6
			User user = new User( "user-" + i );
6
			Parent p = new Parent( String.valueOf( i + 100 ) );
7
			Group group = new Group( "group-" + i );
7
			Child child = new Child( "child" + i );
8
			s.save( user );
8
			child.setParent( p );
9
			s.save( group );
9
			p.getChildren().add( child );
10
			user.addMembership( group );
10
			s.save( p );
11
		}
11
			parents.add(p);
12
		StatsBatcher.reset();
12
		}
13
		s.getTransaction().commit();
13
		s.getTransaction().commit();
14
		s.close();
14
		s.close();
15
15
16
		assertEquals( 6, StatsBatcher.batchSizes.size() );  // 2 batches of each insert statement
16
		s = openSession();
17
17
		s.beginTransaction();
18
		s = openSession();
18
		for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
19
		s.beginTransaction();
19
			Parent p = (Parent) it.next();
20
		Iterator users = s.createQuery( "from User u left join fetch u.memberships m left join fetch m.group" ).list().iterator();
20
			assertEquals( 1, p.getChildren().size() );
21
		while ( users.hasNext() ) {
21
			s.evict(p);
22
			s.delete( users.next() );
22
		}
23
		}
23
		s.getTransaction().commit();
24
		s.getTransaction().commit();
24
		s.close();
25
		s.close();
25
26
	}
26
		s = openSession();
27
		s.beginTransaction();
28
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
29
			s.delete(it.next());
30
		}
31
		s.getTransaction().commit();
32
		s.close();
33
	}
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score1.000
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    17
    while (users.hasNext())
    17
    while (users.hasNext())
    23
    for (Iterator it = parents.iterator(); it.hasNext(); )
    Differences
    Expression1Expression2Difference
    usersitVARIABLE_NAME_MISMATCH
    java.util.Listjava.util.SetVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.List of variable s.createQuery("from User u left join fetch u.memberships m left join fetch m.group").list() does not match with type java.util.Set of variable parents
    • Make classes java.util.List and java.util.Set extend a common superclass
    23
    for (Iterator it = parents.iterator(); it.hasNext(); )
    18
    s.delete(users.next());
    18
    s.delete(users.next());
    24
    s.delete(it.next());
    Differences
    Expression1Expression2Difference
    usersitVARIABLE_NAME_MISMATCH
    24
    s.delete(it.next());
    Precondition Violations (1)
    Row Violation
    1Type java.util.List of variable s.createQuery("from User u left join fetch u.memberships m left join fetch m.group").list() does not match with type java.util.Set of variable parents