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() ); Child newChild = parent.addChild( "new" ); 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 = 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 );
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 testUpdateParentNoneToOneChild() Method name: void testUpdateParentOneToTwoChildren()
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 = createParentWithNoChildren( "parent" );
2
		ParentWithCollection parent = createParentWithOneChild( "parent"
3
		listeners.clear();
3
, "child" );
4
		assertEquals( 0, parent.getChildren().size() );
4
		assertEquals( 1, parent.getChildren().size() );
5
		
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
		Child newChild = parent.addChild( "new" );
9
		Child newChild = parent.addChild( "new2" );
10
		tx.commit();
10
		tx.commit();
11
		s.close();
11
		s.close();
12
		int index = 0;
12
		int index = 0;
13
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
13
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
14
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
14
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
15
		}
15
		}
16
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
16
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
17
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
17
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
18
		if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
18
		if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
19
			checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
19
			checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
20
			checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
20
			checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
21
		}
21
		}
22
		checkNumberOfResults( listeners, index );
22
		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.5
Clones locationClones are declared in the same class
Number of node comparisons148
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements19
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)133.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    2
    ParentWithCollection parent = createParentWithOneChild("parent", "child");
    Differences
    Expression1Expression2Difference
    createParentWithNoChildrencreateParentWithOneChildMETHOD_INVOCATION_NAME_MISMATCH
    createParentWithNoChildren("parent")createParentWithOneChild("parent","child")ARGUMENT_NUMBER_MISMATCH
    2
    ParentWithCollection parent = createParentWithOneChild("parent", "child");
    3
    listeners.clear();
    4
    listeners.clear();
    4
    assertEquals(0, parent.getChildren().size());
    4
    assertEquals(0, parent.getChildren().size());
    3
    assertEquals(1, parent.getChildren().size());
    Differences
    Expression1Expression2Difference
    01LITERAL_VALUE_MISMATCH
    3
    assertEquals(1, parent.getChildren().size());
    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
    Child newChild = parent.addChild("new");
    8
    Child newChild = parent.addChild("new");
    8
    Child newChild = parent.addChild("new2");
    Differences
    Expression1Expression2Difference
    "new""new2"LITERAL_VALUE_MISMATCH
    8
    Child newChild = parent.addChild("new2");
    9
    tx.commit();
    9
    tx.commit();
    10
    s.close();
    10
    s.close();
    11
    int index = 0;
    11
    int index = 0;
    12
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    12
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    13
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    13
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    14
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    14
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    15
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    15
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    16
    if (newChild instanceof ChildWithBidirectionalManyToMany)
    16
    if (newChild instanceof ChildWithBidirectionalManyToMany)
    17
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    17
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    18
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    18
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    19
    checkNumberOfResults(listeners, index);
    19
    checkNumberOfResults(listeners, index);
    Precondition Violations (0)
    Row Violation