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 subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.5
Clones locationClones are declared in the same class
Number of node comparisons5