HHH-2616 : add new collection events to hibernate-configuration-3.0.dtd; added accessor for affected owner ID to AbstractCollectionEvent

git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_2@14302 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Gail Badner 2008-01-31 01:13:44 +00:00
parent 3813841cff
commit bc6708fcf6
11 changed files with 203 additions and 165 deletions

View File

@ -1,6 +1,8 @@
//$Id: $
package org.hibernate.event;
import java.io.Serializable;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
@ -13,11 +15,14 @@ public abstract class AbstractCollectionEvent extends AbstractEvent {
private final PersistentCollection collection;
private final Object affectedOwner;
private final Serializable affectedOwnerId;
public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
super(source);
this.collection = collection;
this.affectedOwner = affectedOwner;
this.affectedOwnerId =
( ( SessionImplementor ) source ).getPersistenceContext().getEntry( affectedOwner ).getId();
}
protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) {
@ -31,4 +36,8 @@ public abstract class AbstractCollectionEvent extends AbstractEvent {
public Object getAffectedOwner() {
return affectedOwner;
}
public Serializable getAffectedOwnerId() {
return affectedOwnerId;
}
}

View File

@ -34,10 +34,10 @@ in JNDI.
<!ATTLIST collection-cache usage (read-only|read-write|nonstrict-read-write|transactional) #REQUIRED>
<!ELEMENT event (listener*)>
<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|post-load|post-update|post-insert|post-delete|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED>
<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED>
<!ELEMENT listener EMPTY>
<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|post-load|post-update|post-insert|post-delete|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED>
<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED>
<!ATTLIST listener class CDATA #REQUIRED>
<!ELEMENT session-factory (property*, mapping*, (class-cache|collection-cache)*, event*, listener*)>

View File

@ -94,9 +94,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
Child child = ( Child ) parent.getChildren().iterator().next();
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -119,9 +119,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
if ( newChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -143,9 +143,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
if ( newChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -167,9 +167,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
if ( newChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -183,8 +183,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( child instanceof ChildEntity ) {
child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.addChild( child );
tx.commit();
@ -193,16 +193,20 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
ChildWithBidirectionalManyToMany childWithManyToMany = null;
if ( child instanceof ChildWithBidirectionalManyToMany ) {
childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
}
}
if ( !( parent.getChildren() instanceof PersistentSet ) ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
}
if ( child.hasBidirectionalManyToMany() && !( getParents( child ) instanceof PersistentSet ) ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
if ( childWithManyToMany != null && !( childWithManyToMany.getParents() instanceof PersistentSet ) ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), childWithManyToMany, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), childWithManyToMany, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -226,9 +230,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++ );
if ( newChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@ -254,9 +258,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
if ( newChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@ -272,8 +276,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( child instanceof ChildEntity ) {
child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child).getId() );
}
Collection oldCollection = parent.getChildren();
parent.newChildren( createCollection() );
@ -284,16 +288,19 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
}
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
if ( child.hasBidirectionalManyToMany() ) {
if ( child instanceof ChildWithBidirectionalManyToMany ) {
// hmmm, the same parent was removed and re-added to the child's collection;
// should this be considered an update?
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@ -309,8 +316,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( oldChild instanceof ChildEntity ) {
oldChild = ( ChildEntity ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild).getId() );
if ( oldChild instanceof Entity ) {
oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild).getId() );
}
Collection oldCollection = parent.getChildren();
parent.newChildren( createCollection() );
@ -321,16 +328,19 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
}
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
if ( oldChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@ -346,8 +356,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( child instanceof ChildEntity ) {
child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
tx.commit();
@ -356,14 +366,17 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
if ( ( ( PersistentCollection ) childWithManyToMany.getParents( ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
}
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -377,8 +390,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( child instanceof ChildEntity ) {
child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.clearChildren();
tx.commit();
@ -387,14 +400,17 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
}
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -415,8 +431,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
s = openSession();
tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( oldChild instanceof ChildEntity ) {
oldChild = ( Child ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild ).getId() );
if ( oldChild instanceof Entity ) {
oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild ).getId() );
}
parent.removeChild( oldChild );
tx.commit();
@ -425,14 +441,17 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
}
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
if ( oldChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -479,11 +498,11 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
if ( child instanceof ChildEntity ) {
child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
if ( child instanceof ChildEntity ) {
if ( child instanceof Entity ) {
s.delete( child );
}
s.delete( parent );
@ -491,14 +510,14 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
s.close();
int index = 0;
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionRemoveListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -513,8 +532,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
if ( child instanceof ChildEntity ) {
child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
otherParent.addChild( child );
@ -524,8 +543,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
@ -534,9 +553,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -551,8 +570,8 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
if ( child instanceof ChildEntity ) {
child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
if ( child instanceof Entity ) {
child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
otherParent.addAllChildren( parent.getChildren() );
parent.clearChildren();
@ -565,16 +584,16 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
}
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@ -598,24 +617,24 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ );
otherChildOrig = ( Child ) otherCollectionOrig.iterator().next();
if ( otherChildOrig.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ );
if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
}
}
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherParent.getChildren(), index++ );
Child otherChild = ( Child ) otherParent.getChildren().iterator().next();
if ( otherChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherChild, index++ );
if ( otherChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
if ( otherChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChild, index++ );
if ( otherChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, index++ );
@ -649,24 +668,24 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ );
otherChildOrig = ( Child ) otherCollectionOrig.iterator().next();
if ( otherChildOrig.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ );
if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
}
}
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherOtherParent.getChildren(), index++ );
Child otherOtherChild = ( Child ) otherOtherParent.getChildren().iterator().next();
if ( otherOtherChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherOtherChild, index++ );
if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
if ( otherOtherChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ );
if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
@ -677,9 +696,9 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
if ( otherOtherChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ );
if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherOtherParent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherOtherParent, index++ );
@ -721,11 +740,6 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
return parent;
}
protected Collection getParents( Child child ) {
return ( ( child instanceof ChildWithBidirectionalManyToMany )
? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
: null );
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
ParentWithCollection parent,
@ -734,14 +748,14 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
Child child,
ChildWithBidirectionalManyToMany child,
int index) {
checkResult( listeners, listenerExpected, child, getParents( child ), index );
checkResult( listeners, listenerExpected, child, child.getParents(), index );
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
Object ownerExpected,
Entity ownerExpected,
Collection collExpected,
int index) {
assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
@ -749,6 +763,10 @@ public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
ownerExpected,
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
);
assertSame(
ownerExpected.getId(),
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
);
assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);

