Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27280 Modified Files: CInjectedObject.vb CInjectedObjects.vb CJoin.vb COID.vb COIDFactory.vb CPersistenceBroker.vb CPersistentObject.vb CXMLConfigLoader.vb Log Message: Fix for cache problems when changing key values of objects that don't inherit from CPersistentObject Also fixed problem where many-to-many associations tried to save associationclass multiple times. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -r1.72 -r1.73 --- CPersistenceBroker.vb 22 Oct 2004 05:33:17 -0000 1.72 +++ CPersistenceBroker.vb 25 Oct 2004 07:12:31 -0000 1.73 @@ -774,6 +774,11 @@ obj.IsDirty = False obj.IsQueued = False 'Update cache key in-case primary key fields have changed value + If Not obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then + If Not obj.OriginalCacheKey Is Nothing Then + m_cache.Remove(obj.OriginalCacheKey) + End If + End If obj.OriginalCacheKey = New CCacheKey(obj) If m_useCache Then m_cache.Add(obj) 'Add to the cache @@ -2477,6 +2482,8 @@ Dim value As IPersistableObject Dim queue As Queue Dim injObj As CInjectedObject + Dim ckey As CCacheKey + Dim savedKeys As New ArrayList injObj = m_injectedObjects.LocateObject(obj) If injObj Is Nothing Then @@ -2496,7 +2503,14 @@ Do While queue.Count > 0 value = queue.Dequeue() Try - saveObject(value) + 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") + Else + saveObject(value) + savedKeys.Add(ckey) + 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 Index: CInjectedObjects.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObjects.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CInjectedObjects.vb 15 Oct 2004 06:42:56 -0000 1.2 +++ CInjectedObjects.vb 25 Oct 2004 07:12:31 -0000 1.3 @@ -7,38 +7,42 @@ Private m_keyvalues As Collection Public Sub New(ByVal obj As Object) - m_keyvalues = New Collection - m_hashCode = obj.GetHashCode - Dim injObj As New CInjectedObject(obj) - populateKey(injObj) + If obj.GetType Is GetType(CInjectedObject) Then + NewInjObj(CType(obj, CInjectedObject)) + Else + m_keyvalues = New Collection + m_hashCode = obj.GetHashCode + Dim injObj As New CInjectedObject(obj) + populateKey(injObj) + End If End Sub - Public Sub New(ByVal obj As CInjectedObject) + Public Sub NewInjObj(ByVal injobj As CInjectedObject) m_keyvalues = New Collection - If obj.ReferencedObject Is Nothing Then + If injobj.ReferencedObject Is Nothing Then m_hashCode = 0 Else - m_hashCode = obj.ReferencedObject.GetHashCode + m_hashCode = injobj.ReferencedObject.GetHashCode End If - populateKey(obj) + populateKey(injobj) End Sub Public Overrides Function GetHashCode() As Integer Return m_hashCode End Function - Protected Sub populateKey(ByVal obj As IPersistableObject) + Protected Sub populateKey(ByVal injObj As IPersistableObject) Dim cm As CClassMap - Dim i As Integer + Dim i As Short Dim am As CAttributeMap Dim x As Object m_keyvalues = New Collection - m_type = obj.GetObjectType - cm = obj.getClassMap + m_type = injObj.GetObjectType + cm = injObj.GetClassMap For i = 1 To cm.getKeySize am = cm.getKeyAttributeMap(i) - x = obj.getValueByAttribute(am.Name) + x = injObj.GetValueByAttribute(am.Name) m_keyvalues.Add(x) Next End Sub @@ -47,8 +51,8 @@ Dim flag As Boolean Dim i As Integer Dim key1, key2 As CInjectedObjectKey - key1 = obj1 - key2 = obj2 + key1 = CType(obj1, CInjectedObjectKey) + key2 = CType(obj2, CInjectedObjectKey) Return key1.Equals(key2) End Function @@ -56,7 +60,7 @@ Dim flag As Boolean Dim i As Integer Dim key As CInjectedObjectKey - key = obj1 + key = CType(obj1, CInjectedObjectKey) flag = False For i = 1 To m_keyvalues.Count If Me.GetHashCode <> key.GetHashCode Then @@ -117,7 +121,7 @@ Dim injObj As CInjectedObject injKey = New CInjectedObjectKey(obj) If Not (MyBase.Item(injKey) Is Nothing) Then - injObj = MyBase.Item(injKey) + injObj = CType(MyBase.Item(injKey), CInjectedObject) Return injObj Else Return Nothing @@ -152,11 +156,12 @@ Dim injObj As CInjectedObject Dim x As DictionaryEntry Dim attrmap As CAttributeMap - Dim i As Integer + Dim i As Short Dim found As Boolean Dim cm As CClassMap Dim t As Type Dim interval As Double + Dim ikey As CInjectedObjectKey cm = obj.getClassMap @@ -164,14 +169,14 @@ Dim m_Enumerator As Collections.IEnumerator = Me.GetEnumerator() While m_Enumerator.MoveNext() - x = m_Enumerator.Current - injObj = x.Value + x = CType(m_Enumerator.Current, DictionaryEntry) + injObj = CType(x.Value, CInjectedObject) t = injObj.GetObjectType If t Is obj.GetObjectType Or t.IsSubclassOf(obj.GetObjectType) Then found = True If useFindAttributes Then For i = 1 To cm.getFindSize - attrmap = cm.FindAttributeMaps(i) + attrmap = CType(cm.FindAttributeMaps(i), CAttributeMap) If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then found = False Exit For @@ -179,7 +184,7 @@ Next i Else For i = 1 To cm.getKeySize - attrmap = cm.KeyAttributeMaps(i) + attrmap = CType(cm.KeyAttributeMaps(i), CAttributeMap) If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then found = False Exit For @@ -190,7 +195,8 @@ 'If ce.TransactionType = CCacheEntry.CacheTransaction.Deleted Then ' Return Nothing 'End If - Debug.WriteLine([String].Format("Injection Cache - getting {0} object from cache. Key..." & vbCrLf & x.Key.ToString, x.Key.ObjType.Name)) + ikey = CType(x.Key, CInjectedObjectKey) + Debug.WriteLine([String].Format("Injection Cache - getting object from cache. Key..." & vbCrLf & ikey.ToString)) Return injObj End If End If @@ -218,9 +224,9 @@ outString = ">>>> START TRACKED OBJECTS DUMP <<<<" & vbCrLf i = 1 For Each x In Me - injObj = x.Value + injObj = CType(x.Value, CInjectedObject) t = injObj.GetObjectType - key = x.Key + key = CType(x.Key, CInjectedObjectKey) outString &= i.ToString & "> " & t.ToString & vbCrLf & injObj.ToString & vbCrLf i += 1 Next x Index: CXMLConfigLoader.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CXMLConfigLoader.vb,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- CXMLConfigLoader.vb 19 Oct 2004 01:59:57 -0000 1.25 +++ CXMLConfigLoader.vb 25 Oct 2004 07:12:32 -0000 1.26 @@ -619,8 +619,7 @@ Loop fromClassMap.addAssociationMap(udaAm) Else - Throw New XMLMappingException("Error in association definition: Missing FromClass, ToClass or Target attributes") - End If - + Throw New XMLMappingException([String].Format("Error in association definition: Missing FromClass({0}), ToClass({1}) or Target({2}) attributes", attrFromClass, attrToClass, attrTarget)) + End If End Sub End Class \ No newline at end of file Index: CJoin.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CJoin.vb,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- CJoin.vb 19 Oct 2004 03:32:08 -0000 1.8 +++ CJoin.vb 25 Oct 2004 07:12:31 -0000 1.9 @@ -269,14 +269,14 @@ Dim s As String Dim tm As CTableMap Dim cm As CClassMap - Dim i, j As Integer + Dim i, j As Short Dim udaEntry As CUDAMapEntry - Dim db As CRelationalDatabase + Dim db As _CRelationalDatabase Dim leftBracket As String = "(" Dim rightBracket As String = ")" If LeftSide Is Nothing Then - tm = RightSide.Tables.Item(1) + tm = CType(RightSide.Tables.Item(1), CTableMap) s = RightSide.RelationalDatabase.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) Else If IsSuperClass Then @@ -286,7 +286,7 @@ leftBracket = "" rightBracket = "" End If - tm = RightSide.Tables.Item(1) + tm = CType(RightSide.Tables.Item(1), CTableMap) s = leftBracket & LeftSide.GetSQLString & " " & db.getClauseStringLeftJoin _ & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " For i = 1 To cm.getReferenceSize @@ -307,7 +307,7 @@ leftBracket = "" rightBracket = "" End If - tm = RightSide.Tables.Item(1) + tm = CType(RightSide.Tables.Item(1), CTableMap) s = leftBracket & LeftSide.GetSQLString & " " & db.getClauseStringLeftJoin & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " For i = 1 To cm.getReferenceSize If i > 1 Then @@ -324,10 +324,10 @@ leftBracket = "" rightBracket = "" End If - tm = cm.Tables.Item(1) + tm = CType(cm.Tables.Item(1), CTableMap) s = leftBracket & LeftSide.GetSQLString & " " & db.getClauseStringLeftJoin _ & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " - For i = 1 To Association.Entries.Count + For i = 1 To CType(Association.Entries.Count, Short) If i > 1 Then s = s & " " & db.getClauseStringAnd & " " End If Index: COID.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/COID.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- COID.vb 21 Jul 2004 02:55:38 -0000 1.4 +++ COID.vb 25 Oct 2004 07:12:31 -0000 1.5 @@ -89,7 +89,7 @@ m_aValueString = Value.Substring(0, 8) m_bValueString = Value.Substring(8) m_aValue = CInt("&H" & m_aValueString) - m_bValue = CInt("&H" & m_bValueString) + m_bValue = CShort("&H" & m_bValueString) End Set End Property End Class Index: COIDFactory.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/COIDFactory.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- COIDFactory.vb 21 Jul 2004 02:55:38 -0000 1.3 +++ COIDFactory.vb 25 Oct 2004 07:12:31 -0000 1.4 @@ -35,7 +35,7 @@ Dim oid As New COID oid.AValue = fetchAValue() Try - m_nextBValue += 1 + m_nextBValue += 1S Catch m_fetchedAValue = False oid.AValue = fetchAValue() ' get a new A value @@ -65,7 +65,7 @@ If m_fetchedAValue = False Then persistenceBroker = getPersistenceBrokerInstance() For Each de In persistenceBroker.Databases - reldb = de.Value + reldb = CType(de.Value, _CRelationalDatabase) 'Just use the first database with an OID setting to get the AValue If reldb.OIDTable.Length > 0 Then m_nextAValue = reldb.getNextOIDAValue Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CInjectedObject.vb 20 Oct 2004 06:44:23 -0000 1.4 +++ CInjectedObject.vb 25 Oct 2004 07:12:31 -0000 1.5 @@ -61,7 +61,7 @@ End If Dim injObj As CInjectedObject If TypeOf (obj) Is CInjectedObject Then - injObj = obj + injObj = CType(obj, CInjectedObject) ReplaceValues(injObj.m_object, m_object) Else ReplaceValues(obj, m_object) @@ -363,7 +363,7 @@ dotPos = pName.IndexOf(".") Try If dotPos = -1 Then - Return CallByName(m_object, pName, CallType.Get) + Return CType(CallByName(m_object, pName, CallType.Get), IList) Else Dim o As Object Dim objName As String @@ -371,7 +371,7 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) - Return CallByName(o, propertyName, CallType.Get) + Return CType(CallByName(o, propertyName, CallType.Get), IList) End If Catch err As Exception Throw New Exception("getCollectionByAttribute failed", err) @@ -398,7 +398,7 @@ End If If obj Is Nothing Then Return Nothing If obj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then - injobj = obj + injobj = CType(obj, CInjectedObject) Else pbroker = getPersistenceBrokerInstance() injobj = pbroker.getInjectedObject(obj) @@ -470,7 +470,7 @@ Public Function Copy() As IPersistableObject Implements IPersistableObject.Copy 'Dim m_object2 As Object Dim injobj As CInjectedObject - injobj = Me.MemberwiseClone + injobj = CType(Me.MemberwiseClone, CInjectedObject) 'm_object2 = Activator.CreateInstance(m_object.GetType) 'ReplaceValues(m_object, m_object2) 'injobj = New CInjectedObject(m_object2) @@ -484,7 +484,7 @@ Function getObjectByClassMap(ByVal classMap As CClassMap) As IPersistableObject Implements IPersistableObject.getObjectByClassMap Dim obj, Value As IPersistableObject Dim col As IList - Dim i, k As Integer + Dim i, k As Short Dim cm As CClassMap Dim de As DictionaryEntry Dim udamap As CUDAMap @@ -509,7 +509,7 @@ Next i 'set object's attributes - For i = 1 To classMap.AttributeMaps.Count + For i = 1 To CType(classMap.AttributeMaps.Count, Short) obj.SetAttributeValue(classMap.getAttributeMap(i).Name, Me.getValueByAttribute(classMap.getAttributeMap(i).Name)) Next @@ -529,7 +529,7 @@ Next i 'set superclass's attributes - For i = 1 To cm.AttributeMaps.Count + For i = 1 To CType(cm.AttributeMaps.Count, Short) obj.SetAttributeValue(cm.getAttributeMap(i).Name, Me.getValueByAttribute(cm.getAttributeMap(i).Name)) Next cm = cm.SuperClass @@ -555,7 +555,7 @@ Public Overrides Function ToString() As String Dim s As String - Dim i As Integer + Dim i As Short Dim indent As Integer Dim formatString As String Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- CPersistentObject.vb 21 Oct 2004 23:35:23 -0000 1.46 +++ CPersistentObject.vb 25 Oct 2004 07:12:32 -0000 1.47 @@ -871,6 +871,8 @@ Dim persistentBroker As CPersistenceBroker Dim value As IPersistableObject Dim queue As Queue + Dim savedKeys As New ArrayList + Dim ckey As CCacheKey persistentBroker = getPersistenceBrokerInstance() queue = persistentBroker.getObjectsToSave(obj, True, checkAssociationsRecursivly) @@ -881,7 +883,14 @@ Do While queue.Count > 0 value = queue.Dequeue() Try - persistentBroker.saveObject(value) + 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") + Else + persistentBroker.saveObject(value) + savedKeys.Add(ckey) + 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 |