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 );
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 );
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 testMoveAllChildrenToDifferentParent() Method name: void testMoveChildToDifferentParent()
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
		otherParent.addAllChildren( parent.getChildren() );
13
		
14
		p
14
parent.removeChild( child );
15
arent.clearChildren();
15
		otherParent.addChild( child );
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 ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
22
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
23
			checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
23
			checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
24
		}
24
		}
25
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
25
		if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
26
			checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
26
			checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
27
		}
27
		}
28
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
28
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
29
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
29
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
30
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
30
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
31
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
31
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
32
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
32
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
33
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
33
			checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
34
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
34
			checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
35
		}
35
		}
36
		checkNumberOfResults( listeners, index );
36
		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.1
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)15.2
    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());
    12
    otherParent.addAllChildren(parent.getChildren());
    30
    checkNumberOfResults(listeners, index);
    Differences
    Expression1Expression2Difference
    addAllChildrencheckNumberOfResultsMETHOD_INVOCATION_NAME_MISMATCH
    otherParent.addAllChildren(parent.getChildren())checkNumberOfResults(listeners,index)ARGUMENT_NUMBER_MISMATCH
    otherParentMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression otherParent.addAllChildren(parent.getChildren()) 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.addAllChildren(parent.getChildren()) 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.addAllChildren(parent.getChildren()) 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.addAllChildren(parent.getChildren()) 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);
    13
    parent.clearChildren();
    13
    parent.clearChildren();
    12
    parent.removeChild(child);
    Differences
    Expression1Expression2Difference
    clearChildrenremoveChildMETHOD_INVOCATION_NAME_MISMATCH
    parent.clearChildren()parent.removeChild(child)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent.removeChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    Expression parent.removeChild(child) is a void method call, and thus it cannot be parameterized
    Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent.removeChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    Expression parent.removeChild(child) is a void method call, and thus it cannot be parameterized
    12
    parent.removeChild(child);
    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 (((PersistentCollection)otherParent.getChildren()).wasInitialized())
    21
    if (((PersistentCollection)otherParent.getChildren()).wasInitialized())
    20
    checkResult(listeners, listeners.getInitializeCollectionListener(), otherParent, index++);
    22
    checkResult(listeners, listeners.getInitializeCollectionListener(), otherParent, index++);
    21
    if (child instanceof ChildWithBidirectionalManyToMany)
    19
    if (child instanceof ChildWithBidirectionalManyToMany)
    22
    checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany)child, index++);
    20
    checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany)child, 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);
    13
    otherParent.addChild(child);
    Differences
    Expression1Expression2Difference
    checkNumberOfResultsaddChildMETHOD_INVOCATION_NAME_MISMATCH
    checkNumberOfResults(listeners,index)otherParent.addChild(child)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.addChild(child) 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.addChild(child) 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.addChild(child) 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.addChild(child) is a void method call, and thus it cannot be parameterized
    13
    otherParent.addChild(child);
    Precondition Violations (24)
    Row Violation
    1Expression otherParent.addAllChildren(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression otherParent.addAllChildren(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    4Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    5Expression otherParent.addAllChildren(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression checkNumberOfResults(listeners,index) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression otherParent.addAllChildren(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    8Expression checkNumberOfResults(listeners,index) is a void method call, and thus it cannot be parameterized
    9Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression parent.removeChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    12Expression parent.removeChild(child) is a void method call, and thus it cannot be parameterized
    13Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression parent.removeChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized
    16Expression parent.removeChild(child) 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.addChild(child) 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.addChild(child) 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.addChild(child) 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.addChild(child) is a void method call, and thus it cannot be parameterized