HHH-2616 : added owner ID and name getters to collection events; added partial support for property-refs; added Javadoc
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14363 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
8f458e07e7
commit
5414f6bf99
|
@ -53,7 +53,7 @@ public final class CollectionRecreateAction extends CollectionAction {
|
|||
.getPreCollectionRecreateEventListeners();
|
||||
if (preListeners.length > 0) {
|
||||
PreCollectionRecreateEvent preEvent = new PreCollectionRecreateEvent(
|
||||
getCollection(), ( EventSource ) getSession() );
|
||||
getPersister(), getCollection(), ( EventSource ) getSession() );
|
||||
for ( int i = 0; i < preListeners.length; i++ ) {
|
||||
preListeners[i].onPreRecreateCollection( preEvent );
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public final class CollectionRecreateAction extends CollectionAction {
|
|||
.getPostCollectionRecreateEventListeners();
|
||||
if (postListeners.length > 0) {
|
||||
PostCollectionRecreateEvent postEvent = new PostCollectionRecreateEvent(
|
||||
getCollection(), ( EventSource ) getSession() );
|
||||
getPersister(), getCollection(), ( EventSource ) getSession() );
|
||||
for ( int i = 0; i < postListeners.length; i++ ) {
|
||||
postListeners[i].onPostRecreateCollection( postEvent );
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public final class CollectionRemoveAction extends CollectionAction {
|
|||
// the loaded owner will be set to null after the collection is removed,
|
||||
// so capture its value as the affected owner so it is accessible to
|
||||
// both pre- and post- events
|
||||
this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwner( collection );
|
||||
this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ public final class CollectionRemoveAction extends CollectionAction {
|
|||
final SessionImplementor session)
|
||||
throws CacheException {
|
||||
super( persister, null, id, session );
|
||||
if (affectedOwner == null) { throw new AssertionFailure("affectedOwner == null"); };
|
||||
if (affectedOwner == null) { throw new AssertionFailure("affectedOwner == null"); }
|
||||
this.emptySnapshot = emptySnapshot;
|
||||
this.affectedOwner = affectedOwner;
|
||||
}
|
||||
|
@ -106,9 +106,7 @@ public final class CollectionRemoveAction extends CollectionAction {
|
|||
.getPreCollectionRemoveEventListeners();
|
||||
if (preListeners.length>0) {
|
||||
PreCollectionRemoveEvent preEvent = new PreCollectionRemoveEvent(
|
||||
getCollection(),
|
||||
affectedOwner,
|
||||
( EventSource )getSession() );
|
||||
getPersister(), getCollection(), ( EventSource ) getSession(), affectedOwner );
|
||||
for ( int i = 0; i < preListeners.length; i++ ) {
|
||||
preListeners[i].onPreRemoveCollection(preEvent);
|
||||
}
|
||||
|
@ -120,9 +118,7 @@ public final class CollectionRemoveAction extends CollectionAction {
|
|||
.getPostCollectionRemoveEventListeners();
|
||||
if (postListeners.length>0) {
|
||||
PostCollectionRemoveEvent postEvent = new PostCollectionRemoveEvent(
|
||||
getCollection(),
|
||||
affectedOwner,
|
||||
( EventSource )getSession() );
|
||||
getPersister(), getCollection(), ( EventSource ) getSession(), affectedOwner );
|
||||
for ( int i = 0; i < postListeners.length; i++ ) {
|
||||
postListeners[i].onPostRemoveCollection(postEvent);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public final class CollectionUpdateAction extends CollectionAction {
|
|||
.getPreCollectionUpdateEventListeners();
|
||||
if (preListeners.length > 0) {
|
||||
PreCollectionUpdateEvent preEvent = new PreCollectionUpdateEvent(
|
||||
getCollection(), ( EventSource ) getSession() );
|
||||
getPersister(), getCollection(), ( EventSource ) getSession() );
|
||||
for ( int i = 0; i < preListeners.length; i++ ) {
|
||||
preListeners[i].onPreUpdateCollection( preEvent );
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public final class CollectionUpdateAction extends CollectionAction {
|
|||
.getPostCollectionUpdateEventListeners();
|
||||
if (postListeners.length > 0) {
|
||||
PostCollectionUpdateEvent postEvent = new PostCollectionUpdateEvent(
|
||||
getCollection(), ( EventSource ) getSession() );
|
||||
getPersister(), getCollection(), ( EventSource ) getSession() );
|
||||
for ( int i = 0; i < postListeners.length; i++ ) {
|
||||
postListeners[i].onPostUpdateCollection( postEvent );
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//$Id: PersistenceContext.java 11319 2007-03-20 03:12:56Z steve.ebersole@jboss.com $
|
||||
//$Id: PersistenceContext.java 14312 2008-02-05 23:55:35Z gbadner $
|
||||
package org.hibernate.engine;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -252,8 +252,20 @@ public interface PersistenceContext {
|
|||
|
||||
/**
|
||||
* Get the entity that owned this persistent collection when it was loaded
|
||||
*
|
||||
* @param collection The persistent collection
|
||||
* @return the owner if its entity ID is available from the collection's loaded key
|
||||
* and the owner entity is in the persistence context; otherwise, returns null
|
||||
*/
|
||||
Object getLoadedCollectionOwner(PersistentCollection collection);
|
||||
Object getLoadedCollectionOwnerOrNull(PersistentCollection collection);
|
||||
|
||||
/**
|
||||
* Get the ID for the entity that owned this persistent collection when it was loaded
|
||||
*
|
||||
* @param collection The persistent collection
|
||||
* @return the owner ID if available from the collection's loaded key; otherwise, returns null
|
||||
*/
|
||||
public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection);
|
||||
|
||||
/**
|
||||
* add a collection we just loaded up (still needs initializing)
|
||||
|
|
|
@ -680,13 +680,49 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
/**
|
||||
* Get the entity that owned this persistent collection when it was loaded
|
||||
*
|
||||
* @param collection The persistent collection
|
||||
* @return the owner, if its entity ID is available from the collection's loaded key
|
||||
* and the owner entity is in the persistence context; otherwise, returns null
|
||||
*/
|
||||
public Object getLoadedCollectionOwner(PersistentCollection collection) {
|
||||
CollectionEntry ce = getCollectionEntry(collection);
|
||||
if ( ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) {
|
||||
public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection) {
|
||||
CollectionEntry ce = getCollectionEntry( collection );
|
||||
if ( ce.getLoadedPersister() == null ) {
|
||||
return null; // early exit...
|
||||
}
|
||||
Object loadedOwner = null;
|
||||
// TODO: an alternative is to check if the owner has changed; if it hasn't then
|
||||
// return collection.getOwner()
|
||||
Serializable entityId = getLoadedCollectionOwnerIdOrNull( ce );
|
||||
if ( entityId != null ) {
|
||||
loadedOwner = getCollectionOwner( entityId, ce.getLoadedPersister() );
|
||||
}
|
||||
return loadedOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID for the entity that owned this persistent collection when it was loaded
|
||||
*
|
||||
* @param collection The persistent collection
|
||||
* @return the owner ID if available from the collection's loaded key; otherwise, returns null
|
||||
*/
|
||||
public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection) {
|
||||
return getLoadedCollectionOwnerIdOrNull( getCollectionEntry( collection ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID for the entity that owned this persistent collection when it was loaded
|
||||
*
|
||||
* @param ce The collection entry
|
||||
* @return the owner ID if available from the collection's loaded key; otherwise, returns null
|
||||
*/
|
||||
private Serializable getLoadedCollectionOwnerIdOrNull(CollectionEntry ce) {
|
||||
if ( ce == null || ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) {
|
||||
return null;
|
||||
}
|
||||
return getCollectionOwner(ce.getLoadedKey(), ce.getLoadedPersister());
|
||||
// TODO: an alternative is to check if the owner has changed; if it hasn't then
|
||||
// get the ID from collection.getOwner()
|
||||
return ce.getLoadedPersister().getCollectionType().getIdOfOwnerOrNull( ce.getLoadedKey(), session );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,32 +1,12 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//$Id: $
|
||||
package org.hibernate.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.engine.CollectionEntry;
|
||||
import org.hibernate.engine.EntityEntry;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* Defines a base class for events involving collections.
|
||||
|
@ -37,22 +17,99 @@ public abstract class AbstractCollectionEvent extends AbstractEvent {
|
|||
|
||||
private final PersistentCollection collection;
|
||||
private final Object affectedOwner;
|
||||
private final Serializable affectedOwnerId;
|
||||
private final String affectedOwnerEntityName;
|
||||
|
||||
public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
|
||||
/**
|
||||
* Constructs an AbstractCollectionEvent object.
|
||||
*
|
||||
* @param collection - the collection
|
||||
* @param source - the Session source
|
||||
* @param affectedOwner - the owner that is affected by this event;
|
||||
* can be null if unavailable
|
||||
* @param affectedOwnerId - the ID for the owner that is affected
|
||||
* by this event; can be null if unavailable
|
||||
* that is affected by this event; can be null if unavailable
|
||||
*/
|
||||
public AbstractCollectionEvent( CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source,
|
||||
Object affectedOwner,
|
||||
Serializable affectedOwnerId) {
|
||||
super(source);
|
||||
this.collection = collection;
|
||||
this.affectedOwner = affectedOwner;
|
||||
this.affectedOwnerId = affectedOwnerId;
|
||||
this.affectedOwnerEntityName =
|
||||
getAffectedOwnerEntityName( collectionPersister, affectedOwner, source );
|
||||
}
|
||||
|
||||
protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) {
|
||||
return ( ( SessionImplementor ) source ).getPersistenceContext().getLoadedCollectionOwner( collection );
|
||||
protected static CollectionPersister getLoadedCollectionPersister( PersistentCollection collection, EventSource source ) {
|
||||
CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection );
|
||||
return ( ce == null ? null : ce.getLoadedPersister() );
|
||||
}
|
||||
|
||||
protected static Object getLoadedOwnerOrNull( PersistentCollection collection, EventSource source ) {
|
||||
return source.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection );
|
||||
}
|
||||
|
||||
protected static Serializable getLoadedOwnerIdOrNull( PersistentCollection collection, EventSource source ) {
|
||||
return source.getPersistenceContext().getLoadedCollectionOwnerIdOrNull( collection );
|
||||
}
|
||||
|
||||
protected static Serializable getOwnerIdOrNull( Object owner, EventSource source ) {
|
||||
EntityEntry ownerEntry = source.getPersistenceContext().getEntry( owner );
|
||||
return ( ownerEntry == null ? null : ownerEntry.getId() );
|
||||
}
|
||||
|
||||
protected static String getAffectedOwnerEntityName(CollectionPersister collectionPersister, Object affectedOwner, EventSource source ) {
|
||||
|
||||
// collectionPersister should not be null, but we don't want to throw
|
||||
// an exception if it is null
|
||||
String entityName =
|
||||
( collectionPersister == null ? null : collectionPersister.getOwnerEntityPersister().getEntityName() );
|
||||
if ( affectedOwner != null ) {
|
||||
EntityEntry ee = source.getPersistenceContext().getEntry( affectedOwner );
|
||||
if ( ee != null && ee.getEntityName() != null) {
|
||||
entityName = ee.getEntityName();
|
||||
}
|
||||
}
|
||||
return entityName;
|
||||
}
|
||||
|
||||
public PersistentCollection getCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
public Object getAffectedOwner() {
|
||||
/**
|
||||
* Get the collection owner entity that is affected by this event.
|
||||
*
|
||||
* @return the affected owner; returns null if the entity is not in the persistence context
|
||||
* (e.g., because the collection from a detached entity was moved to a new owner)
|
||||
*/
|
||||
public Object getAffectedOwnerOrNull() {
|
||||
return affectedOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID for the collection owner entity that is affected by this event.
|
||||
*
|
||||
* @return the affected owner ID; returns null if the ID cannot be obtained
|
||||
* from the collection's loaded key (e.g., a property-ref is used for the
|
||||
* collection and does not include the entity's ID)
|
||||
*/
|
||||
public Serializable getAffectedOwnerIdOrNull() {
|
||||
return affectedOwnerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity name for the collection owner entity that is affected by this event.
|
||||
*
|
||||
* @return the entity name; if the owner is not in the PersistenceContext, the
|
||||
* returned value may be a superclass name, instead of the actual class name
|
||||
*/
|
||||
public String getAffectedOwnerEntityName() {
|
||||
return affectedOwnerEntityName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//$Id: InitializeCollectionEvent.java 6929 2005-05-27 03:54:08Z oneovthafew $
|
||||
//$Id: InitializeCollectionEvent.java 14313 2008-02-06 07:46:52Z gbadner $
|
||||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
|
@ -11,7 +11,11 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class InitializeCollectionEvent extends AbstractCollectionEvent {
|
||||
|
||||
public InitializeCollectionEvent(PersistentCollection collection, EventSource source) {
|
||||
super(collection, source, getLoadedOwner( collection, source ) );
|
||||
public InitializeCollectionEvent(PersistentCollection collection, EventSource source ) {
|
||||
super( getLoadedCollectionPersister( collection, source ),
|
||||
collection,
|
||||
source,
|
||||
getLoadedOwnerOrNull( collection, source ),
|
||||
getLoadedOwnerIdOrNull( collection, source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* An event that occurs after a collection is recreated
|
||||
|
@ -10,7 +11,11 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class PostCollectionRecreateEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PostCollectionRecreateEvent(PersistentCollection collection, EventSource source) {
|
||||
super(collection, source, collection.getOwner());
|
||||
public PostCollectionRecreateEvent( CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source ) {
|
||||
super( collectionPersister, collection, source,
|
||||
collection.getOwner(),
|
||||
getOwnerIdOrNull( collection.getOwner(), source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* An event that occurs after a collection is removed
|
||||
|
@ -10,7 +11,12 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class PostCollectionRemoveEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PostCollectionRemoveEvent(PersistentCollection collection, Object loadedOwner, EventSource source) {
|
||||
super(collection, source, loadedOwner);
|
||||
public PostCollectionRemoveEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source,
|
||||
Object loadedOwner ) {
|
||||
super( collectionPersister, collection, source,
|
||||
loadedOwner,
|
||||
getOwnerIdOrNull( loadedOwner, source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* An event that occurs after a collection is updated
|
||||
|
@ -10,7 +11,11 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class PostCollectionUpdateEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PostCollectionUpdateEvent(PersistentCollection collection, EventSource source) {
|
||||
super(collection, source, getLoadedOwner( collection, source ));
|
||||
public PostCollectionUpdateEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super( collectionPersister, collection, source,
|
||||
getLoadedOwnerOrNull( collection, source ),
|
||||
getLoadedOwnerIdOrNull( collection, source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* An event that occurs before a collection is recreated
|
||||
|
@ -10,7 +11,11 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class PreCollectionRecreateEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PreCollectionRecreateEvent(PersistentCollection collection, EventSource source) {
|
||||
super(collection, source, collection.getOwner());
|
||||
public PreCollectionRecreateEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super( collectionPersister, collection, source,
|
||||
collection.getOwner(),
|
||||
getOwnerIdOrNull( collection.getOwner(), source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,8 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//$Id: $
|
||||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* An event that occurs before a collection is removed
|
||||
|
@ -34,7 +11,12 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class PreCollectionRemoveEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PreCollectionRemoveEvent(PersistentCollection collection, Object loadedOwner, EventSource source) {
|
||||
super(collection, source, loadedOwner);
|
||||
public PreCollectionRemoveEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source,
|
||||
Object loadedOwner) {
|
||||
super( collectionPersister, collection, source,
|
||||
loadedOwner,
|
||||
getOwnerIdOrNull( loadedOwner, source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package org.hibernate.event;
|
||||
|
||||
import org.hibernate.collection.PersistentCollection;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* An event that occurs before a collection is updated
|
||||
|
@ -10,7 +11,11 @@ import org.hibernate.collection.PersistentCollection;
|
|||
*/
|
||||
public class PreCollectionUpdateEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PreCollectionUpdateEvent(PersistentCollection collection, EventSource source) {
|
||||
super(collection, source, getLoadedOwner( collection, source ));
|
||||
public PreCollectionUpdateEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super( collectionPersister, collection, source,
|
||||
getLoadedOwnerOrNull( collection, source ),
|
||||
getLoadedOwnerIdOrNull( collection, source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
|||
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -26,6 +27,7 @@ import org.hibernate.engine.SessionFactoryImplementor;
|
|||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.Joinable;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
@ -260,6 +262,13 @@ public abstract class CollectionType extends AbstractType implements Association
|
|||
return getPersister( session ).getOwnerEntityPersister().isVersioned();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our underlying collection persister (using the session to access the
|
||||
* factory).
|
||||
*
|
||||
* @param session The session from which the request is originating.
|
||||
* @return The underlying collection persister
|
||||
*/
|
||||
private CollectionPersister getPersister(SessionImplementor session) {
|
||||
return session.getFactory().getCollectionPersister( role );
|
||||
}
|
||||
|
@ -335,6 +344,7 @@ public abstract class CollectionType extends AbstractType implements Association
|
|||
}
|
||||
|
||||
// NOTE VERY HACKISH WORKAROUND!!
|
||||
// TODO: Fix this so it will work for non-POJO entity mode
|
||||
Type keyType = getPersister( session ).getKeyType();
|
||||
if ( !keyType.getReturnedClass().isInstance( id ) ) {
|
||||
id = (Serializable) keyType.semiResolve(
|
||||
|
@ -348,6 +358,37 @@ public abstract class CollectionType extends AbstractType implements Association
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id value from the owning entity key, usually the same as the key, but might be some
|
||||
* other property, in the case of property-ref
|
||||
*
|
||||
* @param key The collection owner key
|
||||
* @param session The session from which the request is originating.
|
||||
* @return The collection owner's id, if it can be obtained from the key;
|
||||
* otherwise, null is returned
|
||||
*/
|
||||
public Serializable getIdOfOwnerOrNull(Serializable key, SessionImplementor session) {
|
||||
Serializable ownerId = null;
|
||||
if ( foreignKeyPropertyName == null ) {
|
||||
ownerId = key;
|
||||
}
|
||||
else {
|
||||
Type keyType = getPersister( session ).getKeyType();
|
||||
EntityPersister ownerPersister = getPersister( session ).getOwnerEntityPersister();
|
||||
// TODO: Fix this so it will work for non-POJO entity mode
|
||||
Class ownerMappedClass = ownerPersister.getMappedClass( session.getEntityMode() );
|
||||
if ( ownerMappedClass.isAssignableFrom( keyType.getReturnedClass() ) &&
|
||||
keyType.getReturnedClass().isInstance( key ) ) {
|
||||
// the key is the owning entity itself, so get the ID from the key
|
||||
ownerId = ownerPersister.getIdentifier( key, session.getEntityMode() );
|
||||
}
|
||||
else {
|
||||
// TODO: check if key contains the owner ID
|
||||
}
|
||||
}
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public Object hydrate(ResultSet rs, String[] name, SessionImplementor session, Object owner) {
|
||||
// can't just return null here, since that would
|
||||
// cause an owning component to become null
|
||||
|
|
|
@ -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*)>
|
||||
|
|
|
@ -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,20 +748,28 @@ 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 ) );
|
||||
assertSame(
|
||||
ownerExpected,
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerOrNull()
|
||||
);
|
||||
assertEquals(
|
||||
ownerExpected.getId(),
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerIdOrNull()
|
||||
);
|
||||
assertEquals(
|
||||
ownerExpected.getClass().getName(),
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerEntityName()
|
||||
);
|
||||
assertSame(
|
||||
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
|
||||
|
|
|
@ -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,33 +290,36 @@ 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 ) );
|
||||
assertSame(
|
||||
ownerExpected,
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerOrNull()
|
||||
);
|
||||
assertEquals(
|
||||
ownerExpected.getId(),
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerIdOrNull()
|
||||
);
|
||||
assertEquals(
|
||||
ownerExpected.getClass().getName(),
|
||||
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerEntityName()
|
||||
);
|
||||
assertSame(
|
||||
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
|
||||
|
|
|
@ -27,8 +27,6 @@ package org.hibernate.test.event.collection;
|
|||
*/
|
||||
public interface Child {
|
||||
|
||||
boolean hasBidirectionalManyToMany();
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -35,10 +35,6 @@ public class ChildValue implements Child {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean hasBidirectionalManyToMany() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -40,10 +40,6 @@ public class ChildWithBidirectionalManyToMany extends ChildEntity {
|
|||
this.parents = parents;
|
||||
}
|
||||
|
||||
public boolean hasBidirectionalManyToMany() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Collection getParents() {
|
||||
return parents;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
//$Id: $
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution statements
|
||||
* applied by the authors.
|
||||
*
|
||||
* All third-party contributions are distributed under license by Red Hat
|
||||
* Middleware LLC. This copyrighted material is made available to anyone
|
||||
* wishing to use, modify, copy, or redistribute it subject to the terms
|
||||
* and conditions of the GNU Lesser General Public License, as published by
|
||||
* the Free Software Foundation. This program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU Lesser General Public License for more details. You should
|
||||
* have received a copy of the GNU Lesser General Public License along with
|
||||
* this distribution; if not, write to: Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.event.collection.association.bidirectional.onetomany;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
import org.hibernate.test.event.collection.Child;
|
||||
import org.hibernate.test.event.collection.ParentWithCollection;
|
||||
import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
|
||||
import org.hibernate.test.event.collection.association.bidirectional.onetomany.ChildWithManyToOne;
|
||||
import org.hibernate.test.event.collection.association.bidirectional.onetomany.ParentWithBidirectionalOneToMany;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class BidirectionalOneToManyBagSubclassCollectionEventTest extends BidirectionalOneToManyBagCollectionEventTest {
|
||||
|
||||
public BidirectionalOneToManyBagSubclassCollectionEventTest(String string) {
|
||||
super( string );
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new FunctionalTestClassTestSuite( BidirectionalOneToManyBagSubclassCollectionEventTest.class );
|
||||
}
|
||||
|
||||
public String[] getMappings() {
|
||||
return new String[] { "event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagSubclassMapping.hbm.xml" };
|
||||
}
|
||||
|
||||
public ParentWithCollection createParent(String name) {
|
||||
return new ParentWithBidirectionalOneToManySubclass( name );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<!--
|
||||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.event.collection.association.bidirectional.onetomany">
|
||||
|
||||
<class name="ParentWithBidirectionalOneToMany" table="PARENT" discriminator-value="P">
|
||||
<id name="id" column="ID" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
|
||||
<discriminator column="TYPE" type="string" length="1"/>
|
||||
|
||||
<bag name="children"
|
||||
inverse="true"
|
||||
cascade="all">
|
||||
<key column="parent_id"/>
|
||||
<one-to-many class="ChildWithManyToOne"/>
|
||||
</bag>
|
||||
|
||||
<subclass name="ParentWithBidirectionalOneToManySubclass"
|
||||
discriminator-value="S">
|
||||
</subclass>
|
||||
</class>
|
||||
|
||||
<class name="ChildWithManyToOne" table="CHILD">
|
||||
<id name="id" column="ID" type="long">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="name" column="NAME" type="string"/>
|
||||
<many-to-one name="parent" column="parent_id" class="ParentWithBidirectionalOneToMany" cascade="none"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,42 @@
|
|||
//$Id: $
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution statements
|
||||
* applied by the authors.
|
||||
*
|
||||
* All third-party contributions are distributed under license by Red Hat
|
||||
* Middleware LLC. This copyrighted material is made available to anyone
|
||||
* wishing to use, modify, copy, or redistribute it subject to the terms
|
||||
* and conditions of the GNU Lesser General Public License, as published by
|
||||
* the Free Software Foundation. This program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU Lesser General Public License for more details. You should
|
||||
* have received a copy of the GNU Lesser General Public License along with
|
||||
* this distribution; if not, write to: Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.event.collection.association.bidirectional.onetomany;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.hibernate.test.event.collection.Child;
|
||||
import org.hibernate.test.event.collection.AbstractParentWithCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ParentWithBidirectionalOneToManySubclass extends ParentWithBidirectionalOneToMany {
|
||||
public ParentWithBidirectionalOneToManySubclass() {
|
||||
}
|
||||
|
||||
public ParentWithBidirectionalOneToManySubclass(String name) {
|
||||
super( name );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue