CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); assertEquals( 1, parent.getChildren().size() ); Child child = ( Child ) parent.getChildren().iterator().next(); listeners.clear(); 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() ); } parent.removeChild( child ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } if ( child instanceof ChildWithBidirectionalManyToMany ) { ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; if ( ( ( PersistentCollection ) childWithManyToMany.getParents( ) ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); } } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, 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" ); assertEquals( 1, parent.getChildren().size() ); Child child = ( Child ) parent.getChildren().iterator().next(); listeners.clear(); 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() ); } parent.clearChildren(); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } if ( child instanceof ChildWithBidirectionalManyToMany ) { ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child; if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ ); } } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, 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 testUpdateParentOneChildToNoneByRemove() Method name: void testUpdateParentOneChildToNoneByClear()
Number of AST nodes: 26 Number of AST nodes: 26
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
		assertEquals( 1, parent.getChildren().size() );
3
		assertEquals( 1, parent.getChildren().size() );
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
		if ( child instanceof Entity ) {
9
		if ( child instanceof Entity ) {
10
			child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
10
			child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
11
		}
11
		}
12
		parent.removeChild( child );
12
		parent.clearChildren();
13
		tx.commit();
13
		tx.commit();
14
		s.close();
14
		s.close();
15
		int index = 0;
15
		int index = 0;
16
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
16
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
17
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
17
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
18
		}
18
		}
19
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
19
		if ( child instanceof ChildWithBidirectionalManyToMany ) {
20
			ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
20
			ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
21
			if ( ( ( PersistentCollection ) childWithManyToMany.getParents( ) ).wasInitialized() ) {
21
			if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
22
				checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
22
				checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
23
			}
23
			}
24
		}
24
		}
25
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
25
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
26
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
26
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, 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
		}
30
		}
31
		checkNumberOfResults( listeners, index );
31
		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)0.7
Clones locationClones are declared in the same class
Number of node comparisons195
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements26
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)32.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
    assertEquals(1, parent.getChildren().size());
    3
    assertEquals(1, parent.getChildren().size());
    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
    if (child instanceof Entity)
    9
    if (child instanceof Entity)
    10
    child = (Child)s.get(child.getClass(), ((Entity)child).getId());
    10
    child = (Child)s.get(child.getClass(), ((Entity)child).getId());
    11
    parent.removeChild(child);
    11
    parent.removeChild(child);
    11
    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
    11
    parent.clearChildren();
    12
    tx.commit();
    12
    tx.commit();
    13
    s.close();
    13
    s.close();
    14
    int index = 0;
    14
    int index = 0;
    15
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    15
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    16
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    16
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    17
    if (child instanceof ChildWithBidirectionalManyToMany)
    17
    if (child instanceof ChildWithBidirectionalManyToMany)
    18
    ChildWithBidirectionalManyToMany childWithManyToMany = (ChildWithBidirectionalManyToMany)child;
    18
    ChildWithBidirectionalManyToMany childWithManyToMany = (ChildWithBidirectionalManyToMany)child;
    19
    if (((PersistentCollection)childWithManyToMany.getParents()).wasInitialized())
    19
    if (((PersistentCollection)childWithManyToMany.getParents()).wasInitialized())
    20
    checkResult(listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++);
    20
    checkResult(listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++);
    21
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    21
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    22
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    22
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    23
    if (child instanceof ChildWithBidirectionalManyToMany)
    23
    if (child instanceof ChildWithBidirectionalManyToMany)
    24
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    24
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    25
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    25
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), (ChildWithBidirectionalManyToMany)child, index++);
    26
    checkNumberOfResults(listeners, index);
    26
    checkNumberOfResults(listeners, index);
    Precondition Violations (8)
    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