CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithOneChild( "parent", "child" ); assertEquals( 1, parent.getChildren().size() ); listeners.clear(); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); Child newChild = parent.addChild( "new2" ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); if ( newChild instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkNumberOfResults( listeners, index );
CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithNoChildren( "parent" ); listeners.clear(); assertEquals( 0, parent.getChildren().size() ); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); Collection oldCollection = parent.getChildren(); parent.newChildren( null ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); // pre- and post- collection recreate events should be created when updating an entity with a "null" collection checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, 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/BrokenCollectionEventTest.java
Method name: void testUpdateParentOneToTwoChildren() Method name: void testUpdateParentNoChildrenToNullFailureExpected()
Number of AST nodes: 19 Number of AST nodes: 19
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
2
		ParentWithCollection parent = createParentWithOneChild( "parent", "child" 
2
		ParentWithCollection parent = createParentWithNoChildren( "parent" );
3
);
3
		listeners.clear();
4
		assertEquals( 1, parent.getChildren().size() );
4
		assertEquals( 0, parent.getChildren().size() );
5
		listeners.clear();
5
		
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
		Child newChild = 
9
		Collection oldCollection = parent.getChildren();
10
parent.addChild( "new2" );
10
		parent.newChildren( null );
11
		tx.commit();
11
		tx.commit();
12
		s.close();
12
		s.close();
13
		int index = 0;
13
		int index = 0;
14
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
14
		if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
15
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
15
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
16
		}
16
		}
17
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
17
		checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
18
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
18
		checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, 
19
		if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
20
	
19
oldCollection, index++ );
20
		// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
21
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
21
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
22
			checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
22
		checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
23
		}
23
		
24
		checkNumberOfResults( listeners, index );
24
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)0.3
Clones locationClones are in different classes having the same super class
Number of node comparisons172
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements15
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment4
    Time elapsed for statement mapping (ms)165.9
    Clone typeType 3
    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");
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    Differences
    Expression1Expression2Difference
    createParentWithOneChildcreateParentWithNoChildrenMETHOD_INVOCATION_NAME_MISMATCH
    createParentWithOneChild("parent","child")createParentWithNoChildren("parent")ARGUMENT_NUMBER_MISMATCH
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    3
    assertEquals(1, parent.getChildren().size());
    3
    assertEquals(1, parent.getChildren().size());
    4
    assertEquals(0, parent.getChildren().size());
    Differences
    Expression1Expression2Difference
    10LITERAL_VALUE_MISMATCH
    4
    assertEquals(0, parent.getChildren().size());
    4
    listeners.clear();
    3
    listeners.clear();
    5
    Session s = openSession();
    5
    Session s = openSession();
    6
    Transaction tx = s.beginTransaction();
    6
    Transaction tx = s.beginTransaction();
    7
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    7
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
                                                                                                      
    8
    Collection oldCollection = parent.getChildren();
    Preondition Violations
    Unmatched statement Collection oldCollection=parent.getChildren(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    Collection oldCollection = parent.getChildren();
    8
    Child newChild = parent.addChild("new2");
    8
    Child newChild = parent.addChild("new2");
    Preondition Violations
    Unmatched statement Child newChild=parent.addChild("new2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                        
                                                            
    9
    parent.newChildren(null);
    Preondition Violations
    Unmatched statement parent.newChildren(null); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    parent.newChildren(null);
    9
    tx.commit();
    10
    tx.commit();
    10
    s.close();
    11
    s.close();
    11
    int index = 0;
    12
    int index = 0;
    12
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    12
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    13
    if (((PersistentCollection)oldCollection).wasInitialized())
    Differences
    Expression1Expression2Difference
    parent.getChildren()oldCollectionTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression parent.getChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression oldCollection cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    if (((PersistentCollection)oldCollection).wasInitialized())
    13
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    13
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    14
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++);
    Differences
    Expression1Expression2Difference
    checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++)checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) is a void method call, and thus it cannot be parameterized
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) is a void method call, and thus it cannot be parameterized
    14
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++);
                                                                                                                                                                                                          
    15
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++);
    Preondition Violations
    Unmatched statement checkResult(listeners,listeners.getPreCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++);
                                                                                                                                                                                                            
    16
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++);
    Preondition Violations
    Unmatched statement checkResult(listeners,listeners.getPostCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++);
    14
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    14
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    17
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    Differences
    Expression1Expression2Difference
    getPreCollectionUpdateListenergetPreCollectionRecreateListenerMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression listeners.getPreCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression listeners.getPreCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    15
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    15
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    18
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    Differences
    Expression1Expression2Difference
    getPostCollectionUpdateListenergetPostCollectionRecreateListenerMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression listeners.getPostCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression listeners.getPostCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    19
    checkNumberOfResults(listeners, index);
    19
    checkNumberOfResults(listeners, index);
    Precondition Violations (16)
    Row Violation
    1Unmatched statement Collection oldCollection=parent.getChildren(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement Child newChild=parent.addChild("new2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement parent.newChildren(null); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Expression parent.getChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression oldCollection cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) is a void method call, and thus it cannot be parameterized
    9Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) is a void method call, and thus it cannot be parameterized
    10Unmatched statement checkResult(listeners,listeners.getPreCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement checkResult(listeners,listeners.getPostCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Expression listeners.getPreCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression listeners.getPreCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression listeners.getPostCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression listeners.getPostCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Clone fragment #1 returns variables parent, listeners, index , while Clone fragment #2 returns variables parent, listeners, index