From: Richard B. <rb...@us...> - 2005-01-31 22:29:17
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15167 Modified Files: CCacheEntry.vb Log Message: -- incomplete -- Code for precopying collections referenced by cached objects, and for restoring those collections. The precopy/restore code will be called on transaction start/rollback. Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- CCacheEntry.vb 16 Nov 2004 21:39:34 -0000 1.23 +++ CCacheEntry.vb 31 Jan 2005 22:29:06 -0000 1.24 @@ -1,6 +1,8 @@ Option Strict Off Option Explicit On +Imports System.Reflection + '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CCacheEntry @@ -30,7 +32,8 @@ Private m_objectCopy As IPersistableObject Private m_transactionType As CCacheEntry.CacheTransaction Private m_expiryTime As Date - Private m_originalObject As IPersistableObject + Private m_originalObject As IPersistableObject + Private m_collectionCollection As System.Collections.Specialized.StringDictionary '''----------------------------------------------------------------------------- ''' <summary> @@ -117,91 +120,122 @@ Public Sub RestoreObject() m_object = m_objectCopy - End Sub + End Sub - Public Sub New(ByVal lifetime As Double) - m_expiryTime = DateAdd(DateInterval.Minute, lifetime, Now) - End Sub + Public Sub CopyCollections() + Dim t, t_coll As Type + Dim prop, props() As PropertyInfo + + m_collectionCollection = New Specialized.StringDictionary + t_coll = GetType(CollectionBase) + t = m_object.GetObjectType + props = t.GetProperties + For Each prop In props + If prop.PropertyType Is t_coll OrElse prop.PropertyType.IsSubclassOf(t_coll) Then + 'We must precopy this collection into the collection copy + m_collectionCollection.Add(prop.Name, m_object.GetValueByAttribute(prop.Name)) + End If + Next + End Sub - Friend Sub resetExpiry(ByVal lifetime As Double) - m_expiryTime = DateAdd(DateInterval.Minute, lifetime, Now) - End Sub + Public Sub RestoreCollections() + Dim t, t_coll As Type + Dim prop, props() As PropertyInfo + + t_coll = GetType(CollectionBase) + t = m_object.GetObjectType + props = t.GetProperties + For Each prop In props + If prop.PropertyType Is t_coll OrElse prop.PropertyType.IsSubclassOf(t_coll) Then + 'We must restore this collection from the collection copy + m_object.SetAttributeValue(prop.Name, m_collectionCollection.Item(prop.Name)) + End If + Next + End Sub - Public Overrides Function ToString() As String - Dim s As String - Dim i As Short - Dim indent As Integer - Dim formatString As String + Public Sub New(ByVal lifetime As Double) + m_expiryTime = DateAdd(DateInterval.Minute, lifetime, Now) + End Sub - Dim cm As CClassMap - Dim am As CAttributeMap - Dim x As Object - Dim y As Object - Dim xstring As String - Dim ystring As String + Friend Sub resetExpiry(ByVal lifetime As Double) + m_expiryTime = DateAdd(DateInterval.Minute, lifetime, Now) + End Sub - If m_object Is Nothing Then - Return "No persistent object" - End If + Public Overrides Function ToString() As String + Dim s As String + Dim i As Short + Dim indent As Integer + Dim formatString As String - s = m_object.GetObjectType.Name & ": " - indent = s.Length - If m_object.IsDirty Then - s &= "Dirty" - Else - s &= "Not Dirty" - End If - If m_object.Persistent Then - s &= ", Persistent" - Else - s &= ", NonPersistent" - End If - If m_object.IsLoading Then - s &= ", Loading" - Else - s &= ", Loaded" - End If - If m_object.AssociationsLoaded Then - s &= ", Assoc. Loaded" - Else - s &= ", No Assoc. Loaded" - End If - s &= vbCrLf - formatString = Space(indent) & "{0,-9}" & vbTab & "{1,-13}" & vbTab & "{2,-13}" & vbCrLf - s &= [String].Format(formatString, "Attribute", "Current Value", "Original Value") - s &= [String].Format(formatString, "---------", "-------------", "--------------") - i = 0 - cm = m_object.GetClassMap() - For i = 1 To cm.getKeySize - am = cm.getKeyAttributeMap(i) - x = m_object.GetValueByAttribute(am.Name) - Try - xstring = x.ToString - Catch ex As Exception - If x Is Nothing Then - xstring = "Nothing" - Else - xstring = "Unprintable" - End If - End Try - Try - If m_originalObject Is Nothing Then - ystring = "N/A" - Else - y = m_originalObject.GetValueByAttribute(am.Name) - ystring = y.ToString - End If - Catch ex As Exception - If y Is Nothing Then - ystring = "Nothing" - Else - ystring = "Unprintable" - End If - End Try - s &= [String].Format(formatString, am.Name, xstring, ystring) - Next - Return s - End Function + Dim cm As CClassMap + Dim am As CAttributeMap + Dim x As Object + Dim y As Object + Dim xstring As String + Dim ystring As String + + If m_object Is Nothing Then + Return "No persistent object" + End If + + s = m_object.GetObjectType.Name & ": " + indent = s.Length + If m_object.IsDirty Then + s &= "Dirty" + Else + s &= "Not Dirty" + End If + If m_object.Persistent Then + s &= ", Persistent" + Else + s &= ", NonPersistent" + End If + If m_object.IsLoading Then + s &= ", Loading" + Else + s &= ", Loaded" + End If + If m_object.AssociationsLoaded Then + s &= ", Assoc. Loaded" + Else + s &= ", No Assoc. Loaded" + End If + s &= vbCrLf + formatString = Space(indent) & "{0,-9}" & vbTab & "{1,-13}" & vbTab & "{2,-13}" & vbCrLf + s &= [String].Format(formatString, "Attribute", "Current Value", "Original Value") + s &= [String].Format(formatString, "---------", "-------------", "--------------") + i = 0 + cm = m_object.GetClassMap() + For i = 1 To cm.getKeySize + am = cm.getKeyAttributeMap(i) + x = m_object.GetValueByAttribute(am.Name) + Try + xstring = x.ToString + Catch ex As Exception + If x Is Nothing Then + xstring = "Nothing" + Else + xstring = "Unprintable" + End If + End Try + Try + If m_originalObject Is Nothing Then + ystring = "N/A" + Else + y = m_originalObject.GetValueByAttribute(am.Name) + ystring = y.ToString + End If + Catch ex As Exception + If y Is Nothing Then + ystring = "Nothing" + Else + ystring = "Unprintable" + End If + End Try + s &= [String].Format(formatString, am.Name, xstring, ystring) + Next + Return s + End Function End Class '''----------------------------------------------------------------------------- |