From: Richard B. <rb...@us...> - 2005-02-17 22:01:13
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10814 Modified Files: Tag: v2_0 CCacheEntry.vb CPersistenceBroker.vb CPersistentCollection.vb Log Message: Make sure collections with a containerobject get retargeted when copying the containerobject. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.89.2.3 retrieving revision 1.89.2.4 diff -u -d -r1.89.2.3 -r1.89.2.4 --- CPersistenceBroker.vb 16 Feb 2005 22:23:38 -0000 1.89.2.3 +++ CPersistenceBroker.vb 17 Feb 2005 22:00:55 -0000 1.89.2.4 @@ -3055,6 +3055,13 @@ toColl = Nothing End If End If + If f.FieldType Is GetType(CPersistentCollection) OrElse f.FieldType.IsSubclassOf(GetType(CPersistentCollection)) Then + Dim c As CPersistentCollection + c = CType(toColl, CPersistentCollection) + If Not c.ContainerObject Is Nothing AndAlso c.ContainerObject.Equals(fromObject) Then + c.ContainerObject = toObject + End If + End If f.SetValue(toObject.GetSourceObject, toColl) End If Next Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.25.2.4 retrieving revision 1.25.2.5 diff -u -d -r1.25.2.4 -r1.25.2.5 --- CCacheEntry.vb 16 Feb 2005 22:23:38 -0000 1.25.2.4 +++ CCacheEntry.vb 17 Feb 2005 22:00:53 -0000 1.25.2.5 @@ -132,62 +132,6 @@ m_object = m_objectCopyAtTransactionStart End Sub - ' Public Sub CopyCollections() - ' Dim t, iEnumerableType, iListType, iDicType As Type ' Dim coll, obj As Object - ' Dim il As IList - ' Dim id As IDictionary - ' Dim f, fields() As FieldInfo - ' Dim value As Object - - ' 'We must precopy this collection into the collection copy ' 'A simple assignment would just copy a reference to the colletion, while ' 'we need to copy the collection itself, so that adding/removing elements ' 'of the original won't effect the copy - ' m_collectionCollection = New Specialized.HybridDictionary ' t = m_object.GetObjectType - ' fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - ' For Each f In fields - ' iListType = f.FieldType.GetInterface("IList", True) - ' iDicType = f.FieldType.GetInterface("IDictionary", True) - ' If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - ' Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) - ' If Not ICloneType Is Nothing Then - ' 'Getting the ICloneable interface from the object. - ' If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then - ' Dim IClone As ICloneable = CType(f.GetValue(m_object.GetSourceObject), ICloneable) - ' coll = IClone.Clone() - ' Else - ' coll = Nothing - ' End If - ' Else - ' If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then - ' 'If the field doesn't support the ICloneable interface then just set it. - ' coll = Activator.CreateInstance(f.FieldType) ' 'need to copy references one-by-one - ' If Not iListType Is Nothing Then - ' il = CType(coll, IList) - ' For Each obj In f.GetValue(m_object.GetSourceObject) - ' il.Add(obj) - ' Next - ' Else - ' id = CType(coll, IDictionary) - ' For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) - ' id.Add(de.Key, de.Value) - ' Next - ' End If - ' Else - ' coll = Nothing - ' End If - ' End If - ' m_collectionCollection.Add(f.Name, coll) ' End If ' Next - 'End Sub - - 'Public Sub RestoreCollections() - ' Dim t, iEnumerableType, iListType, iDicType As Type ' Dim f, fields() As FieldInfo - ' t = m_object.GetObjectType - ' fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - ' For Each f In fields - ' iListType = f.FieldType.GetInterface("IList", True) - ' iDicType = f.FieldType.GetInterface("IDictionary", True) - ' If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - ' 'We must restore this collection from the collection copy ' 'Just use a straight value assignment - no need to worry about cloning ' f.SetValue(m_object.GetSourceObject, m_collectionCollection.Item(f.Name)) ' End If ' Next - 'End Sub - Public Sub New(ByVal lifetime As Double) m_expiryTime = DateAdd(DateInterval.Minute, lifetime, Now) End Sub @@ -956,7 +900,6 @@ For Each x In Me ce = x.Value If ce.PersistentObject.GetClassMap.RelationalDatabase Is reldb Then - 'ce.CopyCollections() ce.CopyObject() End If Next Index: CPersistentCollection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCollection.vb,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.2 diff -u -d -r1.15.2.1 -r1.15.2.2 --- CPersistentCollection.vb 16 Feb 2005 22:23:39 -0000 1.15.2.1 +++ CPersistentCollection.vb 17 Feb 2005 22:01:03 -0000 1.15.2.2 @@ -43,7 +43,7 @@ ''' [rbanks] 17/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - <Browsable(False), Obsolete("Changes in collection management have made this obsolete. Please use the ListChanged event for equivalent functionality")> _ + <Browsable(False)> _ Public Property ContainerObject() As CPersistentObject Get Return m_container @@ -198,10 +198,10 @@ Private Sub ItemDirtiedHandler(ByVal sender As Object, ByVal e As EventArgs) ' Debug.WriteLine("Collection trapped item dirtied event for " & sender.GetType.Name) RaiseEvent ItemDirtied(Me, e) - 'If Not Me.ContainerObject Is Nothing Then - ' 'Debug.WriteLine("item dirtied - dirtying container") - ' ContainerObject.SetDirtyFlag() - 'End If + If Not Me.ContainerObject Is Nothing Then + 'Debug.WriteLine("item dirtied - dirtying container") + ContainerObject.SetDirtyFlag() + End If End Sub #End Region |