Hibernate SVN: r14303 - in core/branches/Branch_3_2: test/org/hibernate/test/event/collection and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-01-30 22:02:51 -0500 (Wed, 30 Jan 2008)
New Revision: 14303
Modified:
core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
Log:
HHH-2616 : backed out of changes that provide the affected owner ID from collection events due to unit test failures
Modified: core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java 2008-01-31 01:13:44 UTC (rev 14302)
+++ core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java 2008-01-31 03:02:51 UTC (rev 14303)
@@ -15,14 +15,11 @@
private final PersistentCollection collection;
private final Object affectedOwner;
- private final Serializable affectedOwnerId;
public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
super(source);
this.collection = collection;
this.affectedOwner = affectedOwner;
- this.affectedOwnerId =
- ( ( SessionImplementor ) source ).getPersistenceContext().getEntry( affectedOwner ).getId();
}
protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) {
@@ -36,8 +33,4 @@
public Object getAffectedOwner() {
return affectedOwner;
}
-
- public Serializable getAffectedOwnerId() {
- return affectedOwnerId;
- }
}
Modified: 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 2008-01-31 01:13:44 UTC (rev 14302)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java 2008-01-31 03:02:51 UTC (rev 14303)
@@ -763,11 +763,11 @@
ownerExpected,
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
);
+ //assertSame(
+ // ownerExpected.getId(),
+ // ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
+ //);
assertSame(
- ownerExpected.getId(),
- ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
- );
- assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);
}
Modified: 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 2008-01-31 01:13:44 UTC (rev 14302)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java 2008-01-31 03:02:51 UTC (rev 14303)
@@ -313,11 +313,11 @@
ownerExpected,
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
);
+ //assertSame(
+ // ownerExpected.getId(),
+ // ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
+ //);
assertSame(
- ownerExpected.getId(),
- ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
- );
- assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);
}
16 years, 10 months
Hibernate SVN: r14302 - in core/branches/Branch_3_2: src/org/hibernate/event and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-01-30 20:13:44 -0500 (Wed, 30 Jan 2008)
New Revision: 14302
Added:
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Entity.java
Modified:
core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java
core/branches/Branch_3_2/src/org/hibernate/hibernate-configuration-3.0.dtd
core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.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/ParentWithCollection.java
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/manytomany/ChildWithBidirectionalManyToMany.java
Log:
HHH-2616 : add new collection events to hibernate-configuration-3.0.dtd; added accessor for affected owner ID to AbstractCollectionEvent
Modified: core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/src/org/hibernate/event/AbstractCollectionEvent.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -1,6 +1,8 @@
//$Id: $
package org.hibernate.event;
+import java.io.Serializable;
+
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
@@ -13,11 +15,14 @@
private final PersistentCollection collection;
private final Object affectedOwner;
+ private final Serializable affectedOwnerId;
- public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
+ public AbstractCollectionEvent(PersistentCollection collection, EventSource source, Object affectedOwner) {
super(source);
this.collection = collection;
this.affectedOwner = affectedOwner;
+ this.affectedOwnerId =
+ ( ( SessionImplementor ) source ).getPersistenceContext().getEntry( affectedOwner ).getId();
}
protected static Object getLoadedOwner( PersistentCollection collection, EventSource source ) {
@@ -31,4 +36,8 @@
public Object getAffectedOwner() {
return affectedOwner;
}
+
+ public Serializable getAffectedOwnerId() {
+ return affectedOwnerId;
+ }
}
Modified: core/branches/Branch_3_2/src/org/hibernate/hibernate-configuration-3.0.dtd
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hibernate-configuration-3.0.dtd 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/src/org/hibernate/hibernate-configuration-3.0.dtd 2008-01-31 01:13:44 UTC (rev 14302)
@@ -34,10 +34,10 @@
<!ATTLIST collection-cache usage (read-only|read-write|nonstrict-read-write|transactional) #REQUIRED>
<!ELEMENT event (listener*)>
-<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|post-load|post-update|post-insert|post-delete|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED>
+<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED>
<!ELEMENT listener EMPTY>
-<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|post-load|post-update|post-insert|post-delete|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED>
+<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED>
<!ATTLIST listener class CDATA #REQUIRED>
<!ELEMENT session-factory (property*, mapping*, (class-cache|collection-cache)*, event*, listener*)>
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/AbstractCollectionEventTest.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -94,9 +94,9 @@
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
Child child = ( Child ) parent.getChildren().iterator().next();
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -119,9 +119,9 @@
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -143,9 +143,9 @@
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -167,9 +167,9 @@
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -183,8 +183,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.addChild( child );
tx.commit();
@@ -193,16 +193,20 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ ChildWithBidirectionalManyToMany childWithManyToMany = null;
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
if ( !( parent.getChildren() instanceof PersistentSet ) ) {
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && !( getParents( child ) instanceof PersistentSet ) ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( childWithManyToMany != null && !( childWithManyToMany.getParents() instanceof PersistentSet ) ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), childWithManyToMany, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), childWithManyToMany, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -226,9 +230,9 @@
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -254,9 +258,9 @@
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( newChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -272,8 +276,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child).getId() );
}
Collection oldCollection = parent.getChildren();
parent.newChildren( createCollection() );
@@ -284,16 +288,19 @@
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
// hmmm, the same parent was removed and re-added to the child's collection;
// should this be considered an update?
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -309,8 +316,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( oldChild instanceof ChildEntity ) {
- oldChild = ( ChildEntity ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild).getId() );
+ if ( oldChild instanceof Entity ) {
+ oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild).getId() );
}
Collection oldCollection = parent.getChildren();
parent.newChildren( createCollection() );
@@ -321,16 +328,19 @@
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPreCollectionRecreateListener(), newChild, index++ );
- checkResult( listeners, listeners.getPostCollectionRecreateListener(), newChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
@@ -346,8 +356,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
tx.commit();
@@ -356,14 +366,17 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents( ) ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -377,8 +390,8 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.clearChildren();
tx.commit();
@@ -387,14 +400,17 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( child ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany childWithManyToMany = ( ChildWithBidirectionalManyToMany ) child;
+ if ( ( ( PersistentCollection ) childWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), childWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -415,8 +431,8 @@
s = openSession();
tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( oldChild instanceof ChildEntity ) {
- oldChild = ( Child ) s.get( oldChild.getClass(), ( ( ChildEntity ) oldChild ).getId() );
+ if ( oldChild instanceof Entity ) {
+ oldChild = ( Child ) s.get( oldChild.getClass(), ( ( Entity ) oldChild ).getId() );
}
parent.removeChild( oldChild );
tx.commit();
@@ -425,14 +441,17 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -479,11 +498,11 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
- if ( child instanceof ChildEntity ) {
+ if ( child instanceof Entity ) {
s.delete( child );
}
s.delete( parent );
@@ -491,14 +510,14 @@
s.close();
int index = 0;
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionRemoveListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionRemoveListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionRemoveListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -513,8 +532,8 @@
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( Child ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
parent.removeChild( child );
otherParent.addChild( child );
@@ -524,8 +543,8 @@
if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
}
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
@@ -534,9 +553,9 @@
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -551,8 +570,8 @@
Transaction tx = s.beginTransaction();
parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
otherParent = ( ParentWithCollection ) s.get( otherParent.getClass(), otherParent.getId() );
- if ( child instanceof ChildEntity ) {
- child = ( ChildEntity ) s.get( child.getClass(), ( ( ChildEntity ) child ).getId() );
+ if ( child instanceof Entity ) {
+ child = ( Child ) s.get( child.getClass(), ( ( Entity ) child ).getId() );
}
otherParent.addAllChildren( parent.getChildren() );
parent.clearChildren();
@@ -565,16 +584,16 @@
if ( ( ( PersistentCollection ) otherParent.getChildren() ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, index++ );
}
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherParent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
@@ -598,24 +617,24 @@
if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ );
otherChildOrig = ( Child ) otherCollectionOrig.iterator().next();
- if ( otherChildOrig.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ );
+ if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
}
}
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherParent.getChildren(), index++ );
Child otherChild = ( Child ) otherParent.getChildren().iterator().next();
- if ( otherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherChild, index++ );
+ if ( otherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
- if ( otherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChild, index++ );
+ if ( otherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, index++ );
@@ -649,24 +668,24 @@
if ( ( ( PersistentCollection ) otherCollectionOrig ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), otherParent, otherCollectionOrig, index++ );
otherChildOrig = ( Child ) otherCollectionOrig.iterator().next();
- if ( otherChildOrig.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherChildOrig, index++ );
+ if ( otherChildOrig instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
}
}
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, otherOtherParent.getChildren(), index++ );
Child otherOtherChild = ( Child ) otherOtherParent.getChildren().iterator().next();
- if ( otherOtherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), otherOtherChild, index++ );
+ if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherCollectionOrig, index++ );
- if ( otherOtherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherChildOrig, index++ );
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ );
+ if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherChildOrig, index++ );
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherParent, otherOtherParent.getChildren(), index++ );
@@ -677,9 +696,9 @@
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherParent, otherOtherParent.getChildren(), index++ );
checkResult( listeners, listeners.getPreCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), otherOtherParent, otherOtherCollectionOrig, index++ );
- if ( otherOtherChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), otherOtherChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), otherOtherChild, index++ );
+ if ( otherOtherChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) otherOtherChild, index++ );
}
checkResult( listeners, listeners.getPreCollectionRecreateListener(), otherOtherParent, index++ );
checkResult( listeners, listeners.getPostCollectionRecreateListener(), otherOtherParent, index++ );
@@ -721,11 +740,6 @@
return parent;
}
- protected Collection getParents( Child child ) {
- return ( ( child instanceof ChildWithBidirectionalManyToMany )
- ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
- : null );
- }
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
ParentWithCollection parent,
@@ -734,14 +748,14 @@
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Child child,
+ ChildWithBidirectionalManyToMany child,
int index) {
- checkResult( listeners, listenerExpected, child, getParents( child ), index );
+ checkResult( listeners, listenerExpected, child, child.getParents(), index );
}
protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Object ownerExpected,
+ Entity ownerExpected,
Collection collExpected,
int index) {
assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
@@ -750,6 +764,10 @@
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
);
assertSame(
+ ownerExpected.getId(),
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
+ );
+ assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);
}
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/BrokenCollectionEventTest.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -112,7 +112,7 @@
/*
public void testUpdateDetachedParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
- AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
Child oldChild = ( Child ) parent.getChildren().iterator().next();
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
@@ -126,9 +126,9 @@
int index = 0;
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) oldChild, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@@ -186,7 +186,7 @@
/*
public void testUpdateParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
- AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
Child oldChild = ( Child ) parent.getChildren().iterator().next();
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
@@ -204,14 +204,18 @@
if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
}
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = null;
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChildWithManyToMany != null ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@@ -221,7 +225,7 @@
public void testUpdateMergedParentOneChildToNullFailureExpected() {
CollectionListeners listeners = new CollectionListeners( getSessions() );
- AbstractParentWithCollection parent = createParentWithOneChild( "parent", "child" );
+ ParentWithCollection parent = createParentWithOneChild( "parent", "child" );
assertEquals( 1, parent.getChildren().size() );
listeners.clear();
Session s = openSession();
@@ -233,14 +237,18 @@
s.close();
int index = 0;
Child oldChild = ( Child ) oldCollection.iterator().next();
- if ( oldChild.hasBidirectionalManyToMany() && ( ( PersistentCollection ) getParents( oldChild ) ).wasInitialized() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), oldChild, index++ );
+ ChildWithBidirectionalManyToMany oldChildWithManyToMany = null;
+ if ( oldChild instanceof ChildWithBidirectionalManyToMany ) {
+ oldChildWithManyToMany = ( ChildWithBidirectionalManyToMany ) oldChild;
+ if ( ( ( PersistentCollection ) oldChildWithManyToMany.getParents() ).wasInitialized() ) {
}
+ checkResult( listeners, listeners.getInitializeCollectionListener(), oldChildWithManyToMany, index++ );
+ }
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
- if ( oldChild.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChild, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChild, index++ );
+ if ( oldChildWithManyToMany != null ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), oldChildWithManyToMany, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), oldChildWithManyToMany, index++ );
}
// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
@@ -282,27 +290,22 @@
return parent;
}
- private Collection getParents( Child child ) {
- return ( ( child instanceof ChildWithBidirectionalManyToMany )
- ? ( ( ChildWithBidirectionalManyToMany ) child ).getParents()
- : null );
- }
- private void checkResult(CollectionListeners listeners,
+ protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
ParentWithCollection parent,
int index) {
checkResult( listeners, listenerExpected, parent, parent.getChildren(), index );
}
- private void checkResult(CollectionListeners listeners,
+ protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Child child,
+ ChildWithBidirectionalManyToMany child,
int index) {
- checkResult( listeners, listenerExpected, child, getParents( child ), index );
+ checkResult( listeners, listenerExpected, child, child.getParents(), index );
}
- private void checkResult(CollectionListeners listeners,
+ protected void checkResult(CollectionListeners listeners,
CollectionListeners.Listener listenerExpected,
- Object ownerExpected,
+ Entity ownerExpected,
Collection collExpected,
int index) {
assertSame( listenerExpected, listeners.getListenersCalled().get( index ) );
@@ -311,6 +314,10 @@
( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwner()
);
assertSame(
+ ownerExpected.getId(),
+ ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerId()
+ );
+ assertSame(
collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection()
);
}
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Child.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -27,8 +27,6 @@
*/
public interface Child {
- boolean hasBidirectionalManyToMany();
-
String getName();
void setName(String name);
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildEntity.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -25,10 +25,9 @@
*
* @author Gail Badner
*/
-public class ChildEntity extends ChildValue {
+public class ChildEntity extends ChildValue implements Entity {
private Long id;
-
public ChildEntity() {
super();
}
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ChildValue.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -35,10 +35,6 @@
this.name = name;
}
- public boolean hasBidirectionalManyToMany() {
- return false;
- }
-
public String getName() {
return name;
}
Added: core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Entity.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Entity.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/Entity.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -0,0 +1,14 @@
+package org.hibernate.test.event.collection;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gbadner
+ * Date: Jan 30, 2008
+ * Time: 2:39:37 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface Entity {
+ Long getId();
+
+ void setId(Long id);
+}
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/ParentWithCollection.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -27,7 +27,7 @@
*
* @author Gail Badner
*/
-public interface ParentWithCollection {
+public interface ParentWithCollection extends Entity {
void newChildren(Collection collection);
Child createChild(String name);
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -21,12 +21,13 @@
*/
package org.hibernate.test.event.collection.association;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
import org.hibernate.test.event.collection.AbstractCollectionEventTest;
+import org.hibernate.test.event.collection.ChildEntity;
import org.hibernate.test.event.collection.CollectionListeners;
-import org.hibernate.test.event.collection.ChildEntity;
import org.hibernate.test.event.collection.ParentWithCollection;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
+import org.hibernate.test.event.collection.association.bidirectional.manytomany.ChildWithBidirectionalManyToMany;
/**
*
@@ -52,14 +53,14 @@
s.close();
int index = 0;
checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getInitializeCollectionListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getInitializeCollectionListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, index++ );
checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, index++ );
- if ( child.hasBidirectionalManyToMany() ) {
- checkResult( listeners, listeners.getPreCollectionUpdateListener(), child, index++ );
- checkResult( listeners, listeners.getPostCollectionUpdateListener(), child, index++ );
+ if ( child instanceof ChildWithBidirectionalManyToMany ) {
+ checkResult( listeners, listeners.getPreCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
+ checkResult( listeners, listeners.getPostCollectionUpdateListener(), ( ChildWithBidirectionalManyToMany ) child, index++ );
}
checkNumberOfResults( listeners, index );
}
Modified: 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 2008-01-30 22:55:47 UTC (rev 14301)
+++ core/branches/Branch_3_2/test/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java 2008-01-31 01:13:44 UTC (rev 14302)
@@ -40,10 +40,6 @@
this.parents = parents;
}
- public boolean hasBidirectionalManyToMany() {
- return true;
- }
-
public Collection getParents() {
return parents;
}
16 years, 10 months
Hibernate SVN: r14301 - search/trunk/src/test/org/hibernate/search/test/embedded.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-30 17:55:47 -0500 (Wed, 30 Jan 2008)
New Revision: 14301
Modified:
search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
Log:
style
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-01-30 22:47:58 UTC (rev 14300)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-01-30 22:55:47 UTC (rev 14301)
@@ -12,10 +12,8 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.event.PostCollectionRecreateEventListener;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.event.PostUpdateEventListener;
-import org.hibernate.event.PostCollectionUpdateEventListener;
import org.hibernate.event.PostCollectionRemoveEventListener;
+import org.hibernate.event.PostCollectionUpdateEventListener;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.event.FullTextIndexCollectionEventListener;
16 years, 10 months
Hibernate SVN: r14300 - in search/trunk/src: java/org/hibernate/search/backend and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-30 17:47:58 -0500 (Wed, 30 Jan 2008)
New Revision: 14300
Added:
search/trunk/src/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java
search/trunk/src/java/org/hibernate/search/lucene/
Modified:
search/trunk/src/java/org/hibernate/search/backend/WorkType.java
search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
Log:
HSEARCH-56 use Hibernate collection events to index on collection change
Modified: search/trunk/src/java/org/hibernate/search/backend/WorkType.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/WorkType.java 2008-01-30 17:54:10 UTC (rev 14299)
+++ search/trunk/src/java/org/hibernate/search/backend/WorkType.java 2008-01-30 22:47:58 UTC (rev 14300)
@@ -13,6 +13,7 @@
ADD,
UPDATE,
DELETE,
+ COLLECTION,
/**
* Used to remove a specific instance
* of a class from an index.
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2008-01-30 17:54:10 UTC (rev 14299)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2008-01-30 22:47:58 UTC (rev 14300)
@@ -98,6 +98,7 @@
public void add(Work work, WorkQueue workQueue) {
//don't check for builder it's done in prepareWork
+ //FIXME WorkType.COLLECTION does not play well with batchSize
workQueue.add( work );
if ( batchSize > 0 && workQueue.size() >= batchSize ) {
WorkQueue subQueue = workQueue.splitQueue();
@@ -111,17 +112,33 @@
List<Work> queue = workQueue.getQueue();
int initialSize = queue.size();
List<LuceneWork> luceneQueue = new ArrayList<LuceneWork>( initialSize ); //TODO load factor for containedIn
+ /**
+ * Collection work type are process second, so if the owner entity has already been processed for whatever reason
+ * the work will be ignored.
+ * However if the owner entity has not been processed, an "UPDATE" work is executed
+ *
+ * Processing collection works last is mandatory to avoid reindexing a object to be deleted
+ */
+ processWorkByLayer( queue, initialSize, luceneQueue, Layer.FIRST );
+ processWorkByLayer( queue, initialSize, luceneQueue, Layer.SECOND );
+ workQueue.setSealedQueue( luceneQueue );
+ }
+
+ private void processWorkByLayer(List<Work> queue, int initialSize, List<LuceneWork> luceneQueue, Layer layer) {
for ( int i = 0 ; i < initialSize ; i++ ) {
Work work = queue.get( i );
- queue.set( i, null ); // help GC and avoid 2 loaded queues in memory
- Class entityClass = work.getEntityClass() != null ?
- work.getEntityClass() :
- Hibernate.getClass( work.getEntity() );
- DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( entityClass );
- if ( builder == null ) return; //or exception?
- builder.addWorkToQueue(entityClass, work.getEntity(), work.getId(), work.getType(), luceneQueue, searchFactoryImplementor );
+ if ( work != null) {
+ if ( layer.isRightLayer( work.getType() ) ) {
+ queue.set( i, null ); // help GC and avoid 2 loaded queues in memory
+ Class entityClass = work.getEntityClass() != null ?
+ work.getEntityClass() :
+ Hibernate.getClass( work.getEntity() );
+ DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( entityClass );
+ if ( builder == null ) continue; //or exception?
+ builder.addWorkToQueue(entityClass, work.getEntity(), work.getId(), work.getType(), luceneQueue, searchFactoryImplementor );
+ }
+ }
}
- workQueue.setSealedQueue( luceneQueue );
}
//TODO implements parallel batchWorkers (one per Directory)
@@ -151,4 +168,15 @@
}
}
+ private static enum Layer {
+ FIRST,
+ SECOND;
+
+ public boolean isRightLayer(WorkType type) {
+ if (this == FIRST && type != WorkType.COLLECTION) return true;
+ if (this == SECOND && type == WorkType.COLLECTION) return true;
+ return false;
+ }
+ }
+
}
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-01-30 17:54:10 UTC (rev 14299)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-01-30 22:47:58 UTC (rev 14300)
@@ -392,7 +392,7 @@
//TODO could we use T instead of EntityClass?
public void addWorkToQueue(Class entityClass, T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
- //TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition
+ //TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition
for (LuceneWork luceneWork : queue) {
//any work on the same entity should be ignored
if ( luceneWork.getEntityClass() == entityClass
@@ -418,7 +418,7 @@
else if ( workType == WorkType.PURGE_ALL ) {
queue.add( new PurgeAllLuceneWork( entityClass ) );
}
- else if ( workType == WorkType.UPDATE ) {
+ else if ( workType == WorkType.UPDATE || workType == WorkType.COLLECTION ) {
Document doc = getDocument( entity, id );
/**
* even with Lucene 2.1, use of indexWriter to update is not an option
Added: search/trunk/src/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java (rev 0)
+++ search/trunk/src/java/org/hibernate/search/event/FullTextIndexCollectionEventListener.java 2008-01-30 22:47:58 UTC (rev 14300)
@@ -0,0 +1,49 @@
+//$
+package org.hibernate.search.event;
+
+import java.io.Serializable;
+
+import org.hibernate.event.PostCollectionRecreateEventListener;
+import org.hibernate.event.PostCollectionRemoveEventListener;
+import org.hibernate.event.PostCollectionUpdateEventListener;
+import org.hibernate.event.PostCollectionRecreateEvent;
+import org.hibernate.event.PostCollectionRemoveEvent;
+import org.hibernate.event.PostCollectionUpdateEvent;
+import org.hibernate.event.AbstractEvent;
+import org.hibernate.search.backend.WorkType;
+
+/**
+ * Support collection event listening (starts from hibernate core 3.2.6)
+ * FIXME deprecate as soon as we target Core 3.3 and merge back into the superclass
+ *
+ * @author Emmanuel Bernard
+ */
+public class FullTextIndexCollectionEventListener extends FullTextIndexEventListener
+ implements PostCollectionRecreateEventListener,
+ PostCollectionRemoveEventListener,
+ PostCollectionUpdateEventListener {
+ public void onPostRecreateCollection(PostCollectionRecreateEvent event) {
+ Object entity = event.getAffectedOwner();
+ if ( used && searchFactoryImplementor.getDocumentBuilders().containsKey( entity.getClass() ) ) {
+ processWork( entity, getId( entity, event ), WorkType.COLLECTION, event );
+ }
+ }
+
+ private Serializable getId(Object entity, AbstractEvent event) {
+ return event.getSession().getPersistenceContext().getEntry( entity ).getId();
+ }
+
+ public void onPostRemoveCollection(PostCollectionRemoveEvent event) {
+ Object entity = event.getAffectedOwner();
+ if ( used && searchFactoryImplementor.getDocumentBuilders().containsKey( entity.getClass() ) ) {
+ processWork( entity, getId( entity, event ), WorkType.COLLECTION, event );
+ }
+ }
+
+ public void onPostUpdateCollection(PostCollectionUpdateEvent event) {
+ Object entity = event.getAffectedOwner();
+ if ( used && searchFactoryImplementor.getDocumentBuilders().containsKey( entity.getClass() ) ) {
+ processWork( entity, getId( entity, event ), WorkType.COLLECTION, event );
+ }
+ }
+}
Modified: search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2008-01-30 17:54:10 UTC (rev 14299)
+++ search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2008-01-30 22:47:58 UTC (rev 14300)
@@ -35,11 +35,9 @@
public class FullTextIndexEventListener implements PostDeleteEventListener, PostInsertEventListener,
PostUpdateEventListener, Initializable {
- private static final Log log = LogFactory.getLog( FullTextIndexEventListener.class );
- private boolean used;
+ protected boolean used;
+ protected SearchFactoryImplementor searchFactoryImplementor;
- private SearchFactoryImplementor searchFactoryImplementor;
-
public void initialize(Configuration cfg) {
searchFactoryImplementor = SearchFactoryImpl.getSearchFactory( cfg );
String indexingStrategy = cfg.getProperties().getProperty( Environment.INDEXING_STRATEGY, "event" );
@@ -88,7 +86,7 @@
}
}
- private void processWork(Object entity, Serializable id, WorkType workType, AbstractEvent event) {
+ protected void processWork(Object entity, Serializable id, WorkType workType, AbstractEvent event) {
Work work = new Work(entity, id, workType);
searchFactoryImplementor.getWorker().performWork( work, event.getSession() );
}
Modified: search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-01-30 17:54:10 UTC (rev 14299)
+++ search/trunk/src/test/org/hibernate/search/test/embedded/EmbeddedTest.java 2008-01-30 22:47:58 UTC (rev 14300)
@@ -11,8 +11,14 @@
import org.apache.lucene.search.TermQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.event.PostCollectionRecreateEventListener;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.event.PostCollectionUpdateEventListener;
+import org.hibernate.event.PostCollectionRemoveEventListener;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
+import org.hibernate.search.event.FullTextIndexCollectionEventListener;
import org.hibernate.search.test.SearchTestCase;
/**
@@ -231,6 +237,14 @@
}
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ FullTextIndexCollectionEventListener del = new FullTextIndexCollectionEventListener();
+ cfg.getEventListeners().setPostCollectionRecreateEventListeners( new PostCollectionRecreateEventListener[]{del} );
+ cfg.getEventListeners().setPostCollectionUpdateEventListeners( new PostCollectionUpdateEventListener[]{del} );
+ cfg.getEventListeners().setPostCollectionRemoveEventListeners( new PostCollectionRemoveEventListener[]{del} );
+ }
+
protected Class[] getMappings() {
return new Class[] {
Tower.class,
16 years, 10 months
Hibernate SVN: r14299 - annotations/trunk/src/java/org/hibernate/cfg/annotations.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-30 12:54:10 -0500 (Wed, 30 Jan 2008)
New Revision: 14299
Modified:
annotations/trunk/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
Log:
better exception description on @Temporal usage
Modified: annotations/trunk/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2008-01-30 17:51:29 UTC (rev 14298)
+++ annotations/trunk/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2008-01-30 17:54:10 UTC (rev 14299)
@@ -91,7 +91,7 @@
}
else {
throw new AnnotationException(
- "@Temporal should be set on a java.util.Date or java.util.Calendar property: "
+ "@Temporal should only be set on a java.util.Date or java.util.Calendar property: "
+ StringHelper.qualify( persistentClassName, propertyName )
);
}
16 years, 10 months
Hibernate SVN: r14298 - jpa-api/trunk/src/javax/persistence.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-01-30 12:51:29 -0500 (Wed, 30 Jan 2008)
New Revision: 14298
Modified:
jpa-api/trunk/src/javax/persistence/TemporalType.java
Log:
Javadoc cleaning
Modified: jpa-api/trunk/src/javax/persistence/TemporalType.java
===================================================================
--- jpa-api/trunk/src/javax/persistence/TemporalType.java 2008-01-28 22:18:35 UTC (rev 14297)
+++ jpa-api/trunk/src/javax/persistence/TemporalType.java 2008-01-30 17:51:29 UTC (rev 14298)
@@ -3,7 +3,7 @@
package javax.persistence;
/**
- * Type used to indicate a specific mapping of Date or Calendar.
+ * Type used to indicate a specific mapping of {@link java.util.Date} or {@link java.util.Calendar).
*/
public enum TemporalType {
/**
16 years, 10 months
Hibernate SVN: r14297 - in core/trunk: core/src/main/java/org/hibernate/cfg and 14 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2008-01-28 17:18:35 -0500 (Mon, 28 Jan 2008)
New Revision: 14297
Added:
core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEventListener.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEventListener.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEventListener.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEventListener.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEventListener.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java
core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEventListener.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractParentWithCollection.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionEventSuite.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionListeners.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml
Modified:
core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java
core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java
core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java
core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java
core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
core/trunk/core/src/main/java/org/hibernate/event/EventListeners.java
core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java
core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java
Log:
HHH-2616 : collection recreate/remove/update events and listeners
Modified: core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionRecreateAction.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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,8 +26,12 @@
}
public void execute() throws HibernateException {
+ // 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 PersistentCollection collection = getCollection();
+ preRecreate();
+
getPersister().recreate( collection, getKey(), getSession() );
getSession().getPersistenceContext()
@@ -31,12 +40,37 @@
evict();
+ postRecreate();
+
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor()
.recreateCollection( getPersister().getRole() );
}
}
+ 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/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionRemoveAction.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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,20 +18,71 @@
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 {
- 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) {
@@ -36,18 +93,39 @@
evict();
+ postRemove();
+
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor()
.removeCollection( getPersister().getRole() );
}
}
+ 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/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/action/CollectionUpdateAction.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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;
@@ -33,6 +38,8 @@
final PersistentCollection collection = getCollection();
boolean affectedByFilters = persister.isAffectedByEnabledFilters(session);
+ preUpdate();
+
if ( !collection.wasInitialized() ) {
if ( !collection.hasQueuedOperations() ) throw new AssertionFailure( "no queued adds" );
//do nothing - we only need to notify the cache...
@@ -62,12 +69,37 @@
evict();
+ postUpdate();
+
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor().
updateCollection( getPersister().getRole() );
}
}
+
+ 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/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/AbstractCollectionEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.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/trunk/core/src/main/java/org/hibernate/event/EventListeners.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/EventListeners.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/event/EventListeners.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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;
}
Modified: core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/event/InitializeCollectionEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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;
- }
-
- public PersistentCollection getCollection() {
- return collection;
- }
+ super(collection, source, getLoadedOwner( collection, source ) );
+ }
}
Added: core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEventListener.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRecreateEventListener.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEventListener.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionRemoveEventListener.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEventListener.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PostCollectionUpdateEventListener.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEventListener.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRecreateEventListener.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -0,0 +1,40 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+//$Id: $
+package org.hibernate.event;
+
+import org.hibernate.collection.PersistentCollection;
+
+/**
+ * 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/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEventListener.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionRemoveEventListener.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEvent.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEventListener.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreCollectionUpdateEventListener.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java 2008-01-28 20:17:23 UTC (rev 14296)
+++ core/trunk/core/src/main/java/org/hibernate/event/def/ReattachVisitor.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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 ) );
}
/**
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractParentWithCollection.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractParentWithCollection.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractParentWithCollection.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/Child.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildEntity.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ChildValue.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionEventSuite.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionEventSuite.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionEventSuite.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionListeners.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionListeners.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/CollectionListeners.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/ParentWithCollection.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/AbstractAssociationCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManyBagToSetMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/BidirectionalManyToManySetToSetMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ChildWithBidirectionalManyToMany.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/manytomany/ParentWithBidirectionalManyToMany.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManyBagMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/BidirectionalOneToManySetMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ChildWithManyToOne.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/bidirectional/onetomany/ParentWithBidirectionalOneToMany.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/ParentWithCollectionOfEntities.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/manytomany/UnidirectionalManyToManyBagMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManyBagMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/association/unidirectional/onetomany/UnidirectionalOneToManySetMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ParentWithCollectionOfValues.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagCollectionEventTest.java 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/event/collection/values/ValuesBagMapping.hbm.xml 2008-01-28 22:18:35 UTC (rev 14297)
@@ -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, 10 months
Hibernate SVN: r14295 - core/branches/Branch_3_2/lib.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2008-01-28 15:16:36 -0500 (Mon, 28 Jan 2008)
New Revision: 14295
Removed:
core/branches/Branch_3_2/lib/connector.jar
core/branches/Branch_3_2/lib/connector.licence.txt
core/branches/Branch_3_2/lib/jdbc2_0-stdext.jar
core/branches/Branch_3_2/lib/jdbc2_0-stdext.licence.txt
Log:
HHH-3085 & HHH-3086 : remove unnecessary jars
Deleted: core/branches/Branch_3_2/lib/connector.jar
===================================================================
(Binary files differ)
Deleted: core/branches/Branch_3_2/lib/connector.licence.txt
===================================================================
--- core/branches/Branch_3_2/lib/connector.licence.txt 2008-01-28 20:16:15 UTC (rev 14294)
+++ core/branches/Branch_3_2/lib/connector.licence.txt 2008-01-28 20:16:36 UTC (rev 14295)
@@ -1,48 +0,0 @@
-Sun Microsystems, Inc.
-Binary Code License Agreement
-
-READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY "AGREEMENT") CAREFULLY BEFORE OPENING THE SOFTWARE MEDIA PACKAGE. BY OPENING THE SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS AGREEMENT. IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY, INDICATE YOUR ACCEPTANCE OF THESE TERMS BY SELECTING THE "ACCEPT" BUTTON AT THE END OF THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL THESE TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUND OR, IF THE SOFTWARE IS ACCESSED ELECTRONICALLY, SELECT THE "DECLINE" BUTTON AT THE END OF THIS AGREEMENT.
-
-1. LICENSE TO USE. Sun grants you a non-exclusive and non-transferable license for the internal use only of the accompanying software and documentation and any error corrections provided by Sun (collectively "Software"), by the number of users and the class of computer hardware for which the corresponding fee has been paid.
-
-2. RESTRICTIONS. Software is confidential and copyrighted. Title to Software and all associated intellectual property rights is retained by Sun and/or its licensors. Except as specifically authorized in any Supplemental License Terms, you may not make copies of Software, other than a single copy of Software for archival purposes. Unless enforcement is prohibited by applicable law, you may not modify, decompile, or reverse engineer Software. You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. Sun disclaims any express or implied warranty of fitness for such uses. No right, title or interest in or to any trademark, service mark, logo or trade name of Sun or its licensors is granted under this Agreement.
-
-3. LIMITED WARRANTY. Sun warrants to you that for a period of ninety (90) days from the date of purchase, as evidenced by a copy of the receipt, the media on which Software is furnished (if any) will be free of defects in materials and workmanship under normal use. Except for the foregoing, Software is provided "AS IS". Your exclusive remedy and Sun's entire liability under this limited warranty will be at Sun's option to replace Software media or refund the fee paid for Software.
-
-4. DISCLAIMER OF WARRANTY. UNLESS SPECIFIED IN THIS AGREEMENT, ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.
-
-5. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event will Sun's liability to you, whether in contract, tort (including negligence), or otherwise, exceed the amount paid by you for Software under this Agreement. The foregoing limitations will apply even if the above stated warranty fails of its essential purpose.
-
-6. Termination. This Agreement is effective until terminated. You may terminate this Agreement at any time by destroying all copies of Software. This Agreement will terminate immediately without notice from Sun if you fail to comply with any provision of this Agreement. Upon Termination, you must destroy all copies of Software.
-
-7. Export Regulations. All Software and technical data delivered under this Agreement are subject to US export control laws and may be subject to export or import regulations in other countries. You agree to comply strictly with all such laws and regulations and acknowledge that you have the responsibility to obtain such licenses to export, re-export, or import as may be required after delivery to you.
-
-8. U.S. Government Restricted Rights. If Software is being acquired by or on behalf of the U.S. Government or by a U.S. Government prime contractor or subcontractor (at any tier), then the Government's rights in Software and accompanying documentation will be only as set forth in this Agreement; this is in accordance with 48 CFR 227.7201 through 227.7202-4 (for Department of Defense (DOD) acquisitions) and with 48 CFR 2.101 and 12.212 (for non-DOD acquisitions).
-
-9. Governing Law. Any action related to this Agreement will be governed by California law and controlling U.S. federal law. No choice of law rules of any jurisdiction will apply.
-
-10. Severability. If any provision of this Agreement is held to be unenforceable, this Agreement will remain in effect with the provision omitted, unless omission would frustrate the intent of the parties, in which case this Agreement will immediately terminate.
-
-11. Integration. This Agreement is the entire agreement between you and Sun relating to its subject matter. It supersedes all prior or contemporaneous oral or written communications, proposals, representations and warranties and prevails over any conflicting or additional terms of any quote, order, acknowledgment, or other communication between the parties relating to its subject matter during the term of this Agreement. No modification of this Agreement will be binding, unless in writing and signed by an authorized representative of each party.
-
-JAVA(TM) INTERFACE CLASSES
-
-J2EE(TM) CONNECTOR ARCHITECTURE, VERSION 1.0
-SUPPLEMENTAL LICENSE TERMS
-
-These supplemental license terms ("Supplemental Terms") add to or modify the terms of the Binary Code License Agreement (collectively, the "Agreement"). Capitalized terms not defined in these Supplemental Terms shall have the same meanings ascribed to them in the Agreement. These Supplemental Terms shall supersede any inconsistent or conflicting terms in the Agreement, or in any license contained within the Software.
-
-1. Software Internal Use and Development License Grant. Subject to the terms and conditions of this Agreement, including, but not limited to Section 3 (Java(TM) Technology Restrictions) of these Supplemental Terms, Sun grants you a non-exclusive, non-transferable, limited license to reproduce internally and use internally the binary form of the Software, complete and unmodified, for the sole purpose of designing, developing and testing your Java applets and applications ("Programs").
-
-2. License to Distribute Software. In addition to the license granted in Section 1 (Software Internal Use and Development License Grant) of these Supplemental Terms, subject to the terms and conditions of this Agreement, including but not limited to Section 3 (Java Technology Restrictions), Sun grants you a non-exclusive, non-transferable, limited license to reproduce and distribute the Software in binary form only, provided that you (i) distribute the Software complete and unmodified and only bundled as part of your Programs, (ii) do not distribute additional software intended to replace any component(s) of the Software, (iii) do not remove or alter any proprietary legends or notices contained in the Software, (iv) only distribute the Software subject to a license agreement that protects Sun's interests consistent with the terms contained in this Agreement, and (v) agree to defend and indemnify Sun and its licensors from and against any damages, costs, liabilities, settle!
ment amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software.
-
-3. Java Technology Restrictions. You may not modify the Java Platform Interface ("JPI", identified as classes contained within the "java" package or any subpackages of the "java" package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI. In the event that you create an additional class and associated API(s) which (i) extends the functionality of the Java Platform, and (ii) is exposed to third party software developers for the purpose of developing additional software which invokes such additional API, you must promptly publish broadly an accurate specification for such API for free use by all developers. You may not create, or authorize your licensees to create additional classes, interfaces, or subpackages that are in any way identified as "java", "javax", "sun" or similar convention as specified by Sun in any naming convention designation.
-
-4. Trademarks and Logos. You acknowledge and agree as between you and Sun that Sun owns the SUN, SOLARIS, JAVA, JINI, FORTE, and iPLANET trademarks and all SUN, SOLARIS, JAVA, JINI, FORTE, and iPLANET-related trademarks, service marks, logos and other brand designations ("Sun Marks"), and you agree to comply with the Sun Trademark and Logo Usage Requirements currently located at http://www.sun.com/policies/trademarks. Any use you make of the Sun Marks inures to Sun's benefit.
-
-5. Source Code. Software may contain source code that is provided solely for reference purposes pursuant to the terms of this Agreement. Source code may not be redistributed unless expressly provided for in this Agreement.
-
-6. Termination for Infringement. Either party may terminate this Agreement immediately should any Software become, or in either party's opinion be likely to become, the subject of a claim of infringement of any intellectual property right.
-
-For inquiries please contact: Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303
-
Deleted: core/branches/Branch_3_2/lib/jdbc2_0-stdext.jar
===================================================================
(Binary files differ)
Deleted: core/branches/Branch_3_2/lib/jdbc2_0-stdext.licence.txt
===================================================================
--- core/branches/Branch_3_2/lib/jdbc2_0-stdext.licence.txt 2008-01-28 20:16:15 UTC (rev 14294)
+++ core/branches/Branch_3_2/lib/jdbc2_0-stdext.licence.txt 2008-01-28 20:16:36 UTC (rev 14295)
@@ -1,199 +0,0 @@
- Sun Microsystems, Inc.
-Binary Code License Agreement
-
-READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED
-SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY
-"AGREEMENT") CAREFULLY BEFORE OPENING THE SOFTWARE
-MEDIA PACKAGE. BY OPENING THE SOFTWARE MEDIA
-PACKAGE, YOU AGREE TO THE TERMS OF THIS AGREEMENT.
-IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY,
-INDICATE YOUR ACCEPTANCE OF THESE TERMS BY
-SELECTING THE "ACCEPT" BUTTON AT THE END OF THIS
-AGREEMENT. IF YOU DO NOT AGREE TO ALL THESE
-TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR
-PLACE OF PURCHASE FOR A REFUND OR, IF THE SOFTWARE
-IS ACCESSED ELECTRONICALLY, SELECT THE "DECLINE"
-BUTTON AT THE END OF THIS AGREEMENT.
-
-1. LICENSE TO USE. Sun grants you a
-non-exclusive and non-transferable license for the
-internal use only of the accompanying software and
-documentation and any error corrections provided
-by Sun (collectively "Software"), by the number of
-users and the class of computer hardware for which
-the corresponding fee has been paid.
-
-2. RESTRICTIONS Software is confidential and
-copyrighted. Title to Software and all associated
-intellectual property rights is retained by Sun
-and/or its licensors. Except as specifically
-authorized in any Supplemental License Terms, you
-may not make copies of Software, other than a
-single copy of Software for archival purposes.
-Unless enforcement is prohibited by applicable
-law, you may not modify, decompile, or reverse
-engineer Software. Software is not designed or
-licensed for use in on-line control of aircraft,
-air traffic, aircraft navigation or aircraft
-communications; or in the design, construction,
-operation or maintenance of any nuclear facility.
-No right, title or interest in or to any
-trademark, service mark, logo or trade name of Sun
-or its licensors is granted under this Agreement.
-
-3. LIMITED WARRANTY. Sun warrants to you that for
-a period of ninety (90) days from the date of
-purchase, as evidenced by a copy of the receipt,
-the media on which Software is furnished (if any)
-will be free of defects in materials and
-workmanship under normal use. Except for the
-foregoing, Software is provided "AS IS". Your
-exclusive remedy and Sun's entire liability under
-this limited warranty will be at Sun's option to
-replace Software media or refund the fee paid for
-Software.
-
-4. DISCLAIMER OF WARRANTY. UNLESS SPECIFIED IN
-THIS AGREEMENT, ALL EXPRESS OR IMPLIED CONDITIONS,
-REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
-IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
-PARTICULAR PURPOSE OR NON-INFRINGEMENT ARE
-DISCLAIMED, EXCEPT TO THE EXTENT THAT THESE
-DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.
-
-5. LIMITATION OF LIABILITY. TO THE EXTENT NOT
-PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS
-LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
-OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL,
-INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED
-REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT
-OF OR RELATED TO THE USE OF OR INABILITY TO USE
-SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES. In no event will
-Sun's liability to you, whether in contract, tort
-(including negligence), or otherwise, exceed the
-amount paid by you for Software under this
-Agreement. The foregoing limitations will apply
-even if the above stated warranty fails of its
-essential purpose.
-
-6. Termination. This Agreement is effective
-until terminated. You may terminate this
-Agreement at any time by destroying all copies of
-Software. This Agreement will terminate
-immediately without notice from Sun if you fail to
-comply with any provision of this Agreement. Upon
-Termination, you must destroy all copies of
-Software.
-
-7. Export Regulations. All Software and
-technical data delivered under this Agreement are
-subject to US export control laws and may be
-subject to export or import regulations in other
-countries. You agree to comply strictly with all
-such laws and regulations and acknowledge that you
-have the responsibility to obtain such licenses to
-export, re-export, or import as may be required
-after delivery to you.
-
-8. U.S. Government Restricted Rights. If
-Software is being acquired by or on behalf of the
-U.S. Government or by a U.S. Government prime
-contractor or subcontractor (at any tier), then
-the Government's rights in Software and
-accompanying documentation will be only as set
-forth in this Agreement; this is in accordance
-with 48 CFR 227.7201 through 227.7202-4 (for
-Department of Defense (DOD) acquisitions) and with
-48 CFR 2.101 and 12.212 (for non-DOD
-acquisitions).
-
-9. Governing Law. Any action related to this
-Agreement will be governed by California law and
-controlling U.S. federal law. No choice of law
-rules of any jurisdiction will apply.
-
-10. Severability. If any provision of this
-Agreement is held to be unenforceable, this
-Agreement will remain in effect with the provision
-omitted, unless omission would frustrate the
-intent of the parties, in which case this
-Agreement will immediately terminate.
-
-11. Integration. This Agreement is the entire
-agreement between you and Sun relating to its
-subject matter. It supersedes all prior or
-contemporaneous oral or written communications,
-proposals, representations and warranties and
-prevails over any conflicting or additional terms
-of any quote, order, acknowledgment, or other
-communication between the parties relating to its
-subject matter during the term of this Agreement.
-No modification of this Agreement will be binding,
-unless in writing and signed by an authorized
-representative of each party.
-
-For inquiries please contact: Sun Microsystems,
-Inc. 901 San Antonio Road, Palo Alto, California
-94303
-
-
-SUPPLEMENTAL LICENSE TERMS
-JDBCTM 2.0 INTERFACE CLASSES
-
-These supplemental license terms ("Supplement")
-add to or modify the terms of the Binary Code
-License Agreement (collectively, the
-"Agreement"). Capitalized terms not defined in
-this Supplement shall have the same meanings
-ascribed to them in the Agreement. These
-Supplement terms shall supersede any inconsistent
-or conflicting terms in the Agreement, or in any
-license contained within the Software.
-
-1. License to Distribute. Sun grants you a
-non-exclusive, non-transferable, limited license
-to reproduce and distribute the binary and/or
-source code form of the Software to third party
-end users through multiple tiers of distribution,
-provided that you: (i) distribute the Software
-complete and unmodified in its original Java
-Archive file, and only bundled as a part of your
-program that incorporates the Software
-("Program"); (ii) do not distribute additional
-software intended to replace any component(s) of
-the Software; (iii) agree to incorporate the most
-current version of the Software that was available
-from Sun no later than 180 days prior to each
-production release of the Program; (iv) do not
-remove or alter any proprietary legends or notices
-contained in or on the Software; (v) only
-distribute the Program pursuant to a license
-agreement that protects Sun's interest consistent
-with the terms contained in the Agreement; (vi)
-may not create, or authorize your licensees to cr!
-eate additional classes, interfaces, or
-subpackages that are contained in the "java"
-"javax" or "sun" packages or similar as specified
-by Sun in any class file naming convention; and
-(vii) agree to defend and indemnify Sun and its
-licensors from and against any damages, costs,
-liabilities, settlement amounts and/or expenses
-(including attorneys' fees) incurred in connection
-with any claim, lawsuit or action by any third
-party that arises or results from the use or
-distribution of any and all Programs.
-
-2. Trademarks and Logos. You acknowledge as
-between you and Sun that Sun owns the Java
-trademark and all Java-related trademarks, logos
-and icons including the Coffee Cup and Duke ("Java
-Marks") and agree to comply with the Java
-Trademark Guidelines at
-http://java.sun.com/trademarks.html.
-
-
-
-
-
-
\ No newline at end of file
16 years, 10 months
Hibernate SVN: r14294 - core/branches/Branch_3_2/lib.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2008-01-28 15:16:15 -0500 (Mon, 28 Jan 2008)
New Revision: 14294
Modified:
core/branches/Branch_3_2/lib/version.properties
Log:
HHH-3085 & HHH-3086 : remove unnecessary jars
Modified: core/branches/Branch_3_2/lib/version.properties
===================================================================
--- core/branches/Branch_3_2/lib/version.properties 2008-01-28 11:33:12 UTC (rev 14293)
+++ core/branches/Branch_3_2/lib/version.properties 2008-01-28 20:16:15 UTC (rev 14294)
@@ -108,11 +108,6 @@
## j2ee related
-jdbc-stdext.lib=jdbc2_0-stdext.jar
-jdbc-stdext.version=2.0
-jdbc-stdext.name=Standard Extension JDBC APIs
-jdbc-stdext.when=runtime, required for standalone operation (outside application server)
-
jta.lib=jta.jar
jta.name=Standard JTA API
jta.when=runtime, required for standalone operation (outside application server)
16 years, 10 months
Hibernate SVN: r14293 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/hbm2x/pojo and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2008-01-28 06:33:12 -0500 (Mon, 28 Jan 2008)
New Revision: 14293
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
Log:
Put info about what root element is being processed in the exceptions.
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -10,6 +10,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Component;
+import org.hibernate.mapping.PersistentClass;
import org.hibernate.tool.hbm2x.pojo.ComponentPOJOClass;
import org.hibernate.tool.hbm2x.pojo.POJOClass;
import org.hibernate.util.StringHelper;
@@ -27,7 +28,8 @@
void process(GenericExporter ge) {
TemplateProducer producer = new TemplateProducer(ge.getTemplateHelper(),ge.getArtifactCollector());
- producer.produce(new HashMap(), ge.getTemplateName(), new File(ge.getOutputDirectory(),ge.filePattern), ge.templateName);
+ producer.produce(new HashMap(), ge.getTemplateName(), new File(ge.getOutputDirectory(),ge.filePattern), ge.templateName, "Configuration");
+
}
});
@@ -37,8 +39,8 @@
Iterator iterator = ge.getCfg2JavaTool().getPOJOIterator(ge.getConfiguration().getClassMappings());
Map additionalContext = new HashMap();
while ( iterator.hasNext() ) {
- POJOClass element = (POJOClass) iterator.next();
- ge.exportPersistentClass( additionalContext, element );
+ POJOClass element = (POJOClass) iterator.next();
+ ge.exportPersistentClass( additionalContext, element );
}
}
});
@@ -58,7 +60,7 @@
while ( iterator.hasNext() ) {
Component component = (Component) iterator.next();
ComponentPOJOClass element = new ComponentPOJOClass(component,ge.getCfg2JavaTool());
- ge.exportComponent( additionalContext, element );
+ ge.exportComponent( additionalContext, element );
}
}
});
@@ -143,7 +145,7 @@
if(filename.endsWith(".java") && filename.indexOf('$')>=0) {
log.warn("Filename for " + getClassNameForFile( element ) + " contains a $. Innerclass generation is not supported.");
}
- producer.produce(additionalContext, getTemplateName(), new File(getOutputDirectory(),filename), templateName);
+ producer.produce(additionalContext, getTemplateName(), new File(getOutputDirectory(),filename), templateName, element.toString());
}
protected String resolveFilename(POJOClass element) {
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -39,7 +39,7 @@
Configuration cfg = getConfiguration();
if(c2h.isImportData(cfg) && (c2h.isNamedQueries(cfg)) && (c2h.isNamedSQLQueries(cfg)) && (c2h.isFilterDefinitions(cfg))) {
TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector());
- producer.produce(new HashMap(), "hbm/generalhbm.hbm.ftl", new File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), getTemplateName());
+ producer.produce(new HashMap(), "hbm/generalhbm.hbm.ftl", new File(getOutputDirectory(),"GeneralHbmSettings.hbm.xml"), getTemplateName(), "General Settings");
}
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateHelper.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -245,19 +245,23 @@
}
/** look up the template named templateName via the paths and print the content to the output */
- public void processTemplate(String templateName, Writer output) {
+ public void processTemplate(String templateName, Writer output, String rootContext) {
+ if(rootContext == null) {
+ rootContext = "Unknown context";
+ }
+
try {
Template template = freeMarkerEngine.getTemplate(templateName);
template.process(getContext(), output);
}
catch (IOException e) {
- throw new ExporterException("Error while processing template " + templateName, e);
+ throw new ExporterException("Error while processing " + rootContext + " with template " + templateName, e);
}
- catch (TemplateException te) {
- throw new ExporterException("Error while processing template " + templateName, te);
+ catch (TemplateException te) {
+ throw new ExporterException("Error while processing " + rootContext + " with template " + templateName, te);
}
catch (Exception e) {
- throw new ExporterException("Error while processing template " + templateName, e);
+ throw new ExporterException("Error while processing " + rootContext + " with template " + templateName, e);
}
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/TemplateProducer.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -23,9 +23,9 @@
this.ac = ac;
}
- void produce(Map additionalContext, String templateName, File destination, String identifier, String fileType) {
+ public void produce(Map additionalContext, String templateName, File destination, String identifier, String fileType, String rootContext) {
- String tempResult = produceToString( additionalContext, templateName );
+ String tempResult = produceToString( additionalContext, templateName, rootContext );
if(tempResult.trim().length()==0) {
log.warn("Generated output is empty. Skipped creation for file " + destination);
@@ -58,13 +58,13 @@
}
- private String produceToString(Map additionalContext, String templateName) {
+ private String produceToString(Map additionalContext, String templateName, String rootContext) {
Map contextForFirstPass = additionalContext;
putInContext( th, contextForFirstPass );
StringWriter tempWriter = new StringWriter();
BufferedWriter bw = new BufferedWriter(tempWriter);
// First run - writes to in-memory string
- th.processTemplate(templateName, bw);
+ th.processTemplate(templateName, bw, rootContext);
removeFromContext( th, contextForFirstPass );
try {
bw.flush();
@@ -94,6 +94,12 @@
public void produce(Map additionalContext, String templateName, File outputFile, String identifier) {
String fileType = outputFile.getName();
fileType = fileType.substring(fileType.indexOf('.')+1);
- produce(additionalContext, templateName, outputFile, identifier, fileType);
+ produce(additionalContext, templateName, outputFile, identifier, fileType, null);
}
+
+ public void produce(Map additionalContext, String templateName, File outputFile, String identifier, String rootContext) {
+ String fileType = outputFile.getName();
+ fileType = fileType.substring(fileType.indexOf('.')+1);
+ produce(additionalContext, templateName, outputFile, identifier, fileType, rootContext);
+ }
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -153,7 +153,7 @@
}
public String toString() {
- return getClass().getName() + "(" + (clazz==null?"<none>":clazz.getComponentClassName()) + ")";
+ return "Component: " + (clazz==null?"<none>":clazz.getComponentClassName());
}
public Property getIdentifierProperty(){
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -815,7 +815,7 @@
public String toString() {
- return getClass().getName() + "(" + (clazz==null?"<none>":clazz.getEntityName()) + ")";
+ return "Entity: " + (clazz==null?"<none>":clazz.getEntityName());
}
public boolean hasVersionProperty() {
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java 2008-01-26 22:24:52 UTC (rev 14292)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java 2008-01-28 11:33:12 UTC (rev 14293)
@@ -135,7 +135,43 @@
e.printStackTrace();
}
}
-
+
+ public void testForEachWithExceptionGeneration() {
+
+ GenericExporter ge = new GenericExporter();
+ ge.setConfiguration(getCfg());
+ ge.setOutputDirectory(getOutputDir());
+ ge.setTemplateName("generictemplates/generic-exception.ftl");
+ ge.setFilePattern("{package-name}/generic{class-name}.txt");
+
+ try {
+ ge.setForEach("entity");
+ ge.start();
+ fail();
+ } catch(ExporterException e) {
+ assertTrue(e.getMessage().startsWith("Error while processing Entity: HelloWorld"));
+ }
+
+
+ try {
+ ge.setForEach("component");
+ ge.start();
+ fail();
+ } catch(ExporterException e) {
+ assertTrue(e.getMessage().startsWith("Error while processing Component: UniversalAddress"));
+ }
+
+ try {
+ ge.setForEach("configuration");
+ ge.start();
+ fail();
+ } catch(ExporterException e) {
+ assertTrue(e.getMessage().startsWith("Error while processing Configuration"));
+ }
+
+
+ }
+
public void testPropertySet() throws FileNotFoundException, IOException {
GenericExporter ge = new GenericExporter();
ge.setConfiguration(getCfg());
16 years, 10 months