CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); Child child = ( Child ) parent.getChildren().iterator().next(); listeners.clear(); assertEquals( 1, parent.getChildren().size() ); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); if ( child instanceof Entity ) { child = ( Child ) s.get( child.getClass(), ( ( Entity ) child).getId() ); } Collection oldCollection = parent.getChildren(); parent.newChildren( createCollection() ); parent.addChild( child ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } if ( child instanceof ChildWithBidirectionalManyToMany ) { ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); } } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); if ( child instanceof ChildWithBidirectionalManyToMany ) { // hmmm, the same parent was removed and re-added to the child's collection; // should this be considered an update? checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); checkNumberOfResults( listeners, index );
CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" ); Child child = ( Child ) parent.getChildren().iterator().next(); listeners.clear(); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() ); if ( child instanceof Entity ) { child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() ); } otherParent.addAllChildren( parent.getChildren() ); parent.clearChildren(); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ ); } if ( child instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ ); if ( child instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } checkNumberOfResults( listeners, index );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
Method name: void testUpdateParentOneChildDiffCollectionSameChild() Method name: void testMoveAllChildrenToDifferentParent()
Number of AST nodes: 30 Number of AST nodes: 30
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
2
		ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
2
		ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
3
		
3
		ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" );
4
Child child = ( Child ) parent.getChildren().iterator().next();
4
		Child child = ( Child ) parent.getChildren().iterator().next();
5
		listeners.clear();
5
		listeners.clear();
6
		assertEquals( 1, parent.getChildren().size() );
6
		
7
		Session s = openSession();
7
Session s = openSession();
8
		Transaction tx = s.beginTransaction();
8
		Transaction tx = s.beginTransaction();
9
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
9
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
10
		
10
		otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
11
if ( child instanceof Entity ) {
11
		if ( child instanceof Entity ) {
12
			child = ( Child ) s.get( child.getClass(), ( ( Entity ) child).getId() );
12
			child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
13
		}
13
		}
14
		Collection oldCollection = parent.getChildren();
14
		otherParent.addAllChildren(
15
		parent.newChildren( createCollection() );
15
 parent.getChildren() );
16
		parent.addChild( child );
16
		parent.clearChildren();
17
		tx.commit();
17
		tx.commit();
18
		s.close();
18
		s.close();
19
		int index = 0;
19
		int index = 0;
20
		if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
20
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
21
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
21
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
22
		}
22
		}
23
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
23
		if ( 
24
			ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child
24
( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
25
;
25
			checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
26
		
26
		}
27
	if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
27
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
28
				checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
28
			checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
29
			}
29
		
30
		}
30
}
31
		checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
31
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
32
		checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
32
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, 
33
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
34
			// hmmm, the same parent was removed and re-added to the child's collection;
35
			// should this be cons
33
index++ );
34
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
35
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
36
idered an update?
36
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
37
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
37
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
38
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
38
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
39
		}
39
		}
40
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
40
		
41
		checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
42
		checkNumberOfResults( listeners, index );
41
checkNumberOfResults( listeners, index );
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.6
Clones locationClones are declared in the same class
Number of node comparisons17
  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 fragment9
    Time elapsed for statement mapping (ms)6.4
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                                                                                    
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    Preondition Violations
    Unmatched statement CollectionListeners listeners=new CollectionListeners(getSessions()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    20
    ChildWithBidirectionalManyToMany childWithManyToMany = (ChildWithBidirectionalManyToMany)child;
    20
    ChildWithBidirectionalManyToMany childWithManyToMany = (ChildWithBidirectionalManyToMany)child;
    2
    ParentWithCollection parent = createParentWithOneChild("parent", "child");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToManyorg.hibernate.test.event.collection.ParentWithCollectionSUBCLASS_TYPE_MISMATCH
    childWithManyToManyparentVARIABLE_NAME_MISMATCH
    org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToManyorg.hibernate.test.event.collection.ParentWithCollectionSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToManyorg.hibernate.test.event.collection.ParentWithCollectionSUBCLASS_TYPE_MISMATCH
    (ChildWithBidirectionalManyToMany)childcreateParentWithOneChild("parent","child")TYPE_COMPATIBLE_REPLACEMENT
    2
    ParentWithCollection parent = createParentWithOneChild("parent", "child");
                                                                                                                                                                                      
    3
    ParentWithCollection otherParent = createParentWithOneChild("otherParent", "otherChild");
                                                                                                                              
    4
    Child child = (Child)parent.getChildren().iterator().next();
    Preondition Violations
    Unmatched statement Child child=(Child)parent.getChildren().iterator().next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4
    Child child = (Child)parent.getChildren().iterator().next();
                                              
    5
    listeners.clear();
                                                          
    6
    Session s = openSession();
    Preondition Violations
    Unmatched statement Session s=openSession(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6
    Session s = openSession();
                                                                                  
    7
    Transaction tx = s.beginTransaction();
                                                                                                                                                    
    8
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    Preondition Violations
    Unmatched statement parent=(ParentWithCollection)s.get(parent.getClass(),parent.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
                                                                                                                                                                                  
    9
    otherParent = (ParentWithCollection)s.get(otherParent.getClass(), otherParent.getId());
    21
    if (((PersistentCollection)childWithManyToMany.getParents()).wasInitialized())
    21
    if (((PersistentCollection)childWithManyToMany.getParents()).wasInitialized())
    10
    if (child instanceof Entity)
    Differences
    Expression1Expression2Difference
    ((PersistentCollection)childWithManyToMany.getParents()).wasInitialized()child instanceof EntityTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression ((PersistentCollection)childWithManyToMany.getParents()).wasInitialized() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression child instanceof Entity cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10
    if (child instanceof Entity)
                                                                                                                                      
    11
    child = (Child)s.get(child.getClass(), ((Entity)child).getId());
    Preondition Violations
    Unmatched statement child=(Child)s.get(child.getClass(),((Entity)child).getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement child=(Child)s.get(child.getClass(),((Entity)child).getId()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    11
    child = (Child)s.get(child.getClass(), ((Entity)child).getId());
    22
    checkResult(listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++);
    22
    checkResult(listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++);
    Preondition Violations
    Unmatched statement checkResult(listeners,listeners.getInitializeCollectionListener(),childWithManyToMany,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                          
    Precondition Violations (10)
    Row Violation
    1Unmatched statement CollectionListeners listeners=new CollectionListeners(getSessions()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement Child child=(Child)parent.getChildren().iterator().next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement Session s=openSession(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement parent=(ParentWithCollection)s.get(parent.getClass(),parent.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Expression ((PersistentCollection)childWithManyToMany.getParents()).wasInitialized() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression child instanceof Entity cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Unmatched statement child=(Child)s.get(child.getClass(),((Entity)child).getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Unmatched statement child=(Child)s.get(child.getClass(),((Entity)child).getId()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    9Unmatched statement checkResult(listeners,listeners.getInitializeCollectionListener(),childWithManyToMany,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Clone fragment #1 returns variable childWithManyToMany with type org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany , while Clone fragment #2 returns variable parent with type org.hibernate.test.event.collection.ParentWithCollection