From: Dan M. <dan...@us...> - 2005-01-02 09:41:24
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1805/dotnet Modified Files: CPersistenceBroker.vb Log Message: Add test to check if multiple retrive creteria of oneToMany collections does not duplicate records. Fix the problem in retriveAssociation() in CPersistentBroker.vb. Checks whether the object exist in the collection before adding it. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.87 retrieving revision 1.88 diff -u -d -r1.87 -r1.88 --- CPersistenceBroker.vb 22 Dec 2004 04:15:39 -0000 1.87 +++ CPersistenceBroker.vb 2 Jan 2005 09:41:10 -0000 1.88 @@ -201,7 +201,7 @@ If Not x Is Nothing Then Throw x End If - End Try + End Try End SyncLock End Function @@ -701,6 +701,8 @@ Dim found As Boolean Dim col As IList Dim myKeys(cm.AssociationMaps.Count) As String + Dim tmpObj As IPersistableObject + cm.AssociationMaps.Keys.CopyTo(myKeys, 0) Dim anObjPers As IPersistableObject For i = 0 To cm.AssociationMaps.Count - 1 @@ -751,12 +753,12 @@ End Try End If If found Then - Value.IsDirty = False 'After populating a new object - Value.OriginalCacheKey = New CCacheKey(Value) - obj.SetAttributeValue(udaMap.Target, Value.GetSourceObject) + Value.IsDirty = False 'After populating a new object + Value.OriginalCacheKey = New CCacheKey(Value) + obj.SetAttributeValue(udaMap.Target, Value.GetSourceObject) + End If End If End If - End If ElseIf udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then For j = 1 To udaMap.getSize ValueVar = cm.getValueForRelationalDatabase(obj.GetValueByAttribute(udaMap.getEntry(j).FromAttrMap.Name)) @@ -779,14 +781,26 @@ cursor.loadObject(anObjPers.GetSourceObject) retrieveAssociations(anObjPers, conn, anObjPers.GetClassMap, useCache) End If - anObjPers.IsDirty = False 'After populating a new object - anObjPers.OriginalCacheKey = New CCacheKey(anObjPers) - col.Add(anObjPers.GetSourceObject) - m_cache.Add(anObjPers) 'Add retrieved objects to the cache - Try - PCCacheSize.RawValue = m_cache.Count - Catch - End Try + 'Need to determine if new object is already in the collection + '(prevents duplicates when multiple one-to-many associations exist) + gotValue = False + For Each tmpColObj As Object In col + If tmpColObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then + tmpObj = tmpColObj + Else + tmpObj = LocateOrCreateInjObject(tmpColObj) + End If + If tmpObj.Equals(anObjPers) Then + gotValue = True + End If + Next + + If Not gotValue Then + anObjPers.IsDirty = False 'After populating a new object + anObjPers.OriginalCacheKey = New CCacheKey(anObjPers) + col.Add(anObjPers.GetSourceObject) + m_cache.Add(anObjPers) 'Add retrieved objects to the cache + End If cursor.nextCursor() End While End If @@ -976,7 +990,7 @@ Try deletePrivateObject(obj, conn, deleteSuperClass) conn.commit() - Catch ex As Exception + Catch ex As Exception x = New DeleteException(ex.Message, ex) conn.rollback() Finally @@ -991,7 +1005,7 @@ If Not x Is Nothing Then Throw x End If - End Try + End Try End SyncLock End Sub @@ -1822,9 +1836,9 @@ Return cursor Catch - firstClassMap.RelationalDatabase.freeConnection(conn) - Return Nothing - End Try + firstClassMap.RelationalDatabase.freeConnection(conn) + Return Nothing + End Try End Function |