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 testMoveChildToDifferentParent()
|
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 | 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 | parent.removeChild( child );↵ | 13 | ↵ | |
14 | otherP↵ | 14 | otherParent.addAllChildren( parent.getChildren() );↵ | |
15 | arent.addChild( child );↵ | 15 | parent.clearChildren();↵ | |
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 ( child instanceof ChildWithBidirectionalManyToMany ) {↵ | 22 | if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {↵ | |
23 | checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );↵ | 23 | checkResult( listeners, listeners.getInitializeCollectionListener(), ↵ | |
24 | }↵ | |||
25 | if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized()↵ | 24 | otherParent, index++ );↵ | |
25 | }↵ | |||
26 | ) {↵ | 26 | if ( child instanceof ChildWithBidirectionalManyToMany ) {↵ | |
27 | checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );↵ | 27 | checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );↵ | |
28 | }↵ | 28 | }↵ | |
29 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );↵ | 29 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );↵ | |
30 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );↵ | 30 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );↵ | |
31 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );↵ | 31 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );↵ | |
32 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );↵ | 32 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );↵ | |
33 | if ( child instanceof ChildWithBidirectionalManyToMany ) {↵ | 33 | if ( child instanceof ChildWithBidirectionalManyToMany ) {↵ | |
34 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );↵ | 34 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );↵ | |
35 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );↵ | 35 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );↵ | |
36 | }↵ | 36 | }↵ | |
37 | checkNumberOfResults( listeners, index ); | 37 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 1 |
Number of non-refactorable cases | 0 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 1.5 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 346 |
Number of mapped statements | 29 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 48.4 |
Clone type | Type 2 |
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 | parent.removeChild(child); |
| | |||||||||||||||||||||||||||
13 | otherParent.addChild(child); |
| 13 | parent.clearChildren(); | ||||||||||||||||||||||||||
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 (child instanceof ChildWithBidirectionalManyToMany) | 21 | if (child instanceof ChildWithBidirectionalManyToMany) | |||||||||||||||||||||||||||
20 | checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany)child, index++); | 22 | checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany)child, index++); | |||||||||||||||||||||||||||
21 | if (((PersistentCollection)otherParent.getChildren()).wasInitialized()) | 19 | if (((PersistentCollection)otherParent.getChildren()).wasInitialized()) | |||||||||||||||||||||||||||
22 | checkResult(listeners, listeners.getInitializeCollectionListener(), otherParent, index++); | 20 | checkResult(listeners, listeners.getInitializeCollectionListener(), otherParent, 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); |
Row | Violation |
---|---|
1 | Unmatched statement otherParent.addAllChildren(parent.getChildren()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement parent.removeChild(child); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized |
6 | Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized |
7 | Expression otherParent cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Expression otherParent.addChild(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | Expression parent.clearChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
11 | Expression otherParent.addChild(child) is a void method call, and thus it cannot be parameterized |
12 | Expression parent.clearChildren() is a void method call, and thus it cannot be parameterized |