Hibernate SVN: r14292 - search/trunk/src/java/org/hibernate/search/backend.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-26 17:24:52 -0500 (Sat, 26 Jan 2008)
New Revision: 14292
Modified:
search/trunk/src/java/org/hibernate/search/backend/Worker.java
Log:
Style
Modified: search/trunk/src/java/org/hibernate/search/backend/Worker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/Worker.java 2008-01-26 22:24:18 UTC (rev 14291)
+++ search/trunk/src/java/org/hibernate/search/backend/Worker.java 2008-01-26 22:24:52 UTC (rev 14292)
@@ -3,9 +3,8 @@
import java.util.Properties;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.event.EventSource;
+import org.hibernate.search.engine.SearchFactoryImplementor;
/**
* Perform work for a given session. This implementation has to be multi threaded
16 years, 3 months
Hibernate SVN: r14291 - in search/trunk/src/java/org/hibernate/search/backend: impl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-26 17:24:18 -0500 (Sat, 26 Jan 2008)
New Revision: 14291
Modified:
search/trunk/src/java/org/hibernate/search/backend/Worker.java
search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
Log:
Style
Modified: search/trunk/src/java/org/hibernate/search/backend/Worker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/Worker.java 2008-01-25 02:34:41 UTC (rev 14290)
+++ search/trunk/src/java/org/hibernate/search/backend/Worker.java 2008-01-26 22:24:18 UTC (rev 14291)
@@ -2,16 +2,18 @@
package org.hibernate.search.backend;
import java.util.Properties;
-import java.io.Serializable;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.event.EventSource;
-import org.hibernate.search.engine.SearchFactoryImplementor;
/**
* Perform work for a given session. This implementation has to be multi threaded
* @author Emmanuel Bernard
*/
public interface Worker {
+ //Use of EventSource since it's the common subinterface for Session and SessionImplementor
+ //the alternative would have been to do a subcasting or to retrieve 2 parameters :(
void performWork(Work work, EventSource session);
void initialize(Properties props, SearchFactoryImplementor searchFactoryImplementor);
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2008-01-25 02:34:41 UTC (rev 14290)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2008-01-26 22:24:18 UTC (rev 14291)
@@ -2,18 +2,15 @@
package org.hibernate.search.backend.impl;
import java.util.Properties;
-import java.io.Serializable;
-import org.hibernate.search.backend.Worker;
+import org.hibernate.Transaction;
+import org.hibernate.event.EventSource;
import org.hibernate.search.backend.QueueingProcessor;
-import org.hibernate.search.backend.WorkType;
-import org.hibernate.search.backend.WorkQueue;
import org.hibernate.search.backend.Work;
-import org.hibernate.search.backend.impl.BatchedQueueingProcessor;
-import org.hibernate.search.util.WeakIdentityHashMap;
+import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.backend.Worker;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.event.EventSource;
-import org.hibernate.Transaction;
+import org.hibernate.search.util.WeakIdentityHashMap;
/**
* Queue works per transaction.
16 years, 3 months
Hibernate SVN: r14290 - in core/branches/Branch_3_2: src/org/hibernate/cfg and 14 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-01-24 21:34:41 -0500 (Thu, 24 Jan 2008)
New Revision: 14290
Added:
core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEventListener.java
core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEventListener.java
core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEventListener.java
core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEventListener.java
core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEventListener.java
core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEventListener.java
core/branches/Branch_3_2/test/org/hibernate/test/event/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractParentWithCollection.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Child.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildEntity.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildValue.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionEventSuite.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionListeners.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ParentWithCollection.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml
Modified:
core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java
core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java
core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java
core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java
core/branches/Branch_3_2/src/org/hibernate/engine/PersistenceContext.java
core/branches/Branch_3_2/src/org/hibernate/engine/StatefulPersistenceContext.java
core/branches/Branch_3_2/src/org/hibernate/event/EventListeners.java
core/branches/Branch_3_2/src/org/hibernate/event/InitializeCollectionEvent.java
core/branches/Branch_3_2/src/org/hibernate/event/def/AbstractFlushingEventListener.java
core/branches/Branch_3_2/src/org/hibernate/event/def/ReattachVisitor.java
core/branches/Branch_3_2/test/org/hibernate/test/AllTests.java
Log:
HHH-2616 : collection recreate/remove/update events and listeners
Modified: core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -2,6 +2,11 @@
package org.hibernate.action;
import org.hibernate.HibernateException;
+import org.hibernate.event.PostCollectionRecreateEventListener;
+import org.hibernate.event.PostCollectionRecreateEvent;
+import org.hibernate.event.EventSource;
+import org.hibernate.event.PreCollectionRecreateEvent;
+import org.hibernate.event.PreCollectionRecreateEventListener;
import org.hibernate.cache.CacheException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
@@ -21,12 +26,16 @@
}
public void execute() throws HibernateException {
- final boolean stats = getSession().getFactory().getStatistics().isStatisticsEnabled();
- long startTime = 0;
- if ( stats ) startTime = System.currentTimeMillis();
+ // this method is called when a new non-null collection is persisted
+ // or when an existing (non-null) collection is moved to a new owner
+ final boolean stats = getSession().getFactory().getStatistics().isStatisticsEnabled();
+ long startTime = 0;
+ if ( stats ) startTime = System.currentTimeMillis();
- final PersistentCollection collection = getCollection();
+ final PersistentCollection collection = getCollection();
+ preRecreate();
+
getPersister().recreate( collection, getKey(), getSession() );
getSession().getPersistenceContext()
@@ -35,12 +44,37 @@
evict();
+ postRecreate();
+
if ( stats ) {
getSession().getFactory().getStatisticsImplementor()
.recreateCollection( getPersister().getRole(), System.currentTimeMillis() - startTime);
}
}
+ private void preRecreate() {
+ PreCollectionRecreateEventListener[] preListeners = getSession().getListeners()
+ .getPreCollectionRecreateEventListeners();
+ if (preListeners.length > 0) {
+ PreCollectionRecreateEvent preEvent = new PreCollectionRecreateEvent(
+ getCollection(), ( EventSource ) getSession() );
+ for ( int i = 0; i < preListeners.length; i++ ) {
+ preListeners[i].onPreRecreateCollection( preEvent );
+ }
+ }
+ }
+
+ private void postRecreate() {
+ PostCollectionRecreateEventListener[] postListeners = getSession().getListeners()
+ .getPostCollectionRecreateEventListeners();
+ if (postListeners.length > 0) {
+ PostCollectionRecreateEvent postEvent = new PostCollectionRecreateEvent(
+ getCollection(), ( EventSource ) getSession() );
+ for ( int i = 0; i < postListeners.length; i++ ) {
+ postListeners[i].onPostRecreateCollection( postEvent );
+ }
+ }
+ }
}
Modified: core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -2,6 +2,12 @@
package org.hibernate.action;
import org.hibernate.HibernateException;
+import org.hibernate.AssertionFailure;
+import org.hibernate.event.PostCollectionRemoveEvent;
+import org.hibernate.event.PreCollectionRemoveEvent;
+import org.hibernate.event.PreCollectionRemoveEventListener;
+import org.hibernate.event.EventSource;
+import org.hibernate.event.PostCollectionRemoveEventListener;
import org.hibernate.cache.CacheException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
@@ -12,25 +18,76 @@
public final class CollectionRemoveAction extends CollectionAction {
private boolean emptySnapshot;
+ private final Object affectedOwner;
+ /**
+ * Removes a persistent collection from its loaded owner.
+ *
+ * Use this constructor when the collection is non-null.
+ *
+ * @param collection The collection to to remove; must be non-null
+ * @param persister The collection's persister
+ * @param id The collection key
+ * @param emptySnapshot Indicates if the snapshot is empty
+ * @param session The session
+ * @throws AssertionFailure if collection is null.
+ */
public CollectionRemoveAction(
final PersistentCollection collection,
final CollectionPersister persister,
- final Serializable id,
- final boolean emptySnapshot,
+ final Serializable id,
+ final boolean emptySnapshot,
final SessionImplementor session)
throws CacheException {
super( persister, collection, id, session );
+ if (collection == null) { throw new AssertionFailure("collection == null"); }
this.emptySnapshot = emptySnapshot;
+ // 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 );
}
+ /**
+ * Removes a persistent collection from a specified owner.
+ *
+ * Use this constructor when the collection to be removed has not been loaded.
+ *
+ * @param affectedOwner The collection's owner; must be non-null
+ * @param persister The collection's persister
+ * @param id The collection key
+ * @param emptySnapshot Indicates if the snapshot is empty
+ * @param session The session
+ * @throws AssertionFailure if affectedOwner is null.
+ */
+ public CollectionRemoveAction(
+ final Object affectedOwner,
+ final CollectionPersister persister,
+ final Serializable id,
+ final boolean emptySnapshot,
+ final SessionImplementor session)
+ throws CacheException {
+ super( persister, null, id, session );
+ if (affectedOwner == null) { throw new AssertionFailure("affectedOwner == null"); };
+ this.emptySnapshot = emptySnapshot;
+ this.affectedOwner = affectedOwner;
+ }
+
public void execute() throws HibernateException {
- final boolean stats = getSession().getFactory().getStatistics().isStatisticsEnabled();
- long startTime = 0;
- if ( stats ) startTime = System.currentTimeMillis();
+ final boolean stats = getSession().getFactory().getStatistics().isStatisticsEnabled();
+ long startTime = 0;
+ if ( stats ) startTime = System.currentTimeMillis();
- if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() );
-
+ preRemove();
+
+ if ( !emptySnapshot ) {
+ // an existing collection that was either non-empty or uninitialized
+ // is replaced by null or a different collection
+ // (if the collection is uninitialized, hibernate has no way of
+ // knowing if the collection is actually empty without querying the db)
+ getPersister().remove( getKey(), getSession() );
+ }
+
final PersistentCollection collection = getCollection();
if (collection!=null) {
getSession().getPersistenceContext()
@@ -40,18 +97,39 @@
evict();
+ postRemove();
+
if ( stats ) {
getSession().getFactory().getStatisticsImplementor()
.removeCollection( getPersister().getRole(), System.currentTimeMillis() - startTime);
}
}
+ private void preRemove() {
+ PreCollectionRemoveEventListener[] preListeners = getSession().getListeners()
+ .getPreCollectionRemoveEventListeners();
+ if (preListeners.length>0) {
+ PreCollectionRemoveEvent preEvent = new PreCollectionRemoveEvent(
+ getCollection(),
+ affectedOwner,
+ ( EventSource )getSession() );
+ for ( int i = 0; i < preListeners.length; i++ ) {
+ preListeners[i].onPreRemoveCollection(preEvent);
+ }
+ }
+ }
+ private void postRemove() {
+ PostCollectionRemoveEventListener[] postListeners = getSession().getListeners()
+ .getPostCollectionRemoveEventListeners();
+ if (postListeners.length>0) {
+ PostCollectionRemoveEvent postEvent = new PostCollectionRemoveEvent(
+ getCollection(),
+ affectedOwner,
+ ( EventSource )getSession() );
+ for ( int i = 0; i < postListeners.length; i++ ) {
+ postListeners[i].onPostRemoveCollection(postEvent);
+ }
+ }
+ }
}
-
-
-
-
-
-
-
Modified: core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -3,6 +3,11 @@
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
+import org.hibernate.event.PostCollectionUpdateEvent;
+import org.hibernate.event.PreCollectionUpdateEvent;
+import org.hibernate.event.PreCollectionUpdateEventListener;
+import org.hibernate.event.EventSource;
+import org.hibernate.event.PostCollectionUpdateEventListener;
import org.hibernate.cache.CacheException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
@@ -32,10 +37,12 @@
final CollectionPersister persister = getPersister();
final PersistentCollection collection = getCollection();
boolean affectedByFilters = persister.isAffectedByEnabledFilters(session);
- final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
- long startTime = 0;
- if ( stats ) startTime = System.currentTimeMillis();
+ final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
+ long startTime = 0;
+ if ( stats ) startTime = System.currentTimeMillis();
+ preUpdate();
+
if ( !collection.wasInitialized() ) {
if ( !collection.hasQueuedOperations() ) throw new AssertionFailure( "no queued adds" );
//do nothing - we only need to notify the cache...
@@ -65,12 +72,37 @@
evict();
+ postUpdate();
+
if ( stats ) {
getSession().getFactory().getStatisticsImplementor().
updateCollection( getPersister().getRole(), System.currentTimeMillis() - startTime);
}
}
+ private void preUpdate() {
+ PreCollectionUpdateEventListener[] preListeners = getSession().getListeners()
+ .getPreCollectionUpdateEventListeners();
+ if (preListeners.length > 0) {
+ PreCollectionUpdateEvent preEvent = new PreCollectionUpdateEvent(
+ getCollection(), ( EventSource ) getSession() );
+ for ( int i = 0; i < preListeners.length; i++ ) {
+ preListeners[i].onPreUpdateCollection( preEvent );
+ }
+ }
+ }
+
+ private void postUpdate() {
+ PostCollectionUpdateEventListener[] postListeners = getSession().getListeners()
+ .getPostCollectionUpdateEventListeners();
+ if (postListeners.length > 0) {
+ PostCollectionUpdateEvent postEvent = new PostCollectionUpdateEvent(
+ getCollection(), ( EventSource ) getSession() );
+ for ( int i = 0; i < postListeners.length; i++ ) {
+ postListeners[i].onPostUpdateCollection( postEvent );
+ }
+ }
+ }
}
Modified: core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/cfg/Configuration.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -67,6 +67,12 @@
import org.hibernate.event.RefreshEventListener;
import org.hibernate.event.ReplicateEventListener;
import org.hibernate.event.SaveOrUpdateEventListener;
+import org.hibernate.event.PreCollectionRecreateEventListener;
+import org.hibernate.event.PreCollectionRemoveEventListener;
+import org.hibernate.event.PreCollectionUpdateEventListener;
+import org.hibernate.event.PostCollectionUpdateEventListener;
+import org.hibernate.event.PostCollectionRemoveEventListener;
+import org.hibernate.event.PostCollectionRecreateEventListener;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.impl.SessionFactoryImpl;
@@ -1863,6 +1869,30 @@
eventListeners.setPreInsertEventListeners( (PreInsertEventListener[]) listeners );
}
}
+ else if ( "pre-collection-recreate".equals( type ) ) {
+ if ( listeners == null ) {
+ eventListeners.setPreCollectionRecreateEventListeners( new PreCollectionRecreateEventListener[]{} );
+ }
+ else {
+ eventListeners.setPreCollectionRecreateEventListeners( (PreCollectionRecreateEventListener[]) listeners );
+ }
+ }
+ else if ( "pre-collection-remove".equals( type ) ) {
+ if ( listeners == null ) {
+ eventListeners.setPreCollectionRemoveEventListeners( new PreCollectionRemoveEventListener[]{} );
+ }
+ else {
+ eventListeners.setPreCollectionRemoveEventListeners( ( PreCollectionRemoveEventListener[]) listeners );
+ }
+ }
+ else if ( "pre-collection-update".equals( type ) ) {
+ if ( listeners == null ) {
+ eventListeners.setPreCollectionUpdateEventListeners( new PreCollectionUpdateEventListener[]{} );
+ }
+ else {
+ eventListeners.setPreCollectionUpdateEventListeners( ( PreCollectionUpdateEventListener[]) listeners );
+ }
+ }
else if ( "post-load".equals( type ) ) {
if ( listeners == null ) {
eventListeners.setPostLoadEventListeners( new PostLoadEventListener[]{} );
@@ -1925,6 +1955,30 @@
eventListeners.setPostCommitInsertEventListeners( (PostInsertEventListener[]) listeners );
}
}
+ else if ( "post-collection-recreate".equals( type ) ) {
+ if ( listeners == null ) {
+ eventListeners.setPostCollectionRecreateEventListeners( new PostCollectionRecreateEventListener[]{} );
+ }
+ else {
+ eventListeners.setPostCollectionRecreateEventListeners( (PostCollectionRecreateEventListener[]) listeners );
+ }
+ }
+ else if ( "post-collection-remove".equals( type ) ) {
+ if ( listeners == null ) {
+ eventListeners.setPostCollectionRemoveEventListeners( new PostCollectionRemoveEventListener[]{} );
+ }
+ else {
+ eventListeners.setPostCollectionRemoveEventListeners( ( PostCollectionRemoveEventListener[]) listeners );
+ }
+ }
+ else if ( "post-collection-update".equals( type ) ) {
+ if ( listeners == null ) {
+ eventListeners.setPostCollectionUpdateEventListeners( new PostCollectionUpdateEventListener[]{} );
+ }
+ else {
+ eventListeners.setPostCollectionUpdateEventListeners( ( PostCollectionUpdateEventListener[]) listeners );
+ }
+ }
else {
throw new MappingException("Unrecognized listener type [" + type + "]");
}
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/PersistenceContext.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/PersistenceContext.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/PersistenceContext.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -251,6 +251,11 @@
throws MappingException;
/**
+ * Get the entity that owned this persistent collection when it was loaded
+ */
+ Object getLoadedCollectionOwner(PersistentCollection collection);
+
+ /**
* add a collection we just loaded up (still needs initializing)
*/
public void addUninitializedCollection(CollectionPersister persister,
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/StatefulPersistenceContext.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/StatefulPersistenceContext.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -679,6 +679,17 @@
}
/**
+ * Get the entity that owned this persistent collection when it was loaded
+ */
+ public Object getLoadedCollectionOwner(PersistentCollection collection) {
+ CollectionEntry ce = getCollectionEntry(collection);
+ if ( ce.getLoadedKey() == null || ce.getLoadedPersister() == null ) {
+ return null;
+ }
+ return getCollectionOwner(ce.getLoadedKey(), ce.getLoadedPersister());
+ }
+
+ /**
* add a collection we just loaded up (still needs initializing)
*/
public void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id) {
Added: core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,34 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+
+/**
+ * Defines a base class for events involving collections.
+ *
+ * @author Gail Badner
+ */
+public abstract class AbstractCollectionEvent extends AbstractEvent {
+
+ private final PersistentCollection collection;
+ private final Object affectedOwner;
+
+ public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
+ super(source);
+ this.collection = collection;
+ this.affectedOwner = affectedOwner;
+ }
+
+ protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) {
+ return ( ( SessionImplementor ) source ).getPersistenceContext().getLoadedCollectionOwner( collection );
+ }
+
+ public PersistentCollection getCollection() {
+ return collection;
+ }
+
+ public Object getAffectedOwner() {
+ return affectedOwner;
+ }
+}
Modified: core/branches/Branch_3_2/src/org/hibernate/event/EventListeners.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/EventListeners.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/event/EventListeners.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -69,6 +69,13 @@
private PostUpdateEventListener[] postCommitUpdateEventListeners = {};
private PostInsertEventListener[] postCommitInsertEventListeners = {};
+ private PreCollectionRecreateEventListener[] preCollectionRecreateEventListeners = {};
+ private PostCollectionRecreateEventListener[] postCollectionRecreateEventListeners = {};
+ private PreCollectionRemoveEventListener[] preCollectionRemoveEventListeners = {};
+ private PostCollectionRemoveEventListener[] postCollectionRemoveEventListeners = {};
+ private PreCollectionUpdateEventListener[] preCollectionUpdateEventListeners = {};
+ private PostCollectionUpdateEventListener[] postCollectionUpdateEventListeners = {};
+
private SaveOrUpdateEventListener[] saveEventListeners = { new DefaultSaveEventListener() };
private SaveOrUpdateEventListener[] updateEventListeners = { new DefaultUpdateEventListener() };
private MergeEventListener[] saveOrUpdateCopyEventListeners = { new DefaultSaveOrUpdateCopyEventListener() };//saveOrUpdateCopy() is deprecated!
@@ -99,6 +106,9 @@
eventInterfaceFromType.put("pre-update", PreUpdateEventListener.class);
eventInterfaceFromType.put("pre-delete", PreDeleteEventListener.class);
eventInterfaceFromType.put("pre-insert", PreInsertEventListener.class);
+ eventInterfaceFromType.put("pre-collection-recreate", PreCollectionRecreateEventListener.class);
+ eventInterfaceFromType.put("pre-collection-remove", PreCollectionRemoveEventListener.class);
+ eventInterfaceFromType.put("pre-collection-update", PreCollectionUpdateEventListener.class);
eventInterfaceFromType.put("post-load", PostLoadEventListener.class);
eventInterfaceFromType.put("post-update", PostUpdateEventListener.class);
eventInterfaceFromType.put("post-delete", PostDeleteEventListener.class);
@@ -106,6 +116,9 @@
eventInterfaceFromType.put("post-commit-update", PostUpdateEventListener.class);
eventInterfaceFromType.put("post-commit-delete", PostDeleteEventListener.class);
eventInterfaceFromType.put("post-commit-insert", PostInsertEventListener.class);
+ eventInterfaceFromType.put("post-collection-recreate", PostCollectionRecreateEventListener.class);
+ eventInterfaceFromType.put("post-collection-remove", PostCollectionRemoveEventListener.class);
+ eventInterfaceFromType.put("post-collection-update", PostCollectionUpdateEventListener.class);
eventInterfaceFromType = Collections.unmodifiableMap( eventInterfaceFromType );
}
@@ -279,6 +292,30 @@
this.preLoadEventListeners = preLoadEventListener;
}
+ public PreCollectionRecreateEventListener[] getPreCollectionRecreateEventListeners() {
+ return preCollectionRecreateEventListeners;
+ }
+
+ public void setPreCollectionRecreateEventListeners(PreCollectionRecreateEventListener[] preCollectionRecreateEventListener) {
+ this.preCollectionRecreateEventListeners = preCollectionRecreateEventListener;
+ }
+
+ public PreCollectionRemoveEventListener[] getPreCollectionRemoveEventListeners() {
+ return preCollectionRemoveEventListeners;
+ }
+
+ public void setPreCollectionRemoveEventListeners(PreCollectionRemoveEventListener[] preCollectionRemoveEventListener) {
+ this.preCollectionRemoveEventListeners = preCollectionRemoveEventListener;
+ }
+
+ public PreCollectionUpdateEventListener[] getPreCollectionUpdateEventListeners() {
+ return preCollectionUpdateEventListeners;
+ }
+
+ public void setPreCollectionUpdateEventListeners(PreCollectionUpdateEventListener[] preCollectionUpdateEventListeners) {
+ this.preCollectionUpdateEventListeners = preCollectionUpdateEventListeners;
+ }
+
public PostDeleteEventListener[] getPostDeleteEventListeners() {
return postDeleteEventListeners;
}
@@ -303,6 +340,30 @@
this.postUpdateEventListeners = postUpdateEventListener;
}
+ public PostCollectionRecreateEventListener[] getPostCollectionRecreateEventListeners() {
+ return postCollectionRecreateEventListeners;
+ }
+
+ public void setPostCollectionRecreateEventListeners(PostCollectionRecreateEventListener[] postCollectionRecreateEventListener) {
+ this.postCollectionRecreateEventListeners = postCollectionRecreateEventListener;
+ }
+
+ public PostCollectionRemoveEventListener[] getPostCollectionRemoveEventListeners() {
+ return postCollectionRemoveEventListeners;
+ }
+
+ public void setPostCollectionRemoveEventListeners(PostCollectionRemoveEventListener[] postCollectionRemoveEventListener) {
+ this.postCollectionRemoveEventListeners = postCollectionRemoveEventListener;
+ }
+
+ public PostCollectionUpdateEventListener[] getPostCollectionUpdateEventListeners() {
+ return postCollectionUpdateEventListeners;
+ }
+
+ public void setPostCollectionUpdateEventListeners(PostCollectionUpdateEventListener[] postCollectionUpdateEventListeners) {
+ this.postCollectionUpdateEventListeners = postCollectionUpdateEventListeners;
+ }
+
public PreDeleteEventListener[] getPreDeleteEventListeners() {
return preDeleteEventListeners;
}
@@ -325,8 +386,8 @@
public void setPreUpdateEventListeners(PreUpdateEventListener[] preUpdateEventListener) {
this.preUpdateEventListeners = preUpdateEventListener;
- }
-
+ }
+
/**
* Call <tt>initialize()</tt> on any listeners that implement
* <tt>Initializable</tt>.
Modified: core/branches/Branch_3_2/src/org/hibernate/event/InitializeCollectionEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/InitializeCollectionEvent.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/event/InitializeCollectionEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -9,16 +9,9 @@
*
* @author Gavin King
*/
-public class InitializeCollectionEvent extends AbstractEvent {
-
- private final PersistentCollection collection;
+public class InitializeCollectionEvent extends AbstractCollectionEvent {
public InitializeCollectionEvent(PersistentCollection collection, EventSource source) {
- super(source);
- this.collection = collection;
+ super(collection, source, getLoadedOwner( collection, source ) );
}
-
- public PersistentCollection getCollection() {
- return collection;
- }
}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * An event that occurs after a collection is recreated
+ *
+ * @author Gail Badner
+ */
+public class PostCollectionRecreateEvent extends AbstractCollectionEvent {
+
+ public PostCollectionRecreateEvent(PersistentCollection collection, EventSource source) {
+ super(collection, source, collection.getOwner());
+ }
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEventListener.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRecreateEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,13 @@
+//$Id: $
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+/**
+ * Called after recreating a collection
+ *
+ * @author Gail Badner
+ */
+public interface PostCollectionRecreateEventListener extends Serializable {
+ public void onPostRecreateCollection(PostCollectionRecreateEvent event);
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * An event that occurs after a collection is removed
+ *
+ * @author Gail Badner
+ */
+public class PostCollectionRemoveEvent extends AbstractCollectionEvent {
+
+ public PostCollectionRemoveEvent(PersistentCollection collection, Object loadedOwner, EventSource source) {
+ super(collection, source, loadedOwner);
+ }
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEventListener.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionRemoveEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,13 @@
+//$Id: $
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+/**
+ * Called after removing a collection
+ *
+ * @author Gail Badner
+ */
+public interface PostCollectionRemoveEventListener extends Serializable {
+ public void onPostRemoveCollection(PostCollectionRemoveEvent event);
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * An event that occurs after a collection is updated
+ *
+ * @author Gail Badner
+ */
+public class PostCollectionUpdateEvent extends AbstractCollectionEvent {
+
+ public PostCollectionUpdateEvent(PersistentCollection collection, EventSource source) {
+ super(collection, source, getLoadedOwner( collection, source ));
+ }
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEventListener.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PostCollectionUpdateEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,13 @@
+//$Id: $
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+/**
+ * Called after updating a collection
+ *
+ * @author Gail Badner
+ */
+public interface PostCollectionUpdateEventListener extends Serializable {
+ public void onPostUpdateCollection(PostCollectionUpdateEvent event);
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * An event that occurs before a collection is recreated
+ *
+ * @author Gail Badner
+ */
+public class PreCollectionRecreateEvent extends AbstractCollectionEvent {
+
+ public PreCollectionRecreateEvent(PersistentCollection collection, EventSource source) {
+ super(collection, source, collection.getOwner());
+ }
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEventListener.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRecreateEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,13 @@
+//$Id: $
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+/**
+ * Called before recreating a collection
+ *
+ * @author Gail Badner
+ */
+public interface PreCollectionRecreateEventListener extends Serializable {
+ public void onPreRecreateCollection(PreCollectionRecreateEvent event);
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * An event that occurs before a collection is removed
+ *
+ * @author Gail Badner
+ */
+public class PreCollectionRemoveEvent extends AbstractCollectionEvent {
+
+ public PreCollectionRemoveEvent(PersistentCollection collection, Object loadedOwner, EventSource source) {
+ super(collection, source, loadedOwner);
+ }
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEventListener.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionRemoveEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,13 @@
+//$Id: $
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+/**
+ * Called before removing a collection
+ *
+ * @author Gail Badner
+ */
+public interface PreCollectionRemoveEventListener extends Serializable {
+ public void onPreRemoveCollection(PreCollectionRemoveEvent event);
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEvent.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEvent.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * An event that occurs before a collection is updated
+ *
+ * @author Gail Badner
+ */
+public class PreCollectionUpdateEvent extends AbstractCollectionEvent {
+
+ public PreCollectionUpdateEvent(PersistentCollection collection, EventSource source) {
+ super(collection, source, getLoadedOwner( collection, source ));
+ }
+}
Added: core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEventListener.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/event/PreCollectionUpdateEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,12 @@
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+/**
+ * Called before updating a collection
+ *
+ * @author Gail Badner
+ */
+public interface PreCollectionUpdateEventListener extends Serializable {
+ public void onPreUpdateCollection(PreCollectionUpdateEvent event);
+}
Modified: core/branches/Branch_3_2/src/org/hibernate/event/def/AbstractFlushingEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/AbstractFlushingEventListener.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/AbstractFlushingEventListener.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -246,7 +246,7 @@
session.getInterceptor().onCollectionRemove( coll, ce.getLoadedKey() );
actionQueue.addAction(
new CollectionRemoveAction(
- coll,
+ coll,
ce.getLoadedPersister(),
ce.getLoadedKey(),
ce.isSnapshotEmpty(coll),
Modified: core/branches/Branch_3_2/src/org/hibernate/event/def/ReattachVisitor.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/ReattachVisitor.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/ReattachVisitor.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -79,7 +79,7 @@
MessageHelper.collectionInfoString( role, ownerIdentifier, source.getFactory() )
);
}
- source.getActionQueue().addAction( new CollectionRemoveAction( null, role, collectionKey, false, source ) );
+ source.getActionQueue().addAction( new CollectionRemoveAction( owner, role, collectionKey, false, source ) );
}
/**
Modified: core/branches/Branch_3_2/test/org/hibernate/test/AllTests.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/AllTests.java 2008-01-21 22:06:50 UTC (rev 14289)
+++ core/branches/Branch_3_2/test/org/hibernate/test/AllTests.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -38,6 +38,7 @@
import org.hibernate.test.dynamicentity.tuplizer.TuplizerDynamicEntityTest;
import org.hibernate.test.ecid.EmbeddedCompositeIdTest;
import org.hibernate.test.entitymode.EntityModeSuite;
+import org.hibernate.test.event.collection.CollectionEventSuite;
import org.hibernate.test.exception.SQLExceptionConversionTest;
import org.hibernate.test.extralazy.ExtraLazyTest;
import org.hibernate.test.filter.DynamicFilterTest;
@@ -261,6 +262,7 @@
suite.addTest( IterateTest.suite() );
suite.addTest( CascadeSuite.suite() );
suite.addTest( ListenerTest.suite() );
+ suite.addTest( CollectionEventSuite.suite() );
suite.addTest( ExtraLazyTest.suite() );
suite.addTest( StatsTest.suite() );
suite.addTest( SessionStatsTest.suite() );
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,761 @@
+//$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;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.collection.PersistentSet;
+import org.hibernate.event.AbstractCollectionEvent;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public abstract class AbstractCollectionEventTest extends FunctionalTestCase {
+
+ public AbstractCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public abstract String[] getMappings();
+
+ public abstract ParentWithCollection createParent(String name);
+
+ public abstract Collection createCollection();
+
+ protected void cleanupTest() {
+ ParentWithCollection dummyParent = createParent( "dummyParent" );
+ dummyParent.newChildren( createCollection() );
+ Child dummyChild = dummyParent.addChild( "dummyChild" );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ List children = s.createCriteria( dummyChild.getClass() ).list();
+ List parents = s.createCriteria( dummyParent.getClass() ).list();
+ for ( Iterator it = parents.iterator(); it.hasNext(); ) {
+ ParentWithCollection parent = ( ParentWithCollection ) it.next();
+ parent.clearChildren();
+ s.delete( parent );
+ }
+ for ( Iterator it = children.iterator(); it.hasNext(); ) {
+ s.delete( it.next() );
+ }
+ tx.commit();
+ s.close();
+ }
+
+ public void testSaveParentEmptyChildren() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNoChildren( "parent" );
+ assertEquals( 0, parent.getChildren().size() );
+ int index = 0;
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ tx.commit();
+ s.close();
+ assertNotNull( parent.getChildren() );
+ checkNumberOfResults( listeners, 0 );
+ }
+
+ public void testSaveParentOneChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ int index = 0;
+ 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentNullToOneChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNullChildren( "parent" );
+ listeners.clear();
+ assertNull( parent.getChildren() );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ assertNotNull( parent.getChildren() );
+ Child newChild = parent.addChild( "new" );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentNoneToOneChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNoChildren( "parent" );
+ listeners.clear();
+ assertEquals( 0, parent.getChildren().size() );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ Child newChild = parent.addChild( "new" );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentOneToTwoChildren() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ assertEquals( 1, parent.getChildren().size() );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ Child newChild = parent.addChild( "new2" );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentOneToTwoSameChildren() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ assertEquals( 1, parent.getChildren().size() );
+ listeners.clear();
+ 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() );
+ }
+ parent.addChild( child );
+ tx.commit();
+ s.close();
+ int index = 0;
+ 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 ( !( 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentNullToOneChildDiffCollection() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNullChildren( "parent" );
+ listeners.clear();
+ assertNull( parent.getChildren() );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ Collection collectionOrig = parent.getChildren();
+ parent.newChildren( createCollection() );
+ Child newChild = parent.addChild( "new" );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) collectionOrig ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, collectionOrig, index++ );
+ }
+ 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++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentNoneToOneChildDiffCollection() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNoChildren( "parent" );
+ listeners.clear();
+ assertEquals( 0, parent.getChildren().size() );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( createCollection() );
+ Child newChild = parent.addChild( "new" );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
+ }
+ 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++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentOneChildDiffCollectionSameChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ assertEquals( 1, parent.getChildren().size() );
+ 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() );
+ }
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( createCollection() );
+ parent.addChild( child );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
+ }
+ if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
+ if ( child.hasBidirectionalManyToMany() ) {
+ // 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.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentOneChildDiffCollectionDiffChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ Child oldChild = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ assertEquals( 1, parent.getChildren().size() );
+ 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() );
+ }
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( createCollection() );
+ Child newChild = parent.addChild( "new1" );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
+ }
+ if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, 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++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentOneChildToNoneByRemove() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ assertEquals( 1, parent.getChildren().size() );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ 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() );
+ }
+ parent.removeChild( child );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), child, 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentOneChildToNoneByClear() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ assertEquals( 1, parent.getChildren().size() );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ 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() );
+ }
+ parent.clearChildren();
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), child, 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateParentTwoChildrenToOne() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ assertEquals( 1, parent.getChildren().size() );
+ Child oldChild = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ parent.addChild( "new" );
+ tx.commit();
+ s.close();
+ listeners.clear();
+ 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() );
+ }
+ parent.removeChild( oldChild );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testDeleteParentWithNullChildren() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNullChildren( "parent" );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ s.delete( parent );
+ tx.commit();
+ s.close();
+ int index = 0;
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testDeleteParentWithNoChildren() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNoChildren( "parent" );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ s.delete( parent );
+ tx.commit();
+ s.close();
+ int index = 0;
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testDeleteParentAndChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ 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() );
+ }
+ parent.removeChild( child );
+ if ( child instanceof ChildEntity ) {
+ s.delete( child );
+ }
+ s.delete( parent );
+ tx.commit();
+ s.close();
+ int index = 0;
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ if ( child.hasBidirectionalManyToMany() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testMoveChildToDifferentParent() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ Session s = openSession();
+ 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() );
+ }
+ parent.removeChild( child );
+ otherParent.addChild( child );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ if ( child.hasBidirectionalManyToMany() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ }
+ if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testMoveAllChildrenToDifferentParent() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" );
+ Child child = ( Child ) parent.getChildren().iterator().next();
+ listeners.clear();
+ Session s = openSession();
+ 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() );
+ }
+ otherParent.addAllChildren( parent.getChildren() );
+ parent.clearChildren();
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ }
+ if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
+ }
+ if ( child.hasBidirectionalManyToMany() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testMoveCollectionToDifferentParent() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
+ Collection otherCollectionOrig = otherParent.getChildren();
+ otherParent.newChildren( parent.getChildren() );
+ parent.newChildren( null );
+ tx.commit();
+ s.close();
+ int index = 0;
+ Child otherChildOrig = null;
+ 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++ );
+ }
+ }
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherParent.getChildren(), index++ );
+ Child otherChild = ( Child ) otherParent.getChildren().iterator().next();
+ if ( otherChild.hasBidirectionalManyToMany() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), 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++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, index++ );
+ // there should also be pre- and post-recreate collection events for parent, but thats broken now;
+ // this is covered in BrokenCollectionEventTest
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testMoveCollectionToDifferentParentFlushMoveToDifferentParent() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection otherParent = createParentWithOneChild( "otherParent", "otherChild" );
+ ParentWithCollection otherOtherParent = createParentWithNoChildren( "otherParent" );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
+ otherOtherParent = ( ParentWithCollection ) s.get( otherOtherParent.getClass(), otherOtherParent.getId() );
+ Collection otherCollectionOrig = otherParent.getChildren();
+ Collection otherOtherCollectionOrig = otherOtherParent.getChildren();
+ otherParent.newChildren( parent.getChildren() );
+ parent.newChildren( null );
+ s.flush();
+ otherOtherParent.newChildren( otherParent.getChildren() );
+ otherParent.newChildren( null );
+ tx.commit();
+ s.close();
+ int index = 0;
+ Child otherChildOrig = null;
+ 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++ );
+ }
+ }
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherOtherParent.getChildren(), index++ );
+ Child otherOtherChild = ( Child ) otherOtherParent.getChildren().iterator().next();
+ if ( otherOtherChild.hasBidirectionalManyToMany() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), 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++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
+ if ( ( ( PersistentCollection ) otherOtherCollectionOrig ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherOtherParent.getChildren(), index++ );
+ 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++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherOtherParent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherOtherParent, index++ );
+ // there should also be pre- and post-recreate collection events for parent, and otherParent
+ // but thats broken now; this is covered in BrokenCollectionEventTest
+ checkNumberOfResults( listeners, index );
+ }
+
+ protected ParentWithCollection createParentWithNullChildren(String parentName) {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ ParentWithCollection parent = createParent( parentName );
+ s.save( parent );
+ tx.commit();
+ s.close();
+ return parent;
+ }
+
+ protected ParentWithCollection createParentWithNoChildren(String parentName) {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ ParentWithCollection parent = createParent( parentName );
+ parent.newChildren( createCollection() );
+ s.save( parent );
+ tx.commit();
+ s.close();
+ return parent;
+ }
+
+ protected ParentWithCollection createParentWithOneChild(String parentName, String ChildName) {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ ParentWithCollection parent = createParent( parentName );
+ parent.newChildren( createCollection() );
+ parent.addChild( ChildName );
+ s.save( parent );
+ tx.commit();
+ s.close();
+ 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,
+ int index) {
+ checkResult( listeners, listenerExpected, parent, parent.getChildren(), index );
+ }
+ protected void checkResult(CollectionListeners listeners,
+ CollectionListeners.Listener listenerExpected,
+ Child child,
+ int index) {
+ checkResult( listeners, listenerExpected, child, getParents( child ), index );
+ }
+
+ protected void checkResult(CollectionListeners listeners,
+ CollectionListeners.Listener listenerExpected,
+ Object ownerExpected,
+ Collection collExpected,
+ int index) {
+ assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
+ assertSame(
+ ownerExpected,
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
+ );
+ assertSame(
+ collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
+ );
+ }
+
+ protected void checkNumberOfResults(CollectionListeners listeners, int nEventsExpected) {
+ assertEquals( nEventsExpected, listeners.getListenersCalled().size() );
+ assertEquals( nEventsExpected, listeners.getEvents().size() );
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractParentWithCollection.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractParentWithCollection.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractParentWithCollection.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,100 @@
+//$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;
+
+import java.util.Collection;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public abstract class AbstractParentWithCollection implements ParentWithCollection {
+ private Long id;
+ private String name;
+
+ private Collection children;
+
+ public AbstractParentWithCollection() {
+ }
+
+ public AbstractParentWithCollection(String name) {
+ this.name = name;
+ }
+
+ public void newChildren(Collection collection) {
+ setChildren( collection );
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getChildren() {
+ return children;
+ }
+
+ public void setChildren(Collection children) {
+ this.children = children;
+ }
+
+ public Child addChild(String name) {
+ Child child = createChild( name );
+ addChild( child );
+ return child;
+ }
+
+ public void addChild(Child child) {
+ if ( child != null ) {
+ children.add( child );
+ }
+ }
+
+ public void addAllChildren(Collection children) {
+ this.children.addAll( children );
+ }
+
+ public void removeChild(Child child) {
+ children.remove( child );
+ }
+
+ public void removeAllChildren(Collection children) {
+ children.removeAll( children );
+ }
+
+ public void clearChildren() {
+ if ( children != null && !children.isEmpty() ) {
+ this.children.clear();
+ }
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,322 @@
+//$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;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.event.AbstractCollectionEvent;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany;
+import org.hibernate.test.event.collection.association.unidirectional.ParentWithCollectionOfEntities;
+
+/**
+ *
+ * @author Gail Badner
+ *
+ * These tests are known to fail. When the functionality is corrected, the
+ * corresponding method will be moved into AbstractCollectionEventTest.
+ */
+public class BrokenCollectionEventTest extends FunctionalTestCase {
+
+ public BrokenCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BrokenCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithCollectionOfEntities( name );
+ }
+
+ public Collection createCollection() {
+ return new HashSet();
+ }
+
+ protected void cleanupTest() {
+ ParentWithCollection dummyParent = createParent( "dummyParent" );
+ dummyParent.setChildren( createCollection() );
+ Child dummyChild = dummyParent.addChild( "dummyChild" );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ List children = s.createCriteria( dummyChild.getClass() ).list();
+ List parents = s.createCriteria( dummyParent.getClass() ).list();
+ for ( Iterator it = parents.iterator(); it.hasNext(); ) {
+ ParentWithCollection parent = ( ParentWithCollection ) it.next();
+ parent.clearChildren();
+ s.delete( parent );
+ }
+ for ( Iterator it = children.iterator(); it.hasNext(); ) {
+ s.delete( it.next() );
+ }
+ tx.commit();
+ s.close();
+ }
+
+ public void testUpdateDetachedParentNoChildrenToNullFailureExpected() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNoChildren( "parent" );
+ listeners.clear();
+ assertEquals( 0, parent.getChildren().size() );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( null );
+ s.update( parent );
+ tx.commit();
+ s.close();
+ int index = 0;
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
+ // pre- and post- collection recreate events should be created when updating an entity with a "null" collection
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ // The following fails for the same reason as testUpdateDetachedParentNoChildrenToNullFailureExpected
+ // When that issue is fixed, this one should also be fixed and moved into AbstractCollectionEventTest.
+ /*
+ public void testUpdateDetachedParentOneChildToNullFailureExpected() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ Child oldChild = ( Child ) parent.getChildren().iterator().next();
+ assertEquals( 1, parent.getChildren().size() );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( null );
+ s.update( parent );
+ tx.commit();
+ s.close();
+ 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++ );
+ }
+ // pre- and post- collection recreate events should be created when updating an entity with a "null" collection
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+ */
+
+ public void testSaveParentNullChildrenFailureExpected() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNullChildren( "parent" );
+ assertNull( parent.getChildren() );
+ int index = 0;
+ // pre- and post- collection recreate events should be created when creating an entity with a "null" collection
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ tx.commit();
+ s.close();
+ assertNotNull( parent.getChildren() );
+ checkNumberOfResults( listeners, 0 );
+ }
+
+ public void testUpdateParentNoChildrenToNullFailureExpected() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithNoChildren( "parent" );
+ listeners.clear();
+ assertEquals( 0, parent.getChildren().size() );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( null );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
+ }
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
+ // pre- and post- collection recreate events should be created when updating an entity with a "null" collection
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+
+ // The following two tests fail for the same reason as testUpdateParentNoChildrenToNullFailureExpected
+ // When that issue is fixed, this one should also be fixed and moved into AbstractCollectionEventTest.
+ /*
+ public void testUpdateParentOneChildToNullFailureExpected() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ Child oldChild = ( Child ) parent.getChildren().iterator().next();
+ assertEquals( 1, parent.getChildren().size() );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( AbstractParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ if ( oldChild instanceof ChildEntity ) {
+ oldChild = ( Child ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild ).getId() );
+ }
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( null );
+ tx.commit();
+ s.close();
+ int index = 0;
+ if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
+ }
+ if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, 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++ );
+ }
+ // pre- and post- collection recreate events should be created when updating an entity with a "null" collection
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+
+ public void testUpdateMergedParentOneChildToNullFailureExpected() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ assertEquals( 1, parent.getChildren().size() );
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( AbstractParentWithCollection ) s.merge( parent );
+ Collection oldCollection = parent.getChildren();
+ parent.newChildren( null );
+ tx.commit();
+ s.close();
+ int index = 0;
+ Child oldChild = ( Child ) oldCollection.iterator().next();
+ if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, 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++ );
+ }
+ // pre- and post- collection recreate events should be created when updating an entity with a "null" collection
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
+ checkNumberOfResults( listeners, index );
+ }
+ */
+
+ private ParentWithCollection createParentWithNullChildren(String parentName) {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ ParentWithCollection parent = createParent( parentName );
+ s.save( parent );
+ tx.commit();
+ s.close();
+ return parent;
+ }
+
+ private ParentWithCollection createParentWithNoChildren(String parentName) {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ ParentWithCollection parent = createParent( parentName );
+ parent.setChildren( createCollection() );
+ s.save( parent );
+ tx.commit();
+ s.close();
+ return parent;
+ }
+
+ private ParentWithCollection createParentWithOneChild(String parentName, String ChildName) {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ ParentWithCollection parent = createParent( parentName );
+ parent.setChildren( createCollection() );
+ parent.addChild( ChildName );
+ s.save( parent );
+ tx.commit();
+ s.close();
+ return parent;
+ }
+
+ private Collection getParents( Child child ) {
+ return ( ( child instanceof ChildWithBidirectionalManyToMany )
+ ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
+ : null );
+ }
+ private void checkResult(CollectionListeners listeners,
+ CollectionListeners.Listener listenerExpected,
+ ParentWithCollection parent,
+ int index) {
+ checkResult( listeners, listenerExpected, parent, parent.getChildren(), index );
+ }
+ private void checkResult(CollectionListeners listeners,
+ CollectionListeners.Listener listenerExpected,
+ Child child,
+ int index) {
+ checkResult( listeners, listenerExpected, child, getParents( child ), index );
+ }
+
+ private void checkResult(CollectionListeners listeners,
+ CollectionListeners.Listener listenerExpected,
+ Object ownerExpected,
+ Collection collExpected,
+ int index) {
+ assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
+ assertSame(
+ ownerExpected,
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
+ );
+ assertSame(
+ collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
+ );
+ }
+
+ private void checkNumberOfResults(CollectionListeners listeners, int nEventsExpected) {
+ assertEquals( nEventsExpected, listeners.getListenersCalled().size() );
+ assertEquals( nEventsExpected, listeners.getEvents().size() );
+ }
+}
\ No newline at end of file
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Child.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Child.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Child.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,35 @@
+//$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;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public interface Child {
+
+ boolean hasBidirectionalManyToMany();
+
+ String getName();
+
+ void setName(String name);
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildEntity.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildEntity.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildEntity.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,48 @@
+//$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;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ChildEntity extends ChildValue {
+ private Long id;
+
+
+ public ChildEntity() {
+ super();
+ }
+
+ public ChildEntity(String name) {
+ super( name );
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildValue.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildValue.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildValue.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,63 @@
+//$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;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ChildValue implements Child {
+ private String name;
+
+ public ChildValue() {
+ }
+
+ public ChildValue(String name) {
+ this.name = name;
+ }
+
+ public boolean hasBidirectionalManyToMany() {
+ return false;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean equals(Object otherChild) {
+ if ( this == otherChild ) {
+ return true;
+ }
+ if ( !( otherChild instanceof ChildValue ) ) {
+ return false;
+ }
+ return name.equals( ( ( ChildValue ) otherChild ).name );
+ }
+
+ public int hashCode() {
+ return name.hashCode();
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionEventSuite.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionEventSuite.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionEventSuite.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,54 @@
+//$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;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.BidirectionalManyToManyBagToSetCollectionEventTest;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.BidirectionalManyToManySetToSetCollectionEventTest;
+import org.hibernate.test.event.collection.association.bidirectional.onetomany.BidirectionalOneToManyBagCollectionEventTest;
+import org.hibernate.test.event.collection.association.bidirectional.onetomany.BidirectionalOneToManySetCollectionEventTest;
+import org.hibernate.test.event.collection.association.unidirectional.manytomany.UnidirectionalManyToManyBagCollectionEventTest;
+import org.hibernate.test.event.collection.association.unidirectional.onetomany.UnidirectionalOneToManyBagCollectionEventTest;
+import org.hibernate.test.event.collection.association.unidirectional.onetomany.UnidirectionalOneToManySetCollectionEventTest;
+import org.hibernate.test.event.collection.values.ValuesBagCollectionEventTest;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class CollectionEventSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "Collection event test suite" );
+ suite.addTest( BrokenCollectionEventTest.suite() );
+ suite.addTest( BidirectionalManyToManyBagToSetCollectionEventTest.suite() );
+ suite.addTest( BidirectionalManyToManySetToSetCollectionEventTest.suite() );
+ suite.addTest( BidirectionalOneToManyBagCollectionEventTest.suite() );
+ suite.addTest( BidirectionalOneToManySetCollectionEventTest.suite() );
+ suite.addTest( UnidirectionalManyToManyBagCollectionEventTest.suite() );
+ suite.addTest( UnidirectionalOneToManyBagCollectionEventTest.suite() );
+ suite.addTest( UnidirectionalOneToManySetCollectionEventTest.suite() );
+ suite.addTest( ValuesBagCollectionEventTest.suite() );
+ return suite;
+ }
+}
\ No newline at end of file
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionListeners.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionListeners.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/CollectionListeners.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,214 @@
+//$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;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.event.AbstractCollectionEvent;
+import org.hibernate.event.InitializeCollectionEvent;
+import org.hibernate.event.InitializeCollectionEventListener;
+import org.hibernate.event.PostCollectionRecreateEvent;
+import org.hibernate.event.PostCollectionRecreateEventListener;
+import org.hibernate.event.PostCollectionRemoveEvent;
+import org.hibernate.event.PostCollectionRemoveEventListener;
+import org.hibernate.event.PostCollectionUpdateEvent;
+import org.hibernate.event.PostCollectionUpdateEventListener;
+import org.hibernate.event.PreCollectionRecreateEvent;
+import org.hibernate.event.PreCollectionRecreateEventListener;
+import org.hibernate.event.PreCollectionRemoveEvent;
+import org.hibernate.event.PreCollectionRemoveEventListener;
+import org.hibernate.event.PreCollectionUpdateEvent;
+import org.hibernate.event.PreCollectionUpdateEventListener;
+import org.hibernate.event.def.DefaultInitializeCollectionEventListener;
+import org.hibernate.impl.SessionFactoryImpl;
+
+/**
+ * Author: Gail Badner
+ */
+public class CollectionListeners {
+
+
+ public interface Listener extends Serializable {
+ void addEvent(AbstractCollectionEvent event, Listener listener);
+ }
+
+ public static abstract class AbstractListener implements Listener {
+
+ private final CollectionListeners listeners;
+
+ protected AbstractListener( CollectionListeners listeners ) {
+ this.listeners = listeners;
+ }
+
+ public void addEvent(AbstractCollectionEvent event, Listener listener) {
+ listeners.addEvent( event, listener );
+ }
+ }
+
+ public static class InitializeCollectionListener
+ extends DefaultInitializeCollectionEventListener
+ implements Listener {
+ private final CollectionListeners listeners;
+ private InitializeCollectionListener(CollectionListeners listeners) {
+ this.listeners = listeners;
+ }
+ public void onInitializeCollection(InitializeCollectionEvent event) {
+ super.onInitializeCollection( event );
+ addEvent( event, this );
+ }
+ public void addEvent(AbstractCollectionEvent event, Listener listener) {
+ listeners.addEvent( event, listener );
+ }
+ }
+
+ public static class PreCollectionRecreateListener extends AbstractListener
+ implements PreCollectionRecreateEventListener {
+ private PreCollectionRecreateListener(CollectionListeners listeners) {
+ super( listeners );
+ }
+ public void onPreRecreateCollection(PreCollectionRecreateEvent event) {
+ addEvent( event, this );
+ }
+ }
+
+ public static class PostCollectionRecreateListener extends AbstractListener
+ implements PostCollectionRecreateEventListener {
+ private PostCollectionRecreateListener(CollectionListeners listeners) {
+ super( listeners );
+ }
+ public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
+ addEvent( event, this );
+ }
+ }
+
+ public static class PreCollectionRemoveListener extends AbstractListener
+ implements PreCollectionRemoveEventListener {
+ private PreCollectionRemoveListener(CollectionListeners listeners) {
+ super( listeners );
+ }
+ public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
+ addEvent( event, this );
+ }
+ }
+
+ public static class PostCollectionRemoveListener extends AbstractListener
+ implements PostCollectionRemoveEventListener {
+ private PostCollectionRemoveListener(CollectionListeners listeners) {
+ super( listeners );
+ }
+ public void onPostRemoveCollection(PostCollectionRemoveEvent event) {
+ addEvent( event, this );
+ }
+ }
+
+ public static class PreCollectionUpdateListener extends AbstractListener
+ implements PreCollectionUpdateEventListener {
+ private PreCollectionUpdateListener(CollectionListeners listeners) {
+ super( listeners );
+ }
+ public void onPreUpdateCollection(PreCollectionUpdateEvent event) {
+ addEvent( event, this );
+ }
+ }
+
+ public static class PostCollectionUpdateListener extends AbstractListener
+ implements PostCollectionUpdateEventListener {
+ private PostCollectionUpdateListener(CollectionListeners listeners) {
+ super( listeners );
+ }
+ public void onPostUpdateCollection(PostCollectionUpdateEvent event) {
+ addEvent( event, this );
+ }
+ }
+
+ private final PreCollectionRecreateListener preCollectionRecreateListener;
+ private final InitializeCollectionListener initializeCollectionListener;
+ private final PreCollectionRemoveListener preCollectionRemoveListener;
+ private final PreCollectionUpdateListener preCollectionUpdateListener;
+ private final PostCollectionRecreateListener postCollectionRecreateListener;
+ private final PostCollectionRemoveListener postCollectionRemoveListener;
+ private final PostCollectionUpdateListener postCollectionUpdateListener;
+
+ private List listenersCalled = new ArrayList();
+ private List events = new ArrayList();
+
+ public CollectionListeners( SessionFactory sf) {
+ preCollectionRecreateListener = new PreCollectionRecreateListener( this );
+ initializeCollectionListener = new InitializeCollectionListener( this );
+ preCollectionRemoveListener = new PreCollectionRemoveListener( this );
+ preCollectionUpdateListener = new PreCollectionUpdateListener( this );
+ postCollectionRecreateListener = new PostCollectionRecreateListener( this );
+ postCollectionRemoveListener = new PostCollectionRemoveListener( this );
+ postCollectionUpdateListener = new PostCollectionUpdateListener( this );
+ SessionFactoryImpl impl = ( SessionFactoryImpl ) sf;
+ impl.getEventListeners().setInitializeCollectionEventListeners(
+ new InitializeCollectionEventListener[] { initializeCollectionListener }
+ );
+ impl.getEventListeners().setPreCollectionRecreateEventListeners(
+ new PreCollectionRecreateEventListener[] { preCollectionRecreateListener }
+ );
+ impl.getEventListeners().setPostCollectionRecreateEventListeners(
+ new PostCollectionRecreateEventListener[] { postCollectionRecreateListener }
+ );
+ impl.getEventListeners().setPreCollectionRemoveEventListeners(
+ new PreCollectionRemoveEventListener[] { preCollectionRemoveListener }
+ );
+ impl.getEventListeners().setPostCollectionRemoveEventListeners(
+ new PostCollectionRemoveEventListener[] { postCollectionRemoveListener }
+ );
+ impl.getEventListeners().setPreCollectionUpdateEventListeners(
+ new PreCollectionUpdateEventListener[] { preCollectionUpdateListener }
+ );
+ impl.getEventListeners().setPostCollectionUpdateEventListeners(
+ new PostCollectionUpdateEventListener[] { postCollectionUpdateListener }
+ );
+ }
+
+ public void addEvent(AbstractCollectionEvent event, Listener listener) {
+ listenersCalled.add( listener );
+ events.add( event );
+ }
+
+ public List getListenersCalled() {
+ return listenersCalled;
+ }
+
+ public List getEvents() {
+ return events;
+ }
+
+ public void clear() {
+ listenersCalled.clear();
+ events.clear();
+ }
+
+ public PreCollectionRecreateListener getPreCollectionRecreateListener() { return preCollectionRecreateListener; }
+ public InitializeCollectionListener getInitializeCollectionListener() { return initializeCollectionListener; }
+ public PreCollectionRemoveListener getPreCollectionRemoveListener() { return preCollectionRemoveListener; }
+ public PreCollectionUpdateListener getPreCollectionUpdateListener() { return preCollectionUpdateListener; }
+ public PostCollectionRecreateListener getPostCollectionRecreateListener() { return postCollectionRecreateListener; }
+ public PostCollectionRemoveListener getPostCollectionRemoveListener() { return postCollectionRemoveListener; }
+ public PostCollectionUpdateListener getPostCollectionUpdateListener() { return postCollectionUpdateListener; }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ParentWithCollection.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ParentWithCollection.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ParentWithCollection.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,58 @@
+//$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;
+
+import java.util.Collection;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public interface ParentWithCollection {
+ void newChildren(Collection collection);
+
+ Child createChild(String name);
+
+ Long getId();
+
+ void setId(Long id);
+
+ String getName();
+
+ void setName(String name);
+
+ Collection getChildren();
+
+ void setChildren(Collection children);
+
+ Child addChild(String name);
+
+ void addChild(Child child);
+
+ void addAllChildren(Collection children);
+
+ void removeChild(Child child);
+
+ void removeAllChildren(Collection children);
+
+ void clearChildren();
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,66 @@
+//$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;
+
+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;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public abstract class AbstractAssociationCollectionEventTest extends AbstractCollectionEventTest {
+ public AbstractAssociationCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public void testDeleteParentButNotChild() {
+ CollectionListeners listeners = new CollectionListeners( getSessions() );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ChildEntity child = ( ChildEntity ) parent.getChildren().iterator().next();
+ listeners.clear();
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
+ child = ( ChildEntity ) s.get( child.getClass(), child.getId() );
+ parent.removeChild( child );
+ s.delete( parent );
+ tx.commit();
+ s.close();
+ int index = 0;
+ checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
+ if ( child.hasBidirectionalManyToMany() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), 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++ );
+ }
+ checkNumberOfResults( listeners, index );
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,59 @@
+//$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.manytomany;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.ParentWithBidirectionalManyToMany;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class BidirectionalManyToManyBagToSetCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public BidirectionalManyToManyBagToSetCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BidirectionalManyToManyBagToSetCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithBidirectionalManyToMany( name );
+ }
+
+ public Collection createCollection() {
+ return new ArrayList();
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,35 @@
+<?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.manytomany">
+
+ <class name="ParentWithBidirectionalManyToMany" table="PARENT">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <bag name="children" table="PARENT_CHILD"
+ inverse="false" cascade="all">
+ <key column="parent_id"/>
+ <many-to-many column="child_id" class="ChildWithBidirectionalManyToMany"/>
+ </bag>
+ </class>
+
+ <class name="ChildWithBidirectionalManyToMany" table="CHILD">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ <set name="parents" table="PARENT_CHILD"
+ inverse="true">
+ <key column="child_id"/>
+ <many-to-many column="parent_id" class="ParentWithBidirectionalManyToMany"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,59 @@
+//$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.manytomany;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.ParentWithBidirectionalManyToMany;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class BidirectionalManyToManySetToSetCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public BidirectionalManyToManySetToSetCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BidirectionalManyToManySetToSetCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithBidirectionalManyToMany( name );
+ }
+
+ public Collection createCollection() {
+ return new HashSet();
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,35 @@
+<?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.manytomany">
+
+ <class name="ParentWithBidirectionalManyToMany" table="PARENT">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <set name="children" table="PARENT_CHILD"
+ inverse="false" cascade="all">
+ <key column="parent_id"/>
+ <many-to-many column="child_id" class="ChildWithBidirectionalManyToMany"/>
+ </set>
+ </class>
+
+ <class name="ChildWithBidirectionalManyToMany" table="CHILD">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ <set name="parents" table="PARENT_CHILD"
+ inverse="true">
+ <key column="child_id"/>
+ <many-to-many column="parent_id" class="ParentWithBidirectionalManyToMany"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,66 @@
+//$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.manytomany;
+
+import java.util.Collection;
+
+import org.hibernate.test.event.collection.ChildEntity;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ChildWithBidirectionalManyToMany extends ChildEntity {
+ private Collection parents;
+
+ public ChildWithBidirectionalManyToMany() {
+ }
+
+ public ChildWithBidirectionalManyToMany(String name, Collection parents) {
+ super( name );
+ this.parents = parents;
+ }
+
+ public boolean hasBidirectionalManyToMany() {
+ return true;
+ }
+
+ public Collection getParents() {
+ return parents;
+ }
+
+ public void setParents(Collection parents) {
+ this.parents = parents;
+ }
+
+ public void addParent(ParentWithBidirectionalManyToMany parent) {
+ if ( parent != null ) {
+ parents.add( parent );
+ }
+ }
+
+ public void removeParent(ParentWithBidirectionalManyToMany parent) {
+ if ( parent != null ) {
+ parents.remove( parent );
+ }
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,105 @@
+//$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.manytomany;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.hibernate.test.event.collection.Child;
+import org.hibernate.test.event.collection.AbstractParentWithCollection;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ParentWithBidirectionalManyToMany extends AbstractParentWithCollection {
+ public ParentWithBidirectionalManyToMany() {
+ }
+
+ public ParentWithBidirectionalManyToMany(String name) {
+ super( name );
+ }
+
+ public void newChildren(Collection children) {
+ if ( children == getChildren() ) {
+ return;
+ }
+ if ( getChildren() != null ) {
+ for ( Iterator it = getChildren().iterator(); it.hasNext(); ) {
+ ChildWithBidirectionalManyToMany child = ( ChildWithBidirectionalManyToMany ) it.next();
+ child.removeParent( this );
+ }
+ }
+ if ( children != null ) {
+ for ( Iterator it = children.iterator(); it.hasNext(); ) {
+ ChildWithBidirectionalManyToMany child = ( ChildWithBidirectionalManyToMany ) it.next();
+ child.addParent( this );
+ }
+ }
+ super.newChildren( children );
+ }
+
+ public Child createChild(String name) {
+ return new ChildWithBidirectionalManyToMany( name, new HashSet() );
+ }
+
+ public void addChild(Child child) {
+ super.addChild( child );
+ ( ( ChildWithBidirectionalManyToMany ) child ).addParent( this );
+ }
+
+ public void addAllChildren(Collection children) {
+ super.addAllChildren( children );
+ for ( Iterator it = children.iterator(); it.hasNext(); ) {
+ ChildWithBidirectionalManyToMany child = ( ChildWithBidirectionalManyToMany ) it.next();
+ child.addParent( this );
+ }
+ }
+
+ public void removeChild(Child child) {
+ // Note: if the collection is a bag, the same child can be in the collection more than once
+ super.removeChild( child );
+ // only remove the parent from the child's set if child is no longer in the collection
+ if ( ! getChildren().contains( child ) ) {
+ ( ( ChildWithBidirectionalManyToMany ) child ).removeParent( this );
+ }
+ }
+
+ public void removeAllChildren(Collection children) {
+ super.removeAllChildren( children );
+ for ( Iterator it = children.iterator(); it.hasNext(); ) {
+ ChildWithBidirectionalManyToMany child = ( ChildWithBidirectionalManyToMany ) it.next();
+ child.removeParent( this );
+ }
+ }
+
+ public void clearChildren() {
+ if ( getChildren() != null ) {
+ for ( Iterator it = getChildren().iterator(); it.hasNext(); ) {
+ ChildWithBidirectionalManyToMany child = ( ChildWithBidirectionalManyToMany ) it.next();
+ child.removeParent( this );
+ }
+ }
+ super.clearChildren();
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,65 @@
+//$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 BidirectionalOneToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public BidirectionalOneToManyBagCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BidirectionalOneToManyBagCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithBidirectionalOneToMany( name );
+ }
+
+ public Collection createCollection() {
+ return new ArrayList();
+ }
+
+ public Child createChild(String name) {
+ return new ChildWithManyToOne( name );
+ }
+}
\ No newline at end of file
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,32 @@
+<?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">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <bag name="children"
+ inverse="true"
+ cascade="all">
+ <key column="parent_id"/>
+ <one-to-many class="ChildWithManyToOne"/>
+ </bag>
+ </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>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,65 @@
+//$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.HashSet;
+
+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 BidirectionalOneToManySetCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public BidirectionalOneToManySetCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( BidirectionalOneToManySetCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithBidirectionalOneToMany( name );
+ }
+
+ public Collection createCollection() {
+ return new HashSet();
+ }
+
+ public Child createChild(String name) {
+ return new ChildWithManyToOne( name );
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,32 @@
+<?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">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <set name="children"
+ inverse="true"
+ cascade="all">
+ <key column="parent_id"/>
+ <one-to-many class="ChildWithManyToOne"/>
+ </set>
+ </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>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,47 @@
+//$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 org.hibernate.test.event.collection.ChildEntity;
+import org.hibernate.test.event.collection.ParentWithCollection;
+
+/**
+ * @author Gail Badner
+ */
+public class ChildWithManyToOne extends ChildEntity {
+ private ParentWithCollection parent;
+
+ public ChildWithManyToOne() {
+ }
+
+ public ChildWithManyToOne(String name) {
+ super( name );
+ }
+
+ public ParentWithCollection getParent() {
+ return parent;
+ }
+
+ public void setParent(ParentWithCollection parent) {
+ this.parent = parent;
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,85 @@
+//$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 ParentWithBidirectionalOneToMany extends AbstractParentWithCollection {
+ public ParentWithBidirectionalOneToMany() {
+ }
+
+ public ParentWithBidirectionalOneToMany(String name) {
+ super( name );
+ }
+
+ public Child createChild( String name ) {
+ return new ChildWithManyToOne( name );
+ }
+
+ public Child addChild(String name) {
+ Child child = createChild( name );
+ addChild( child );
+ return child;
+ }
+
+ public void addChild(Child child) {
+ super.addChild( child );
+ ( ( ChildWithManyToOne ) child ).setParent( this );
+ }
+
+ public void newChildren(Collection children) {
+ if ( children == getChildren() ) {
+ return;
+ }
+ if ( getChildren() != null ) {
+ for ( Iterator it = getChildren().iterator(); it.hasNext(); ) {
+ ChildWithManyToOne child = ( ChildWithManyToOne ) it.next();
+ child.setParent( null );
+ }
+ }
+ if ( children != null ) {
+ for ( Iterator it = children.iterator(); it.hasNext(); ) {
+ ChildWithManyToOne child = ( ChildWithManyToOne ) it.next();
+ child.setParent( this );
+ }
+ }
+ super.newChildren( children );
+ }
+
+ public void removeChild(Child child) {
+ // Note: there can be more than one child in the collection
+ super.removeChild( child );
+ // only set the parent to null if child is no longer in the bag
+ if ( ! getChildren().contains( child ) ) {
+ ( ( ChildWithManyToOne ) child ).setParent( null );
+ }
+ }
+
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,43 @@
+//$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.unidirectional;
+
+import org.hibernate.test.event.collection.AbstractParentWithCollection;
+import org.hibernate.test.event.collection.Child;
+import org.hibernate.test.event.collection.ChildEntity;
+
+/**
+ * @author Gail Badner
+ */
+public class ParentWithCollectionOfEntities extends AbstractParentWithCollection {
+
+ public ParentWithCollectionOfEntities() {
+ }
+
+ public ParentWithCollectionOfEntities(String name) {
+ super( name );
+ }
+
+ public Child createChild(String name) {
+ return new ChildEntity( name );
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,65 @@
+//$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.unidirectional.manytomany;
+
+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.ChildEntity;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
+import org.hibernate.test.event.collection.association.unidirectional.ParentWithCollectionOfEntities;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class UnidirectionalManyToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public UnidirectionalManyToManyBagCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( UnidirectionalManyToManyBagCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithCollectionOfEntities( name );
+ }
+
+ public Collection createCollection() {
+ return new ArrayList();
+ }
+
+ public Child createChild(String name) {
+ return new ChildEntity( name );
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,30 @@
+<?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.unidirectional">
+
+ <class name="ParentWithCollectionOfEntities" table="PARENT">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <bag name="children" table="PARENT_CHILD"
+ inverse="false" cascade="all">
+ <key column="parent_id"/>
+ <many-to-many column="child_id" class="org.hibernate.test.event.collection.ChildEntity"/>
+ </bag>
+ </class>
+
+ <class name="org.hibernate.test.event.collection.ChildEntity" table="CHILD">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,65 @@
+//$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.unidirectional.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.ChildEntity;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
+import org.hibernate.test.event.collection.association.unidirectional.ParentWithCollectionOfEntities;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class UnidirectionalOneToManyBagCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public UnidirectionalOneToManyBagCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( UnidirectionalOneToManyBagCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithCollectionOfEntities( name );
+ }
+
+ public Collection createCollection() {
+ return new ArrayList();
+ }
+
+ public Child createChild(String name) {
+ return new ChildEntity( name );
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,30 @@
+<?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.unidirectional">
+
+ <class name="ParentWithCollectionOfEntities" table="PARENT">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <bag name="children"
+ cascade="all">
+ <key column="parent_id"/>
+ <one-to-many class="org.hibernate.test.event.collection.ChildEntity"/>
+ </bag>
+ </class>
+
+ <class name="org.hibernate.test.event.collection.ChildEntity" table="CHILD">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,60 @@
+//$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.unidirectional.onetomany;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.association.AbstractAssociationCollectionEventTest;
+import org.hibernate.test.event.collection.association.unidirectional.ParentWithCollectionOfEntities;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class UnidirectionalOneToManySetCollectionEventTest extends AbstractAssociationCollectionEventTest {
+
+ public UnidirectionalOneToManySetCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( UnidirectionalOneToManySetCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithCollectionOfEntities( name );
+ }
+
+ public Collection createCollection() {
+ return new HashSet();
+ }
+}
+
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,30 @@
+<?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.unidirectional">
+
+ <class name="ParentWithCollectionOfEntities" table="PARENT">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <set name="children"
+ cascade="all">
+ <key column="parent_id"/>
+ <one-to-many class="org.hibernate.test.event.collection.ChildEntity"/>
+ </set>
+ </class>
+
+ <class name="org.hibernate.test.event.collection.ChildEntity" table="CHILD">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,45 @@
+//$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.values;
+
+import java.util.Collection;
+
+import org.hibernate.test.event.collection.Child;
+import org.hibernate.test.event.collection.ChildValue;
+import org.hibernate.test.event.collection.AbstractParentWithCollection;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ParentWithCollectionOfValues extends AbstractParentWithCollection {
+ public ParentWithCollectionOfValues() {
+ }
+
+ public ParentWithCollectionOfValues(String name) {
+ super( name );
+ }
+
+ public Child createChild(String name) {
+ return new ChildValue( name );
+ }
+}
\ No newline at end of file
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,59 @@
+//$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.values;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.event.collection.AbstractCollectionEventTest;
+import org.hibernate.test.event.collection.ParentWithCollection;
+import org.hibernate.test.event.collection.values.ParentWithCollectionOfValues;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class ValuesBagCollectionEventTest extends AbstractCollectionEventTest {
+
+ public ValuesBagCollectionEventTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ValuesBagCollectionEventTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "event/collection/values/ValuesBagMapping.hbm.xml" };
+ }
+
+ public ParentWithCollection createParent(String name) {
+ return new ParentWithCollectionOfValues( name );
+ }
+
+ public Collection createCollection() {
+ return new ArrayList();
+ }
+}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml 2008-01-25 02:34:41 UTC (rev 14290)
@@ -0,0 +1,25 @@
+<?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.values">
+
+ <class name="ParentWithCollectionOfValues" table="PARENT">
+ <id name="id" column="ID" type="long">
+ <generator class="native"/>
+ </id>
+ <bag name="children"
+ cascade="all">
+ <key column="parent_id"/>
+ <composite-element class="org.hibernate.test.event.collection.ChildValue">
+ <property name="name"/>
+ </composite-element>
+ </bag>
+ </class>
+
+</hibernate-mapping>
16 years, 3 months
Hibernate SVN: r14289 - annotations/tags.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2008-01-21 17:06:50 -0500 (Mon, 21 Jan 2008)
New Revision: 14289
Added:
annotations/tags/3_2_1_GA_CP01/
Log:
CP01 release for EAP CP02
Copied: annotations/tags/3_2_1_GA_CP01 (from rev 14288, annotations/branches/v3_2_1_GA_CP)
16 years, 3 months
Hibernate SVN: r14288 - core/tags.
by hibernate-commits@lists.jboss.org
Author: cbredesen
Date: 2008-01-21 16:38:57 -0500 (Mon, 21 Jan 2008)
New Revision: 14288
Added:
core/tags/Branch_3_2_4_SP1_CP02/
Log:
CP02 release
Copied: core/tags/Branch_3_2_4_SP1_CP02 (from rev 14287, core/branches/Branch_3_2_4_SP1_CP)
16 years, 3 months
Hibernate SVN: r14287 - in branches/Branch_3_2/HibernateExt/tools/src: test/org/hibernate/tool/ide/completion and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2008-01-18 14:44:33 -0500 (Fri, 18 Jan 2008)
New Revision: 14287
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
Log:
Made code completion for HQL (previous comment were wrong ;) case insensitive (http://jira.jboss.com/jira/browse/JBIDE-1424)
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2008-01-18 19:22:46 UTC (rev 14286)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2008-01-18 19:44:33 UTC (rev 14287)
@@ -331,7 +331,7 @@
}
private void findMatchingWords(int cursorPosition, String prefix, String[] words, int kind, IHQLCompletionRequestor hcc) {
- int i = Arrays.binarySearch(words, prefix);
+ int i = Arrays.binarySearch(words, prefix.toLowerCase());
if(i<0) {
i = Math.abs(i+1);
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2008-01-18 19:22:46 UTC (rev 14286)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2008-01-18 19:44:33 UTC (rev 14287)
@@ -145,6 +145,17 @@
assertEquals(1, completionProposals.length);
assertEquals("x", completionProposals[0].getCompletion());
+
+ hcc.clear();
+ cc.getMatchingKeywords("FR", 3, hcc);
+ completionProposals = hcc.getCompletionProposals();
+ assertEquals(1, completionProposals.length);
+
+ hcc.clear();
+ cc.getMatchingFunctions( "MA", 2, hcc );
+ completionProposals = hcc.getCompletionProposals();
+ assertEquals(1, completionProposals.length);
+
}
public void testUnmappedClassFields() {
16 years, 3 months
Hibernate SVN: r14286 - in branches/Branch_3_2/HibernateExt/tools/src: test/org/hibernate/tool/ide/completion and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2008-01-18 14:22:46 -0500 (Fri, 18 Jan 2008)
New Revision: 14286
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
Log:
Made code completion for hbm.xml case insensitive (http://jira.jboss.com/jira/browse/JBIDE-1424)
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2008-01-17 21:04:06 UTC (rev 14285)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2008-01-18 19:22:46 UTC (rev 14286)
@@ -1,351 +1,350 @@
-package org.hibernate.tool.ide.completion;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.Collection;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.OneToMany;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.mapping.ToOne;
-import org.hibernate.mapping.Value;
-import org.hibernate.tool.hbm2x.Cfg2JavaTool;
-import org.hibernate.tool.hbm2x.pojo.EntityPOJOClass;
-
-/**
- * Completion based on a Configuration.
- * package protected for now - not meant to be used externally.
- *
- * @author Max Rydahl Andersen
- *
- */
-class ConfigurationCompletion {
-
- private final Configuration cfg;
-
- public ConfigurationCompletion(Configuration cfg) {
- this.cfg = cfg;
-
- }
-
- public void getMatchingImports(String prefix , IHQLCompletionRequestor collector) {
- getMatchingImports( prefix, prefix.length() , collector );
- }
-
- public void getMatchingImports(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
- Iterator iterator = cfg.getImports().entrySet().iterator();
- while ( iterator.hasNext() ) {
- Map.Entry entry = (Entry) iterator.next();
- String entityImport = (String) entry.getKey();
- String entityName = (String) entry.getValue();
-
- if(entityImport.startsWith(prefix)) {
- String remaining = entityImport.substring( prefix.length() );
- HQLCompletionProposal proposal = new HQLCompletionProposal(
- HQLCompletionProposal.ENTITY_NAME,
- cursorPosition);
- proposal.setCompletion( remaining );
- proposal.setSimpleName( entityImport );
- proposal.setReplaceStart( cursorPosition );
- proposal.setReplaceEnd( cursorPosition+0 ); // we don't replace anything here
-
- proposal.setShortEntityName( entityImport );
- proposal.setEntityName( entityName );
- collector.accept(proposal);
-
- }
- }
- }
-
- public void getMatchingKeywords(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
- findMatchingWords( cursorPosition, prefix, HQLAnalyzer.getHQLKeywords(), HQLCompletionProposal.KEYWORD, collector);
- }
-
- public void getMatchingFunctions(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
- findMatchingWords( cursorPosition, prefix, HQLAnalyzer.getHQLFunctionNames(), HQLCompletionProposal.FUNCTION, collector);
- }
-
- public void getMatchingProperties(String path, String prefix, IHQLCompletionRequestor hcc) {
- getMatchingProperties( path, prefix, prefix.length(), hcc );
- }
-
- public void getMatchingProperties(String path, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
- int idx = path.indexOf('/');
- if (idx == -1) { // root name
- PersistentClass cmd = getPersistentClass(path);
- if (cmd == null) {
- return;
- }
- addPropertiesToList(cmd, prefix, cursorPosition, hcc);
- } else {
- String baseEntityName = path.substring(0, idx);
- String propertyPath = path.substring(idx + 1);
- Value value = getNextAttributeType(baseEntityName, propertyPath);
- if (value == null) {
- return;
- }
-
- // Go to the next property (get the y of x/y/z when root is x)
- idx = propertyPath.indexOf('/');
- if (idx == -1) {
- path = "";
- } else {
- path = propertyPath.substring(idx + 1);
- }
- if (path.length() == 0) {
- // No properties left
- if (value instanceof Component) {
- addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
- } else if (value instanceof Collection && ((Collection)value).getElement() instanceof Component) {
- addPropertiesToList((Component) ((Collection)value).getElement(), prefix, cursorPosition, hcc);
- } else {
- addPropertiesToList(getPersistentClass( getReferencedEntityName( value ) ), prefix, cursorPosition, hcc);
- }
- } else {
- // Nested properties
- if (value instanceof Component) {
- // We need to find the first non-component type
- while (value instanceof Component && path.length() > 0) {
- value = getNextAttributeType((Component) value, path);
- if (value != null) {
- // Consume part of the canonical path
- idx = path.indexOf('/');
- if (idx != -1) {
- path = path.substring(idx + 1);
- } else {
- path = "";
- }
- }
- }
- if (value instanceof Component) {
- addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
- } else if (value != null) {
- if (path.length() > 0) {
- path = getReferencedEntityName( value ) + "/" + path;
- } else {
- path = getReferencedEntityName( value );
- }
- getMatchingProperties( path, prefix, cursorPosition, hcc );
- }
- } else {
- // Just call the method recursively to add our new type
- getMatchingProperties(getReferencedEntityName( value ) + "/" + path, prefix, cursorPosition, hcc);
- }
- }
- }
- }
-
- private String getReferencedEntityName(Value value) {
- if(value instanceof ToOne) {
- return ((ToOne)value).getReferencedEntityName();
- }
- if ( value instanceof Collection ) {
- Collection collection = ((Collection)value);
- Value element = collection.getElement();
- String elementType = getReferencedEntityName( element );
- if(collection.isIndexed()) {
- //TODO..list/map
- /*IndexedCollection idxCol = (IndexedCollection) collection;
- if(!idxCol.isList()) {
- Value idxElement = idxCol.getIndex();
- String indexType = getReferencedEntityName( value );
- genericDecl = indexType + "," + elementType;
- }*/
- }
- return elementType;
- }
-
- if(value instanceof OneToMany) {
- return ((OneToMany)value).getReferencedEntityName();
- }
-
- return null;
- }
-
- private void addPropertiesToList(PersistentClass cmd, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
- if (cmd == null) {
- return;
- }
- if (prefix == null) {
- prefix = "";
- }
-
- EntityPOJOClass pc = new EntityPOJOClass(cmd, new Cfg2JavaTool()); // TODO: we should extract the needed functionallity from this hbm2java class.
-
- Iterator allPropertiesIterator = pc.getAllPropertiesIterator();
- while ( allPropertiesIterator.hasNext() ) {
- Property property = (Property) allPropertiesIterator.next();
- String candidate = property.getName();
- if (prefix.length() == 0 || candidate.startsWith(prefix)) {
- HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
- proposal.setEntityName( cmd.getEntityName() );
- proposal.setProperty( property );
- proposal.setPropertyName( candidate );
- hcc.accept( proposal);
- }
- }
- }
-
- private HQLCompletionProposal createStartWithCompletionProposal(String prefix, int cursorPosition, int kind, String candidate) {
- HQLCompletionProposal proposal = new HQLCompletionProposal(kind, cursorPosition);
- proposal.setCompletion( candidate.substring( prefix.length() ) );
- proposal.setSimpleName( candidate );
- proposal.setReplaceEnd( cursorPosition );
- proposal.setReplaceStart( cursorPosition );
- return proposal;
- }
-
- /** returns PersistentClass for path. Can be null if path is an imported non-mapped class */
- private PersistentClass getPersistentClass(String path) {
- if(path==null) return null;
- String entityName = (String) cfg.getImports().get( path );
- if(entityName==null) {
- return cfg.getClassMapping( path ); // annotationconfiguration does not put full imports into imports.
- } else {
- return cfg.getClassMapping( entityName );
- }
- }
-
- public String getCanonicalPath(List qts, String name) {
- Map alias2Type = new HashMap();
- for (Iterator iter = qts.iterator(); iter.hasNext();) {
- EntityNameReference qt = (EntityNameReference) iter.next();
- alias2Type.put(qt.getAlias(), qt.getEntityName());
- }
- if (qts.size() == 1) {
- EntityNameReference visible = (EntityNameReference) qts.get(0);
- String alias = visible.getAlias();
- if (name.equals(alias)) {
- return visible.getEntityName();
- } else if (alias == null || alias.length() == 0 || alias.equals(visible.getEntityName())) {
- return visible.getEntityName() + "/" + name;
- }
- }
- return getCanonicalPath(new HashSet(), alias2Type, name);
- }
-
- private String getCanonicalPath(Set resolved, Map alias2Type, String name) {
- if (resolved.contains(name)) {
- // To prevent a stack overflow
- return name;
- }
- resolved.add(name);
- String type = (String) alias2Type.get(name);
- if (type != null) {
- return name.equals(type) ? name : getCanonicalPath(resolved, alias2Type, type);
- }
- int idx = name.lastIndexOf('.');
- if (idx == -1) {
- return type != null ? type : name;
- }
- String baseName = name.substring(0, idx);
- String prop = name.substring(idx + 1);
- if (isAliasKnown(alias2Type, baseName)) {
- return getCanonicalPath(resolved, alias2Type, baseName) + "/" + prop;
- } else {
- return name;
- }
- }
-
- private static boolean isAliasKnown(Map alias2Type, String alias) {
- if (alias2Type.containsKey(alias)) {
- return true;
- }
- int idx = alias.lastIndexOf('.');
- if (idx == -1) {
- return false;
- }
- return isAliasKnown(alias2Type, alias.substring(0, idx));
- }
-
- private Value getNextAttributeType(String type, String attributePath) {
- PersistentClass cmd = getPersistentClass( type );
- if (cmd == null) {
- return null;
- }
- String attribute;
- int idx = attributePath.indexOf('/');
- if (idx == -1) {
- attribute = attributePath;
- } else {
- attribute = attributePath.substring(0, idx);
- }
-
- String idName = cmd.getIdentifierProperty()==null?null:cmd.getIdentifierProperty().getName();
- if (attribute.equals(idName)) {
- return cmd.getIdentifierProperty().getValue();
- }
- try {
- Property property = cmd.getProperty( attribute );
- return property==null?null:property.getValue();
- } catch (HibernateException he) {
- return null;
- }
-
- }
-
- private Value getNextAttributeType(Component t, String attributeName) {
- int idx = attributeName.indexOf('/');
- if (idx != -1) {
- attributeName = attributeName.substring(0, idx);
- }
- Iterator names = t.getPropertyIterator();
- int i = 0;
- while ( names.hasNext() ) {
- Property element = (Property) names.next();
- String name = element.getName();
- if (attributeName.equals(name)) {
- return element.getValue();
- }
- i++;
- }
- return null;
- }
-
- void addPropertiesToList(Component t, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
- if (t == null) {
- return;
- }
- Iterator props = t.getPropertyIterator();
- int i = 0;
- while ( props.hasNext() ) {
- Property element = (Property) props.next();
- String candidate = element.getName();
- if (candidate.startsWith(prefix)) {
- HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
- //proposal.setEntityName( cmd.getEntityName() ); ...we don't know here..TODO: pass in the "path"
- proposal.setPropertyName( candidate );
- proposal.setProperty(element);
- hcc.accept( proposal);
- }
- i++;
- }
- }
-
- private void findMatchingWords(int cursorPosition, String prefix, String[] words, int kind, IHQLCompletionRequestor hcc) {
- int i = Arrays.binarySearch(words, prefix);
- if(i<0) {
- i = Math.abs(i+1);
- }
-
- for (int cnt = i; cnt < words.length; cnt++) {
- String word = words[cnt];
- if(word.startsWith(prefix)) {
- HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, kind, word );
- hcc.accept( proposal);
- } else {
- break;
- }
- }
- }
-
-}
+package org.hibernate.tool.ide.completion;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.ToOne;
+import org.hibernate.mapping.Value;
+import org.hibernate.tool.hbm2x.Cfg2JavaTool;
+import org.hibernate.tool.hbm2x.pojo.EntityPOJOClass;
+
+/**
+ * Completion based on a Configuration.
+ * package protected for now - not meant to be used externally.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+class ConfigurationCompletion {
+
+ private final Configuration cfg;
+
+ public ConfigurationCompletion(Configuration cfg) {
+ this.cfg = cfg;
+
+ }
+
+ public void getMatchingImports(String prefix , IHQLCompletionRequestor collector) {
+ getMatchingImports( prefix, prefix.length() , collector );
+ }
+
+ public void getMatchingImports(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
+ Iterator iterator = cfg.getImports().entrySet().iterator();
+ while ( iterator.hasNext() ) {
+ Map.Entry entry = (Entry) iterator.next();
+ String entityImport = (String) entry.getKey();
+ String entityName = (String) entry.getValue();
+
+ if(entityImport.toLowerCase().startsWith(prefix.toLowerCase())) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.ENTITY_NAME, entityImport );
+ proposal.setShortEntityName( entityImport );
+ proposal.setEntityName( entityName );
+ collector.accept(proposal);
+
+ }
+ }
+ }
+
+ public void getMatchingKeywords(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
+ findMatchingWords( cursorPosition, prefix, HQLAnalyzer.getHQLKeywords(), HQLCompletionProposal.KEYWORD, collector);
+ }
+
+ public void getMatchingFunctions(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
+ findMatchingWords( cursorPosition, prefix, HQLAnalyzer.getHQLFunctionNames(), HQLCompletionProposal.FUNCTION, collector);
+ }
+
+ public void getMatchingProperties(String path, String prefix, IHQLCompletionRequestor hcc) {
+ getMatchingProperties( path, prefix, prefix.length(), hcc );
+ }
+
+ public void getMatchingProperties(String path, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
+ int idx = path.indexOf('/');
+ if (idx == -1) { // root name
+ PersistentClass cmd = getPersistentClass(path);
+ if (cmd == null) {
+ return;
+ }
+ addPropertiesToList(cmd, prefix, cursorPosition, hcc);
+ } else {
+ String baseEntityName = path.substring(0, idx);
+ String propertyPath = path.substring(idx + 1);
+ Value value = getNextAttributeType(baseEntityName, propertyPath);
+ if (value == null) {
+ return;
+ }
+
+ // Go to the next property (get the y of x/y/z when root is x)
+ idx = propertyPath.indexOf('/');
+ if (idx == -1) {
+ path = "";
+ } else {
+ path = propertyPath.substring(idx + 1);
+ }
+ if (path.length() == 0) {
+ // No properties left
+ if (value instanceof Component) {
+ addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
+ } else if (value instanceof Collection && ((Collection)value).getElement() instanceof Component) {
+ addPropertiesToList((Component) ((Collection)value).getElement(), prefix, cursorPosition, hcc);
+ } else {
+ addPropertiesToList(getPersistentClass( getReferencedEntityName( value ) ), prefix, cursorPosition, hcc);
+ }
+ } else {
+ // Nested properties
+ if (value instanceof Component) {
+ // We need to find the first non-component type
+ while (value instanceof Component && path.length() > 0) {
+ value = getNextAttributeType((Component) value, path);
+ if (value != null) {
+ // Consume part of the canonical path
+ idx = path.indexOf('/');
+ if (idx != -1) {
+ path = path.substring(idx + 1);
+ } else {
+ path = "";
+ }
+ }
+ }
+ if (value instanceof Component) {
+ addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
+ } else if (value != null) {
+ if (path.length() > 0) {
+ path = getReferencedEntityName( value ) + "/" + path;
+ } else {
+ path = getReferencedEntityName( value );
+ }
+ getMatchingProperties( path, prefix, cursorPosition, hcc );
+ }
+ } else {
+ // Just call the method recursively to add our new type
+ getMatchingProperties(getReferencedEntityName( value ) + "/" + path, prefix, cursorPosition, hcc);
+ }
+ }
+ }
+ }
+
+ private String getReferencedEntityName(Value value) {
+ if(value instanceof ToOne) {
+ return ((ToOne)value).getReferencedEntityName();
+ }
+ if ( value instanceof Collection ) {
+ Collection collection = ((Collection)value);
+ Value element = collection.getElement();
+ String elementType = getReferencedEntityName( element );
+ if(collection.isIndexed()) {
+ //TODO..list/map
+ /*IndexedCollection idxCol = (IndexedCollection) collection;
+ if(!idxCol.isList()) {
+ Value idxElement = idxCol.getIndex();
+ String indexType = getReferencedEntityName( value );
+ genericDecl = indexType + "," + elementType;
+ }*/
+ }
+ return elementType;
+ }
+
+ if(value instanceof OneToMany) {
+ return ((OneToMany)value).getReferencedEntityName();
+ }
+
+ return null;
+ }
+
+ private void addPropertiesToList(PersistentClass cmd, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
+ if (cmd == null) {
+ return;
+ }
+ if (prefix == null) {
+ prefix = "";
+ }
+
+ EntityPOJOClass pc = new EntityPOJOClass(cmd, new Cfg2JavaTool()); // TODO: we should extract the needed functionallity from this hbm2java class.
+
+ Iterator allPropertiesIterator = pc.getAllPropertiesIterator();
+ while ( allPropertiesIterator.hasNext() ) {
+ Property property = (Property) allPropertiesIterator.next();
+ String candidate = property.getName();
+ if (prefix.length() == 0 || candidate.toLowerCase().startsWith(prefix.toLowerCase())) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
+ proposal.setEntityName( cmd.getEntityName() );
+ proposal.setProperty( property );
+ proposal.setPropertyName( candidate );
+ hcc.accept( proposal);
+ }
+ }
+ }
+
+ private HQLCompletionProposal createStartWithCompletionProposal(String prefix, int cursorPosition, int kind, String candidate) {
+ HQLCompletionProposal proposal = new HQLCompletionProposal(kind, cursorPosition);
+ if(candidate.startsWith(prefix)) {
+ proposal.setCompletion( candidate.substring(prefix.length()) );
+ proposal.setSimpleName( candidate );
+ proposal.setReplaceStart( cursorPosition );
+ proposal.setReplaceEnd( cursorPosition );
+ } else {
+ proposal.setCompletion( candidate );
+ proposal.setSimpleName( candidate );
+ proposal.setReplaceStart( cursorPosition - prefix.length() );// replace prefix
+ proposal.setReplaceEnd( cursorPosition );
+ }
+ return proposal;
+ }
+
+ /** returns PersistentClass for path. Can be null if path is an imported non-mapped class */
+ private PersistentClass getPersistentClass(String path) {
+ if(path==null) return null;
+ String entityName = (String) cfg.getImports().get( path );
+ if(entityName==null) {
+ return cfg.getClassMapping( path ); // annotationconfiguration does not put full imports into imports.
+ } else {
+ return cfg.getClassMapping( entityName );
+ }
+ }
+
+ public String getCanonicalPath(List qts, String name) {
+ Map alias2Type = new HashMap();
+ for (Iterator iter = qts.iterator(); iter.hasNext();) {
+ EntityNameReference qt = (EntityNameReference) iter.next();
+ alias2Type.put(qt.getAlias(), qt.getEntityName());
+ }
+ if (qts.size() == 1) {
+ EntityNameReference visible = (EntityNameReference) qts.get(0);
+ String alias = visible.getAlias();
+ if (name.equals(alias)) {
+ return visible.getEntityName();
+ } else if (alias == null || alias.length() == 0 || alias.equals(visible.getEntityName())) {
+ return visible.getEntityName() + "/" + name;
+ }
+ }
+ return getCanonicalPath(new HashSet(), alias2Type, name);
+ }
+
+ private String getCanonicalPath(Set resolved, Map alias2Type, String name) {
+ if (resolved.contains(name)) {
+ // To prevent a stack overflow
+ return name;
+ }
+ resolved.add(name);
+ String type = (String) alias2Type.get(name);
+ if (type != null) {
+ return name.equals(type) ? name : getCanonicalPath(resolved, alias2Type, type);
+ }
+ int idx = name.lastIndexOf('.');
+ if (idx == -1) {
+ return type != null ? type : name;
+ }
+ String baseName = name.substring(0, idx);
+ String prop = name.substring(idx + 1);
+ if (isAliasKnown(alias2Type, baseName)) {
+ return getCanonicalPath(resolved, alias2Type, baseName) + "/" + prop;
+ } else {
+ return name;
+ }
+ }
+
+ private static boolean isAliasKnown(Map alias2Type, String alias) {
+ if (alias2Type.containsKey(alias)) {
+ return true;
+ }
+ int idx = alias.lastIndexOf('.');
+ if (idx == -1) {
+ return false;
+ }
+ return isAliasKnown(alias2Type, alias.substring(0, idx));
+ }
+
+ private Value getNextAttributeType(String type, String attributePath) {
+ PersistentClass cmd = getPersistentClass( type );
+ if (cmd == null) {
+ return null;
+ }
+ String attribute;
+ int idx = attributePath.indexOf('/');
+ if (idx == -1) {
+ attribute = attributePath;
+ } else {
+ attribute = attributePath.substring(0, idx);
+ }
+
+ String idName = cmd.getIdentifierProperty()==null?null:cmd.getIdentifierProperty().getName();
+ if (attribute.equals(idName)) {
+ return cmd.getIdentifierProperty().getValue();
+ }
+ try {
+ Property property = cmd.getProperty( attribute );
+ return property==null?null:property.getValue();
+ } catch (HibernateException he) {
+ return null;
+ }
+
+ }
+
+ private Value getNextAttributeType(Component t, String attributeName) {
+ int idx = attributeName.indexOf('/');
+ if (idx != -1) {
+ attributeName = attributeName.substring(0, idx);
+ }
+ Iterator names = t.getPropertyIterator();
+ int i = 0;
+ while ( names.hasNext() ) {
+ Property element = (Property) names.next();
+ String name = element.getName();
+ if (attributeName.equals(name)) {
+ return element.getValue();
+ }
+ i++;
+ }
+ return null;
+ }
+
+ void addPropertiesToList(Component t, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
+ if (t == null) {
+ return;
+ }
+ Iterator props = t.getPropertyIterator();
+ int i = 0;
+ while ( props.hasNext() ) {
+ Property element = (Property) props.next();
+ String candidate = element.getName();
+ if (candidate.toLowerCase().startsWith(prefix.toLowerCase())) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
+ //proposal.setEntityName( cmd.getEntityName() ); ...we don't know here..TODO: pass in the "path"
+ proposal.setPropertyName( candidate );
+ proposal.setProperty(element);
+ hcc.accept( proposal);
+ }
+ i++;
+ }
+ }
+
+ private void findMatchingWords(int cursorPosition, String prefix, String[] words, int kind, IHQLCompletionRequestor hcc) {
+ int i = Arrays.binarySearch(words, prefix);
+ if(i<0) {
+ i = Math.abs(i+1);
+ }
+
+ for (int cnt = i; cnt < words.length; cnt++) {
+ String word = words[cnt];
+ if(word.toLowerCase().startsWith(prefix.toLowerCase())) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, kind, word );
+ hcc.accept( proposal);
+ } else {
+ break;
+ }
+ }
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2008-01-17 21:04:06 UTC (rev 14285)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2008-01-18 19:22:46 UTC (rev 14286)
@@ -74,7 +74,7 @@
hcc.clear();
cc.getMatchingImports( "pro", hcc );
- assertTrue("Completion should be case sensitive", hcc.getCompletionProposals().length==0);
+ assertTrue("Completion should not be case sensitive", hcc.getCompletionProposals().length==2);
hcc.clear();
cc.getMatchingImports( "StoreC", hcc );
@@ -108,8 +108,11 @@
hcc.clear();
cc.getMatchingProperties( "Product", "V", hcc );
- doTestFields(hcc.getCompletionProposals(), new String[0]);
+ doTestFields(hcc.getCompletionProposals(), new String[] {"version"} );
hcc.clear();
+
+ cc.getMatchingProperties( "Product", "X", hcc );
+ doTestFields(hcc.getCompletionProposals(), new String[0] );
}
public void testGetStoreFields() {
@@ -280,6 +283,31 @@
}
}
+ public void testBasicFromPartialDifferentCaseEntityName() {
+ Collector c = new Collector();
+
+ IHQLCodeAssist hqlEval = new HQLCodeAssist(sf);
+
+ String query = "from pro| ";
+ int caretPosition = getCaretPosition(query);
+ hqlEval.codeComplete(query, caretPosition, c);
+
+ HQLCompletionProposal[] completionProposals = c.getCompletionProposals();
+
+ assertEquals(2, completionProposals.length);
+ assertEquals("Product", completionProposals[0].getSimpleName());
+ assertEquals("Product", completionProposals[0].getCompletion());
+ assertEquals("ProductOwnerAddress", completionProposals[1].getSimpleName());
+ assertEquals("ProductOwnerAddress", completionProposals[1].getCompletion());
+ for (int i = 0; i < completionProposals.length; i++) {
+ HQLCompletionProposal proposal = completionProposals[i];
+ assertEquals(HQLCompletionProposal.ENTITY_NAME, proposal.getCompletionKind());
+ assertEquals(caretPosition, proposal.getCompletionLocation());
+ assertEquals(caretPosition-3, proposal.getReplaceStart());
+ assertEquals(caretPosition, proposal.getReplaceEnd());
+ }
+ }
+
public void testDottedFromPartialEntityName() {
Collector c = new Collector();
16 years, 3 months
Hibernate SVN: r14285 - in core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2: entity and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-01-17 16:04:06 -0500 (Thu, 17 Jan 2008)
New Revision: 14285
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java
Log:
Eliminate "FailureExpected" overrides of fixed tests
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java 2008-01-17 21:03:28 UTC (rev 14284)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticInvalidatedTransactionalTestCase.java 2008-01-17 21:04:06 UTC (rev 14285)
@@ -55,14 +55,6 @@
assertTrue("Synchronous mode", isSynchronous());
}
- // Known failures
+ // Known failures
- public void testEvictAllFailureExpected() {
- super.testEvictAll();
- }
-
- public void testRemoveAllFailureExpected() {
- super.testRemoveAll();
- }
-
}
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java 2008-01-17 21:03:28 UTC (rev 14284)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/PessimisticReadOnlyTestCase.java 2008-01-17 21:04:06 UTC (rev 14285)
@@ -48,15 +48,7 @@
return getTestSetup(suite, "pessimistic-entity");
}
- // Known failures
-
- public void testEvictAllFailureExpected() {
- super.testEvictAll();
- }
-
- public void testRemoveAllFailureExpected() {
- super.testRemoveAll();
- }
+ // Known failures
// Overrides
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java 2008-01-17 21:03:28 UTC (rev 14284)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticInvalidatedTransactionalTestCase.java 2008-01-17 21:04:06 UTC (rev 14285)
@@ -48,16 +48,8 @@
return getTestSetup(suite, "pessimistic-entity");
}
- // Known failures
+ // Known failures
- public void testEvictAllFailureExpected() {
- super.testEvictAll();
- }
-
- public void testRemoveAllFailureExpected() {
- super.testRemoveAll();
- }
-
// Overrides
@Override
Modified: core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java
===================================================================
--- core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java 2008-01-17 21:03:28 UTC (rev 14284)
+++ core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/PessimisticReadOnlyTestCase.java 2008-01-17 21:04:06 UTC (rev 14285)
@@ -48,15 +48,7 @@
return getTestSetup(suite, "pessimistic-entity");
}
- // Known failures
-
- public void testEvictAllFailureExpected() {
- super.testEvictAll();
- }
-
- public void testRemoveAllFailureExpected() {
- super.testRemoveAll();
- }
+ // Known failures
// Overrides
16 years, 3 months
Hibernate SVN: r14284 - core/trunk/cache-jbosscache2.
by hibernate-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-01-17 16:03:28 -0500 (Thu, 17 Jan 2008)
New Revision: 14284
Modified:
core/trunk/cache-jbosscache2/pom.xml
Log:
Move to JBoss Cache 2.1.0.CR3
Modified: core/trunk/cache-jbosscache2/pom.xml
===================================================================
--- core/trunk/cache-jbosscache2/pom.xml 2008-01-16 13:24:08 UTC (rev 14283)
+++ core/trunk/cache-jbosscache2/pom.xml 2008-01-17 21:03:28 UTC (rev 14284)
@@ -27,7 +27,7 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>2.1.0.CR2</version>
+ <version>2.1.0.CR3</version>
</dependency>
<!-- TODO Remove once JBC 2.1.0.GA uses JG 2.6.1 -->
<dependency>
16 years, 3 months
Hibernate SVN: r14283 - in search/trunk/src: java/org/hibernate/search/engine and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-16 08:24:08 -0500 (Wed, 16 Jan 2008)
New Revision: 14283
Modified:
search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
search/trunk/src/test/org/hibernate/search/test/bridge/BridgeTest.java
search/trunk/src/test/org/hibernate/search/test/bridge/Cloud.java
Log:
HSEARCH-149 EnumType failed on string to object
Modified: search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-01-16 01:02:22 UTC (rev 14282)
+++ search/trunk/src/java/org/hibernate/search/bridge/BridgeFactory.java 2008-01-16 13:24:08 UTC (rev 14283)
@@ -28,6 +28,7 @@
import org.hibernate.search.util.BinderHelper;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMember;
+import org.hibernate.annotations.common.reflection.ReflectionManager;
/**
* @author Emmanuel Bernard
@@ -124,7 +125,7 @@
return bridge;
}
- public static FieldBridge guessType(Field field, XMember member) {
+ public static FieldBridge guessType(Field field, XMember member, ReflectionManager reflectionManager) {
FieldBridge bridge = null;
org.hibernate.search.annotations.FieldBridge bridgeAnn;
//@Field bridge has priority over @FieldBridge
@@ -172,7 +173,7 @@
bridge = builtInBridges.get( returnType.getName() );
if ( bridge == null && returnType.isEnum() ) {
bridge = new TwoWayString2FieldBridgeAdaptor(
- new EnumBridge( (Class<? extends Enum>) returnType.getClass() )
+ new EnumBridge( (Class<? extends Enum>) reflectionManager.toClass( returnType ) )
);
}
}
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-01-16 01:02:22 UTC (rev 14282)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-01-16 13:24:08 UTC (rev 14283)
@@ -184,7 +184,7 @@
+ idKeywordName + " and " + BinderHelper.getAttributeName( member, documentIdAnn.name() ) );
}
idKeywordName = prefix + BinderHelper.getAttributeName( member, documentIdAnn.name() );
- FieldBridge fieldBridge = BridgeFactory.guessType( null, member );
+ FieldBridge fieldBridge = BridgeFactory.guessType( null, member, reflectionManager );
if ( fieldBridge instanceof TwoWayFieldBridge ) {
idBridge = (TwoWayFieldBridge) fieldBridge;
}
@@ -204,7 +204,7 @@
propertiesMetadata.fieldNames.add( fieldName );
propertiesMetadata.fieldStore.add( getStore( Store.YES ) );
propertiesMetadata.fieldIndex.add( getIndex( Index.UN_TOKENIZED ) );
- propertiesMetadata.fieldBridges.add( BridgeFactory.guessType( null, member ) );
+ propertiesMetadata.fieldBridges.add( BridgeFactory.guessType( null, member, reflectionManager ) );
// Field > property > entity analyzer
Analyzer analyzer = null; //no field analyzer
if ( analyzer == null ) analyzer = getAnalyzer( member );
@@ -322,7 +322,7 @@
propertiesMetadata.fieldNames.add( fieldName );
propertiesMetadata.fieldStore.add( getStore( fieldAnn.store() ) );
propertiesMetadata.fieldIndex.add( getIndex( fieldAnn.index() ) );
- propertiesMetadata.fieldBridges.add( BridgeFactory.guessType( fieldAnn, member ) );
+ propertiesMetadata.fieldBridges.add( BridgeFactory.guessType( fieldAnn, member, reflectionManager ) );
// Field > property > entity analyzer
Analyzer analyzer = getAnalyzer( fieldAnn.analyzer() );
if ( analyzer == null ) analyzer = getAnalyzer( member );
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/BridgeTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/BridgeTest.java 2008-01-16 01:02:22 UTC (rev 14282)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/BridgeTest.java 2008-01-16 13:24:08 UTC (rev 14283)
@@ -59,7 +59,11 @@
result = session.createFullTextQuery(query).list();
assertEquals( "null elements should not be stored", 0, result.size() ); //the query is dumb because restrictive
- s.delete( s.get( Cloud.class, cloud.getId() ) );
+ query = parser.parse("type:dog");
+ result = session.createFullTextQuery(query).setProjection( "type" ).list();
+ assertEquals( "Enum projection works", 1, result.size() ); //the query is dumb because restrictive
+
+ s.delete( s.get( Cloud.class, cloud.getId() ) );
tx.commit();
s.close();
Modified: search/trunk/src/test/org/hibernate/search/test/bridge/Cloud.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/bridge/Cloud.java 2008-01-16 01:02:22 UTC (rev 14282)
+++ search/trunk/src/test/org/hibernate/search/test/bridge/Cloud.java 2008-01-16 13:24:08 UTC (rev 14283)
@@ -236,7 +236,7 @@
this.dateMillisecond = dateMillisecond;
}
- @Field(index = Index.TOKENIZED )
+ @Field(index = Index.TOKENIZED, store = Store.YES)
public CloudType getType() {
return type;
}
16 years, 3 months