From: Richard B. <rb...@us...> - 2005-04-04 01:27:39
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20383 Modified Files: CCacheEntry.vb CInjectedObject.vb CInjectedObjects.vb CPersistenceBroker.vb CPersistentObject.vb IPersistentObject.vb Log Message: Fix to stop changes to injected objects screwing up the persistence cache version. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.103 retrieving revision 1.104 diff -u -d -r1.103 -r1.104 --- CPersistenceBroker.vb 1 Apr 2005 00:04:08 -0000 1.103 +++ CPersistenceBroker.vb 4 Apr 2005 01:27:20 -0000 1.104 @@ -318,7 +318,13 @@ t = tmpObj.GetObjectType If t Is obj.GetObjectType Or t.IsSubclassOf(obj.GetObjectType) Then Debug.WriteLine("retrievePrivateObject: retreived from cache") + If Not obj.IsIPersistentObject Then + 'Cannot change reference for injected objects otherwise + 'the injection cache version doesn't get updated + obj.ReplaceWith(tmpObj, False) + Else obj = tmpObj + End If Try PCCacheHits.Increment() Catch @@ -410,10 +416,10 @@ cm2 = cm2.SuperClass End While obj.IsProxy = False 'Need to set non-proxy in case object is loaded via a retrieve criteria - m_cache.Add(obj) 'Add retrieved object to the cache If Not obj.IsIPersistentObject Then obj = LocateOrCacheInjObject(obj, False) End If + m_cache.Add(obj) 'Add retrieved object to the cache Try PCCacheSize.RawValue = m_cache.Count Catch @@ -446,8 +452,9 @@ If targetobj.Persistent Then If Not targetobj.IsIPersistentObject Then targetobj = LocateOrCacheInjObject(targetobj, True) + Else + tmpObj = m_cache.Item(targetobj) End If - tmpObj = m_cache.Item(targetobj) If Not (tmpObj Is Nothing) Then targetobj = tmpObj Try @@ -483,9 +490,10 @@ If udamap.ToClass.ChildrenMaps.Count > 0 Then targetobj = Me.createTargetObjectForMultipleInheritance(udamap.ToClass, obj.GetObjectType, obj.GetObjectType.Namespace, rs.ResultSet.Tables(0).Rows(i), joins, conn) If Not targetobj Is Nothing AndAlso targetobj.Persistent Then - tmpObj = m_cache.Item(targetobj) If Not targetobj.IsIPersistentObject Then targetobj = LocateOrCacheInjObject(targetobj, True) + Else + tmpObj = m_cache.Item(targetobj) End If If Not (tmpObj Is Nothing) Then targetobj = tmpObj @@ -524,8 +532,9 @@ If targetobj.Persistent Then If Not targetobj.IsIPersistentObject Then targetobj = LocateOrCacheInjObject(targetobj, True) + Else + tmpObj = m_cache.Item(targetobj) End If - tmpObj = m_cache.Item(targetobj) If Not (tmpObj Is Nothing) Then targetobj = tmpObj Try @@ -591,9 +600,10 @@ classMapCount += Me.getChildCountForMultipleInheritance(toClass) classMapCount -= 1 'This is because we added one in the beginning of the for loop If Not targetobj Is Nothing AndAlso targetobj.Persistent Then - tmpObj = m_cache.Item(targetobj) If Not targetobj.IsIPersistentObject Then targetobj = LocateOrCacheInjObject(targetobj, True) + Else + tmpObj = m_cache.Item(targetobj) End If If Not (tmpObj Is Nothing) Then targetobj = tmpObj @@ -648,9 +658,14 @@ toClass.populateObject(toClass, targetobj, rw, mapName) If targetobj.Persistent Then If Not targetobj.IsIPersistentObject Then + 'For injected objects we want to work with just one version + 'By not checking the persistent cache we can ensure this, and + 'we will also be keeping the persistent cache updated targetobj = LocateOrCacheInjObject(targetobj, True) + tmpObj = Nothing + Else + tmpObj = m_cache.Item(targetobj) End If - tmpObj = m_cache.Item(targetobj) If Not (tmpObj Is Nothing) Then targetobj = tmpObj Try @@ -712,14 +727,14 @@ End If 'now replace the cache entry with the complete object and it's populated collections obj.IsLoading = False - If resetLoadingFlag Then - m_cache.ObjectsAreLoading = False - End If m_cache.Add(obj) Try PCCacheSize.RawValue = m_cache.Count Catch End Try + If resetLoadingFlag Then + m_cache.ObjectsAreLoading = False + End If Return True End Function @@ -838,8 +853,9 @@ col.Add(anObjPers.GetSourceObject) If Not anObjPers.IsIPersistentObject Then anObjPers = LocateOrCacheInjObject(anObjPers, True) + Else + m_cache.Add(anObjPers) 'Add retrieved objects to the cache End If - m_cache.Add(anObjPers) 'Add retrieved objects to the cache Try PCCacheSize.RawValue = m_cache.Count Catch @@ -2569,7 +2585,7 @@ Dim qObj As Object Dim col As IList 'Dim stack As New Stack - Dim queue As New Queue + Dim queue As New queue Dim i, k As Integer Dim tmpObj As Object Dim injObj As IPersistableObject @@ -3016,7 +3032,7 @@ Public Sub PersistChanges(ByVal obj As Object, ByVal checkAssociationsRecursively As Boolean) Dim value As IPersistableObject - Dim queue As Queue + Dim queue As queue Dim qObject As Object Dim injObj, tmpObj As CInjectedObject Dim ckey As CCacheKey @@ -3383,4 +3399,38 @@ End If Return End Sub + + ''' ----------------------------------------------------------------------------- + ''' <summary> + ''' Forces the object to have it's attribute values refreshed. + ''' </summary> + ''' <param name="obj">The object to refresh</param> + ''' <param name="useCache">Boolean indicating wether the data should be refreshed + ''' from the cache or the database.</param> + ''' <remarks>Refresh will cause an existing object to be reset to either the values + ''' last retrieved from the database, or to the latest version of the object from + ''' the database. + ''' </remarks> + ''' <history> + ''' [rbanks] 1/04/2005 Created + ''' </history> + ''' ----------------------------------------------------------------------------- + Public Sub RefreshObject(ByRef obj As Object, ByVal useCache As Boolean) + Dim injObj As CInjectedObject + If TypeOf obj Is IPersistentObject Then + Throw New RetrieveException("The RefreshObject method cannot be used for classes that inherit from CPersistentObject. Use obj.Refresh()") + End If + injObj = LocateOrCacheInjObject(obj, False) + injObj.ResetToOriginal() + If Not useCache Then + retrieveObject(injObj, False, False) + End If + obj = injObj.GetSourceObject + End Sub + + Public ReadOnly Property Cache() As CCacheCollection + Get + Return m_cache + End Get + End Property End Class \ No newline at end of file Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- IPersistentObject.vb 1 Apr 2005 00:04:20 -0000 1.13 +++ IPersistentObject.vb 4 Apr 2005 01:27:29 -0000 1.14 @@ -69,6 +69,7 @@ Event MarkedAsDirty As EventHandler Event LoadStarted As EventHandler Event LoadFinished As EventHandler + End Interface Public Interface IValidation Index: CInjectedObjects.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObjects.vb,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CInjectedObjects.vb 1 Apr 2005 00:04:07 -0000 1.7 +++ CInjectedObjects.vb 4 Apr 2005 01:27:20 -0000 1.8 @@ -361,7 +361,8 @@ Public Function GetValueArray() As ArrayList Dim al As ArrayList - Dim valArray(Me.Values.Count) As Object + If Me.Values.Count = 0 Then Return New ArrayList + Dim valArray(Me.Values.Count - 1) As Object Me.Values.CopyTo(valArray, 0) al = New ArrayList(valArray) Return al @@ -369,7 +370,8 @@ Public Function GetKeyArray() As ArrayList Dim al As ArrayList - Dim valArray(Me.Keys.Count) As Object + If Me.Keys.Count = 0 Then Return New ArrayList + Dim valArray(Me.Keys.Count - 1) As Object Me.Keys.CopyTo(valArray, 0) al = New ArrayList(valArray) Return al Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- CCacheEntry.vb 1 Apr 2005 00:03:51 -0000 1.31 +++ CCacheEntry.vb 4 Apr 2005 01:27:19 -0000 1.32 @@ -577,7 +577,7 @@ ce.TransactionType = CCacheEntry.CacheTransaction.Saved End If Try - ce.OriginalObject = obj + ce.OriginalObject.ReplaceWith(obj, False) ce.PersistentObject.ReplaceWith(obj, False) Catch MyBase.Remove(ckey) @@ -591,7 +591,7 @@ ce = New CCacheEntry(m_expiryInterval) End If ce.PersistentObject = obj.Copy - ce.OriginalObject = obj + ce.OriginalObject = obj.Copy If obj.GetClassMap.RelationalDatabase.getConnection(Nothing).Started Then ce.TransactionType = CCacheEntry.CacheTransaction.Added End If @@ -994,7 +994,8 @@ Public Function GetValueArray() As ArrayList Dim al As ArrayList - Dim valArray(Me.Values.Count) As Object + If Me.Values.Count = 0 Then Return New ArrayList + Dim valArray(Me.Values.Count - 1) As Object Me.Values.CopyTo(valArray, 0) al = New ArrayList(valArray) Return al @@ -1002,7 +1003,8 @@ Public Function GetKeyArray() As ArrayList Dim al As ArrayList - Dim valArray(Me.Keys.Count) As Object + If Me.Keys.Count = 0 Then Return New ArrayList + Dim valArray(Me.Keys.Count - 1) As Object Me.Keys.CopyTo(valArray, 0) al = New ArrayList(valArray) Return al Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- CInjectedObject.vb 1 Apr 2005 00:04:07 -0000 1.21 +++ CInjectedObject.vb 4 Apr 2005 01:27:20 -0000 1.22 @@ -177,7 +177,13 @@ Public Property AssociationsLoaded() As Boolean Implements IPersistableObject.AssociationsLoaded Get + If Me.getClassMap.AssociationMapCount > 0 Then Return m_associationsLoaded + Else + 'If the class has no associations then associations are already "loaded" + 'However if the object is not persistent then the associations obviously can't be loaded yet + Return Me.Persistent + End If End Get Set(ByVal Value As Boolean) m_associationsLoaded = Value @@ -501,10 +507,14 @@ Public Function Copy() As IPersistableObject Implements IPersistableObject.Copy Dim injobj As CInjectedObject - injobj = CType(Me.MemberwiseClone, CInjectedObject) + injobj = Me.getClassMap.CreateObjectInstance + Me.ReplaceValues(Me.GetSourceObject, injobj.GetSourceObject, False) + 'For now we will copy the full object including event handlers + 'Me.ReplaceValues(Me.GetSourceObject, injobj.GetSourceObject, True) + 'injobj = CType(Me.MemberwiseClone, CInjectedObject) 'Because memberwise clone only reference copies collections we should also 'copy the collections as well, since failing to do so can corrupt the cache. - CPersistenceBroker.CopyCollections(Me.GetSourceObject, injobj.GetSourceObject) + 'CPersistenceBroker.CopyCollections(Me.GetSourceObject, injobj.GetSourceObject) Return injobj End Function @@ -744,5 +754,6 @@ Return True 'Return m_object.IsAlive End Function + End Class Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- CPersistentObject.vb 1 Apr 2005 00:04:18 -0000 1.61 +++ CPersistentObject.vb 4 Apr 2005 01:27:24 -0000 1.62 @@ -903,7 +903,7 @@ Public Overridable Sub Save(ByVal obj As CPersistentObject, ByVal checkAssociationsRecursivly As Boolean) Implements IPersistentObject.save Dim persistentBroker As CPersistenceBroker Dim value As IPersistableObject - Dim queue As Queue + Dim queue As queue Dim qObject As Object Dim savedKeys As New ArrayList Dim ckey As CCacheKey @@ -1959,4 +1959,5 @@ Public Function IsIPersistentObject() As Boolean Implements IPersistableObject.IsIPersistentObject Return True End Function + End Class |