From: Richard B. <rb...@us...> - 2005-04-11 23:17:40
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5193 Modified Files: Tag: v2_1 CInjectedObject.vb CPersistenceBroker.vb CPersistentObject.vb Log Message: Only copy one-to-many collections if the association is retrieveAutomatic. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.107 retrieving revision 1.107.2.1 diff -u -d -r1.107 -r1.107.2.1 --- CPersistenceBroker.vb 7 Apr 2005 07:08:16 -0000 1.107 +++ CPersistenceBroker.vb 11 Apr 2005 23:17:26 -0000 1.107.2.1 @@ -2716,6 +2716,7 @@ End If 'Now go through and find out which objects have been removed from the collection 'and attempt to modify and/or delete them. + If udamap.RetrieveAutomatic = True And udamap.LazyLoad = False Then For Each value In obj.GetRemovedCollectionItems(udamap.FromClassTarget) If udamap.DeleteAutomatic = True Then 'Delete the object @@ -2738,6 +2739,7 @@ q.Enqueue(value) End If Next + End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.MANY_TO_MANY Then If obj.GetClassMap.Name = udamap.FromClass.Name Then col = obj.GetCollectionByAttribute(udamap.FromClassTarget) @@ -3409,12 +3411,17 @@ Dim p As PropertyInfo Dim tmpObj As Object + p = fromObject.GetObjectType.GetProperty(propertyName, BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + If p Is Nothing Then + 'Property propertyName couldn't be found + Return Nothing + End If + fromColl = fromObject.GetCollectionByAttribute(propertyName) If fromColl Is Nothing Then Return Nothing End If - p = fromObject.GetObjectType.GetProperty(propertyName, BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) iListType = p.PropertyType.GetInterface("IList", True) iDicType = p.PropertyType.GetInterface("IDictionary", True) If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.25 retrieving revision 1.25.2.1 diff -u -d -r1.25 -r1.25.2.1 --- CInjectedObject.vb 7 Apr 2005 07:08:16 -0000 1.25 +++ CInjectedObject.vb 11 Apr 2005 23:17:19 -0000 1.25.2.1 @@ -665,11 +665,11 @@ 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 - coll = CPersistenceBroker.CopyCollection(Me, aMap.FromClassTarget) - m_oneToManyCollections.Add(coll, aMap.FromClassTarget) - End If - Next + If aMap.Cardinality = aMap.CardinalityEnum.ONE_TO_MANY And aMap.LazyLoad = False And aMap.RetrieveAutomatic = True And aMap.SaveAutomatic = True Then + coll = CPersistenceBroker.CopyCollection(Me, aMap.FromClassTarget) + m_oneToManyCollections.Add(coll, aMap.FromClassTarget) + End If + Next cm = cm.SuperClass End While End Sub Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.65 retrieving revision 1.65.2.1 diff -u -d -r1.65 -r1.65.2.1 --- CPersistentObject.vb 7 Apr 2005 07:08:18 -0000 1.65 +++ CPersistentObject.vb 11 Apr 2005 23:17:28 -0000 1.65.2.1 @@ -602,17 +602,17 @@ dotPos = pName.IndexOf(".") Try - If dotPos = -1 Then + If dotPos = -1 Then obj = CallByName(Me, pName, CallType.Get) - Else - Dim o As Object - Dim objName As String - Dim propertyName As String - objName = pName.Substring(0, dotPos) - propertyName = pName.Substring(dotPos + 1) - o = CallByName(Me, objName, CallType.Get) + Else + Dim o As Object + Dim objName As String + Dim propertyName As String + objName = pName.Substring(0, dotPos) + propertyName = pName.Substring(dotPos + 1) + o = CallByName(Me, objName, CallType.Get) obj = CallByName(o, propertyName, CallType.Get) - End If + End If If obj Is Nothing Then Return Nothing If TypeOf obj Is IPersistableObject Then injobj = obj @@ -919,57 +919,57 @@ 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 persistentBroker = getPersistenceBrokerInstance() Try - queue = persistentBroker.getObjectsToSave(obj, True, checkAssociationsRecursivly) - 'All objects to be saved must be saved in a single transaction. - If queue.Count > 0 Then - persistentBroker.startTransaction() - Do While queue.Count > 0 - qObject = queue.Dequeue() - Try - If GetType(CAssociationObject).IsInstanceOfType(qObject) Then - persistentBroker.saveAssociationObject(qObject) - ElseIf GetType(CQueuedDelete).IsInstanceOfType(qObject) Then - Try - persistentBroker.deleteObject(CType(qObject, CQueuedDelete).ObjectToDelete) - Catch ex As Exception - Debug.WriteLine("(Queued Delete) Tried to delete an object that has already been removed") - Debug.WriteLine(ex.Message) - End Try - Else - value = qObject - 'Normal object saving - ckey = New CCacheKey(value) - If savedKeys.Contains(ckey) Then - 'object was already saved (could be new object referenced by multiple other new objects) - Debug.WriteLine("The object with key " & ckey.ToString & " was already saved once") + queue = persistentBroker.getObjectsToSave(obj, True, checkAssociationsRecursivly) + 'All objects to be saved must be saved in a single transaction. + If queue.Count > 0 Then + persistentBroker.startTransaction() + Do While queue.Count > 0 + qObject = queue.Dequeue() + Try + If GetType(CAssociationObject).IsInstanceOfType(qObject) Then + persistentBroker.saveAssociationObject(qObject) + ElseIf GetType(CQueuedDelete).IsInstanceOfType(qObject) Then + Try + persistentBroker.deleteObject(CType(qObject, CQueuedDelete).ObjectToDelete) + Catch ex As Exception + Debug.WriteLine("(Queued Delete) Tried to delete an object that has already been removed") + Debug.WriteLine(ex.Message) + End Try Else - persistentBroker.saveObject(value) - 'Recopy one-to-many collections incase object is resaved later - value.CopyOneToManyCollections() - 'Need to recalculate the key here to handle objects using identity (autonumber) keys + value = qObject + 'Normal object saving ckey = New CCacheKey(value) - savedKeys.Add(ckey) + If savedKeys.Contains(ckey) Then + 'object was already saved (could be new object referenced by multiple other new objects) + Debug.WriteLine("The object with key " & ckey.ToString & " was already saved once") + Else + persistentBroker.saveObject(value) + 'Recopy one-to-many collections incase object is resaved later + value.CopyOneToManyCollections() + 'Need to recalculate the key here to handle objects using identity (autonumber) keys + ckey = New CCacheKey(value) + savedKeys.Add(ckey) + End If End If - End If - Catch ex As Exception - 'After an error remove the cached object so that the next retrieve - ' will refresh the cache with the item from the database - persistentBroker.deleteCachedObject(value) - 'Abort the transaction and throw an error - persistentBroker.rollback() - Throw New SaveException(ex.Message, ex) - End Try - value.IsDirty = False - Loop - persistentBroker.commit() - End If + Catch ex As Exception + 'After an error remove the cached object so that the next retrieve + ' will refresh the cache with the item from the database + persistentBroker.deleteCachedObject(value) + 'Abort the transaction and throw an error + persistentBroker.rollback() + Throw New SaveException(ex.Message, ex) + End Try + value.IsDirty = False + Loop + persistentBroker.commit() + End If Catch sx As SaveException Throw sx Catch ex As Exception @@ -1754,13 +1754,14 @@ 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 - coll = CPersistenceBroker.CopyCollection(Me, aMap.FromClassTarget) - m_oneToManyCollections.Add(coll, aMap.FromClassTarget) - End If - Next + For Each de As DictionaryEntry In cm.AssociationMaps + aMap = de.Value + 'Only copy associations with retrieveAutomatic="true". Exclude lazy loaded associations. + If aMap.Cardinality = aMap.CardinalityEnum.ONE_TO_MANY And aMap.RetrieveAutomatic = True And aMap.LazyLoad = False And aMap.SaveAutomatic = True Then + coll = CPersistenceBroker.CopyCollection(Me, aMap.FromClassTarget) + m_oneToManyCollections.Add(coll, aMap.FromClassTarget) + End If + Next cm = cm.SuperClass End While End Sub |