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