View File

@ -112,7 +112,7 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
/*
public void testUpdateDetachedParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
Child oldChild = ( Child ) parent.getChildren().iterator().next();
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
@ -126,9 +126,9 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
int index = 0;
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
if ( oldChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@ -186,7 +186,7 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
/*
public void testUpdateParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
Child oldChild = ( Child ) parent.getChildren().iterator().next();
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
@ -204,14 +204,18 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
ChildWithBidirectionalManyToMany oldChildWithManyToMany = null;
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
}
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
if ( oldChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
if ( oldChildWithManyToMany != null ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@ -221,7 +225,7 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
public void testUpdateMergedParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
Session s = openSession();
@ -233,14 +237,18 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
s.close();
int index = 0;
Child oldChild = ( Child ) oldCollection.iterator().next();
if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
ChildWithBidirectionalManyToMany oldChildWithManyToMany = null;
if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
}
checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
if ( oldChild.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
if ( oldChildWithManyToMany != null ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@ -282,27 +290,22 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
return parent;
}
private Collection getParents( Child child ) {
return ( ( child instanceof ChildWithBidirectionalManyToMany )
? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
: null );
}
private void checkResult(CollectionListeners listeners,
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
ParentWithCollection parent,
int index) {
checkResult( listeners, listenerExpected, parent, parent.getChildren(), index );
}
private void checkResult(CollectionListeners listeners,
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
Child child,
ChildWithBidirectionalManyToMany child,
int index) {
checkResult( listeners, listenerExpected, child, getParents( child ), index );
checkResult( listeners, listenerExpected, child, child.getParents(), index );
}
private void checkResult(CollectionListeners listeners,
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
Object ownerExpected,
Entity ownerExpected,
Collection collExpected,
int index) {
assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
@ -310,6 +313,10 @@ public class BrokenCollectionEventTest extends FunctionalTestCase {
ownerExpected,
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
);
assertSame(
ownerExpected.getId(),
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
);
assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);

View File

@ -27,8 +27,6 @@ package org.hibernate.test.event.collection;
*/
public interface Child {
boolean hasBidirectionalManyToMany();
String getName();
void setName(String name);

View File

@ -25,10 +25,9 @@ package org.hibernate.test.event.collection;
*
* @author Gail Badner
*/
public class ChildEntity extends ChildValue {
public class ChildEntity extends ChildValue implements Entity {
private Long id;
public ChildEntity() {
super();
}

View File

@ -35,10 +35,6 @@ public class ChildValue implements Child {
this.name = name;
}
public boolean hasBidirectionalManyToMany() {
return false;
}
public String getName() {
return name;
}

View File

@ -0,0 +1,14 @@
package org.hibernate.test.event.collection;
/**
* Created by IntelliJ IDEA.
* User: gbadner
* Date: Jan 30, 2008
* Time: 2:39:37 PM
* To change this template use File | Settings | File Templates.
*/
public interface Entity {
Long getId();
void setId(Long id);
}

View File

@ -27,7 +27,7 @@ import java.util.Collection;
*
* @author Gail Badner
*/
public interface ParentWithCollection {
public interface ParentWithCollection extends Entity {
void newChildren(Collection collection);
Child createChild(String name);

View File

@ -21,12 +21,13 @@
*/
package org.hibernate.test.event.collection.association;
import org.hibernate.test.event.collection.AbstractCollectionEventTest;
import org.hibernate.test.event.collection.CollectionListeners;
import org.hibernate.test.event.collection.ChildEntity;
import org.hibernate.test.event.collection.ParentWithCollection;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.event.collection.AbstractCollectionEventTest;
import org.hibernate.test.event.collection.ChildEntity;
import org.hibernate.test.event.collection.CollectionListeners;
import org.hibernate.test.event.collection.ParentWithCollection;
import org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany;
/**
*
@ -52,14 +53,14 @@ public abstract class AbstractAssociationCollectionEventTest extends AbstractCol
s.close();
int index = 0;
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
if ( child.hasBidirectionalManyToMany() ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
if ( child instanceof ChildWithBidirectionalManyToMany ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}

View File

@ -40,10 +40,6 @@ public class ChildWithBidirectionalManyToMany extends ChildEntity {
this.parents = parents;
}
public boolean hasBidirectionalManyToMany() {
return true;
}
public Collection getParents() {
return parents;
}