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 |
| |
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) | 0.6 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 17 |
Number of mapped statements | 2 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 9 |
Time elapsed for statement mapping (ms) | 6.4 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| 1 | CollectionListeners listeners = new CollectionListeners(getSessions()); | |||||||||||||||||||||||
20 | ChildWithBidirectionalManyToMany childWithManyToMany = (ChildWithBidirectionalManyToMany)child; |
| 2 | ParentWithCollection parent = createParentWithOneChild("parent", "child"); | ||||||||||||||||||||||
| 3 | ParentWithCollection otherParent = createParentWithOneChild("otherParent", "otherChild"); | ||||||||||||||||||||||||
|
| 4 | Child child = (Child)parent.getChildren().iterator().next(); | |||||||||||||||||||||||
| 5 | listeners.clear(); | ||||||||||||||||||||||||
|
| 6 | Session s = openSession(); | |||||||||||||||||||||||
| 7 | Transaction tx = s.beginTransaction(); | ||||||||||||||||||||||||
|
| 8 | parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId()); | |||||||||||||||||||||||
| 9 | otherParent = (ParentWithCollection)s.get(otherParent.getClass(), otherParent.getId()); | ||||||||||||||||||||||||
21 | if (((PersistentCollection)childWithManyToMany.getParents()).wasInitialized()) |
| 10 | if (child instanceof Entity) | ||||||||||||||||||||||
|
| 11 | child = (Child)s.get(child.getClass(), ((Entity)child).getId()); | |||||||||||||||||||||||
22 | checkResult(listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++); |
| |
Row | Violation |
---|---|
1 | Unmatched statement CollectionListeners listeners=new CollectionListeners(getSessions()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
2 | Unmatched statement Child child=(Child)parent.getChildren().iterator().next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement Session s=openSession(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
4 | Unmatched statement parent=(ParentWithCollection)s.get(parent.getClass(),parent.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | Expression ((PersistentCollection)childWithManyToMany.getParents()).wasInitialized() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression child instanceof Entity cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement child=(Child)s.get(child.getClass(),((Entity)child).getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
8 | Unmatched statement child=(Child)s.get(child.getClass(),((Entity)child).getId()); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
9 | Unmatched statement checkResult(listeners,listeners.getInitializeCollectionListener(),childWithManyToMany,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
10 | Clone fragment #1 returns variable childWithManyToMany with type org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany , while Clone fragment #2 returns variable parent with type org.hibernate.test.event.collection.ParentWithCollection |