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 cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)1.0
Clones locationClones are declared in the same class
Number of node comparisons346
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements30
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)14.7
    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
    parent.removeChild(child);
    12
    parent.removeChild(child);
    13
    parent.clearChildren();
    Differences
    Expression1Expression2Difference
    removeChildclearChildrenMETHOD_INVOCATION_NAME_MISMATCH
    parent.removeChild(child)parent.clearChildren()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression parent.removeChild(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 parent.removeChild(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 parent.removeChild(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 parent.removeChild(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();
    13
    otherParent.addChild(child);
    13
    otherParent.addChild(child);
    30
    checkNumberOfResults(listeners, index);
    Differences
    Expression1Expression2Difference
    addChildcheckNumberOfResultsMETHOD_INVOCATION_NAME_MISMATCH
    otherParent.addChild(child)checkNumberOfResults(listeners,index)ARGUMENT_NUMBER_MISMATCH
    otherParentMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkNumberOfResults(listeners,index) 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 checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkNumberOfResults(listeners,index) 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 checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    30
    checkNumberOfResults(listeners, index);
    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);
    12
    otherParent.addAllChildren(parent.getChildren());
    Differences
    Expression1Expression2Difference
    checkNumberOfResultsaddAllChildrenMETHOD_INVOCATION_NAME_MISMATCH
    checkNumberOfResults(listeners,index)otherParent.addAllChildren(parent.getChildren())ARGUMENT_NUMBER_MISMATCH
    otherParentMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression otherParent.addAllChildren(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    Expression otherParent.addAllChildren(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression otherParent.addAllChildren(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    Expression otherParent.addAllChildren(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    12
    otherParent.addAllChildren(parent.getChildren());
    Precondition Violations (24)
    Row Violation
    1Expression parent.removeChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression parent.removeChild(child) is a void method call, and thus it cannot be parameterized
    4Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    5Expression parent.removeChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression parent.removeChild(child) is a void method call, and thus it cannot be parameterized
    8Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    9Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression checkNumberOfResults(listeners,index) 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 checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    13Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized
    16Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    17Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression otherParent.addAllChildren(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    20Expression otherParent.addAllChildren(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    21Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression otherParent.addAllChildren(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    24Expression otherParent.addAllChildren(parent.getChildren()) is a void method call, and thus it cannot be parameterized