From: Richard B. <rb...@us...> - 2004-10-27 07:39:09
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9422 Modified Files: CClassMap.vb CInjectedObject.vb CPersistenceBroker.vb CPersistentCollection.vb CPersistentObject.vb Log Message: Fixes to: 1. PersistChanges() to handle new objects being added to tracking when saving object hierarchy 2. Updating ValueTypes (structures) mapped via structure.field naming 3. Getting classmaps for interfaces that use inheritance 4. Persistent flag not being correctly set on LoadProxy Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.73 retrieving revision 1.74 diff -u -d -r1.73 -r1.74 --- CPersistenceBroker.vb 25 Oct 2004 07:12:31 -0000 1.73 +++ CPersistenceBroker.vb 27 Oct 2004 07:38:48 -0000 1.74 @@ -961,14 +961,23 @@ Public Function getClassMap(ByVal pType As Type) As CClassMap Dim ClassMap As CClassMap + Dim tmpCMap As CClassMap ClassMap = getClassMapByTypeName(pType.Name, pType.FullName) If ClassMap Is Nothing Then 'try to find an interface that is mapped - first mapped interface we find will be used Dim intType, interfaces() As Type - For Each intType In pType.GetInterfaces() - ClassMap = getClassMapByTypeName(intType.Name, intType.FullName) - If Not ClassMap Is Nothing Then - Exit For + interfaces = pType.GetInterfaces + For Each intType In interfaces + tmpCMap = getClassMapByTypeName(intType.Name, intType.FullName) + 'If this class has children, iterate through other class maps to see if + 'the object inherits a child class, otherwise we can get the wrong class map + 'returned. + If Not tmpCMap Is Nothing Then + If ClassMap Is Nothing Then ClassMap = tmpCMap + If tmpCMap.ChildrenMaps.Count = 0 Then + ClassMap = tmpCMap + Exit For + End If End If Next End If @@ -2461,7 +2470,13 @@ Try Dim injObj As CInjectedObject m_inPersistChangesLoop = True + 'Need to copy the injected object cache as saving objects may result + 'in new objects being added to the cache (via the object hierarchy) + Dim objectsToPersist As New CInjectedObjects For Each de As DictionaryEntry In m_injectedObjects + objectsToPersist.Add(de.Key, de.Value) + Next + For Each de As DictionaryEntry In objectsToPersist injObj = de.Value PersistChanges(injObj.ReferencedObject) Next Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- CInjectedObject.vb 25 Oct 2004 07:12:31 -0000 1.5 +++ CInjectedObject.vb 27 Oct 2004 07:38:48 -0000 1.6 @@ -99,14 +99,23 @@ Public Function getClassMap() As CClassMap Implements IPersistableObject.getClassMap Dim ClassMap As CClassMap + Dim tmpCMap As CClassMap ClassMap = getClassMap(TypeName(m_object), m_object.GetType.FullName) If ClassMap Is Nothing Then 'try to find an interface that is mapped - first mapped interface we find will be used Dim intType, interfaces() As Type - For Each intType In m_object.GetType.GetInterfaces() - ClassMap = getClassMap(intType.Name, intType.FullName) - If Not ClassMap Is Nothing Then - Exit For + interfaces = m_object.GetType.GetInterfaces + For Each intType In interfaces + tmpCMap = getClassMap(intType.Name, intType.FullName) + 'If this class has children, iterate through other class maps to see if + 'the object inherits a child class, otherwise we can get the wrong class map + 'returned. + If Not tmpCMap Is Nothing Then + If ClassMap Is Nothing Then ClassMap = tmpCMap + If tmpCMap.ChildrenMaps.Count = 0 Then + ClassMap = tmpCMap + Exit For + End If End If Next End If @@ -429,13 +438,24 @@ Dim o As Object Dim objName As String Dim propertyName As String + Dim val As ValueType objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) - If TypeOf (Value) Is System.SByte Then - CallByName(o, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) + If o.GetType.IsValueType Then + val = o + If TypeOf (Value) Is System.SByte Then + CallByName(val, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) + Else + CallByName(val, propertyName, CallType.Set, Value) + End If + CallByName(m_object, objName, CallType.Set, val) Else - CallByName(o, propertyName, CallType.Set, Value) + If TypeOf (Value) Is System.SByte Then + CallByName(o, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) + Else + CallByName(o, propertyName, CallType.Set, Value) + End If End If End If Catch ex As Exception @@ -537,7 +557,7 @@ 'copy the OriginalModifiedDate and the ModifiedDate from the child to the parent. 'if we don't do this the object won't get saved correctly on subsequent calls. - obj.SetAttributeValue("ModifiedDate", Me.getValueByAttribute("ModifiedDate")) + obj.ModifiedDate = Me.ModifiedDate obj.OriginalModifiedDate = Me.OriginalModifiedDate obj.IsDirty = Me.IsDirty Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- CPersistentObject.vb 25 Oct 2004 07:12:32 -0000 1.47 +++ CPersistentObject.vb 27 Oct 2004 07:38:48 -0000 1.48 @@ -49,26 +49,26 @@ Public Event MarkedAsDirty As EventHandler Implements IPersistentObject.MarkedAsDirty Public Event LoadStarted As EventHandler Implements IPersistentObject.LoadStarted Public Event LoadFinished As EventHandler Implements IPersistentObject.LoadFinished - Friend Event RemoveMe(ByVal pObj As CPersistentObject) + Friend Event RemoveMe(ByVal pObj As CPersistentObject) <NonSerialized()> Private m_preEditCopy As CPersistentObject <NonSerialized()> Private m_retrievedCacheKey As CCacheKey #Region "Properties" - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Flag to indicate if the object is read only. - ''' </summary> - ''' <value>Boolean indicating whether the object is read only or not.</value> - ''' <remarks>Objects that are read only can still be modified by the application - ''' however when any of the persistence methods are called (such as save and delete) - ''' an exception will be thrown indicating that the object is read only. - ''' <para>Read only objects are typically used to map database views.</para></remarks> - ''' <history> - ''' [rbanks] 25/11/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Flag to indicate if the object is read only. + ''' </summary> + ''' <value>Boolean indicating whether the object is read only or not.</value> + ''' <remarks>Objects that are read only can still be modified by the application + ''' however when any of the persistence methods are called (such as save and delete) + ''' an exception will be thrown indicating that the object is read only. + ''' <para>Read only objects are typically used to map database views.</para></remarks> + ''' <history> + ''' [rbanks] 25/11/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- <Browsable(False)> Public ReadOnly Property isReadOnly() As Boolean Implements IPersistentObject.isReadOnly Get Return getClassMap(Me).isReadOnly @@ -508,18 +508,29 @@ Dim o As Object Dim objName As String Dim propertyName As String + Dim val As ValueType objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(Me, objName, CallType.Get) - If TypeOf (Value) Is System.SByte Then - CallByName(o, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) + If o.GetType.IsValueType Then + Val = o + If TypeOf (Value) Is System.SByte Then + CallByName(Val, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) + Else + CallByName(Val, propertyName, CallType.Set, Value) + End If + CallByName(Me, objName, CallType.Set, val) Else - CallByName(o, propertyName, CallType.Set, Value) + If TypeOf (Value) Is System.SByte Then + CallByName(o, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) + Else + CallByName(o, propertyName, CallType.Set, Value) + End If End If End If Catch ex As Exception Throw New AttributeValueException("Could not set attribute " & pName & " (Value Type: " _ - & Value.GetType.Name & ") in CPersistentObject::SetAttributeValue." & vbCrLf & ex.Message, ex) + & Value.GetType.Name & ") in CPersistentObject::SetAttributeValue." & vbCrLf & ex.Message, ex) End Try End Sub Index: CPersistentCollection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCollection.vb,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- CPersistentCollection.vb 28 Sep 2004 04:19:04 -0000 1.13 +++ CPersistentCollection.vb 27 Oct 2004 07:38:48 -0000 1.14 @@ -18,26 +18,26 @@ ''' </history> ''' ----------------------------------------------------------------------------- Public Class CPersistentCollection - Inherits CollectionBase + Inherits CollectionBase Implements IComponent Implements IBindingList - Private m_container As CPersistentObject + Private m_container As CPersistentObject - Public Event ItemDirtied As EventHandler + Public Event ItemDirtied As EventHandler #Region "Collection Properties and Methods" - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Back reference to the object that references (owns) this collection object. - ''' </summary> - ''' <value>A CPersistentObject that uses this collection</value> - ''' <remarks>When objects are added to or removed from the collection the - ''' dirty flag on the ContainerObject is set.</remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Back reference to the object that references (owns) this collection object. + ''' </summary> + ''' <value>A CPersistentObject that uses this collection</value> + ''' <remarks>When objects are added to or removed from the collection the + ''' dirty flag on the ContainerObject is set.</remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- <Browsable(False)> Public Property ContainerObject() As CPersistentObject Get Return m_container @@ -200,13 +200,13 @@ #End Region #Region "IBindlingList" - Public Overridable Sub AddIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.AddIndex + Public Overridable Sub AddIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.AddIndex - End Sub + End Sub - Public Overridable Function AddNew() As Object Implements System.ComponentModel.IBindingList.AddNew + Public Overridable Function AddNew() As Object Implements System.ComponentModel.IBindingList.AddNew - End Function + End Function <Browsable(False)> Public Overridable ReadOnly Property AllowEdit() As Boolean Implements System.ComponentModel.IBindingList.AllowEdit Get @@ -282,42 +282,42 @@ #End Region #Region "Collection Events" - Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object) - ' Debug.WriteLine("CPColl insert complete - attaching handlers") - AddHandler CType(value, CPersistentObject).RemoveMe, AddressOf Remove - AddHandler CType(value, CPersistentObject).MarkedAsDirty, AddressOf ItemDirtiedHandler - RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemAdded, index)) - If Not (m_container Is Nothing) Then - m_container.SetDirtyFlag() - End If - End Sub + Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object) + ' Debug.WriteLine("CPColl insert complete - attaching handlers") + AddHandler CType(value, CPersistentObject).RemoveMe, AddressOf Remove + AddHandler CType(value, CPersistentObject).MarkedAsDirty, AddressOf ItemDirtiedHandler + RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemAdded, index)) + If Not (m_container Is Nothing) Then + m_container.SetDirtyFlag() + End If + End Sub - Protected Overrides Sub OnClearComplete() - ' Debug.WriteLine("CPColl clear complete") - RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.Reset, 0)) - End Sub + Protected Overrides Sub OnClearComplete() + ' Debug.WriteLine("CPColl clear complete") + RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.Reset, 0)) + End Sub - Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object) - ' Debug.WriteLine("CPColl Remove complete (" & index & ") : clearing event handlers") - ' RemoveHandler CType(value, CPersistentObject).MarkedAsDirty, AddressOf ItemDirtiedHandler - ' RemoveHandler CType(value, CPersistentObject).RemoveMe, AddressOf Remove - RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemDeleted, index)) - If Not (m_container Is Nothing) Then - m_container.SetDirtyFlag() - End If - End Sub + Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object) + ' Debug.WriteLine("CPColl Remove complete (" & index & ") : clearing event handlers") + ' RemoveHandler CType(value, CPersistentObject).MarkedAsDirty, AddressOf ItemDirtiedHandler + ' RemoveHandler CType(value, CPersistentObject).RemoveMe, AddressOf Remove + RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemDeleted, index)) + If Not (m_container Is Nothing) Then + m_container.SetDirtyFlag() + End If + End Sub - Protected Overrides Sub OnSetComplete(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object) - 'Debug.WriteLine("CPColl set complete") - RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemChanged, index)) - End Sub + Protected Overrides Sub OnSetComplete(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object) + 'Debug.WriteLine("CPColl set complete") + RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemChanged, index)) + End Sub - Protected Overrides Sub OnClear() - ' Debug.WriteLine("CPColl clearing list") - For Each cp As CPersistentObject In list - RemoveHandler cp.MarkedAsDirty, AddressOf ItemDirtiedHandler - Next - End Sub + Protected Overrides Sub OnClear() + ' Debug.WriteLine("CPColl clearing list") + For Each cp As CPersistentObject In list + RemoveHandler cp.MarkedAsDirty, AddressOf ItemDirtiedHandler + Next + End Sub #End Region #Region "IComponent Interface" Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- CClassMap.vb 18 Oct 2004 03:31:51 -0000 1.36 +++ CClassMap.vb 27 Oct 2004 07:38:48 -0000 1.37 @@ -1565,12 +1565,12 @@ Catch ex As Exception End Try obj.SetAttributeValue(AttrMap.Name, tmpObj) + If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then + obj.Persistent = True + End If End If Next i ClassMap = ClassMap.SuperClass - If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then - obj.Persistent = True - End If Loop While Not ClassMap Is Nothing obj.IsProxy = True obj.IsDirty = False |