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 | checkNumberOfResults( listeners, index );
|