From: Richard B. <rb...@us...> - 2005-04-07 07:08:30
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5117 Modified Files: CClassMap.vb CInjectedObject.vb CPersistenceBroker.vb CPersistentObject.vb Log Message: Fix for one-to-many association cleanup when associations belong to the superclass Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.106 retrieving revision 1.107 diff -u -d -r1.106 -r1.107 --- CPersistenceBroker.vb 6 Apr 2005 06:34:20 -0000 1.106 +++ CPersistenceBroker.vb 7 Apr 2005 07:08:16 -0000 1.107 @@ -417,7 +417,9 @@ End While obj.IsProxy = False 'Need to set non-proxy in case object is loaded via a retrieve criteria If Not obj.IsIPersistentObject Then - obj = LocateOrCacheInjObject(obj, False, True) + 'We need to ensure the object is in the injection cache, but we don't + 'want to replace obj's values if it is already there (ie don't use the return value) + Call LocateOrCacheInjObject(obj, False, True) End If m_cache.Add(obj) 'Add retrieved object to the cache Try @@ -2933,10 +2935,39 @@ obj = injObj.GetSourceObject End Sub + ''' ----------------------------------------------------------------------------- + ''' <summary> + ''' Finds an object in the database using the Find attributes. + ''' </summary> + ''' <param name="obj">The object to be found.</param> + ''' <remarks>Do not pass an object that inherits from the CPersistentObject. For those + ''' objects use the inbuilt Find() method.</br> + ''' This method will use the cache to assist in locating the object. If nothing + ''' is found the object will remain unchanged. + ''' </remarks> + ''' <history> + ''' [rbanks] 7/04/2005 Created + ''' </history> + ''' ----------------------------------------------------------------------------- Public Sub FindObject(ByRef obj As Object) FindObject(obj, True) End Sub + ''' ----------------------------------------------------------------------------- + ''' <summary> + ''' Finds an object in the database using the Find attributes. + ''' </summary> + ''' <param name="obj">The object to be found</param> + ''' <param name="useCache">Indicates wether the cache should be searched</param> + ''' <remarks>Do not pass an object that inherits from the CPersistentObject. For those + ''' objects use the inbuilt Find() method.</br> + ''' This method will optionally use the cache to assist in locating the object. If nothing + ''' is found the object will remain unchanged. + ''' </remarks> + ''' <history> + ''' [rbanks] 7/04/2005 Created + ''' </history> + ''' ----------------------------------------------------------------------------- Public Sub FindObject(ByRef obj As Object, ByVal useCache As Boolean) Dim needToAdd As Boolean = False Dim injObj As CInjectedObject @@ -2956,22 +2987,6 @@ Return LocateOrCacheInjObject(obj, True, createTemporary) End Function - 'Public Function getInjectedObject(ByVal obj As Object, ByVal createTemporary As Boolean) As CInjectedObject - ' Dim injObj As CInjectedObject - ' injObj = m_injectedObjects.Find(obj) - ' If injObj Is Nothing Then - ' injObj = New CInjectedObject(obj) - ' If createTemporary Then - ' 'When a single injected object has a reference to a set of objects that are - ' 'recursively referencing each other we need to add the objects to the cache - ' 'in order to prevent nested recursion. This temporary addition is only - ' 'used in getObjectsToSave - ' m_injectedObjects.AddTemp(injObj, False) - ' End If - ' End If - ' Return injObj - 'End Function - Public Function LocateOrCacheInjObject(ByVal obj As Object, ByVal replaceCachedValues As Boolean, ByVal addToCache As Boolean) As CInjectedObject Dim injObj As CInjectedObject injObj = m_injectedObjects.Find(obj) @@ -2999,16 +3014,6 @@ Return injObj End Function - 'Public Sub StartTracking(ByVal obj As Object) - ' If Not TypeOf (obj) Is CInjectedObject Then - ' Dim injObj As CInjectedObject - ' injObj = New CInjectedObject(obj) - ' m_injectedObjects.Add(injObj) - ' Else - ' m_injectedObjects.Add(obj) - ' End If - 'End Sub - Public Function ObjectIsTracked(ByVal obj) As Boolean Debug.WriteLine(m_injectedObjects) Return m_injectedObjects.isTracked(obj) @@ -3283,7 +3288,7 @@ End Sub Public Shared Sub CopyCollections(ByVal fromObject As Object, ByRef toObject As Object) - Dim t, iEnumerableType, iListType, iDicType As Type + Dim t, t1, iEnumerableType, iListType, iDicType As Type Dim fromColl, toColl, collItem As Object Dim il As IList Dim id As IDictionary @@ -3291,6 +3296,7 @@ Dim value As Object t = toObject.GetType + While Not t Is Nothing fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) For Each f In fields iListType = f.FieldType.GetInterface("IList", True) @@ -3309,16 +3315,16 @@ fromColl = f.GetValue(fromObject) If Not fromColl Is Nothing Then 'If the field doesn't support the ICloneable interface then just set it. - t = f.FieldType - toColl = Activator.CreateInstance(t) + t1 = f.FieldType + toColl = Activator.CreateInstance(t1) 'need to copy references one-by-one 'Also neeed to connect event handlers of new collection to new object based 'on event connections of the old collection and the old object Dim fColl, fieldsColl() As FieldInfo Dim d, newD, delArray(), newDelArray() As [Delegate] Dim collDel As MulticastDelegate - While Not t Is Nothing - fieldsColl = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + While Not t1 Is Nothing + fieldsColl = t1.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) For Each fColl In fieldsColl If fColl.FieldType.Name = fColl.Name & "Handler" OrElse fColl.FieldType Is GetType(EventHandler) Then 'This is an event! @@ -3342,10 +3348,10 @@ End If End If Next - If t.IsSubclassOf(GetType(CPersistentCollection)) Then - t = t.BaseType + If t1.IsSubclassOf(GetType(CPersistentCollection)) Then + t1 = t1.BaseType Else - t = Nothing + t1 = Nothing End If End While If Not iListType Is Nothing Then @@ -3373,6 +3379,13 @@ f.SetValue(toObject, toColl) End If Next + 'Need to make sure collections in base types are also copied + If Not t.BaseType Is Nothing Then + t = t.BaseType + Else + t = Nothing + End If + End While End Sub ''' ----------------------------------------------------------------------------- Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- CInjectedObject.vb 6 Apr 2005 06:34:20 -0000 1.24 +++ CInjectedObject.vb 7 Apr 2005 07:08:16 -0000 1.25 @@ -662,6 +662,7 @@ cm = Me.getClassMap m_oneToManyCollections = New Collection Dim aMap As CUDAMap + While Not cm Is Nothing For Each de As DictionaryEntry In cm.AssociationMaps aMap = de.Value If aMap.Cardinality = aMap.CardinalityEnum.ONE_TO_MANY Then @@ -669,6 +670,8 @@ m_oneToManyCollections.Add(coll, aMap.FromClassTarget) End If Next + cm = cm.SuperClass + End While End Sub Public Function GetRemovedCollectionItems(ByVal propertyName As String) As Collection Implements IPersistableObject.GetRemovedCollectionItems Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- CPersistentObject.vb 6 Apr 2005 06:34:20 -0000 1.64 +++ CPersistentObject.vb 7 Apr 2005 07:08:18 -0000 1.65 @@ -1753,6 +1753,7 @@ cm = Me.getClassMap m_oneToManyCollections = New Collection Dim aMap As CUDAMap + While Not cm Is Nothing For Each de As DictionaryEntry In cm.AssociationMaps aMap = de.Value If aMap.Cardinality = aMap.CardinalityEnum.ONE_TO_MANY Then @@ -1760,6 +1761,8 @@ m_oneToManyCollections.Add(coll, aMap.FromClassTarget) End If Next + cm = cm.SuperClass + End While End Sub Public Function GetRemovedCollectionItems(ByVal propertyName As String) As Collection Implements IPersistableObject.GetRemovedCollectionItems Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.56 retrieving revision 1.57 diff -u -d -r1.56 -r1.57 --- CClassMap.vb 1 Apr 2005 00:03:53 -0000 1.56 +++ CClassMap.vb 7 Apr 2005 07:08:15 -0000 1.57 @@ -2168,7 +2168,7 @@ Try If ClassNameSpace = String.Empty Then For Each tt As Type In asm.GetTypes() - If tt.Name = Name Then + If tt.Name = Name or tt.fullname = name Then t = tt Exit For End If |