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() ); } parent.removeChild( child ); otherParent.addChild( child ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } if ( child instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ ); } if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, 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 );
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 testMoveChildToDifferentParent() 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
		ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" );
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
		Session s = openSession();
6
		Session s = openSession();
7
		Transaction tx = s.beginTransaction();
7
		Transaction tx = s.beginTransaction();
8
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
8
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
9
		otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
9
		otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
10
		if ( child instanceof Entity ) {
10
		if ( child instanceof Entity ) {
11
			child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
11
			child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
12
		}
12
		}
13
		parent.removeChild( child );
13
		
14
		otherP
14
otherParent.addAllChildren( parent.getChildren() );
15
arent.addChild( child );
15
		parent.clearChildren();
16
		tx.commit();
16
		tx.commit();
17
		s.close();
17
		s.close();
18
		int index = 0;
18
		int index = 0;
19
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
19
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
20
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
20
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
21
		}
21
		}
22
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
22
		if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
23
			checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
23
			checkResult( listeners, listeners.getInitializeCollectionListener(), 
24
		}
25
		if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized()
24
otherParent, index++ );
25
		}
26
 ) {
26
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
27
			checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
27
			checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
28
		}
28
		}
29
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
29
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
30
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
30
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
31
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
31
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
32
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
32
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
33
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
33
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
34
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
34
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
35
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
35
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
36
		}
36
		}
37
		checkNumberOfResults( listeners, index );
37
		checkNumberOfResults( listeners, index );
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)1.5
Clones locationClones are declared in the same class
Number of node comparisons346
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements29
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)48.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    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
    ParentWithCollection otherParent = createParentWithOneChild("otherParent", "otherChild");
    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
    Session s = openSession();
    6
    Session s = openSession();
    7
    Transaction tx = s.beginTransaction();
    7
    Transaction tx = s.beginTransaction();
    8
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    8
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    9
    otherParent = (ParentWithCollection)s.get(otherParent.getClass(), otherParent.getId());
    9
    otherParent = (ParentWithCollection)s.get(otherParent.getClass(), otherParent.getId());
    10
    if (child instanceof Entity)
    10
    if (child instanceof Entity)
    11
    child = (Child)s.get(child.getClass(), ((Entity)child).getId());
    11
    child = (Child)s.get(child.getClass(), ((Entity)child).getId());
                                                                                                              
    12
    otherParent.addAllChildren(parent.getChildren());
    Preondition Violations
    Unmatched statement otherParent.addAllChildren(parent.getChildren()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    otherParent.addAllChildren(parent.getChildren());
    12
    parent.removeChild(child);
    12
    parent.removeChild(child);
    Preondition Violations
    Unmatched statement parent.removeChild(child); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                
    13
    otherParent.addChild(child);
    13
    otherParent.addChild(child);
    13
    parent.clearChildren();
    Differences
    Expression1Expression2Difference
    addChildclearChildrenMETHOD_INVOCATION_NAME_MISMATCH
    otherParentparentVARIABLE_NAME_MISMATCH
    otherParent.addChild(child)parent.clearChildren()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized
    Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    Expression otherParent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized
    Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    13
    parent.clearChildren();
    14
    tx.commit();
    14
    tx.commit();
    15
    s.close();
    15
    s.close();
    16
    int index = 0;
    16
    int index = 0;
    17
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    17
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    18
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    18
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    19
    if (child instanceof ChildWithBidirectionalManyToMany)
    21
    if (child instanceof ChildWithBidirectionalManyToMany)
    20
    checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany)child, index++);
    22
    checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany)child, index++);
    21
    if (((PersistentCollection)otherParent.getChildren()).wasInitialized())
    19
    if (((PersistentCollection)otherParent.getChildren()).wasInitialized())
    22
    checkResult(listeners, listeners.getInitializeCollectionListener(), otherParent, index++);
    20
    checkResult(listeners, listeners.getInitializeCollectionListener(), otherParent, index++);
    23
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    23
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    24
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    24
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    25
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++);
    25
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++);
    26
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++);
    26
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++);
    27
    if (child instanceof ChildWithBidirectionalManyToMany)
    27
    if (child instanceof ChildWithBidirectionalManyToMany)
    28
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    28
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    29
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    29
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    30
    checkNumberOfResults(listeners, index);
    30
    checkNumberOfResults(listeners, index);
    Precondition Violations (12)
    Row Violation
    1Unmatched statement otherParent.addAllChildren(parent.getChildren()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement parent.removeChild(child); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized
    6Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    7Expression otherParent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized
    12Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized