From: Richard B. <rb...@us...> - 2004-10-20 06:44:34
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31641 Modified Files: CCursor.vb CInjectedObject.vb CPersistenceBroker.vb CPersistentCriteria.vb CPersistentObject.vb IPersistentObject.vb Log Message: Fixes for bugs in saving object hierarchies Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.69 retrieving revision 1.70 diff -u -d -r1.69 -r1.70 --- CPersistenceBroker.vb 19 Oct 2004 03:32:08 -0000 1.69 +++ CPersistenceBroker.vb 20 Oct 2004 06:44:23 -0000 1.70 @@ -2123,9 +2123,20 @@ Dim i, k As Integer Dim tmpObj As Object - 'Determine if the object needs saving + If obj.IsQueued Then + 'if an object has already been added to the save queue, there is no need to add + 'it again (could result in infinite recursion) + Return queue + End If + If Not checkAssociationsRecursivly Then - If Not obj.IsDirty Then Return queue 'Do not save if nothing changed + If includeBaseObject Then + 'This will be on when we start saving a normal object. Recursive calls + 'to this method while processing parent class maps will turn this off. + 'Note that parent objects will not be dirty so in this case so we cannot + 'do the normal IsDirty check. + If Not obj.IsDirty Then Return queue 'Do not save if nothing changed + End If If obj.IsProxy Then Return queue 'Do not save if object is proxied If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then If Not CType(obj, CPersistentObject).IsValid Then Return queue 'Do not save if object is not valid @@ -2139,6 +2150,7 @@ If includeBaseObject Then obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) + obj.IsQueued = True End If Else 'Determine if the object needs saving @@ -2146,13 +2158,15 @@ If includeBaseObject AndAlso _ (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.IsReadOnly AndAlso Not obj.IsModifyOnly) Then If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then - If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid + If CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) + obj.IsQueued = True End If Else obj.IsDirty = False queue.Enqueue(obj) + obj.IsQueued = True End If End If End If @@ -2168,13 +2182,11 @@ udamap = cm.getStraightAssociationMap(i) If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - tmpObj = obj.GetObjectByAttribute(udamap.Target) - If Not tmpObj Is Nothing Then - If Not value Is Nothing Then - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - End If + value = obj.GetObjectByAttribute(udamap.Target) + If Not value Is Nothing Then + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then col = obj.GetCollectionByAttribute(udamap.Target) @@ -2182,7 +2194,7 @@ For k = 0 To col.Count() - 1 tmpObj = col.Item(k) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2199,13 +2211,11 @@ udamap = cm.getInverseAssociationMap(i) If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - tmpObj = obj.GetObjectByAttribute(udamap.Target) - If Not tmpObj Is Nothing Then - If Not value Is Nothing Then - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - End If + value = obj.GetObjectByAttribute(udamap.Target) + If Not value Is Nothing Then + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then col = obj.GetCollectionByAttribute(udamap.Target) @@ -2213,7 +2223,7 @@ For k = 0 To col.Count() - 1 tmpObj = col.Item(k) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2234,7 +2244,7 @@ If Not cm.SuperClass Is Nothing Then tmpObj = obj.GetObjectByClassMap(cm.SuperClass) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2248,7 +2258,7 @@ If Not cm.SuperClass Is Nothing Then tmpObj = obj.GetObjectByClassMap(cm.SuperClass) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2397,6 +2407,16 @@ Return injObj End Function + Public Function LocateOrCacheInjObject(ByVal obj As Object) As CInjectedObject + Dim injObj As CInjectedObject + injObj = m_injectedObjects.LocateObject(obj) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) + m_injectedObjects.Add(injObj) + End If + Return injObj + End Function + Public Sub StartTracking(ByVal obj As Object) Dim injObj As CInjectedObject injObj = New CInjectedObject(obj) Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- IPersistentObject.vb 15 Oct 2004 06:42:56 -0000 1.4 +++ IPersistentObject.vb 20 Oct 2004 06:44:23 -0000 1.5 @@ -10,6 +10,7 @@ Property OriginalModifiedDate() As Date Property AssociationsLoaded() As Boolean Property IsLoading() As Boolean + Property IsQueued() As Boolean ReadOnly Property IsReadOnly() As Boolean ReadOnly Property IsModifyOnly() As Boolean Property OriginalCacheKey() As CCacheKey Index: CPersistentCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCriteria.vb,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CPersistentCriteria.vb 21 Jul 2004 02:55:38 -0000 1.7 +++ CPersistentCriteria.vb 20 Oct 2004 06:44:23 -0000 1.8 @@ -244,9 +244,11 @@ If m_Associations.Count() > 0 Then If clauseConditionAdded Then statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringAnd & " ") + clauseConditionAdded = False End If End If - ElseIf m_WhereCondition.getSize > 0 Then + End If + If m_WhereCondition.getSize > 0 Then statement.addSqlClause(" ") If clauseConditionAdded Then statement.addSqlClause(Me.ClassMap.RelationalDatabase.getClauseStringAnd & " ") Index: CCursor.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCursor.vb,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- CCursor.vb 18 Oct 2004 03:31:51 -0000 1.11 +++ CCursor.vb 20 Oct 2004 06:44:23 -0000 1.12 @@ -296,7 +296,7 @@ End Sub Public Sub loadPersistentObject(ByRef obj As CPersistentObject) - loadObject(obj, 0) + loadPersistentObject(obj, 0) End Sub '''----------------------------------------------------------------------------- Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CInjectedObject.vb 18 Oct 2004 01:36:43 -0000 1.3 +++ CInjectedObject.vb 20 Oct 2004 06:44:23 -0000 1.4 @@ -21,6 +21,7 @@ Private m_persistent As Boolean Private m_retrievedCacheKey As CCacheKey Private m_loading As Boolean + Private m_queued As Boolean Private m_proxy As Boolean Private m_markedForDeletion As Boolean Private m_deleteParents As Boolean @@ -292,6 +293,15 @@ End Set End Property + Public Property IsQueued() As Boolean Implements IPersistableObject.IsQueued + Get + Return m_queued + End Get + Set(ByVal Value As Boolean) + m_queued = Value + End Set + End Property + Public ReadOnly Property isModifyOnly() As Boolean Implements IPersistableObject.isModifyOnly Get Return getClassMap.isModifyOnly Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- CPersistentObject.vb 19 Oct 2004 03:32:08 -0000 1.44 +++ CPersistentObject.vb 20 Oct 2004 06:44:23 -0000 1.45 @@ -40,7 +40,8 @@ Private m_associationsLoaded As Boolean Private m_guid As Guid Private m_isLoading As Boolean = False - Private m_checkingAssociations As Boolean + Private m_isQueued As Boolean = False + Private m_checkingAssociations As Boolean Private m_isNew As Boolean Private m_editing As Boolean <NonSerialized()> Private m_classmap As CClassMap @@ -435,6 +436,15 @@ End Set End Property + <Browsable(False)> Public Property IsQueued() As Boolean Implements IPersistentObject.IsQueued + Get + Return m_isQueued + End Get + Set(ByVal Value As Boolean) + m_isQueued = Value + End Set + End Property + <Browsable(False)> Friend Property OriginalCacheKey() As CCacheKey Implements IPersistableObject.OriginalCacheKey Get Return m_retrievedCacheKey |