Author: steve.ebersole(a)jboss.com
Date: 2006-11-06 16:56:38 -0500 (Mon, 06 Nov 2006)
New Revision: 10738
Added:
trunk/Hibernate3/test/org/hibernate/test/collection/bag/
trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java
trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java
trunk/Hibernate3/test/org/hibernate/test/collection/list/
trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java
trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java
Modified:
trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java
trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java
trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java
trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java
Log:
HHH-2217 : PersistentCollection mutation methods and dirtying
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-11-06 18:09:47
UTC (rev 10737)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-11-06 21:56:38
UTC (rev 10738)
@@ -57,7 +57,7 @@
public boolean empty() {
return bag.isEmpty();
}
-
+
public Iterator entries(CollectionPersister persister) {
return bag.iterator();
}
@@ -93,8 +93,8 @@
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();
}
-
- private int countOccurrences(Object element, List list, Type elementType, EntityMode
entityMode)
+
+ private int countOccurrences(Object element, List list, Type elementType, EntityMode
entityMode)
throws HibernateException {
Iterator iter = list.iterator();
int result=0;
@@ -208,7 +208,7 @@
return true;
}
}
-
+
public boolean isRowUpdatePossible() {
return false;
}
@@ -237,8 +237,8 @@
*/
public boolean contains(Object object) {
Boolean exists = readElementExistence(object);
- return exists==null ?
- bag.contains(object) :
+ return exists==null ?
+ bag.contains(object) :
exists.booleanValue();
}
@@ -284,8 +284,14 @@
* @see java.util.Collection#remove(Object)
*/
public boolean remove(Object o) {
- write();
- return bag.remove(o);
+ initialize( true );
+ if ( bag.remove( o ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -319,8 +325,14 @@
*/
public boolean removeAll(Collection c) {
if ( c.size()>0 ) {
- write();
- return bag.removeAll(c);
+ initialize( true );
+ if ( bag.removeAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -331,8 +343,14 @@
* @see java.util.Collection#retainAll(Collection)
*/
public boolean retainAll(Collection c) {
- write();
- return bag.retainAll(c);
+ initialize( true );
+ if ( bag.retainAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -343,8 +361,11 @@
queueOperation( new Clear() );
}
else {
- write();
- bag.clear();
+ initialize( true );
+ if ( ! bag.isEmpty() ) {
+ bag.clear();
+ dirty();
+ }
}
}
@@ -509,7 +530,7 @@
final class SimpleAdd implements DelayedOperation {
private Object value;
-
+
public SimpleAdd(Object value) {
this.value = value;
}
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -76,11 +76,11 @@
public Object getIdentifier(Object entry, int i) {
return identifiers.get( new Integer(i) );
}
-
+
public boolean isWrapper(Object collection) {
return values==collection;
}
-
+
public boolean add(Object o) {
write();
values.add(o);
@@ -88,9 +88,12 @@
}
public void clear() {
- write();
- values.clear();
- identifiers.clear();
+ initialize( true );
+ if ( ! values.isEmpty() || ! identifiers.isEmpty() ) {
+ values.clear();
+ identifiers.clear();
+ dirty();
+ }
}
public boolean contains(Object o) {
@@ -113,11 +116,12 @@
}
public boolean remove(Object o) {
- write();
+ initialize( true );
int index = values.indexOf(o);
if (index>=0) {
beforeRemove(index);
values.remove(index);
+ dirty();
return true;
}
else {
@@ -126,9 +130,7 @@
}
public boolean removeAll(Collection c) {
- if ( c.size()>0 ) {
- //write();
- //return values.removeAll(c);
+ if ( c.size() > 0 ) {
boolean result = false;
Iterator iter = c.iterator();
while ( iter.hasNext() ) {
@@ -142,8 +144,14 @@
}
public boolean retainAll(Collection c) {
- write();
- return values.retainAll(c);
+ initialize( true );
+ if ( values.retainAll( c ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
public int size() {
@@ -206,7 +214,7 @@
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Map) snapshot ).isEmpty();
}
-
+
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws
HibernateException {
Map snap = (Map) getSnapshot();
List deletes = new ArrayList( snap.keySet() );
@@ -267,9 +275,9 @@
public Serializable getSnapshot(CollectionPersister persister)
throws HibernateException {
-
+
EntityMode entityMode = getSession().getEntityMode();
-
+
HashMap map = new HashMap( values.size() );
Iterator iter = values.iterator();
int i=0;
@@ -308,11 +316,11 @@
}
public boolean addAll(int index, Collection c) {
- if ( c.size()>0 ) {
- //write();
- //return values.addAll(index, c);
+ if ( c.size() > 0 ) {
Iterator iter = c.iterator();
- while ( iter.hasNext() ) add( index++, iter.next() );
+ while ( iter.hasNext() ) {
+ add( index++, iter.next() );
+ }
return true;
}
else {
Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-11-06 18:09:47
UTC (rev 10737)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-11-06 21:56:38
UTC (rev 10738)
@@ -29,9 +29,9 @@
protected List list;
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException
{
-
+
EntityMode entityMode = getSession().getEntityMode();
-
+
ArrayList clonedList = new ArrayList( list.size() );
Iterator iter = list.iterator();
while ( iter.hasNext() ) {
@@ -62,7 +62,7 @@
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();
}
-
+
public PersistentList(SessionImplementor session) {
super(session);
}
@@ -73,7 +73,7 @@
setInitialized();
setDirectlyAccessible(true);
}
-
+
public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {
this.list = ( List ) persister.getCollectionType().instantiate( anticipatedSize );
}
@@ -81,7 +81,7 @@
public boolean isWrapper(Object collection) {
return list==collection;
}
-
+
public PersistentList() {} //needed for SOAP libraries, etc
/**
@@ -103,8 +103,8 @@
*/
public boolean contains(Object object) {
Boolean exists = readElementExistence(object);
- return exists==null ?
- list.contains(object) :
+ return exists==null ?
+ list.contains(object) :
exists.booleanValue();
}
@@ -150,11 +150,16 @@
* @see java.util.List#remove(Object)
*/
public boolean remove(Object value) {
- Boolean exists = isPutQueueEnabled() ?
- readElementExistence(value) : null;
- if ( exists==null ) {
- write();
- return list.remove(value);
+ Boolean exists = isPutQueueEnabled() ? readElementExistence(value) : null;
+ if ( exists == null ) {
+ initialize( true );
+ if ( list.remove( value ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else if ( exists.booleanValue() ) {
queueOperation( new SimpleRemove(value) );
@@ -177,7 +182,9 @@
* @see java.util.List#addAll(Collection)
*/
public boolean addAll(Collection values) {
- if ( values.size()==0 ) return false;
+ if ( values.size()==0 ) {
+ return false;
+ }
if ( !isOperationQueueEnabled() ) {
write();
return list.addAll(values);
@@ -185,7 +192,7 @@
else {
Iterator iter = values.iterator();
while ( iter.hasNext() ) {
- queueOperation( new SimpleAdd( iter.next() ) );
+ queueOperation( new SimpleAdd( iter.next() ) );
}
return values.size()>0;
}
@@ -209,8 +216,14 @@
*/
public boolean removeAll(Collection coll) {
if ( coll.size()>0 ) {
- write();
- return list.removeAll(coll);
+ initialize( true );
+ if ( list.removeAll( coll ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
return false;
@@ -221,8 +234,14 @@
* @see java.util.List#retainAll(Collection)
*/
public boolean retainAll(Collection coll) {
- write();
- return list.retainAll(coll);
+ initialize( true );
+ if ( list.retainAll( coll ) ) {
+ dirty();
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -233,8 +252,11 @@
queueOperation( new Clear() );
}
else {
- write();
- list.clear();
+ initialize( true );
+ if ( ! list.isEmpty() ) {
+ list.clear();
+ dirty();
+ }
}
}
@@ -256,8 +278,7 @@
if (index<0) {
throw new ArrayIndexOutOfBoundsException("negative index");
}
- Object old = isPutQueueEnabled() ?
- readElementByIndex( new Integer(index) ) : UNKNOWN;
+ Object old = isPutQueueEnabled() ? readElementByIndex( new Integer(index) ) : UNKNOWN;
if ( old==UNKNOWN ) {
write();
return list.set(index, value);
@@ -352,16 +373,16 @@
return list.toString();
}
- public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases
descriptor, Object owner)
+ public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases
descriptor, Object owner)
throws HibernateException, SQLException {
Object element = persister.readElement( rs, owner,
descriptor.getSuffixedElementAliases(), getSession() ) ;
int index = ( (Integer) persister.readIndex( rs, descriptor.getSuffixedIndexAliases(),
getSession() ) ).intValue();
-
+
//pad with nulls from the current last element up to the new index
for ( int i = list.size(); i<=index; i++) {
list.add(i, null);
}
-
+
list.set(index, element);
return element;
}
@@ -420,7 +441,7 @@
public boolean needsUpdating(Object entry, int i, Type elemType) throws
HibernateException {
final List sn = (List) getSnapshot();
- return i<sn.size() && sn.get(i)!=null && list.get(i)!=null
&&
+ return i<sn.size() && sn.get(i)!=null && list.get(i)!=null
&&
elemType.isDirty( list.get(i), sn.get(i), getSession() );
}
@@ -450,7 +471,7 @@
public boolean entryExists(Object entry, int i) {
return entry!=null;
}
-
+
final class Clear implements DelayedOperation {
public void operate() {
list.clear();
@@ -465,7 +486,7 @@
final class SimpleAdd implements DelayedOperation {
private Object value;
-
+
public SimpleAdd(Object value) {
this.value = value;
}
@@ -483,7 +504,7 @@
final class Add implements DelayedOperation {
private int index;
private Object value;
-
+
public Add(int index, Object value) {
this.index = index;
this.value = value;
@@ -503,7 +524,7 @@
private int index;
private Object value;
private Object old;
-
+
public Set(int index, Object value, Object old) {
this.index = index;
this.value = value;
@@ -523,7 +544,7 @@
final class Remove implements DelayedOperation {
private int index;
private Object old;
-
+
public Remove(int index, Object old) {
this.index = index;
this.old = old;
@@ -541,7 +562,7 @@
final class SimpleRemove implements DelayedOperation {
private Object value;
-
+
public SimpleRemove(Object value) {
this.value = value;
}
Modified: trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/CollectionSuite.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -2,11 +2,15 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+
+import org.hibernate.test.collection.bag.PersistentBagTest;
+import org.hibernate.test.collection.idbag.PersistentIdBagTest;
+import org.hibernate.test.collection.list.PersistentListTest;
import org.hibernate.test.collection.map.PersistentMapTest;
import org.hibernate.test.collection.set.PersistentSetTest;
/**
- * todo: describe CollectionSuite
+ * Suite of collection (i.e. PersistentCollection) related tests
*
* @author Steve Ebersole
*/
@@ -15,6 +19,9 @@
public static Test suite() {
TestSuite suite = new TestSuite( "Collection-related tests" );
suite.addTest( CollectionTest.suite() );
+ suite.addTest( PersistentBagTest.suite() );
+ suite.addTest( PersistentIdBagTest.suite() );
+ suite.addTest( PersistentListTest.suite() );
suite.addTest( PersistentMapTest.suite() );
suite.addTest( PersistentSetTest.suite() );
return suite;
Added: trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/bag/BagOwner.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,46 @@
+package org.hibernate.test.collection.bag;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class BagOwner {
+ private String name;
+ private BagOwner parent;
+ private List children = new ArrayList();
+
+ public BagOwner() {
+ }
+
+ public BagOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public BagOwner getParent() {
+ return parent;
+ }
+
+ public void setParent(BagOwner parent) {
+ this.parent = parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/bag/Mappings.hbm.xml 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,20 @@
+<?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.collection.bag">
+
+ <class name="BagOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <many-to-one name="parent" class="BagOwner"
cascade="none" />
+
+ <bag name="children" inverse="true"
cascade="all">
+ <key column="PARENT" />
+ <one-to-many class="BagOwner" />
+ </bag>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java 2006-11-06
18:09:47 UTC (rev 10737)
+++
trunk/Hibernate3/test/org/hibernate/test/collection/bag/PersistentBagTest.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,71 @@
+package org.hibernate.test.collection.bag;
+
+import java.util.HashSet;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentBag;
+
+/**
+ * Tests related to operations on a PersistentBag.
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentBagTest extends TestCase {
+ public PersistentBagTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/bag/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentBagTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ BagOwner parent = new BagOwner( "root" );
+ BagOwner child = new BagOwner( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ BagOwner otherChild = new BagOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentBag...
+ PersistentBag children = ( PersistentBag ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/idbag/IdbagOwner.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,37 @@
+package org.hibernate.test.collection.idbag;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class IdbagOwner {
+ private String name;
+ private List children = new ArrayList();
+
+ public IdbagOwner() {
+ }
+
+ public IdbagOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/idbag/Mappings.hbm.xml 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,21 @@
+<?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.collection.idbag">
+
+ <class name="IdbagOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <idbag name="children" cascade="all"
table="idbag_owner_children">
+ <collection-id column="CHILD" type="long">
+ <generator class="increment"/>
+ </collection-id>
+ <key column="PARENT_FK" />
+ <many-to-many column="CHILD_FK" class="IdbagOwner"
/>
+ </idbag>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java 2006-11-06
18:09:47 UTC (rev 10737)
+++
trunk/Hibernate3/test/org/hibernate/test/collection/idbag/PersistentIdBagTest.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,69 @@
+package org.hibernate.test.collection.idbag;
+
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentIdentifierBag;
+
+/**
+ * Tests related to operations on a PersistentIdentifierBag
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentIdBagTest extends TestCase {
+ public PersistentIdBagTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/idbag/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentIdBagTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ IdbagOwner parent = new IdbagOwner( "root" );
+ IdbagOwner child = new IdbagOwner( "c1" );
+ parent.getChildren().add( child );
+ IdbagOwner otherChild = new IdbagOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentBag...
+ PersistentIdentifierBag children = ( PersistentIdentifierBag ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/list/ListOwner.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,46 @@
+package org.hibernate.test.collection.list;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ListOwner {
+ private String name;
+ private ListOwner parent;
+ private List children = new ArrayList();
+
+ public ListOwner() {
+ }
+
+ public ListOwner(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ListOwner getParent() {
+ return parent;
+ }
+
+ public void setParent(ListOwner parent) {
+ this.parent = parent;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml 2006-11-06
18:09:47 UTC (rev 10737)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/list/Mappings.hbm.xml 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,21 @@
+<?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.collection.list">
+
+ <class name="ListOwner">
+ <id name="name" column="NAME" type="string" />
+
+ <many-to-one name="parent" class="ListOwner"
cascade="none" />
+
+ <list name="children" inverse="true"
cascade="all">
+ <key column="PARENT" />
+ <list-index column="LIST_INDEX"/>
+ <one-to-many class="ListOwner" />
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java
===================================================================
---
trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java 2006-11-06
18:09:47 UTC (rev 10737)
+++
trunk/Hibernate3/test/org/hibernate/test/collection/list/PersistentListTest.java 2006-11-06
21:56:38 UTC (rev 10738)
@@ -0,0 +1,70 @@
+package org.hibernate.test.collection.list;
+
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.collection.PersistentList;
+
+/**
+ * Tests related to operations on a PersistentList
+ *
+ * @author Steve Ebersole
+ */
+public class PersistentListTest extends TestCase {
+ public PersistentListTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "collection/list/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new TestSuite( PersistentListTest.class );
+ }
+
+ public void testWriteMethodDirtying() {
+ ListOwner parent = new ListOwner( "root" );
+ ListOwner child = new ListOwner( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ ListOwner otherChild = new ListOwner( "c2" );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.flush();
+ // at this point, the list on parent has now been replaced with a PersistentList...
+ PersistentList children = ( PersistentList ) parent.getChildren();
+
+ assertFalse( children.remove( otherChild ) );
+ assertFalse( children.isDirty() );
+
+ ArrayList otherCollection = new ArrayList();
+ otherCollection.add( child );
+ assertFalse( children.retainAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ otherCollection = new ArrayList();
+ otherCollection.add( otherChild );
+ assertFalse( children.removeAll( otherCollection ) );
+ assertFalse( children.isDirty() );
+
+ children.clear();
+ session.delete( child );
+ assertTrue( children.isDirty() );
+
+ session.flush();
+
+ children.clear();
+ assertFalse( children.isDirty() );
+
+ session.delete( parent );
+ session.getTransaction().commit();
+ session.close();
+ }
+}