You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(56) |
Nov
(13) |
Dec
(36) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(7) |
Feb
(55) |
Mar
(33) |
Apr
(71) |
May
(12) |
Jun
|
Jul
(5) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Richard B. <rb...@us...> - 2005-03-16 11:34:28
|
Update of /cvsroot/jcframework/Nunit/StandardClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18429/StandardClasses Modified Files: NonInheritedRetreiveCriteria.vb Log Message: Extra unit tests for retrieve criteria. Some minor mods for existing unit tests related to framework changes. Index: NonInheritedRetreiveCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/StandardClasses/NonInheritedRetreiveCriteria.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- NonInheritedRetreiveCriteria.vb 21 Dec 2004 22:00:02 -0000 1.2 +++ NonInheritedRetreiveCriteria.vb 16 Mar 2005 11:34:13 -0000 1.3 @@ -58,7 +58,6 @@ While c.hasElements And Not c.EOF emp = New NPEmployee c.loadObject(emp) - Console.WriteLine(emp.Name) injObj = pbroker.getInjectedObject(emp) Assert.IsTrue(injObj.Persistent) c.nextCursor() |
From: Richard B. <rb...@us...> - 2005-03-16 11:34:27
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18429/InheritedClasses Modified Files: CEmployee.vb ManyToManyClasses_v2.vb MultiRetrieveTests.vb RetrieveCriteriaTests.vb SuperClassTests.vb Log Message: Extra unit tests for retrieve criteria. Some minor mods for existing unit tests related to framework changes. Index: RetrieveCriteriaTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/RetrieveCriteriaTests.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- RetrieveCriteriaTests.vb 21 Dec 2004 22:00:01 -0000 1.4 +++ RetrieveCriteriaTests.vb 16 Mar 2005 11:34:12 -0000 1.5 @@ -81,7 +81,6 @@ While c.hasElements And Not c.EOF emp = New CEmployee c.loadObject(emp) - Console.WriteLine(emp.Name) Assert.IsTrue(emp.Persistent) c.nextCursor() End While Index: ManyToManyClasses_v2.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/ManyToManyClasses_v2.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ManyToManyClasses_v2.vb 14 Feb 2005 02:24:12 -0000 1.2 +++ ManyToManyClasses_v2.vb 16 Mar 2005 11:34:12 -0000 1.3 @@ -81,7 +81,6 @@ Public Sub New() _aCol = New M2MACollection - _aCol.ContainerObject = Me End Sub End Class Index: CEmployee.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/CEmployee.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CEmployee.vb 19 Oct 2004 00:13:38 -0000 1.1 +++ CEmployee.vb 16 Mar 2005 11:34:12 -0000 1.2 @@ -12,7 +12,7 @@ Private m_name As String Private m_parentoid As String Private m_parent As CEmployee - Private m_children As CPersistentCollection + Private WithEvents m_children As CPersistentCollection Private m_team As CTeam Private m_teamoid As String @@ -104,8 +104,10 @@ Public Sub New() MyBase.New() m_children = New CPersistentCollection - m_children.ContainerObject = Me End Sub + Private Sub m_children_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles m_children.ListChanged + Me.SetDirtyFlag() + End Sub End Class End Namespace \ No newline at end of file Index: MultiRetrieveTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/MultiRetrieveTests.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- MultiRetrieveTests.vb 16 Mar 2005 09:35:16 -0000 1.4 +++ MultiRetrieveTests.vb 16 Mar 2005 11:34:12 -0000 1.5 @@ -50,41 +50,58 @@ Assert.AreEqual(3, c.TotalRows) End Sub - <Test()> Public Sub ChainedClassesWithOrderBy() - Dim mr1 As New mr1 - Dim mr2 As New mr2 - Dim mr3 As New mr3 - mrc = New CMultiRetrieveCriteria - mrc.addObjectToJoin(mr1, Nothing, "") - mrc.addObjectToJoin(mr2, mr1, "mr1tomr2") - mrc.addObjectToJoin(mr3, mr2, "mr2tomr3") - mrc.addOrderAttribute("mr3.field1") - mrc.ReturnFullObjects = True - c = mrc.perform - Assert.IsTrue(c.hasElements) - Assert.IsTrue(Not c.EOF) - Assert.IsFalse(c.HoldsProxies) - Assert.AreEqual(3, c.TotalRows) - End Sub + <Test()> Public Sub ChainedClassesWithWhere() + Dim mr1 As New mr1 + Dim mr2 As New mr2 + Dim mr3 As New mr3 + mrc = New CMultiRetrieveCriteria + mrc.addObjectToJoin(mr1, Nothing, "") + mrc.addObjectToJoin(mr2, mr1, "mr1tomr2") + mrc.addObjectToJoin(mr3, mr2, "mr2tomr3") + mrc.WhereCondition.addSelectNotEqualTo("field1", "xxx") + mrc.ReturnFullObjects = True + c = mrc.perform + Assert.IsTrue(c.hasElements) + Assert.IsTrue(Not c.EOF) + Assert.IsFalse(c.HoldsProxies) + Assert.AreEqual(3, c.TotalRows) + End Sub - <Test()> Public Sub SaveMRClasses() - Dim mr1 As New mr1 - mr1.id = "id1" - mr1.field1 = "_a" - mr1.field2 = 1 - Dim mr2 As New mr2 - mr2.id = "id2" - mr2.field1 = "_aa" - mr2.field2 = 2 - mr1.mr2 = mr2 - Dim mr3 As New mr3 - mr3.id = "id3" - mr3.field1 = "zz" - mr3.field2 = 3 - mr2.mr3 = mr3 - mr1.Save() - mr2.field2 = 22 - mr2.Save() + <Test()> Public Sub ChainedClassesWithOrderBy() + Dim mr1 As New mr1 + Dim mr2 As New mr2 + Dim mr3 As New mr3 + mrc = New CMultiRetrieveCriteria + mrc.addObjectToJoin(mr1, Nothing, "") + mrc.addObjectToJoin(mr2, mr1, "mr1tomr2") + mrc.addObjectToJoin(mr3, mr2, "mr2tomr3") + mrc.addOrderAttribute("mr3.field1") + mrc.ReturnFullObjects = True + c = mrc.perform + Assert.IsTrue(c.hasElements) + Assert.IsTrue(Not c.EOF) + Assert.IsFalse(c.HoldsProxies) + Assert.AreEqual(3, c.TotalRows) + End Sub + + <Test()> Public Sub SaveMRClasses() + Dim mr1 As New mr1 + mr1.id = "id1" + mr1.field1 = "_a" + mr1.field2 = 1 + Dim mr2 As New mr2 + mr2.id = "id2" + mr2.field1 = "_aa" + mr2.field2 = 2 + mr1.mr2 = mr2 + Dim mr3 As New mr3 + mr3.id = "id3" + mr3.field1 = "zz" + mr3.field2 = 3 + mr2.mr3 = mr3 + mr1.Save() + mr2.field2 = 22 + mr2.Save() End Sub <Test()> Public Sub SummaryChainedClasses() @@ -103,5 +120,22 @@ Assert.AreEqual(1, c.TotalRows) End Sub + <Test()> Public Sub SummaryChainedClassesWithWhere() + Dim mr1 As New mr1 + Dim mr2 As New mr2 + Dim mr3 As New mr3 + Dim src As CMultiSummaryCriteria + src = New CMultiSummaryCriteria + src.addObjectToJoin(mr1, Nothing, "") + src.addObjectToJoin(mr2, mr1, "mr1tomr2") + src.addObjectToJoin(mr3, mr2, "mr2tomr3") + src.addSummaryField("field1", CMultiSummaryCriteria.SumMethod.Count) + src.WhereCondition.addSelectNotEqualTo("field1", "xxx") + c = src.perform + Assert.IsTrue(c.hasElements) + Assert.IsTrue(Not c.EOF) + Assert.AreEqual(1, c.TotalRows) + End Sub + End Class End Namespace \ No newline at end of file Index: SuperClassTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/SuperClassTests.vb,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SuperClassTests.vb 6 Feb 2005 02:45:19 -0000 1.6 +++ SuperClassTests.vb 16 Mar 2005 11:34:12 -0000 1.7 @@ -72,7 +72,6 @@ 'save root (class A) root.Save(True) 'Now check that A, G and K are in the database - 'Console.WriteLine("\nIf you'll check the data in the tables,\nyou'll find that tblA is populated and tables tblG and tbl K are populated.\nBut tables tblE, tblC, tblH are not populated at all.\n"); pbroker.ClearCache() Dim col As CPersistentCollection @@ -113,7 +112,6 @@ 'save root (class A) root.Save(True) 'Now check that A, G and K are in the database - 'Console.WriteLine("\nIf you'll check the data in the tables,\nyou'll find that tblA is populated and tables tblG and tbl K are populated.\nBut tables tblE, tblC, tblH are not populated at all.\n"); pbroker.ClearCache() Dim col As CPersistentCollection Dim cpo As CPersistentObject = New A |
From: Richard B. <rb...@us...> - 2005-03-16 11:32:58
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18016 Modified Files: CInjectedObjects.vb CMultiRetrieveCriteria.vb CMultiSummaryCriteria.vb CPersistenceBroker.vb CPersistentCriteria.vb Log Message: Multiple fixes covering nested recursive associations in noninherited objects and problems in summary criteria where conditions. Index: CMultiSummaryCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiSummaryCriteria.vb,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- CMultiSummaryCriteria.vb 16 Mar 2005 09:34:25 -0000 1.14 +++ CMultiSummaryCriteria.vb 16 Mar 2005 11:32:41 -0000 1.15 @@ -337,154 +337,198 @@ ''' </history> '''----------------------------------------------------------------------------- Public Sub addOrderAttributeByAscend(ByVal attributeName As String, ByVal pAscend As Boolean) - Dim orderEntry As COrderEntry - orderEntry = New COrderEntry - orderEntry.AttributeMap = ClassMap.getAttributeMapByString(attributeName, True) - orderEntry.Ascend = pAscend - m_orderAttributes.Add(orderEntry) - End Sub + Dim orderEntry As COrderEntry + orderEntry = New COrderEntry - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Returns a new CCriteriaCondition. - ''' </summary> - ''' <returns></returns> - ''' <remarks>The current objects classmap, tables and associations are referenced in the returned CCriteriaCondition object.</remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Function getNewCondition() As CCriteriaCondition - Dim criCond As CCriteriaCondition - criCond = New CCriteriaCondition - criCond.ClassMap = Me.ClassMap - criCond.Tables = Me.Tables - criCond.Associations = Me.Associations - getNewCondition = criCond - End Function + If attributeName.IndexOf(".") >= 0 Then + Dim Parts() As String + Parts = attributeName.Split(".") + attributeName = Parts(1) + Dim cm As CClassMap + For Each cm In m_fromCMaps + If cm.Name.Equals(Parts(0)) Then + orderEntry.ClassMap = cm + orderEntry.AttributeMap = cm.getAttributeMapByString(attributeName, True) + Exit For + End If + Next + Else + orderEntry.ClassMap = ClassMap + orderEntry.AttributeMap = ClassMap.getAttributeMapByString(attributeName, True) + End If + orderEntry.Ascend = pAscend + m_orderAttributes.Add(orderEntry) + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Generates an SQL statement based on the properties of this object. - ''' </summary> - ''' <returns></returns> - ''' <remarks>The SQL statement returned will be a select statement that will - ''' aggregate the specified attributes and group and order the data according - ''' to the values that have been set for this object.</remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Function getSqlStatementParameters() As CSqlStatement - Dim statement As New CSqlStatement - Dim i As Short - Dim persObj As IPersistableObject - Dim cm As CClassMap - Dim isFirst As Boolean = True - Dim s As String - Dim j As Integer - Dim mapname As String + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Returns a new CCriteriaCondition. + ''' </summary> + ''' <returns></returns> + ''' <remarks>The current objects classmap, tables and associations are referenced in the returned CCriteriaCondition object.</remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Function getNewCondition() As CCriteriaCondition + Dim criCond As CCriteriaCondition + criCond = New CCriteriaCondition + criCond.ClassMap = Me.ClassMap + criCond.Tables = Me.Tables + criCond.Associations = Me.Associations + getNewCondition = criCond + End Function - statement.addSqlClause(ClassMap.RelationalDatabase.getClauseStringSelect) - If m_rows > 0 And Me.ClassMap.RelationalDatabase.limitClauseAtStart Then - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringLimit) - If m_offset > 0 AndAlso Me.ClassMap.RelationalDatabase.supportsSelectOffsets Then - statement.addSqlClause(" " & Str(m_offset) & ",") - End If - statement.addSqlClause(" " & Str(m_rows)) - End If - statement.addSqlClause(" ") - isFirst = True - For i = 1 To m_fieldsForSum.Count - mapname = m_aliasForSum(i) - Select Case m_methodsForSum(i) - Case SumMethod.Avg - s = ClassMap.RelationalDatabase.getClauseStringAvg(m_fieldsForSum(i).ColumnMap.getaliasQualifiedName(mapname)) - Case SumMethod.Max - s = ClassMap.RelationalDatabase.getClauseStringMax(m_fieldsForSum(i).ColumnMap.getaliasQualifiedName(mapname)) - Case SumMethod.Min - s = ClassMap.RelationalDatabase.getClauseStringMin(m_fieldsForSum(i).ColumnMap.getAliasQualifiedName(mapname)) - Case SumMethod.Sum - s = ClassMap.RelationalDatabase.getClauseStringSum(m_fieldsForSum(i).ColumnMap.getAliasQualifiedName(mapname)) - Case SumMethod.Count - s = ClassMap.RelationalDatabase.getClauseStringCount(m_fieldsForSum(i).ColumnMap.getaliasQualifiedName(mapname)) - End Select - If isFirst Then - statement.addSqlClause(s) - Else - statement.addSqlClause(", " & s) - End If - isFirst = False - Next i + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Generates an SQL statement based on the properties of this object. + ''' </summary> + ''' <returns></returns> + ''' <remarks>The SQL statement returned will be a select statement that will + ''' aggregate the specified attributes and group and order the data according + ''' to the values that have been set for this object.</remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Function getSqlStatementParameters() As CSqlStatement + Dim statement As New CSqlStatement + Dim i As Short + Dim persObj As IPersistableObject + Dim cm As CClassMap + Dim isFirst As Boolean = True + Dim s As String + Dim j As Integer + Dim mapname As String + Dim ht As New Hashtable - 'Now for the join clauses. We must process in recursive fashion - 'in order to have correct bracketing in the statement. - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringFrom & " ") - statement.addSqlClause(m_joins.GetSQLString) + statement.addSqlClause(ClassMap.RelationalDatabase.getClauseStringSelect) + If m_rows > 0 And Me.ClassMap.RelationalDatabase.limitClauseAtStart Then + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringLimit) + If m_offset > 0 AndAlso Me.ClassMap.RelationalDatabase.supportsSelectOffsets Then + statement.addSqlClause(" " & Str(m_offset) & ",") + End If + statement.addSqlClause(" " & Str(m_rows)) + End If + statement.addSqlClause(" ") + isFirst = True + For i = 1 To m_fieldsForSum.Count + mapname = m_aliasForSum(i) + Select Case m_methodsForSum(i) + Case SumMethod.Avg + s = ClassMap.RelationalDatabase.getClauseStringAvg(m_fieldsForSum(i).ColumnMap.getaliasQualifiedName(mapname)) + Case SumMethod.Max + s = ClassMap.RelationalDatabase.getClauseStringMax(m_fieldsForSum(i).ColumnMap.getaliasQualifiedName(mapname)) + Case SumMethod.Min + s = ClassMap.RelationalDatabase.getClauseStringMin(m_fieldsForSum(i).ColumnMap.getAliasQualifiedName(mapname)) + Case SumMethod.Sum + s = ClassMap.RelationalDatabase.getClauseStringSum(m_fieldsForSum(i).ColumnMap.getAliasQualifiedName(mapname)) + Case SumMethod.Count + s = ClassMap.RelationalDatabase.getClauseStringCount(m_fieldsForSum(i).ColumnMap.getaliasQualifiedName(mapname)) + End Select + If isFirst Then + statement.addSqlClause(s) + Else + statement.addSqlClause(", " & s) + End If + isFirst = False + Next i - If m_offset > 0 And Not Me.ClassMap.RelationalDatabase.supportsSelectOffsets Then - addOffsetSubCriteria(m_offset) - End If - fillStatementWithWhere(statement) + 'Now for the join clauses. We must process in recursive fashion + 'in order to have correct bracketing in the statement. + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringFrom & " ") + statement.addSqlClause(m_joins.GetSQLString) - Dim attMap As CAttributeMap - If m_groupAttributes.Count() > 0 Then - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringGroupBy) - For i = 1 To m_groupAttributes.Count() - attMap = m_groupAttributes.Item(i) - If i > 1 Then - statement.addSqlClause(", ") - Else - statement.addSqlClause(" ") - End If - statement.addSqlClause(attMap.ColumnMap.getFullyQualifiedName) - Next i - End If + 'Need to set correct table aliases for the selection criteria in the where condition + j = 0 + For Each cm In m_fromCMaps + j += 1 + mapname = "t" & j.ToString + ht.Add(cm.Name, mapname) + UpdateConditionAliases(WhereCondition, mapname, cm.Name) + Next - Dim entry As COrderEntry - If m_orderAttributes.Count() > 0 Then - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringOrderBy) - For i = 1 To m_orderAttributes.Count() - entry = m_orderAttributes.Item(i) - If i > 1 Then - statement.addSqlClause(", ") - Else - statement.addSqlClause(" ") - End If - statement.addSqlClause(entry.AttributeMap.ColumnMap.getFullyQualifiedName) - If entry.Ascend Then - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringAscend) - Else - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringDescend) - End If - Next i - End If + If m_offset > 0 And Not Me.ClassMap.RelationalDatabase.supportsSelectOffsets Then + addOffsetSubCriteria(m_offset) + End If + fillStatementWithWhere(statement) - If m_rows > 0 And Not Me.ClassMap.RelationalDatabase.limitClauseAtStart Then - statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringLimit) - If m_offset > 0 AndAlso Me.ClassMap.RelationalDatabase.supportsSelectOffsets Then - statement.addSqlClause(" " & Str(m_offset) & ",") - End If - statement.addSqlClause(" " & Str(m_rows)) - End If + Dim attMap As CAttributeMap + If m_groupAttributes.Count() > 0 Then + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringGroupBy) + For i = 1 To m_groupAttributes.Count() + attMap = m_groupAttributes.Item(i) + If i > 1 Then + statement.addSqlClause(", ") + Else + statement.addSqlClause(" ") + End If + statement.addSqlClause(attMap.ColumnMap.getAliasQualifiedName("t1")) + Next i + End If - getSqlStatementParameters = statement - End Function + Dim entry As COrderEntry + If m_orderAttributes.Count() > 0 Then + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringOrderBy) + For i = 1 To m_orderAttributes.Count() + entry = m_orderAttributes.Item(i) + If i > 1 Then + statement.addSqlClause(", ") + Else + statement.addSqlClause(" ") + End If + statement.addSqlClause(entry.AttributeMap.ColumnMap.getAliasQualifiedName(ht(entry.ClassMap.Name))) + If entry.Ascend Then + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringAscend) + Else + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringDescend) + End If + Next i + End If - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Indicates to the persistence broker that the CMultiSummaryCriteria should now be processed. - ''' </summary> - ''' <returns>A CCursor containing the results of the criteria.</returns> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Function perform() As CCursor - Static persistentBroker As CPersistenceBroker - persistentBroker = getPersistenceBrokerInstance() - perform = persistentBroker.Instance.processMultiSummaryCriteria(Me) - End Function + If m_rows > 0 And Not Me.ClassMap.RelationalDatabase.limitClauseAtStart Then + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringLimit) + If m_offset > 0 AndAlso Me.ClassMap.RelationalDatabase.supportsSelectOffsets Then + statement.addSqlClause(" " & Str(m_offset) & ",") + End If + statement.addSqlClause(" " & Str(m_rows)) + End If + + getSqlStatementParameters = statement + End Function + + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Indicates to the persistence broker that the CMultiSummaryCriteria should now be processed. + ''' </summary> + ''' <returns>A CCursor containing the results of the criteria.</returns> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Function perform() As CCursor + perform = getPersistenceBrokerInstance().processMultiSummaryCriteria(Me) + End Function + + Private Sub UpdateConditionAliases(ByRef criCond As CCriteriaCondition, ByVal tblAlias As String, ByVal className As String) + Dim obj As Object + Dim selcri As CSelectionCriteria + Dim subCond As CCriteriaCondition + + For Each obj In criCond.Parts + If obj.GetType.IsSubclassOf(GetType(CSelectionCriteria)) Then + selcri = obj + If selcri.ClassMap.Name = className Then + selcri.TableAlias = tblAlias + End If + End If + If TypeOf (obj) Is CCriteriaCondition Then + subCond = obj + UpdateConditionAliases(subCond, tblAlias, className) + End If + Next + + End Sub End Class Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.99 retrieving revision 1.100 diff -u -d -r1.99 -r1.100 --- CPersistenceBroker.vb 11 Mar 2005 04:40:55 -0000 1.99 +++ CPersistenceBroker.vb 16 Mar 2005 11:32:42 -0000 1.100 @@ -1763,7 +1763,8 @@ rs = conn.processSelectStatement(statement) Catch ex As Exception rs = Nothing - clMap.RelationalDatabase.freeConnection(conn) + clMap.RelationalDatabase.freeConnection(conn) + Throw ex End Try cursor = New CCursor @@ -2594,99 +2595,101 @@ Return queue End If If includeBaseObject Then - AddToQueue(obj, queue) - End If - Return queue - Else - 'Determine if the object needs saving - 'But, countinue to determine if the object's associations need saving - If includeBaseObject AndAlso _ - (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.IsReadOnly AndAlso Not obj.IsModifyOnly) Then - If GetType(IValidation).IsInstanceOfType(obj.GetSourceObject) Then - 'If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then - If CType(obj.GetSourceObject, IValidation).IsValid Then 'Do not save if object is not valid - 'obj.IsDirty = False 'Added to queue so clear dirty flag - AddToQueue(obj, queue) - End If - Else - AddToQueue(obj, queue) - End If - End If - End If + AddToQueue(obj, queue) + 'Do not return - since we saved this object we also need to check it's associations + Else + Return queue + End If + Else + 'Determine if the object needs saving + 'But, countinue to determine if the object's associations need saving + If includeBaseObject AndAlso _ + (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.IsReadOnly AndAlso Not obj.IsModifyOnly) Then + If GetType(IValidation).IsInstanceOfType(obj.GetSourceObject) Then + 'If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then + If CType(obj.GetSourceObject, IValidation).IsValid Then 'Do not save if object is not valid + 'obj.IsDirty = False 'Added to queue so clear dirty flag + AddToQueue(obj, queue) + End If + Else + AddToQueue(obj, queue) + End If + End If + End If - 'Now process the object associations to see what else needs saving - cm = obj.GetClassMap() + 'Now process the object associations to see what else needs saving + cm = obj.GetClassMap() - While Not cm Is Nothing - For i = 1 To cm.getStraightAssociationMapSize - udamap = cm.getStraightAssociationMap(i) - If udamap.SaveAutomatic Then - If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - value = obj.GetObjectByAttribute(udamap.FromClassTarget) - 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.FromClassTarget) - If Not col Is Nothing Then - For k = 0 To col.Count() - 1 - tmpObj = col.Item(k) - If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = getInjectedObject(tmpObj) - Else - value = tmpObj - End If - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - Next k - End If - ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.MANY_TO_MANY Then - If obj.GetClassMap.Name = udamap.FromClass.Name Then - col = obj.GetCollectionByAttribute(udamap.FromClassTarget) - Else - If Not udamap.ToClassTarget Is Nothing Then - col = obj.GetCollectionByAttribute(udamap.ToClassTarget) - End If - End If - 'To ensure consistency of the association we need to get a list of records in the mapping table - 'and check wether the record is still valid. Removal of an object from a collection - 'should mean that we have to delete the associationtable record. - Dim state As New CAssociationState(obj, udamap) - If Not col Is Nothing Then - For k = 0 To col.Count() - 1 - tmpObj = col.Item(k) - If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = getInjectedObject(tmpObj) - Else - value = tmpObj - End If - aObj = Nothing - isNewManyToMany = state.ValidateObject(value) - For Each qObj In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(qObj) - Next - If isNewManyToMany Then - 'We need to create an association object here for the class. - aObj = New CAssociationObject - aObj.ObjectA = obj - aObj.ObjectB = value - aObj.Association = udamap - queue.Enqueue(aObj) - End If - Next k - 'Remove old association records for items removed from the collection - state.DoCleanUp() - End If - End If - End If - Next i - cm = cm.SuperClass - End While + While Not cm Is Nothing + For i = 1 To cm.getStraightAssociationMapSize + udamap = cm.getStraightAssociationMap(i) + If udamap.SaveAutomatic Then + If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then + value = obj.GetObjectByAttribute(udamap.FromClassTarget) + 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.FromClassTarget) + If Not col Is Nothing Then + For k = 0 To col.Count() - 1 + tmpObj = col.Item(k) + If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then + value = getInjectedObject(tmpObj, True) + Else + value = tmpObj + End If + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next + Next k + End If + ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.MANY_TO_MANY Then + If obj.GetClassMap.Name = udamap.FromClass.Name Then + col = obj.GetCollectionByAttribute(udamap.FromClassTarget) + Else + If Not udamap.ToClassTarget Is Nothing Then + col = obj.GetCollectionByAttribute(udamap.ToClassTarget) + End If + End If + 'To ensure consistency of the association we need to get a list of records in the mapping table + 'and check wether the record is still valid. Removal of an object from a collection + 'should mean that we have to delete the associationtable record. + Dim state As New CAssociationState(obj, udamap) + If Not col Is Nothing Then + For k = 0 To col.Count() - 1 + tmpObj = col.Item(k) + If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then + value = getInjectedObject(tmpObj, True) + Else + value = tmpObj + End If + aObj = Nothing + isNewManyToMany = state.ValidateObject(value) + For Each qObj In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(qObj) + Next + If isNewManyToMany Then + 'We need to create an association object here for the class. + aObj = New CAssociationObject + aObj.ObjectA = obj + aObj.ObjectB = value + aObj.Association = udamap + queue.Enqueue(aObj) + End If + Next k + 'Remove old association records for items removed from the collection + state.DoCleanUp() + End If + End If + End If + Next i + cm = cm.SuperClass + End While - Return queue + Return queue End Function ''' ----------------------------------------------------------------------------- @@ -2846,382 +2849,397 @@ obj = injObj.GetSourceObject End Sub - Public Function getInjectedObject(ByVal obj As Object) As CInjectedObject - Dim injObj As CInjectedObject - injObj = m_injectedObjects.Find(obj) - If injObj Is Nothing Then - injObj = New CInjectedObject(obj) - End If - Return injObj - End Function + Public Function getInjectedObject(ByVal obj As Object) As CInjectedObject + Return getInjectedObject(obj, False) + End Function - Public Function LocateOrCacheInjObject(ByVal obj As Object) As CInjectedObject - Dim injObj As CInjectedObject - injObj = m_injectedObjects.Find(obj) - If injObj Is Nothing Then - injObj = New CInjectedObject(obj) - m_injectedObjects.Add(injObj) - End If - Return injObj - End Function + Public Function getInjectedObject(ByVal obj As Object, ByVal createTemporary As Boolean) As CInjectedObject + Dim injObj As CInjectedObject + injObj = m_injectedObjects.Find(obj) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) + If createTemporary Then + 'When a single injected object has a reference to a set of objects that are + 'recursively referencing each other we need to add the objects to the cache + 'in order to prevent nested recursion. This temporary addition is only + 'used in getObjectsToSave + m_injectedObjects.AddTemp(injObj, True) + End If + End If + Return injObj + End Function - Public Sub StartTracking(ByVal obj As Object) - If Not TypeOf (obj) Is CInjectedObject Then - Dim injObj As CInjectedObject - injObj = New CInjectedObject(obj) - m_injectedObjects.Add(injObj) - Else - m_injectedObjects.Add(obj) - End If - End Sub + Public Function LocateOrCacheInjObject(ByVal obj As Object) As CInjectedObject + Dim injObj As CInjectedObject + injObj = m_injectedObjects.Find(obj) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) + m_injectedObjects.Add(injObj) + End If + Return injObj + End Function - Public Function ObjectIsTracked(ByVal obj) As Boolean - Debug.WriteLine(m_injectedObjects) - Return m_injectedObjects.isTracked(obj) - End Function + Public Sub StartTracking(ByVal obj As Object) + If Not TypeOf (obj) Is CInjectedObject Then + Dim injObj As CInjectedObject + injObj = New CInjectedObject(obj) + m_injectedObjects.Add(injObj) + Else + m_injectedObjects.Add(obj) + End If + End Sub - Public Sub MarkForDeletion(ByVal obj As Object) - MarkForDeletion(obj, False) - End Sub + Public Function ObjectIsTracked(ByVal obj) As Boolean + Debug.WriteLine(m_injectedObjects) + Return m_injectedObjects.isTracked(obj) + End Function - Public Sub MarkForDeletion(ByVal obj As Object, ByVal deleteParents As Boolean) - Dim injObj As CInjectedObject - injObj = m_injectedObjects.Find(obj) - If injObj Is Nothing Then - 'Nothing to do - Else - injObj.MarkedForDeletion = True - injObj.WillDeleteParents = deleteParents - End If - End Sub + Public Sub MarkForDeletion(ByVal obj As Object) + MarkForDeletion(obj, False) + End Sub - Public Sub PersistChanges() - PersistChanges(True) - End Sub + Public Sub MarkForDeletion(ByVal obj As Object, ByVal deleteParents As Boolean) + Dim injObj As CInjectedObject + injObj = m_injectedObjects.Find(obj) + If injObj Is Nothing Then + 'Nothing to do + Else + injObj.MarkedForDeletion = True + injObj.WillDeleteParents = deleteParents + End If + End Sub - Public Sub PersistChanges(ByVal checkAssociationsRecursively As Boolean) - Me.startTransaction() - Try - Dim injObj As CInjectedObject - m_inPersistChangesLoop = True - 'Need to copy the injected object cache as saving objects may result - 'in the collection being modified which would break the for/each loop. - Dim objectsToPersist As New CInjectedObjectCache - For Each de As DictionaryEntry In m_injectedObjects - objectsToPersist.Add(de.Key, de.Value) - Next - 'We will try to save/create objects first and then we will process deletes - 'This will prevent us trying to update objects that have been - 'autodeleted by another object (which would throw an exception) - For Each de As DictionaryEntry In objectsToPersist - injObj = de.Value - If Not injObj.MarkedForDeletion Then - PersistChanges(injObj.ReferencedObject) - End If - Next - For Each de As DictionaryEntry In objectsToPersist - injObj = de.Value - If injObj.MarkedForDeletion And injObj.Persistent Then - PersistChanges(injObj.ReferencedObject) - End If - Next - m_inPersistChangesLoop = False - For Each obj As CInjectedObject In m_objectsToDelete - m_injectedObjects.Remove(obj) - Next - m_objectsToDelete.Clear() - Me.commit() - Catch ex As Exception - m_inPersistChangesLoop = False - Me.rollback() - Throw ex - End Try - End Sub + Public Sub PersistChanges() + PersistChanges(True) + End Sub - Public Sub PersistChanges(ByVal obj As Object) - PersistChanges(obj, True) - End Sub + Public Sub PersistChanges(ByVal checkAssociationsRecursively As Boolean) + Me.startTransaction() + Try + Dim injObj As CInjectedObject + m_inPersistChangesLoop = True + 'Need to copy the injected object cache as saving objects may result + 'in the collection being modified which would break the for/each loop. + Dim objectsToPersist As New CInjectedObjectCache + For Each de As DictionaryEntry In m_injectedObjects + objectsToPersist.Add(de.Key, de.Value) + Next + 'We will try to save/create objects first and then we will process deletes + 'This will prevent us trying to update objects that have been + 'autodeleted by another object (which would throw an exception) + For Each de As DictionaryEntry In objectsToPersist + injObj = de.Value + If Not injObj.MarkedForDeletion Then + PersistChanges(injObj.ReferencedObject) + End If + Next + For Each de As DictionaryEntry In objectsToPersist + injObj = de.Value + If injObj.MarkedForDeletion And injObj.Persistent Then + PersistChanges(injObj.ReferencedObject) + End If + Next + m_inPersistChangesLoop = False + For Each obj As CInjectedObject In m_objectsToDelete + m_injectedObjects.Remove(obj) + Next + m_objectsToDelete.Clear() + Me.commit() + m_injectedObjects.CleanUp() + Catch ex As Exception + m_inPersistChangesLoop = False + Me.rollback() + Throw ex + End Try + End Sub - Public Sub PersistChanges(ByVal obj As Object, ByVal checkAssociationsRecursively As Boolean) - Dim value As IPersistableObject - Dim queue As queue - Dim qObject As Object - Dim injObj As CInjectedObject - Dim ckey As CCacheKey - Dim savedKeys As New ArrayList + Public Sub PersistChanges(ByVal obj As Object) + PersistChanges(obj, True) + End Sub - 'If for some reason the object isn't being tracked for changes yet, we will start - 'tracking it now. - injObj = LocateOrCacheInjObject(obj) + Public Sub PersistChanges(ByVal obj As Object, ByVal checkAssociationsRecursively As Boolean) + Dim value As IPersistableObject + Dim queue As Queue + Dim qObject As Object + Dim injObj As CInjectedObject + Dim ckey As CCacheKey + Dim savedKeys As New ArrayList - If injObj.MarkedForDeletion Then - deleteObject(injObj, injObj.WillDeleteParents) - If Not m_inPersistChangesLoop Then - For Each xobj As CInjectedObject In m_objectsToDelete - m_injectedObjects.Remove(xobj) - Next - m_objectsToDelete.Clear() - End If - Else - queue = getObjectsToSave(injObj, True, checkAssociationsRecursively) - 'All objects to be saved must be saved in a single transaction. - If queue.Count > 0 Then - startTransaction() - Do While queue.Count > 0 - qObject = queue.Dequeue() - Try - If GetType(CAssociationObject).IsInstanceOfType(qObject) Then - saveAssociationObject(qObject) - Else - value = qObject - 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) - 'Recalculate key value - required when identity columns are used - ckey = New CCacheKey(value) - savedKeys.Add(ckey) - End If - value.IsDirty = False - 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 - deleteCachedObject(value) - 'Abort the transaction and throw an error - rollback() - Throw New SaveException(ex.Message, ex) - End Try - Loop - commit() - End If - End If - End Sub + 'If for some reason the object isn't being tracked for changes yet, we will start + 'tracking it now. + injObj = LocateOrCacheInjObject(obj) - Friend Property InjectedObjects() As CInjectedObjectCache - Get - Return m_injectedObjects - End Get - Set(ByVal Value As CInjectedObjectCache) - m_injectedObjects = Value - End Set - End Property + If injObj.MarkedForDeletion Then + deleteObject(injObj, injObj.WillDeleteParents) + If Not m_inPersistChangesLoop Then + For Each xobj As CInjectedObject In m_objectsToDelete + m_injectedObjects.Remove(xobj) + Next + m_objectsToDelete.Clear() + End If + Else + queue = getObjectsToSave(injObj, True, checkAssociationsRecursively) + 'All objects to be saved must be saved in a single transaction. + If queue.Count > 0 Then + startTransaction() + Do While queue.Count > 0 + qObject = queue.Dequeue() + Try + If GetType(CAssociationObject).IsInstanceOfType(qObject) Then + saveAssociationObject(qObject) + Else + value = qObject + 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) + 'Recalculate key value - required when identity columns are used + ckey = New CCacheKey(value) + savedKeys.Add(ckey) + End If + value.IsDirty = False + 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 + deleteCachedObject(value) + 'Abort the transaction and throw an error + rollback() + Throw New SaveException(ex.Message, ex) + End Try + Loop + commit() + End If + End If + If Not m_inPersistChangesLoop Then + m_injectedObjects.CleanUp() + End If + End Sub - Friend Sub InitPerformanceCounters() - Try - If Not PerformanceCounterCategory.Exists("Atoms.Framework") Then + Friend Property InjectedObjects() As CInjectedObjectCache + Get + Return m_injectedObjects + End Get + Set(ByVal Value As CInjectedObjectCache) + m_injectedObjects = Value + End Set + End Property - Dim CCDC As New CounterCreationDataCollection + Friend Sub InitPerformanceCounters() + Try + If Not PerformanceCounterCategory.Exists("Atoms.Framework") Then - Dim SQLHitsCount64 As New CounterCreationData - SQLHitsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - SQLHitsCount64.CounterHelp = "SQLStatements Executed per Sec." - SQLHitsCount64.CounterName = "PCSQLHits" - CCDC.Add(SQLHitsCount64) + Dim CCDC As New CounterCreationDataCollection - Dim CacheHitsCount64 As New CounterCreationData - CacheHitsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - CacheHitsCount64.CounterHelp = "Cache Reads per Sec." - CacheHitsCount64.CounterName = "PCCacheHits" - CCDC.Add(CacheHitsCount64) + Dim SQLHitsCount64 As New CounterCreationData + SQLHitsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + SQLHitsCount64.CounterHelp = "SQLStatements Executed per Sec." + SQLHitsCount64.CounterName = "PCSQLHits" + CCDC.Add(SQLHitsCount64) - Dim InsertsCount64 As New CounterCreationData - InsertsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - InsertsCount64.CounterHelp = "Inserts per Sec." - InsertsCount64.CounterName = "PCInserts" - CCDC.Add(InsertsCount64) + Dim CacheHitsCount64 As New CounterCreationData + CacheHitsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + CacheHitsCount64.CounterHelp = "Cache Reads per Sec." + CacheHitsCount64.CounterName = "PCCacheHits" + CCDC.Add(CacheHitsCount64) - Dim UpdatesCount64 As New CounterCreationData - UpdatesCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - UpdatesCount64.CounterHelp = "Updates per Sec." - UpdatesCount64.CounterName = "PCUpdates" - CCDC.Add(UpdatesCount64) + Dim InsertsCount64 As New CounterCreationData + InsertsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + InsertsCount64.CounterHelp = "Inserts per Sec." + InsertsCount64.CounterName = "PCInserts" + CCDC.Add(InsertsCount64) - Dim ReadsCount64 As New CounterCreationData - ReadsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - ReadsCount64.CounterHelp = "Reads per Sec." - ReadsCount64.CounterName = "PCReads" - CCDC.Add(ReadsCount64) + Dim UpdatesCount64 As New CounterCreationData + UpdatesCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + UpdatesCount64.CounterHelp = "Updates per Sec." + UpdatesCount64.CounterName = "PCUpdates" + CCDC.Add(UpdatesCount64) - Dim DeletesCount64 As New CounterCreationData - DeletesCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - DeletesCount64.CounterHelp = "Deletes per Sec." - DeletesCount64.CounterName = "PCDeletes" - CCDC.Add(DeletesCount64) + Dim ReadsCount64 As New CounterCreationData + ReadsCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + ReadsCount64.CounterHelp = "Reads per Sec." + ReadsCount64.CounterName = "PCReads" + CCDC.Add(ReadsCount64) - Dim CriteriaCount64 As New CounterCreationData - CriteriaCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 - CriteriaCount64.CounterHelp = "xCriteria per Sec." - CriteriaCount64.CounterName = "PCCriteria" - CCDC.Add(CriteriaCount64) + Dim DeletesCount64 As New CounterCreationData + DeletesCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + DeletesCount64.CounterHelp = "Deletes per Sec." + DeletesCount64.CounterName = "PCDeletes" + CCDC.Add(DeletesCount64) - Dim CacheSizeCount64 As New CounterCreationData - CacheSizeCount64.CounterType = PerformanceCounterType.NumberOfItems64 - CacheSizeCount64.CounterHelp = "Cache Size (No. of entries)" - CacheSizeCount64.CounterName = "PCCacheSize" - CCDC.Add(CacheSizeCount64) + Dim CriteriaCount64 As New CounterCreationData + CriteriaCount64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64 + CriteriaCount64.CounterHelp = "xCriteria per Sec." + CriteriaCount64.CounterName = "PCCriteria" + CCDC.Add(CriteriaCount64) - Dim AvgOpTimeCount64 As New CounterCreationData - AvgOpTimeCount64.CounterType = PerformanceCounterType.AverageTimer32 - AvgOpTimeCount64.CounterHelp = "Average Operation Time" - AvgOpTimeCount64.CounterName = "PCAverageTime" - CCDC.Add(AvgOpTimeCount64) + Dim CacheSizeCount64 As New CounterCreationData + CacheSizeCount64.CounterType = PerformanceCounterType.NumberOfItems64 + CacheSizeCount64.CounterHelp = "Cache Size (No. of entries)" + CacheSizeCount64.CounterName = "PCCacheSize" + CCDC.Add(CacheSizeCount64) - Dim BaseAvgOpTimeCount64 As New CounterCreationData - BaseAvgOpTimeCount64.CounterType = PerformanceCounterType.AverageBase - BaseAvgOpTimeCount64.CounterName = "Average Operation Time Count" - BaseAvgOpTimeCount64.CounterHelp = "PCAverageTimeBase" - CCDC.Add(BaseAvgOpTimeCount64) + Dim AvgOpTimeCount64 As New CounterCreationData + AvgOpTimeCount64.CounterType = PerformanceCounterType.AverageTimer32 + AvgOpTimeCount64.CounterHelp = "Average Operation Time" + AvgOpTimeCount64.CounterName = "PCAverageTime" + CCDC.Add(AvgOpTimeCount64) - ' Create the category. - PerformanceCounterCategory.Create("Atoms.Framework", "Performance Counters for the Atoms.Framework", CCDC) - End If + Dim BaseAvgOpTimeCount64 As New CounterCreationData + BaseAvgOpTimeCount64.CounterType = PerformanceCounterType.AverageBase + BaseAvgOpTimeCount64.CounterName = "Average Operation Time Count" + BaseAvgOpTimeCount64.CounterHelp = "PCAverageTimeBase" + CCDC.Add(BaseAvgOpTimeCount64) - Dim instanceName As String - instanceName = System.Diagnostics.Process.GetCurrentProcess.ProcessName - ' Create the counters. - PCSQLHits = New PerformanceCounter("Atoms.Framework", "PCSQLHits", False) - PCCacheHits = New PerformanceCounter("Atoms.Framework", "PCCacheHits", False) - PCInserts = New PerformanceCounter("Atoms.Framework", "PCInserts", False) - PCUpdates = New PerformanceCounter("Atoms.Framework", "PCUpdates", False) - PCReads = New PerformanceCounter("Atoms.Framework", "PCReads", False) - PCDeletes = New PerformanceCounter("Atoms.Framework", "PCDeletes", False) - PCCriteria = New PerformanceCounter("Atoms.Framework", "PCCriteria", False) - PCCacheSize = New PerformanceCounter("Atoms.Framework", "PCCacheSize", False) - PCAverageTime = New PerformanceCounter("Atoms.Framework", "PCAverageTime", False) - PCAverageTimeBase = New PerformanceCounter("Atoms.Framework", "PCAverageTimeBase", False) + ' Create the category. + PerformanceCounterCategory.Create("Atoms.Framework", "Performance Counters for the Atoms.Framework", CCDC) + End If - PCSQLHits.RawValue = 0 - PCCacheHits.RawValue = 0 - PCInserts.RawValue = 0 - PCUpdates.RawValue = 0 - PCReads.RawValue = 0 - PCDeletes.RawValue = 0 - PCCriteria.RawValue = 0 - PCCacheSize.RawValue = 0 - PCAverageTime.RawValue = 0 - PCAverageTimeBase.RawValue = 0 - Catch ex As Exception - Trace.WriteLine("Could not create performance counters. If using ASP.NET please see http://objectsharp.com/Blogs/bruce/archive/2003/12/05/222.aspx" & _ - vbCrLf & ex.Message) - End Try - End Sub + Dim instanceName As String + instanceName = System.Diagnostics.Process.GetCurrentProcess.ProcessName + ' Create the counters. + PCSQLHits = New PerformanceCounter("Atoms.Framework", "PCSQLHits", False) + PCCacheHits = New PerformanceCounter("Atoms.Framework", "PCCacheHits", False) + PCInserts = New PerformanceCounter("Atoms.Framework", "PCInserts", False) + PCUpdates = New PerformanceCounter("Atoms.Framework", "PCUpdates", False) + PCReads = New PerformanceCounter("Atoms.Framework", "PCReads", False) + PCDeletes = New PerformanceCounter("Atoms.Framework", "PCDeletes", False) + PCCriteria = New PerformanceCounter("Atoms.Framework", "PCCriteria", False) + PCCacheSize = New PerformanceCounter("Atoms.Framework", "PCCacheSize", False) + PCAverageTime = New PerformanceCounter("Atoms.Framework", "PCAverageTime", False) + PCAverageTimeBase = New PerformanceCounter("Atoms.Framework", "PCAverageTimeBase", False) - Public Shared Sub CopyCollections(ByVal fromObject As Object, ByRef toObject As Object) - Dim t, iEnumerableType, iListType, iDicType As Type - Dim fromColl, toColl, collItem As Object - Dim il As IList - Dim id As IDictionary - Dim f, fields() As FieldInfo - Dim value As Object + PCSQLHits.RawValue = 0 + PCCacheHits.RawValue = 0 + PCInserts.RawValue = 0 + PCUpdates.RawValue = 0 + PCReads.RawValue = 0 + PCDeletes.RawValue = 0 + PCCriteria.RawValue = 0 + PCCacheSize.RawValue = 0 + PCAverageTime.RawValue = 0 + PCAverageTimeBase.RawValue = 0 + Catch ex As Exception + Trace.WriteLine("Could not create performance counters. If using ASP.NET please see http://objectsharp.com/Blogs/bruce/archive/2003/12/05/222.aspx" & _ + vbCrLf & ex.Message) + End Try + End Sub - t = fromObject.GetType - fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - For Each f In fields - iListType = f.FieldType.GetInterface("IList", True) - iDicType = f.FieldType.GetInterface("IDictionary", True) - If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) - If Not ICloneType Is Nothing Then - 'Getting the ICloneable interface from the object. - If Not f.GetValue(fromObject) Is Nothing Then - Dim IClone As ICloneable = CType(f.GetValue(fromObject), ICloneable) - toColl = IClone.Clone() - Else - toColl = Nothing - End If - Else - fromColl = f.GetValue(fromObject) - If Not fromColl Is Nothing Then - 'If the field doesn't support the ICloneable interface then just set it. - t = f.FieldType - toColl = Activator.CreateInstance(t) - 'need to copy references one-by-one - 'Also neeed to connect event handlers of new collection to new object based - 'on event connections of the old collection and the old object - Dim fColl, fieldsColl() As FieldInfo - Dim d, newD, delArray(), newDelArray() As [Delegate] - Dim collDel As MulticastDelegate - While Not t Is Nothing - fieldsColl = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - For Each fColl In fieldsColl - If fColl.FieldType.Name = fColl.Name & "Handler" OrElse fColl.FieldType Is GetType(EventHandler) Then - 'This is an event! - d = fColl.GetValue(fromColl) - collDel = Nothing - If Not d Is Nothing Then - delArray = d.GetInvocationList - For Each d In delArray - If Not d.Target.GetType.GetInterface("IPersistableObject") Is Nothing Then - If CType(d.Target, IPersistableObject).Equals(fromObject) Then - newD = MulticastDelegate.CreateDelegate(fColl.FieldType, toObject, d.Method.Name) - If collDel Is Nothing Then - collDel = newD - Else - collDel.Combine(collDel, newD) - End If - End If - End If - Next - fColl.SetValue(toColl, collDel) - End If - End If - Next - If t.IsSubclassOf(GetType(CPersistentCollection)) Then - t = t.BaseType - Else - t = Nothing - End If - End While - If Not iListType Is Nothing Then - il = CType(toColl, IList) - For Each collItem In fromColl - il.Add(collItem) - Next - Else - id = CType(toColl, IDictionary) - For Each de As DictionaryEntry In fromColl - id.Add(de.Key, de.Value) - Next - End If - Else - toColl = Nothing - End If - End If - If Not toColl Is Nothing AndAlso f.FieldType Is GetType(CPersistentCollection) OrElse f.FieldType.IsSubclassOf(GetType(CPersistentCollection)) Then - Dim c As CPersistentCollection - c = CType(toColl, CPersistentCollection) - If Not c.ContainerObject Is Nothing AndAlso c.ContainerObject.Equals(fromObject) Then - c.ContainerObject = toObject - End If - End If - f.SetValue(toObject, toColl) - End If - Next - End Sub + Public Shared Sub CopyCollections(ByVal fromObject As Object, ByRef toObject As Object) + Dim t, iEnumerableType, iListType, iDicType As Type + Dim fromColl, toColl, collItem As Object + Dim il As IList + Dim id As IDictionary + Dim f, fields() As FieldInfo + Dim value As Object - Private Sub AddToQueue(ByVal obj As Object, ByRef queue As Queue) - Call AddToQueue(obj, queue, True) - End Sub - Private Sub AddToQueue(ByVal obj As Object, ByRef queue As Queue, ByVal includeObject As Boolean) - 'Called recursively so that objects with superclasses are queued from the - 'top most object down. - Dim cm As CClassMap - Dim tmpobj As Object - cm = obj.GetClassMap() - If Not cm.SuperClass Is Nothing Then - tmpobj = obj.GetObjectByClassMap(cm.SuperClass) - If cm.SharedTableField Is Nothing Then - AddToQueue(tmpobj, queue, True) - Else - AddToQueue(tmpobj, queue, False) - End If - End If - If includeObject Then - queue.Enqueue(obj) - End If - Return - End Sub + t = fromObject.GetType + fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + For Each f In fields + iListType = f.FieldType.GetInterface("IList", True) + iDicType = f.FieldType.GetInterface("IDictionary", True) + If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then + Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) + If Not ICloneType Is Nothing Then + 'Getting the ICloneable interface from the object. + If Not f.GetValue(fromObject) Is Nothing Then + Dim IClone As ICloneable = CType(f.GetValue(fromObject), ICloneable) + toColl = IClone.Clone() + Else + toColl = Nothing + End If + Else + fromColl = f.GetValue(fromObject) + If Not fromColl Is Nothing Then + 'If the field doesn't support the ICloneable interface then just set it. + t = f.FieldType + toColl = Activator.CreateInstance(t) + 'need to copy references one-by-one + 'Also neeed to connect event handlers of new collection to new object based + 'on event connections of the old collection and the old object + Dim fColl, fieldsColl() As FieldInfo + Dim d, newD, delArray(), newDelArray() As [Delegate] + Dim collDel As MulticastDelegate + While Not t Is Nothing + fieldsColl = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + For Each fColl In fieldsColl + If fColl.FieldType.Name = fColl.Name & "Handler" OrElse fColl.FieldType Is GetType(EventHandler) Then + 'This is an event! + d = fColl.GetValue(fromColl) + collDel = Nothing + If Not d Is Nothing Then + delArray = d.GetInvocationList + For Each d In delArray + If Not d.Target.GetType.GetInterface("IPersistableObject") Is Nothing Then + If CType(d.Target, IPersistableObject).Equals(fromObject) Then + newD = MulticastDelegate.CreateDelegate(fColl.FieldType, toObject, d.Method.Name) + If collDel Is Nothing Then + collDel = newD + Else + collDel.Combine(collDel, newD) + End If + End If + End If + Next + fColl.SetValue(toColl, collDel) + End If + End If + Next + If t.IsSubclassOf(GetType(CPersistentCollection)) Then + t = t.BaseType + Else + t = Nothing + End If + End While + If Not iListType Is Nothing Then + il = CType(toColl, IList) + For Each collItem In fromColl + il.Add(collItem) + Next + Else + id = CType(toColl, IDictionary) + For Each de As DictionaryEntry In fromColl + id.Add(de.Key, de.Value) + Next + End If + Else + toColl = Nothing + End If + End If + If Not toColl Is Nothing AndAlso f.FieldType Is GetType(CPersistentCollection) OrElse f.FieldType.IsSubclassOf(GetType(CPersistentCollection)) Then + Dim c As CPersistentCollection + c = CType(toColl, CPersistentCollection) + If Not c.ContainerObject Is Nothing AndAlso c.ContainerObject.Equals(fromObject) Then + c.ContainerObject = toObject + End If + End If + f.SetValue(toObject, toColl) + End If + Next + End Sub + + Private Sub AddToQueue(ByVal obj As Object, ByRef queue As Queue) + Call AddToQueue(obj, queue, True) + End Sub + Private Sub AddToQueue(ByVal obj As Object, ByRef queue As Queue, ByVal includeObject As Boolean) + 'Called recursively so that objects with superclasses are queued from the + 'top most object down. + Dim cm As CClassMap + Dim tmpobj As Object + cm = obj.GetClassMap() + If Not cm.SuperClass Is Nothing Then + tmpobj = obj.GetObjectByClassMap(cm.SuperClass) + If cm.SharedTableField Is Nothing Then + AddToQueue(tmpobj, queue, True) + Else + AddToQueue(tmpobj, queue, False) + End If + End If + If includeObject Then + queue.Enqueue(obj) + End If + Return + End Sub End Class \ No newline at end of file Index: CMultiRetrieveCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiRetrieveCriteria.vb,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- CMultiRetrieveCriteria.vb 28 Feb 2005 23:07:44 -0000 1.19 +++ CMultiRetrieveCriteria.vb 16 Mar 2005 11:32:41 -0000 1.20 @@ -405,7 +405,7 @@ Else statement.addSqlClause(" ") End If - statement.addSqlClause(entry.AttributeMap.ColumnMap.getAliasQualifiedName(ht(entry.ClassMap.Name))) + statement.addSqlClause(entry.AttributeMap.ColumnMap.getAliasQualifiedName(ht(entry.ClassMap.Name))) 'statement.addSqlClause(entry.AttributeMap.ColumnMap.getAliasQualifiedName("t1")) If entry.Ascend Then statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringAscend) Index: CPersistentCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCriteria.vb,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- CPersistentCriteria.vb 1 Mar 2005 03:16:57 -0000 1.11 +++ CPersistentCriteria.vb 16 Mar 2005 11:32:43 -0000 1.12 @@ -7,17 +7,17 @@ ''' </summary> '''----------------------------------------------------------------------------- Public Interface _CPersistentCriteria - Property Criteria() As Collection - Property Tables() As Collection - Property Associations() As Collection - Property ClassName() As String - Property ClassMap() As CClassMap - Property WhereCondition() As CCriteriaCondition - Sub setClassMap(ByRef pClassName As String) - Sub fillStatementWithCondition(ByRef statement As CSqlStatement) - Sub fillStatementWithWhere(ByRef statement As CSqlStatement) - Function getSize() As Short - Sub addOffsetSubCriteria(ByVal offset As Integer) + Property Criteria() As Collection + Property Tables() As Collection + Property Associations() As Collection + Property ClassName() As String + Property ClassMap() As CClassMap + Property WhereCondition() As CCriteriaCondition + Sub setClassMap(ByRef pClassName As String) + Sub fillStatementWithCondition(ByRef statement As CSqlStatement) + Sub fillStatementWithWhere(ByRef statement As CSqlStatement) + Function getSize() As Short + Sub addOffsetSubCriteria(ByVal offset As Integer) End Interface '''----------------------------------------------------------------------------- @@ -40,298 +40,298 @@ ''' </history> '''----------------------------------------------------------------------------- Public Class CPersistentCriteria - Implements _CPersistentCriteria + Implements _CPersistentCriteria - '************************************************** - 'Class: CPersistentCriteria - 'Author: Juan Carlos Alvarez - '************************************************** + '************************************************** + 'Class: CPersistentCriteria + 'Author: Juan Carlos Alvarez + '************************************************** - Private m_criteria As Collection - Private m_className As String - Private m_classMap As CClassMap - Private m_Tables As Collection - Private m_Associations As Collection - Private m_WhereCondition As CCriteriaCondition + Private m_criteria As Collection + Private m_className As String + Private m_classMap As CClassMap + Private m_Tables As Collection + Private m_Associations As Collection + Private m_WhereCondition As CCriteriaCondition - '''----------------------------------------------------------------------------- - ''' <summary> - ''' A collection of the various sub-criteria that make up this criteria. - ''' </summary> - ''' <value>A collection of criteria objects</value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Criteria() As Collection Implements _CPersistentCriteria.Criteria - Get - Criteria = m_criteria - End Get - Set(ByVal Value As Collection) - m_criteria = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' A collection of the various sub-criteria that make up this criteria. + ''' </summary> + ''' <value>A collection of criteria objects</value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Criteria() As Collection Implements _CPersistentCriteria.Criteria + Get + Criteria = m_criteria + End Get + Set(ByVal Value As Collection) + m_criteria = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' A Collection of the various tables used in the criteria. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Tables() As Collection Implements _CPersistentCriteria.Tables - Get - Tables = m_Tables - End Get - Set(ByVal Value As Collection) - m_Tables = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' A Collection of the various tables used in the criteria. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Tables() As Collection Implements _CPersistentCriteria.Tables + Get + Tables = m_Tables + End Get + Set(ByVal Value As Collection) + m_Tables = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' A collection of the associations used to link the tables in the criteria together. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Associations() As Collection Implements _CPersistentCriteria.Associations - Get - Associations = m_Associations - End Get - Set(ByVal Value As Collection) - m_Associations = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' A collection of the associations used to link the tables in the criteria together. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Associations() As Collection Implements _CPersistentCriteria.Associations + Get + Associations = m_Associations + End Get + Set(ByVal Value As Collection) + m_Associations = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' The class name of the primary object in the criteria. - ''' </summary> - ''' <value>A string representing the primary class... [truncated message content] |
From: Richard B. <rb...@us...> - 2005-03-16 09:35:31
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24040/InheritedClasses Modified Files: MultiRetrieveTests.vb Log Message: unit test for multi summary criteria Index: MultiRetrieveTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/MultiRetrieveTests.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- MultiRetrieveTests.vb 21 Dec 2004 22:00:01 -0000 1.3 +++ MultiRetrieveTests.vb 16 Mar 2005 09:35:16 -0000 1.4 @@ -85,6 +85,23 @@ mr1.Save() mr2.field2 = 22 mr2.Save() - End Sub - End Class + End Sub + + <Test()> Public Sub SummaryChainedClasses() + Dim mr1 As New mr1 + Dim mr2 As New mr2 + Dim mr3 As New mr3 + Dim src As CMultiSummaryCriteria + src = New CMultiSummaryCriteria + src.addObjectToJoin(mr1, Nothing, "") + src.addObjectToJoin(mr2, mr1, "mr1tomr2") + src.addObjectToJoin(mr3, mr2, "mr2tomr3") + src.addSummaryField("mr1tomr2.field1", CMultiSummaryCriteria.SumMethod.Count) + c = src.perform + Assert.IsTrue(c.hasElements) + Assert.IsFalse(c.EOF) + Assert.AreEqual(1, c.TotalRows) + End Sub + + End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-03-16 09:34:47
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23873 Modified Files: CMultiSummaryCriteria.vb Log Message: Fixes for multisummarycriteria Index: CMultiSummaryCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiSummaryCriteria.vb,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- CMultiSummaryCriteria.vb 9 Feb 2005 06:24:44 -0000 1.13 +++ CMultiSummaryCriteria.vb 16 Mar 2005 09:34:25 -0000 1.14 @@ -128,7 +128,8 @@ m_rows = -1 m_Having = Nothing m_fieldsForSum = New Collection - m_methodsForSum = New Collection + m_methodsForSum = New Collection + m_aliasForSum = New Collection End Sub Public Sub New(ByVal obj As CPersistentObject) @@ -220,23 +221,24 @@ am = cm2.GetAssociationMapByName(assocName) If am Is Nothing Then Throw New NoAssociationException("Invalid association " & assocName & " selected - no such association exists") - End If - m_fromCMaps.Add(cm2) - i = m_fromCMaps.Count - mapName = "t" & i.ToString - m_joins = New CJoin(m_joins, cm, mapName, am) - mapName = "t" & (i - 1).ToString - m_joins.LeftTableAlias = mapName - cm = cm.SuperClass - While Not cm Is Nothing - i += 1 - m_fromCMaps.Add(cm) - mapName = "t" & i.ToString - m_joins = New CJoin(m_joins, cm, mapName, True) - mapName = "t" & (i - 1).ToString - m_joins.LeftTableAlias = mapName - cm = cm.SuperClass - End While + End If + cm = obj.GetClassMap + m_fromCMaps.Add(cm) + i = m_fromCMaps.Count + mapName = "t" & i.ToString + m_joins = New CJoin(m_joins, cm, mapName, am) + mapName = "t" & (i - 1).ToString + m_joins.LeftTableAlias = mapName + cm = cm.SuperClass + While Not cm Is Nothing + i += 1 + m_fromCMaps.Add(cm) + mapName = "t" & i.ToString + m_joins = New CJoin(m_joins, cm, mapName, True) + mapName = "t" & (i - 1).ToString + m_joins.LeftTableAlias = mapName + cm = cm.SuperClass + End While End Sub '''----------------------------------------------------------------------------- @@ -264,21 +266,27 @@ For i = 0 To UBound(myArrayStrings) - 1 strName = myArrayStrings(i) - udaMap = clMap.AssociationMaps(strName) - clMap = udaMap.toclass - If clMap Is Nothing Then - Exit For - End If - Next i + udaMap = clMap.AssociationMaps(strName) + If udaMap Is Nothing Then + Throw New AToMSFramework.RetrieveException("Could not find association named " & strName & " for class " & clMap.Name) + End If + clMap = udaMap.ToClass + If clMap Is Nothing Then + Exit For + End If + Next i + attributename = myArrayStrings(UBound(myArrayStrings)) j = m_joins strName = "" While Not j Is Nothing If j.RightSide.Name = clMap.Name Then strName = j.TableAlias - j = Nothing - End If - End While + j = Nothing + Else + j = j.LeftSide + End If + End While m_aliasForSum.Add(strName) m_fieldsForSum.Add(clMap.getAttributeMapByString(attributename, True)) |
From: Richard B. <rb...@us...> - 2005-03-16 04:59:45
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3503 Modified Files: CPersistentCollection.vb Log Message: Uncomment container object dirtying when collection changed. Index: CPersistentCollection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCollection.vb,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- CPersistentCollection.vb 15 Mar 2005 11:14:51 -0000 1.17 +++ CPersistentCollection.vb 16 Mar 2005 04:59:24 -0000 1.18 @@ -199,10 +199,10 @@ Private Sub ItemDirtiedHandler(ByVal sender As Object, ByVal e As EventArgs) ' Debug.WriteLine("Collection trapped item dirtied event for " & sender.GetType.Name) RaiseEvent ItemDirtied(Me, e) - 'If Not Me.ContainerObject Is Nothing Then - ' 'Debug.WriteLine("item dirtied - dirtying container") - ' ContainerObject.SetDirtyFlag() - 'End If + If Not Me.ContainerObject Is Nothing Then + 'Debug.WriteLine("item dirtied - dirtying container") + ContainerObject.SetDirtyFlag() + End If End Sub #End Region |
From: Richard B. <rb...@us...> - 2005-03-15 11:15:04
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29967 Modified Files: CCriteriaCondition.vb CPersistentCollection.vb Log Message: Removed some obsolete code. Fixed MySQL parameters to use new syntax. Index: CCriteriaCondition.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCriteriaCondition.vb,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- CCriteriaCondition.vb 9 Feb 2005 06:24:44 -0000 1.17 +++ CCriteriaCondition.vb 15 Mar 2005 11:14:50 -0000 1.18 @@ -177,49 +177,7 @@ m_classMap = cm End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Adds an SQL "OR" condition to the criteria - ''' </summary> - ''' <param name="orCriteria">Another CCriteriaCondition to be "OR"ed with this one.</param> - ''' <remarks>Adds a second criteria condition to this one, and marks it as an - ''' OR condition. The second criteria is used to populate the right hand side of the - ''' OR statement in the SQL when it is generated. - ''' <para>The orCriteria <see cref="P:AToMSFramework.CCriteriaCondition.Parent"/> property is set to the current object.</para></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - <Obsolete("This will be removed in future versions - use addSubCriteria")> _ - Public Sub addOrCriteria(ByVal orCriteria As CCriteriaCondition) - m_Simple = False - m_Parts.Add(orCriteria) - orCriteria.useOrWithParent = True - orCriteria.Parent = Me - End Sub - - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Adds an SQL "AND" condition to the criteria - ''' </summary> - ''' <param name="orCriteria">Another CCriteriaCondition to be "AND"ed with this one.</param> - ''' <remarks>Adds a second criteria condition to this one, and marks it as an - ''' OR condition. The second criteria is used to populate the right hand side of the - ''' OR statement in the SQL when it is generated. - ''' <para>The orCriteria <see cref="P:AToMSFramework.CCriteriaCondition.Parent"/> property is set to the current object.</para></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - <Obsolete("This will be removed in future versions - use addSubCriteria")> _ - Public Sub addAndSubCriteria(ByVal andCriteria As CCriteriaCondition) - m_Simple = False - m_Parts.Add(andCriteria) - andCriteria.useOrWithParent = False - andCriteria.Parent = Me - End Sub - - ''' ----------------------------------------------------------------------------- + ''' ----------------------------------------------------------------------------- ''' <summary> ''' Adds a subcriteria to this criteria ''' </summary> @@ -361,51 +319,7 @@ End If End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Obsolete. Do not use. - ''' </summary> - ''' <param name="attributeName"></param> - ''' <param name="cs"></param> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Private Sub setAttributeMap(ByVal attributeName As String, ByRef cs As CSelectionCriteria) - Dim AttrMap As CAttributeMap - Dim myArrayStrings As Object - myArrayStrings = Split(attributeName, ".", -1, CompareMethod.Text) - Dim clMap As CClassMap - clMap = m_classMap - - Dim i, j As Short - Dim strName As String - Dim udaMap As CUDAMap - For i = 0 To UBound(myArrayStrings) - 1 - strName = myArrayStrings(i) - udaMap = clMap.AssociationMaps(strName) - m_Associations.Add(udaMap) - - clMap = udaMap.toclass - If Not clMap Is Nothing Then - For j = 1 To clMap.Tables.Count() - m_Tables.Add(clMap.Tables.Item(j)) - Next j - Else - Exit For - End If - Next i - - If Not clMap Is Nothing Then - AttrMap = clMap.getAttributeMapByString(myArrayStrings(UBound(myArrayStrings)), True) - End If - - cs.AttrMap = AttrMap - cs.ClassMap = clMap - End Sub - - '''----------------------------------------------------------------------------- + '''----------------------------------------------------------------------------- ''' <summary> ''' Creates a Greater Than selection criteria. ''' </summary> Index: CPersistentCollection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCollection.vb,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- CPersistentCollection.vb 14 Feb 2005 02:23:11 -0000 1.16 +++ CPersistentCollection.vb 15 Mar 2005 11:14:51 -0000 1.17 @@ -44,166 +44,166 @@ ''' [rbanks] 17/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - <Browsable(False), Obsolete("Changes in collection management have made this obsolete. Please use the ListChanged event for equivalent functionality")> _ - Public Property ContainerObject() As CPersistentObject - Get - Return m_container - End Get - Set(ByVal Value As CPersistentObject) - m_container = Value - End Set - End Property + <Browsable(False)> _ + Public Property ContainerObject() As CPersistentObject + Get + Return m_container + End Get + Set(ByVal Value As CPersistentObject) + m_container = Value + End Set + End Property - <Browsable(False)> Public Shadows ReadOnly Property Count() As Integer - Get - Return MyBase.Count - End Get - End Property + <Browsable(False)> Public Shadows ReadOnly Property Count() As Integer + Get + Return MyBase.Count + End Get + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Adds an item to the collection. - ''' </summary> - ''' <param name="cp">A CPersistentObject to be added.</param> - ''' <remarks>The persistent object is added to the collection. If the container - ''' object reference is set then the dirty flag on the container object is set.</remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub Add(ByVal cp As CPersistentObject) - ' Debug.WriteLine("Coll: add method called") - list.Add(cp) - End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Adds an item to the collection. + ''' </summary> + ''' <param name="cp">A CPersistentObject to be added.</param> + ''' <remarks>The persistent object is added to the collection. If the container + ''' object reference is set then the dirty flag on the container object is set.</remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub Add(ByVal cp As CPersistentObject) + ' Debug.WriteLine("Coll: add method called") + list.Add(cp) + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Removes an item from the collection. - ''' </summary> - ''' <param name="index">The zero-based position of the item in the collection to remove.</param> - ''' <remarks>Removes the specified item from the collection and sets the - ''' dirty flag on the container object. - ''' <para>An exception is thrown if the index is greater than the number of items in the collection or is - ''' less than zero.</para></remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub Remove(ByVal index As Integer) - ' Debug.WriteLine("Coll: Removing index " & index) - If index > Count - 1 Or index < 0 Then - Throw New Exception("PersistentCollection index value is outside of bounds") - End If - list.RemoveAt(index) - End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Removes an object from the collection. - ''' </summary> - ''' <param name="value">The object to remove.</param> - ''' <remarks>Removes the specified object from the collection and sets the - ''' dirty flag on the container object.</remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub Remove(ByVal value As CPersistentObject) - ' Debug.WriteLine("Coll: Removing " & value.GetType.Name) - list.Remove(value) - End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Retrieves the item at the specified position. - ''' </summary> - ''' <param name="index">The zero-based position of the item in the collection.</param> - ''' <value>The CPersistentObject from the specified position.</value> - ''' <remarks>If the index does not refer to a valid position within the collection - ''' and exception will be thrown.</remarks> - ''' <history> - ''' [rbanks] 17/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Default Public ReadOnly Property Item(ByVal index As Integer) As CPersistentObject - Get - ' Debug.WriteLine("Coll: index property = " & index) - Return CType(list.Item(index), CPersistentObject) - End Get - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Removes an item from the collection. + ''' </summary> + ''' <param name="index">The zero-based position of the item in the collection to remove.</param> + ''' <remarks>Removes the specified item from the collection and sets the + ''' dirty flag on the container object. + ''' <para>An exception is thrown if the index is greater than the number of items in the collection or is + ''' less than zero.</para></remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub Remove(ByVal index As Integer) + ' Debug.WriteLine("Coll: Removing index " & index) + If index > Count - 1 Or index < 0 Then + Throw New Exception("PersistentCollection index value is outside of bounds") + End If + list.RemoveAt(index) + End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Removes an object from the collection. + ''' </summary> + ''' <param name="value">The object to remove.</param> + ''' <remarks>Removes the specified object from the collection and sets the + ''' dirty flag on the container object.</remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub Remove(ByVal value As CPersistentObject) + ' Debug.WriteLine("Coll: Removing " & value.GetType.Name) + list.Remove(value) + End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Retrieves the item at the specified position. + ''' </summary> + ''' <param name="index">The zero-based position of the item in the collection.</param> + ''' <value>The CPersistentObject from the specified position.</value> + ''' <remarks>If the index does not refer to a valid position within the collection + ''' and exception will be thrown.</remarks> + ''' <history> + ''' [rbanks] 17/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Default Public ReadOnly Property Item(ByVal index As Integer) As CPersistentObject + Get + ' Debug.WriteLine("Coll: index property = " & index) + Return CType(list.Item(index), CPersistentObject) + End Get + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Attempts to save each item in the collection - ''' </summary> - ''' <value>An integer containing the number of objects that were actually saved.</value> - ''' <remarks>Each item in the collection is saved. If an error occurs during the saving - ''' of any object the process is immediately aborted and an exception is thrown. - ''' All objects are saved as part of a single transaction and the transaction is rolled back - ''' when there is an error.</remarks> - ''' <history> - ''' [rbanks] 21/05/2004 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Function Save() As Integer - Dim cp As CPersistentObject - Dim i As Integer = 0 - Dim pb As CPersistenceBroker = getPersistenceBrokerInstance() + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Attempts to save each item in the collection + ''' </summary> + ''' <value>An integer containing the number of objects that were actually saved.</value> + ''' <remarks>Each item in the collection is saved. If an error occurs during the saving + ''' of any object the process is immediately aborted and an exception is thrown. + ''' All objects are saved as part of a single transaction and the transaction is rolled back + ''' when there is an error.</remarks> + ''' <history> + ''' [rbanks] 21/05/2004 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Function Save() As Integer + Dim cp As CPersistentObject + Dim i As Integer = 0 + Dim pb As CPersistenceBroker = getPersistenceBrokerInstance() - pb.startTransaction() - For Each cp In list - Try - If cp.IsDirty Then - cp.Save() - If Not cp.IsDirty Then - 'Object was saved - increment counter - i += 1 - End If - End If - Catch ex As Exception - pb.rollback() - Throw New SaveException(ex.Message, ex) - End Try - Next - pb.commit() - Return i - End Function + pb.startTransaction() + For Each cp In list + Try + If cp.IsDirty Then + cp.Save() + If Not cp.IsDirty Then + 'Object was saved - increment counter + i += 1 + End If + End If + Catch ex As Exception + pb.rollback() + Throw New SaveException(ex.Message, ex) + End Try + Next + pb.commit() + Return i + End Function - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Attempts to delete each item in the collection - ''' </summary> - ''' <remarks>Each item in the collection is deleted. If an error occurs during the process - ''' an exception is thrown. All objects are deleted within a single transaction and the transaction is rolled back - ''' when there is an error.</remarks> - ''' <history> - ''' [rbanks] 21/05/2004 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub Delete() - Dim cp As CPersistentObject - Dim i As Integer = 0 - Dim pb As CPersistenceBroker = getPersistenceBrokerInstance() + '''----------------------------------------------------------------------------- + ''' <summary> + ''' Attempts to delete each item in the collection + ''' </summary> + ''' <remarks>Each item in the collection is deleted. If an error occurs during the process + ''' an exception is thrown. All objects are deleted within a single transaction and the transaction is rolled back + ''' when there is an error.</remarks> + ''' <history> + ''' [rbanks] 21/05/2004 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub Delete() + Dim cp As CPersistentObject + Dim i As Integer = 0 + Dim pb As CPersistenceBroker = getPersistenceBrokerInstance() - pb.startTransaction() - For Each cp In list - Try - cp.Delete() - Catch ex As Exception - pb.rollback() - Throw New DeleteException(ex.Message, ex) - End Try - Next - pb.commit() - Me.Clear() - End Sub + pb.startTransaction() + For Each cp In list + Try + cp.Delete() + Catch ex As Exception + pb.rollback() + Throw New DeleteException(ex.Message, ex) + End Try + Next + pb.commit() + Me.Clear() + End Sub - Private Sub ItemDirtiedHandler(ByVal sender As Object, ByVal e As EventArgs) - ' Debug.WriteLine("Collection trapped item dirtied event for " & sender.GetType.Name) - RaiseEvent ItemDirtied(Me, e) - 'If Not Me.ContainerObject Is Nothing Then - ' 'Debug.WriteLine("item dirtied - dirtying container") - ' ContainerObject.SetDirtyFlag() - 'End If - End Sub + Private Sub ItemDirtiedHandler(ByVal sender As Object, ByVal e As EventArgs) + ' Debug.WriteLine("Collection trapped item dirtied event for " & sender.GetType.Name) + RaiseEvent ItemDirtied(Me, e) + 'If Not Me.ContainerObject Is Nothing Then + ' 'Debug.WriteLine("item dirtied - dirtying container") + ' ContainerObject.SetDirtyFlag() + 'End If + End Sub #End Region #Region "IBindlingList" |
From: Richard B. <rb...@us...> - 2005-03-15 11:15:03
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MySQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29967/Providers/AF_MySQL Modified Files: CMySqlDatabase.vb Log Message: Removed some obsolete code. Fixed MySQL parameters to use new syntax. Index: CMySqlDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_MySQL/CMySqlDatabase.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CMySqlDatabase.vb 7 Feb 2005 13:22:07 -0000 1.2 +++ CMySqlDatabase.vb 15 Mar 2005 11:14:51 -0000 1.3 @@ -311,27 +311,28 @@ '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String 'Return "?" - Return "@p" & CStr(i) - End Function + 'Return "@p" & CStr(i) - this is the old version - only use if still referencing bytefx + Return "?p" & CStr(i) 'New syntax as of v1.04 of MySQLConnect/NET + End Function - Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String - Return Me.m_name & "." & table & " as " & pAlias - End Function + Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String + Return Me.m_name & "." & table & " as " & pAlias + End Function - Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) - If Not m_disposed Then - If disposing Then - Dim conn As CMySqlConnection - While ConnectionPool.Count > 0 - conn = ConnectionPool.Pop - conn.Dispose() - End While - m_disposed = True - End If - End If - End Sub + Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) + If Not m_disposed Then + If disposing Then + Dim conn As CMySqlConnection + While ConnectionPool.Count > 0 + conn = ConnectionPool.Pop + conn.Dispose() + End While + m_disposed = True + End If + End If + End Sub - Public Overrides Function supportsSelectOffsets() As Boolean - Return True - End Function + Public Overrides Function supportsSelectOffsets() As Boolean + Return True + End Function End Class |
From: Richard B. <rb...@us...> - 2005-03-14 03:21:58
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26902 Modified Files: CInjectedObject.vb Log Message: Fix dirty flag checking for subclasses where only attributes in parents were changed. Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- CInjectedObject.vb 11 Mar 2005 04:40:55 -0000 1.16 +++ CInjectedObject.vb 14 Mar 2005 03:21:48 -0000 1.17 @@ -76,8 +76,7 @@ End If Dim f, fields() As FieldInfo Dim value As Object - Dim t, iListType, iDicType As Type - Try + Dim t, iListType, iDicType As Type Try t = sourceObject.GetType While Not t Is Nothing fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) @@ -97,8 +96,7 @@ t = Nothing End If End While - CPersistenceBroker.CopyCollections(sourceObject, targetObject) - Catch ex As Exception + CPersistenceBroker.CopyCollections(sourceObject, targetObject) Catch ex As Exception Debug.WriteLine(ex.Message) End Try End Sub @@ -310,7 +308,7 @@ 'Everything else is ignorable since it's only the database mapped fields 'that are important While Not cmap Is Nothing - For Each att As CAttributeMap In m_classmap.AttributeMaps + For Each att As CAttributeMap In cmap.AttributeMaps If Not att.ColumnMap Is Nothing Then value = getValueByAttribute(att.Name) value1 = getOriginalValueByAttribute(att.Name) |
From: Richard B. <rb...@us...> - 2005-03-11 04:41:06
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21135 Modified Files: CClassMap.vb CInjectedObject.vb CInjectedObjects.vb CPersistenceBroker.vb CRelationalDatabase.vb Log Message: Bug fixes for interface based persistence. Problems with 3+ levels in the hierarchy. Also some small changes to finalize. Index: CRelationalDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CRelationalDatabase.vb,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- CRelationalDatabase.vb 28 Oct 2004 00:16:12 -0000 1.21 +++ CRelationalDatabase.vb 11 Mar 2005 04:40:56 -0000 1.22 @@ -1265,6 +1265,7 @@ Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) + MyBase.finalize() End Sub Public Overridable Function supportsSelectOffsets() As Boolean Implements _CRelationalDatabase.supportsSelectOffsets Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.98 retrieving revision 1.99 diff -u -d -r1.98 -r1.99 --- CPersistenceBroker.vb 3 Mar 2005 00:38:23 -0000 1.98 +++ CPersistenceBroker.vb 11 Mar 2005 04:40:55 -0000 1.99 @@ -295,6 +295,8 @@ Dim isfirst As Boolean = True Dim am As CAttributeMap Dim fromClass, toClass As CClassMap + Dim paramCount As Integer + Dim skipClass As Boolean cm = obj.GetClassMap @@ -336,17 +338,24 @@ Dim statement As New CSqlStatement cm2 = cm + paramCount = 0 + skipClass = False Do If useFind Then + If Not skipClass Then For i = 1 To cm2.getFindSize am = cm2.FindAttributeMaps(i) - statement.addSqlParameter(i, obj.GetValueByAttribute(am.Name), am.ColumnMap) + paramCount += 1 + statement.addSqlParameter(paramCount, obj.GetValueByAttribute(am.Name), am.ColumnMap) Next i + End If + skipClass = Not cm2.SharedTableField Is Nothing cm2 = cm2.SuperClass Else For i = 1 To cm2.getKeySize am = cm2.getKeyAttributeMap(i) - statement.addSqlParameter(i, obj.GetValueByAttribute(am.Name), am.ColumnMap) + paramCount += 1 + statement.addSqlParameter(paramCount, obj.GetValueByAttribute(am.Name), am.ColumnMap) Next i cm2 = Nothing End If @@ -421,6 +430,7 @@ 'Only process one-to-one relationships on the first record retrieved If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE And i = 0 Then gotValue = False + classMapCount += Me.getChildCountForMultipleInheritance(udamap.ToClass) - 1 targetobj = obj.GetObjectByAttribute(udamap.FromClassTarget) If Not targetobj Is Nothing Then 'if the class as child classes then check if the targetobj is of type child @@ -467,8 +477,8 @@ 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) 'update classMapCount with the child count number - classMapCount += Me.getChildCountForMultipleInheritance(udamap.ToClass) - classMapCount -= 1 'This is because we added one in the beginning of the for loop + 'classMapCount += Me.getChildCountForMultipleInheritance(udamap.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) @@ -1310,10 +1320,12 @@ 'the object inherits a child class, otherwise we can get the wrong class map 'returned. If Not tmpCMap Is Nothing Then - If ClassMap Is Nothing Then ClassMap = tmpCMap - If tmpCMap.ChildrenMaps.Count = 0 Then + If ClassMap Is Nothing Then ClassMap = tmpCMap - Exit For + Else + If tmpCMap.IsChildOf(ClassMap) Then + ClassMap = tmpCMap + End If End If End If Next @@ -2582,8 +2594,9 @@ Return queue End If If includeBaseObject Then - queue.Enqueue(obj) + AddToQueue(obj, queue) End If + Return queue Else 'Determine if the object needs saving 'But, countinue to determine if the object's associations need saving @@ -2593,11 +2606,10 @@ 'If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then If CType(obj.GetSourceObject, IValidation).IsValid Then 'Do not save if object is not valid 'obj.IsDirty = False 'Added to queue so clear dirty flag - queue.Enqueue(obj) + AddToQueue(obj, queue) End If Else - 'obj.IsDirty = False - queue.Enqueue(obj) + AddToQueue(obj, queue) End If End If End If @@ -2605,6 +2617,7 @@ 'Now process the object associations to see what else needs saving cm = obj.GetClassMap() + While Not cm Is Nothing For i = 1 To cm.getStraightAssociationMapSize udamap = cm.getStraightAssociationMap(i) If udamap.SaveAutomatic Then @@ -2621,7 +2634,7 @@ For k = 0 To col.Count() - 1 tmpObj = col.Item(k) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCacheInjObject(tmpObj) + value = getInjectedObject(tmpObj) Else value = tmpObj End If @@ -2646,7 +2659,7 @@ For k = 0 To col.Count() - 1 tmpObj = col.Item(k) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCacheInjObject(tmpObj) + value = getInjectedObject(tmpObj) Else value = tmpObj End If @@ -2670,39 +2683,9 @@ End If End If Next i + cm = cm.SuperClass + End While - 'now process the parent objects. Note that children will not be re-added as - 'they are already marked as non-dirty at the start of the method. - 'Also, if the child and parent share the same database table the parent object - 'is not added to the stack as it will be saved in savePrivateObject() - If cm.SharedTableField Is Nothing Then - If Not cm.SuperClass Is Nothing Then - tmpObj = obj.GetObjectByClassMap(cm.SuperClass) - If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCacheInjObject(tmpObj) - Else - value = tmpObj - End If - queue.Enqueue(value) - value.IsDirty = False 'Added to queue so clear dirty flag - For Each o In getObjectsToSave(value, False, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - End If - Else - If Not cm.SuperClass Is Nothing Then - tmpObj = obj.GetObjectByClassMap(cm.SuperClass) - If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCacheInjObject(tmpObj) - Else - value = tmpObj - End If - value.IsDirty = False 'make sure that the parent object is not added - For Each o In getObjectsToSave(value, False, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - End If - End If Return queue End Function @@ -2820,6 +2803,7 @@ Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) + MyBase.Finalize() End Sub Friend ReadOnly Property Disposed() As Boolean @@ -3217,4 +3201,27 @@ End If Next End Sub + + Private Sub AddToQueue(ByVal obj As Object, ByRef queue As Queue) + Call AddToQueue(obj, queue, True) + End Sub + Private Sub AddToQueue(ByVal obj As Object, ByRef queue As Queue, ByVal includeObject As Boolean) + 'Called recursively so that objects with superclasses are queued from the + 'top most object down. + Dim cm As CClassMap + Dim tmpobj As Object + cm = obj.GetClassMap() + If Not cm.SuperClass Is Nothing Then + tmpobj = obj.GetObjectByClassMap(cm.SuperClass) + If cm.SharedTableField Is Nothing Then + AddToQueue(tmpobj, queue, True) + Else + AddToQueue(tmpobj, queue, False) + End If + End If + If includeObject Then + queue.Enqueue(obj) + End If + Return + End Sub End Class \ No newline at end of file Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- CInjectedObject.vb 3 Mar 2005 00:38:23 -0000 1.15 +++ CInjectedObject.vb 11 Mar 2005 04:40:55 -0000 1.16 @@ -76,7 +76,8 @@ End If Dim f, fields() As FieldInfo Dim value As Object - Dim t, iListType, iDicType As Type Try + Dim t, iListType, iDicType As Type + Try t = sourceObject.GetType While Not t Is Nothing fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) @@ -96,7 +97,8 @@ t = Nothing End If End While - CPersistenceBroker.CopyCollections(sourceObject, targetObject) Catch ex As Exception + CPersistenceBroker.CopyCollections(sourceObject, targetObject) + Catch ex As Exception Debug.WriteLine(ex.Message) End Try End Sub @@ -104,61 +106,65 @@ Public Function getClassMap() As CClassMap Implements IPersistableObject.getClassMap Dim tmpCMap As CClassMap If m_classmap Is Nothing Then - m_classmap = getClassMap(TypeName(m_object), m_object.GetType.FullName) - If m_classmap Is Nothing Then - 'try to find an interface that is mapped - first mapped interface we find will be used - Dim intType, tmpType, interfaces() As Type - interfaces = m_object.GetType.GetInterfaces + 'm_classmap = getClassMap(TypeName(m_object), m_object.GetType.FullName) + 'If m_classmap Is Nothing Then + Dim persistenceBroker As CPersistenceBroker + persistenceBroker = getPersistenceBrokerInstance() + m_classmap = persistenceBroker.getClassMap(m_object.GetType) - '----------------------------------------- - Dim n, m As Integer - Dim super As CClassMap + ''try to find an interface that is mapped - first mapped interface we find will be used + 'Dim intType, tmpType, interfaces() As Type + 'interfaces = m_object.GetType.GetInterfaces - ' get the super class map if the object has multi-level inheritance - For n = 0 To interfaces.Length - 1 - m_classmap = getClassMap(interfaces(n).Name, interfaces(n).FullName) - If (Not m_classmap Is Nothing) AndAlso m_classmap.SuperClass Is Nothing Then - super = m_classmap - For m = n To interfaces.Length - 2 - interfaces(m) = interfaces(m + 1) - Next - If interfaces.Length > 1 Then - interfaces(m) = Nothing - End If - Exit For - End If - Next + ''----------------------------------------- + 'Dim n, m As Integer + 'Dim super As CClassMap - 'get actual interface which is the bottom level of inheritance - n = 0 - While n < interfaces.Length - 1 - If Not interfaces(n) Is Nothing Then - tmpCMap = getClassMap(interfaces(n).Name, interfaces(n).FullName) - If (Not tmpCMap Is Nothing) AndAlso tmpCMap.SuperClass Is super Then - super = tmpCMap - m_classmap = super - For m = n To interfaces.Length - 2 - interfaces(m) = interfaces(m + 1) - Next - interfaces(m) = Nothing + '' get the super class map if the object has multi-level inheritance + 'For n = 0 To interfaces.Length - 1 + ' m_classmap = getClassMap(interfaces(n).Name, interfaces(n).FullName) + ' If (Not m_classmap Is Nothing) AndAlso m_classmap.SuperClass Is Nothing Then + ' super = m_classmap + ' For m = n To interfaces.Length - 2 + ' interfaces(m) = interfaces(m + 1) + ' Next + ' If interfaces.Length > 1 Then + ' interfaces(m) = Nothing + ' End If + ' Exit For + ' End If + 'Next - If interfaces(0) Is Nothing Then - m_classmap = tmpCMap - Exit While - End If - n = 0 - Else - n = n + 1 - End If - Else - n = n + 1 - End If - End While + ''get actual interface which is the bottom level of inheritance + 'n = 0 + 'While n < interfaces.Length - 1 + ' If Not interfaces(n) Is Nothing Then + ' tmpCMap = getClassMap(interfaces(n).Name, interfaces(n).FullName) + ' If (Not tmpCMap Is Nothing) AndAlso tmpCMap.SuperClass Is super Then + ' super = tmpCMap + ' m_classmap = super + ' For m = n To interfaces.Length - 2 + ' interfaces(m) = interfaces(m + 1) + ' Next + ' interfaces(m) = Nothing + + ' If interfaces(0) Is Nothing Then + ' m_classmap = tmpCMap + ' Exit While + ' End If + ' n = 0 + ' Else + ' n = n + 1 + ' End If + ' Else + ' n = n + 1 + ' End If + 'End While End If If (m_classmap Is Nothing) Then Throw New NoClassMapException("No class map for " & m_object.GetType.FullName) End If - End If + 'End If Return m_classmap End Function @@ -496,10 +502,6 @@ Else pbroker = getPersistenceBrokerInstance() injobj = pbroker.getInjectedObject(obj) - If injobj Is Nothing Then - pbroker.StartTracking(obj) - injobj = pbroker.getInjectedObject(obj) - End If End If Return injobj End Function Index: CInjectedObjects.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObjects.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CInjectedObjects.vb 28 Feb 2005 23:07:44 -0000 1.4 +++ CInjectedObjects.vb 11 Mar 2005 04:40:55 -0000 1.5 @@ -175,11 +175,19 @@ Public Overloads Function Find(ByVal obj As Object, ByVal useFindAttributes As Boolean) As CInjectedObject Dim injObj As CInjectedObject + If Not TypeOf (obj) Is CInjectedObject Then injObj = New CInjectedObject(obj) + Else + injObj = obj + End If Return Find(injObj, useFindAttributes) End Function Public Overloads Function Find(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As CInjectedObject + Return Find(obj, useFindAttributes, True) + End Function + + Public Overloads Function Find(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean, ByVal CheckSubClasses As Boolean) As CInjectedObject Dim injObj As CInjectedObject Dim x As DictionaryEntry Dim attrmap As CAttributeMap @@ -203,7 +211,7 @@ 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 + If t Is obj.GetObjectType OrElse (CheckSubClasses AndAlso t.IsSubclassOf(obj.GetObjectType)) Then found = True Try If useFindAttributes Then Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- CClassMap.vb 3 Mar 2005 00:38:23 -0000 1.52 +++ CClassMap.vb 11 Mar 2005 04:40:55 -0000 1.53 @@ -1428,7 +1428,18 @@ End If Catch ex As Exception End Try + Try obj.SetAttributeValue(AttrMap.Name, val) + Catch ex As Exception + Dim s As String + s = "Could not populate {0}.{1} with value {2}" + If val Is Nothing Then + s = String.Format(s, Me.Name, AttrMap.Name, "Nothing") + Else + s = String.Format(s, Me.Name, AttrMap.Name, val.ToString) + End If + Throw New RetrieveException(s, ex) + End Try If Not val Is Nothing AndAlso Not IsDBNull(val) Then obj.Persistent = True obj.State = PersistenceState.Persistent @@ -1524,7 +1535,18 @@ Catch ex As Exception End Try + Try obj.SetAttributeValue(AttrMap.Name, tmpObj) + Catch ex As Exception + Dim s As String + s = "Could not populate {0}.{1} with value {2}" + If tmpObj Is Nothing Then + s = String.Format(s, Me.Name, AttrMap.Name, "Nothing") + Else + s = String.Format(s, Me.Name, AttrMap.Name, tmpObj.ToString) + End If + Throw New RetrieveException(s, ex) + End Try If Not tmpObj Is Nothing AndAlso Not IsDBNull(tmpObj) Then obj.Persistent = True obj.State = PersistenceState.Persistent @@ -1590,7 +1612,18 @@ End If Catch ex As Exception End Try + Try obj.SetAttributeValue(AttrMap.Name, tmpObj) + Catch ex As Exception + Dim s As String + s = "Could not populate {0}.{1} with value {2}" + If tmpObj Is Nothing Then + s = String.Format(s, Me.Name, AttrMap.Name, "Nothing") + Else + s = String.Format(s, Me.Name, AttrMap.Name, tmpObj.ToString) + End If + Throw New RetrieveException(s, ex) + End Try If Not tmpObj Is Nothing AndAlso Not IsDBNull(tmpObj) Then obj.Persistent = True obj.State = PersistenceState.Persistent @@ -1626,7 +1659,18 @@ End If Catch ex As Exception End Try + Try obj.SetAttributeValue(AttrMap.Name, tmpObj) + Catch ex As Exception + Dim s As String + s = "Could not populate {0}.{1} with value {2}" + If tmpObj Is Nothing Then + s = String.Format(s, Me.Name, AttrMap.Name, "Nothing") + Else + s = String.Format(s, Me.Name, AttrMap.Name, tmpObj.ToString) + End If + Throw New RetrieveException(s, ex) + End Try If Not tmpObj Is Nothing AndAlso Not IsDBNull(tmpObj) Then obj.Persistent = True obj.State = PersistenceState.Persistent @@ -1886,8 +1930,6 @@ End If statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ & cm2.RelationalDatabase.getClauseStringEqualTo("_" & i.ToString & "_")) - 'statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - ' & " = " & cm2.RelationalDatabase.getParamHolder(i)) Next i cm2 = Nothing Loop While Not cm2 Is Nothing @@ -1929,6 +1971,7 @@ Dim de As DictionaryEntry Dim isfirst As Boolean = True Dim am As CAttributeMap + Dim paramCount As Integer rMaps.Add("t1", Me) 'Joins are not depending on method used for retrieve (ie find or retrieve) so don't @@ -1979,11 +2022,13 @@ statement.addSqlClause(m_joinSet.GetSQLString) statement.addSqlClause(" " & Me.RelationalDatabase.getClauseStringWhere & " ") - Do + paramCount = 0 classMapCount = 1 + isfirst = True mapName = "t" & classMapCount.ToString cm2 = rMaps(mapName) - isfirst = True + Do + mapName = "t" & classMapCount.ToString If Not cm2.SharedTableField Is Nothing Then cm3 = cm2 While Not cm2 Is Nothing @@ -1998,7 +2043,7 @@ If cm2.SharedTableField Is Nothing Then cm2 = Nothing End While cm2 = cm3 - End If + Else For i = 1 To cm2.getFindSize am = cm2.FindAttributeMaps(i) If Not isfirst Then @@ -2006,12 +2051,13 @@ Else isfirst = False End If + paramCount += 1 statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - & cm2.RelationalDatabase.getClauseStringEqualTo("_" & i.ToString & "_")) - 'statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - ' & " = " & cm2.RelationalDatabase.getParamHolder(i)) + & cm2.RelationalDatabase.getClauseStringEqualTo("_" & paramCount.ToString & "_")) Next i - cm2 = Nothing + classMapCount += 1 + End If + cm2 = cm2.SuperClass Loop While Not cm2 Is Nothing m_sqlFindStub = statement.SqlString @@ -2115,9 +2161,7 @@ Try ip = CType(obj, IPersistableObject) Catch ex As Exception - pbroker = getPersistenceBrokerInstance() - 'pbroker.StartTracking(obj) - ip = pbroker.getInjectedObject(obj) + ip = New CInjectedObject(obj) End Try Return ip End Function @@ -2131,10 +2175,21 @@ Try ip = CType(obj, IPersistableObject) Catch ex As Exception - pbroker = getPersistenceBrokerInstance() - 'pbroker.StartTracking(obj) - ip = pbroker.getInjectedObject(obj) + ip = New CInjectedObject(obj) End Try Return ip End Function + + Friend Function IsChildOf(ByVal cm As CClassMap) As Boolean + Dim result As Boolean = False + Dim cm2 As CClassMap + cm2 = Me.SuperClass + While Not cm2 Is Nothing + If cm2.Equals(cm) Then + result = True + Exit While + End If + End While + Return result + End Function End Class \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-03-11 04:41:06
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_OLEDB In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21135/Providers/AF_OLEDB Modified Files: COleDBConnection.vb COleDbDatabase.vb Log Message: Bug fixes for interface based persistence. Problems with 3+ levels in the hierarchy. Also some small changes to finalize. Index: COleDbDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_OLEDB/COleDbDatabase.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- COleDbDatabase.vb 7 Feb 2005 07:37:54 -0000 1.1 +++ COleDbDatabase.vb 11 Mar 2005 04:40:56 -0000 1.2 @@ -312,12 +312,13 @@ Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then + m_disposed = True Dim conn As COleDBConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() + conn = Nothing End While - m_disposed = True End If End If End Sub Index: COleDBConnection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_OLEDB/COleDBConnection.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- COleDBConnection.vb 7 Feb 2005 07:37:54 -0000 1.1 +++ COleDBConnection.vb 11 Mar 2005 04:40:56 -0000 1.2 @@ -431,6 +431,7 @@ If Not m_disposed Then If disposing Then Try + m_disposed = True If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing @@ -443,7 +444,6 @@ Catch ex As Exception Debug.WriteLine(ex.Message) End Try - m_disposed = True End If End If End Sub @@ -451,6 +451,7 @@ Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) + MyBase.finalize() End Sub End Class |
From: Richard B. <rb...@us...> - 2005-03-03 00:38:43
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21979 Modified Files: CClassMap.vb CInjectedObject.vb CPersistenceBroker.vb CPersistentObject.vb CXMLConfigLoader.vb IPersistentObject.vb Log Message: Bug fix (1155465) for saving without first retrieving an object. Also added state property to IPersistableObject to indicate persistent, nonpersistent or unknown state. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.97 retrieving revision 1.98 diff -u -d -r1.97 -r1.98 --- CPersistenceBroker.vb 1 Mar 2005 01:28:19 -0000 1.97 +++ CPersistenceBroker.vb 3 Mar 2005 00:38:23 -0000 1.98 @@ -183,6 +183,11 @@ conn.AutoCommit = False Try obj.Persistent = retrievePrivateObject(obj, conn, useFind, useCache) + If obj.Persistent Then + obj.State = PersistenceState.Persistent + Else + obj.State = PersistenceState.NotPersistent + End If Catch ex As Exception x = New RetrieveException(ex.Message, ex) Finally @@ -674,7 +679,7 @@ End If End If End If - End If + End If End If Next Next @@ -937,6 +942,7 @@ Dim tmpdate As Date Dim statement As CSqlStatement Dim rs As CResultset + Dim usedInsert As Boolean clMap = obj.GetClassMap cm = clMap @@ -948,20 +954,47 @@ If obj.Persistent Then statement = cm.getUpdateSqlFor(obj) conn.processStatement(statement) + usedInsert = False Try PCSQLHits.Increment() PCUpdates.Increment() Catch End Try Else - statement = cm.getInsertSqlFor(obj) - conn.processStatement(statement) - Try - PCSQLHits.Increment() - PCInserts.Increment() - Catch - End Try - If cm.getIdentitySize > 0 Then + If obj.State = PersistenceState.Unknown Then + 'We haven't checked to see if this object exists. + 'We will try to insert by default, and if that doesn't work then + 'we'll attempt to update + Try + statement = cm.getInsertSqlFor(obj) + conn.processStatement(statement) + usedInsert = True + PCSQLHits.Increment() + PCUpdates.Increment() + Catch ex As Exception + Debug.WriteLine("Couldn't insert object in unknown state, trying to update...") + Try + statement = cm.getUpdateSqlFor(obj) + conn.processStatement(statement) + usedInsert = False + PCSQLHits.Increment() + PCUpdates.Increment() + Catch ex1 As Exception + Debug.WriteLine("Couldn't update object in unknown state, throwing initial exception") + Throw ex + End Try + End Try + Else + statement = cm.getInsertSqlFor(obj) + conn.processStatement(statement) + usedInsert = True + Try + PCSQLHits.Increment() + PCInserts.Increment() + Catch + End Try + End If + If usedInsert AndAlso cm.getIdentitySize > 0 Then If CInt(cm.RelationalDatabase.getValueFor(obj.GetValueByAttribute(cm.getIdentityAttributeMap(1).Name))) = 0 Then obj.SetAttributeValue(cm.getIdentityAttributeMap(1).Name, cm.RelationalDatabase.getIdentityValue(conn)) End If @@ -972,6 +1005,7 @@ 'If we don't do this the object won't get saved correctly on subsequent calls. obj.ResetOriginalDates() obj.Persistent = True + obj.State = PersistenceState.Persistent obj.IsDirty = False obj.IsQueued = False 'Update cache key in-case primary key fields have changed value @@ -1145,7 +1179,7 @@ If GetType(IValidation).IsInstanceOfType(obj.GetSourceObject) Then If Not CType(obj.GetSourceObject, IValidation).IsValidToDelete Then Debug.WriteLine("Not valid to delete object") - Return 'Do not delete if object + Return 'Do not delete if object End If End If @@ -1182,6 +1216,7 @@ End If obj.Persistent = False + obj.State = PersistenceState.NotPersistent If m_useCache Then m_cache.Remove(obj) 'remove from the cache Try @@ -1241,33 +1276,6 @@ End If Next i - 'statement = clMap.getDeleteSqlFor(obj) - 'Try - ' PCSQLHits.Increment() - 'Catch - 'End Try - 'conn.processStatement(statement) - - 'If deleteSuperClass Then - ' cm = cm.SuperClass - ' If Not cm Is Nothing Then - ' 'delete super class and its associations - ' Value = obj.GetObjectByClassMap(cm) - ' If retrieveObject(Value, False, True) Then - ' 'If Value.Retrieve() Then - ' deletePrivateObject(Value, conn, True) - ' End If - ' End If - 'End If - - 'obj.Persistent = False - 'If m_useCache Then - ' m_cache.Remove(obj) 'remove from the cache - ' Try - ' PCCacheSize.RawValue = m_cache.Count - ' Catch - ' End Try - 'End If colCriteriaParameters = Nothing End Sub @@ -2467,7 +2475,6 @@ Next 'Not any of the childrens, so check classMap - obj = classMap.CreateObjectInstance 'Retrieve superclass details first @@ -2475,41 +2482,17 @@ cm2 = classMap While Not cm1 Is Nothing classMap.populateObject(cm1, obj, dataRow, joins.GetTableAlias(cm1), True, classMap) - 'classMap.populateObject(cm1, obj, dataRow, joins.GetTableAlias(cm1), True, cm1) cm2 = cm1 cm1 = cm1.SuperClass End While 'set persistent to false because the parent will allways be persistent obj.Persistent = False + 'Now retrieve the class details classMap.populateObject(classMap, obj, dataRow, joins.GetTableAlias(classMap)) - 'Dim tmpobj As CPersistentObject - 'tmpobj = m_cache.Item(obj) - 'If Not tmpobj Is Nothing Then - ' Return tmpobj - 'End If - - 'cm1 = classMap.SuperClass - - 'Dim tmpobj2 As CPersistentObject - 'While Not cm1 Is Nothing - ' tmpobj = obj.GetBaseCopy - ' tmpobj2 = m_cache.Item(tmpobj) - ' If tmpobj2 Is Nothing Then - ' cm1 = cm1.SuperClass - ' Else - ' Return tmpobj2 - ' End If - 'End While - - ''retrieve associations for the class and its super classes - 'obj.IsLoading = True - 'retrieveAssociations(obj, conn, classMap, True) - 'obj.IsLoading = False If obj.Persistent Then - 'obj.AssociationsLoaded = True obj.IsDirty = False obj.OriginalCacheKey = New CCacheKey(obj) End If @@ -2562,7 +2545,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 aObj As CAssociationObject Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- IPersistentObject.vb 1 Mar 2005 01:28:19 -0000 1.9 +++ IPersistentObject.vb 3 Mar 2005 00:38:24 -0000 1.10 @@ -14,6 +14,7 @@ ReadOnly Property IsReadOnly() As Boolean ReadOnly Property IsModifyOnly() As Boolean Property OriginalCacheKey() As CCacheKey + Property State() As PersistenceState Function GetClassMap() As CClassMap Function GetFieldLengthByName(ByVal x As String) As Integer @@ -67,4 +68,10 @@ Public Interface IValidation Function IsValid() As Boolean Function IsValidToDelete() As Boolean -End Interface \ No newline at end of file +End Interface + +Public Enum PersistenceState As Integer + Unknown + NotPersistent + Persistent +End Enum \ No newline at end of file Index: CXMLConfigLoader.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CXMLConfigLoader.vb,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- CXMLConfigLoader.vb 10 Feb 2005 04:22:46 -0000 1.32 +++ CXMLConfigLoader.vb 3 Mar 2005 00:38:24 -0000 1.33 @@ -7,7 +7,7 @@ Imports System.IO '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CXMLConfigLoader ''' '''----------------------------------------------------------------------------- @@ -168,7 +168,7 @@ Try dbMap.Add(reldb.Name, reldb) Catch ex As Exception - Throw New AToMSFramework.XMLMappingException("Could not add database " & reldb.Name & vbCrLf & ex.Message, ex) + Throw New XMLMappingException("Could not add database " & reldb.Name & vbCrLf & ex.Message, ex) End Try ElseIf node.Name = "class" Then clm = getClassMap(elem) @@ -180,7 +180,7 @@ Try clMap.Add(keyStr, clm) Catch ex As Exception - Throw New AToMSFramework.XMLMappingException("Could not add classmap " & clm.Name & vbCrLf & ex.Message, ex) + Throw New XMLMappingException("Could not add classmap " & clm.Name & vbCrLf & ex.Message, ex) End Try ElseIf node.Name = "association" Then processAssociation(elem) @@ -223,12 +223,14 @@ Dim pAsm As [Assembly] Dim types(), t, reldbType As Type + Dim rdb As Type + rdb = GetType(CRelationalDatabase) If ((Not attrPMName Is Nothing) And (Not attrProviderName Is Nothing)) Then Try pAsm = [Assembly].LoadFrom(attrProviderName.Value) types = pAsm.GetTypes() For Each t In types - If t.IsSubclassOf(GetType(CRelationalDatabase)) Then + If t.IsSubclassOf(rdb) Then reldbType = t Exit For End If Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- CClassMap.vb 28 Feb 2005 23:07:43 -0000 1.51 +++ CClassMap.vb 3 Mar 2005 00:38:23 -0000 1.52 @@ -1400,6 +1400,7 @@ Dim rw As DataRow Dim skipAttribute As Boolean + obj.State = PersistenceState.NotPersistent rw = rs.ResultSet.Tables(0).Rows(0) For i = 1 To cm.getSize AttrMap = cm.getAttributeMap(i) @@ -1428,8 +1429,9 @@ Catch ex As Exception End Try obj.SetAttributeValue(AttrMap.Name, val) - If Not IsDBNull(val) And Not val Is Nothing Then + If Not val Is Nothing AndAlso Not IsDBNull(val) Then obj.Persistent = True + obj.State = PersistenceState.Persistent End If End If Next i @@ -1495,6 +1497,7 @@ End If Dim i As Short Dim AttrMap As CAttributeMap + obj.State = PersistenceState.NotPersistent For i = 1 To ClassMap.getSize AttrMap = ClassMap.getAttributeMap(i) 'Attempt to load column via alias first, then table qualified name then column name @@ -1522,8 +1525,9 @@ End Try obj.SetAttributeValue(AttrMap.Name, tmpObj) - If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then + If Not tmpObj Is Nothing AndAlso Not IsDBNull(tmpObj) Then obj.Persistent = True + obj.State = PersistenceState.Persistent End If End If Next i @@ -1569,6 +1573,8 @@ ClassMap = Me Dim i As Short Dim AttrMap As CAttributeMap + + obj.State = PersistenceState.NotPersistent Do For i = 1 To ClassMap.getSize AttrMap = ClassMap.getAttributeMap(i) @@ -1585,8 +1591,9 @@ Catch ex As Exception End Try obj.SetAttributeValue(AttrMap.Name, tmpObj) - If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then + If Not tmpObj Is Nothing AndAlso Not IsDBNull(tmpObj) Then obj.Persistent = True + obj.State = PersistenceState.Persistent End If End If Next i @@ -1603,6 +1610,8 @@ End If Dim i As Short Dim AttrMap As CAttributeMap + + obj.State = PersistenceState.NotPersistent Do For i = 1 To ClassMap.getKeySize AttrMap = ClassMap.getKeyAttributeMap(i) @@ -1618,8 +1627,9 @@ Catch ex As Exception End Try obj.SetAttributeValue(AttrMap.Name, tmpObj) - If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then + If Not tmpObj Is Nothing AndAlso Not IsDBNull(tmpObj) Then obj.Persistent = True + obj.State = PersistenceState.Persistent End If Next i ClassMap = ClassMap.SuperClass Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- CInjectedObject.vb 28 Feb 2005 23:07:44 -0000 1.14 +++ CInjectedObject.vb 3 Mar 2005 00:38:23 -0000 1.15 @@ -19,6 +19,7 @@ Private m_guid As Guid Private m_classmap As CClassMap Private m_persistent As Boolean + Private m_state As PersistenceState = PersistenceState.Unknown Private m_retrievedCacheKey As CCacheKey Private m_loading As Boolean Private m_queued As Boolean @@ -436,6 +437,15 @@ End Set End Property + Public Property State() As PersistenceState Implements IPersistableObject.State + Get + Return m_state + End Get + Set(ByVal Value As PersistenceState) + m_state = Value + End Set + End Property + Public Function getCollectionByAttribute(ByVal pName As String) As IList Implements IPersistableObject.getCollectionByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") @@ -591,18 +601,17 @@ 'set persistent before populating the object since the dirty flag checks its validity If Me.Persistent Then obj.Persistent = True + obj.State = Me.State End If 'set the associated objects For i = 1 To classMap.getStraightAssociationMapSize udamap = classMap.getStraightAssociationMap(i) - 'If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then obj.SetAttributeValue(udamap.FromClassTarget, Me.getObjectByAttribute(udamap.FromClassTarget)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Or udamap.Cardinality = CUDAMap.CardinalityEnum.MANY_TO_MANY Then obj.SetAttributeValue(udamap.FromClassTarget, Me.getCollectionByAttribute(udamap.FromClassTarget)) End If - 'End If Next i 'set object's attributes @@ -616,13 +625,11 @@ 'set the associated objects For i = 1 To cm.getStraightAssociationMapSize udamap = cm.getStraightAssociationMap(i) - 'If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then obj.SetAttributeValue(udamap.FromClassTarget, Me.getObjectByAttribute(udamap.FromClassTarget)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Or udamap.Cardinality = CUDAMap.CardinalityEnum.MANY_TO_MANY Then obj.SetAttributeValue(udamap.FromClassTarget, Me.getCollectionByAttribute(udamap.FromClassTarget)) End If - 'End If Next i 'set superclass's attributes Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- CPersistentObject.vb 1 Mar 2005 01:28:19 -0000 1.57 +++ CPersistentObject.vb 3 Mar 2005 00:38:24 -0000 1.58 @@ -45,6 +45,7 @@ Private m_checkingAssociations As Boolean Private m_isNew As Boolean Private m_editing As Boolean + <NonSerialized()> Private m_state As PersistenceState = PersistenceState.Unknown <NonSerialized()> Private m_classmap As CClassMap Public Event MarkedAsDirty As EventHandler Implements IPersistentObject.MarkedAsDirty @@ -125,6 +126,15 @@ End Set End Property + <Browsable(False)> Public Property State() As PersistenceState Implements IPersistableObject.State + Get + Return m_state + End Get + Set(ByVal Value As PersistenceState) + m_state = Value + End Set + End Property + '''----------------------------------------------------------------------------- ''' <summary> ''' Indicates if the all atributes are populated or only those marked as proxy attributes @@ -1627,7 +1637,7 @@ ''' </summary> ''' <param name="classMap">The class map to get</param> ''' <returns>CPersistentObject The object.</returns> - ''' <remarks>The method creates an object bases on the class map. And populates its attributes + ''' <remarks>The method creates an object based on the class map. And populates its attributes ''' from the child class object. ''' processed. This is used to save the base class object and its assotiations.</remarks> ''' <history> @@ -1648,18 +1658,17 @@ 'set persistent before populating the object since the dirty flag checks its validity If Me.Persistent Then obj.Persistent = True + obj.State = Me.State End If 'set the associated objects For i = 1 To classMap.getStraightAssociationMapSize udamap = classMap.getStraightAssociationMap(i) - 'If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then obj.setAttributeValue(udamap.FromClassTarget, Me.getObjectByAttribute(udamap.FromClassTarget)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Or udamap.Cardinality = CUDAMap.CardinalityEnum.MANY_TO_MANY Then obj.setAttributeValue(udamap.FromClassTarget, Me.getCollectionByAttribute(udamap.FromClassTarget)) End If - 'End If Next i 'set object's attributes @@ -1673,13 +1682,11 @@ 'set the associated objects For i = 1 To cm.getStraightAssociationMapSize udamap = cm.getStraightAssociationMap(i) - 'If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then obj.setAttributeValue(udamap.FromClassTarget, Me.getObjectByAttribute(udamap.FromClassTarget)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Or udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then obj.setAttributeValue(udamap.FromClassTarget, Me.getCollectionByAttribute(udamap.FromClassTarget)) End If - 'End If Next i 'set superclass's attributes @@ -1698,38 +1705,6 @@ Return obj End Function - '<EditorBrowsable(EditorBrowsableState.Advanced)> _ - 'Public Overridable Function GetBaseCopy() As CPersistentObject - ' 'Use reflection to copy all of the fields from Obj to me (by value) - ' If Me.getClassMap.SuperClass Is Nothing Then - ' Return Nothing - ' End If - ' Dim obj As CPersistentObject = Me.getClassMap.SuperClass.CreateObjectInstance - ' Dim f, fields() As FieldInfo - ' Dim value As Object - ' Dim t As Type - ' Try - ' t = obj.GetType - ' While Not t Is Nothing - ' fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - ' 'Note that this will copy event handlers as well - ' For Each f In fields - ' value = f.GetValue(Me) - ' f.SetValue(obj, value) - ' Next - ' If t.IsSubclassOf(GetType(CPersistentObject)) Then - ' t = t.BaseType - ' Else - ' t = Nothing - ' End If - ' End While - ' Return obj - ' Catch ex As Exception - ' Debug.WriteLine(ex.Message) - ' End Try - ' Return Nothing - 'End Function - #End Region #Region "IEditableObject" @@ -1868,5 +1843,4 @@ Public Function GetSourceObject() As Object Implements IPersistableObject.GetSourceObject Return Me End Function - End Class |
From: Richard B. <rb...@us...> - 2005-03-03 00:37:43
|
Update of /cvsroot/jcframework/Nunit/Interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21734/Interfaces Modified Files: EmployeeInterfaceTests.vb Log Message: Unit test for saving without first retrieving Index: EmployeeInterfaceTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/EmployeeInterfaceTests.vb,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- EmployeeInterfaceTests.vb 1 Mar 2005 20:51:33 -0000 1.5 +++ EmployeeInterfaceTests.vb 3 Mar 2005 00:37:25 -0000 1.6 @@ -109,5 +109,18 @@ Assert.IsTrue(pbroker.getInjectedObject(emp2).Persistent) End Sub + <Test()> Public Sub SaveThenSaveWithoutRetrieve() + Dim oidvalue As String + emp.Name = "SaveThisEmp" + pbroker.FindObject(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + pbroker.PersistChanges(emp) + emp = New EmployeeClass + emp.Name = "SaveThisEmp" + 'Should update record, not try to insert + pbroker.PersistChanges(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent, "persistent check failed") + End Sub + End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-03-03 00:37:38
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21734/InheritedClasses Modified Files: AtomsFrameworkTests.vb Log Message: Unit test for saving without first retrieving Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/AtomsFrameworkTests.vb,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- AtomsFrameworkTests.vb 11 Feb 2005 02:53:20 -0000 1.14 +++ AtomsFrameworkTests.vb 3 Mar 2005 00:37:24 -0000 1.15 @@ -579,5 +579,19 @@ Assert.AreEqual("bb52", CType(a1.TableBCollection.Item(1), TableB).Id) End Sub + <Test()> Public Sub SaveThenSaveWithoutRetrieve() + Dim oidvalue As String + emp.Name = "SaveThisEmp" + emp.Find() + Assert.IsFalse(emp.Persistent) + oidvalue = emp.OIDValue + emp.Save() + emp = New CEmployee + emp.OIDValue = oidvalue + emp.Name = "Should update record" + emp.Save() + Assert.IsTrue(emp.Persistent, "persistent check failed") + End Sub + End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-03-01 20:52:02
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20247 Modified Files: Nunit_AtomsFramework.vbproj Nunit_AtomsFramework.vbproj.user Added Files: nunit.sln Log Message: Changed to use proper namespace name again (oops) Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Nunit_AtomsFramework.vbproj 28 Feb 2005 23:05:47 -0000 1.18 +++ Nunit_AtomsFramework.vbproj 1 Mar 2005 20:51:34 -0000 1.19 @@ -86,9 +86,9 @@ HintPath = "..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll" /> <Reference - Name = "Atoms.Framework" - AssemblyName = "Atoms.Framework" - HintPath = "..\bin\Atoms.Framework.dll" + Name = "AToMSFramework" + AssemblyName = "AToMSFramework" + HintPath = "..\dotnet\bin\AToMSFramework.dll" /> </References> <Imports> --- NEW FILE: nunit.sln --- Microsoft Visual Studio Solution File, Format Version 8.00 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Nunit_AtomsFramework", "Nunit_AtomsFramework.vbproj", "{60C96393-CBF7-4F59-B43A-DA1D6608EEBD}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {60C96393-CBF7-4F59-B43A-DA1D6608EEBD}.Debug.ActiveCfg = Debug|.NET {60C96393-CBF7-4F59-B43A-DA1D6608EEBD}.Debug.Build.0 = Debug|.NET {60C96393-CBF7-4F59-B43A-DA1D6608EEBD}.Release.ActiveCfg = Release|.NET {60C96393-CBF7-4F59-B43A-DA1D6608EEBD}.Release.Build.0 = Release|.NET EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection EndGlobal Index: Nunit_AtomsFramework.vbproj.user =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj.user,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Nunit_AtomsFramework.vbproj.user 28 Feb 2005 23:05:47 -0000 1.3 +++ Nunit_AtomsFramework.vbproj.user 1 Mar 2005 20:51:34 -0000 1.4 @@ -1,7 +1,7 @@ <VisualStudioProject> <VisualBasic LastOpenVersion = "7.10.3077" > <Build> - <Settings ReferencePath = "C:\Projects\MMM\Atoms_Framework\bin\;C:\Projects\Atoms.NET\Framework\bin\" > + <Settings ReferencePath = "C:\Program Files\NUnit 2.2\bin\;C:\Projects\Sourceforge\dotnet\bin\" > <Config Name = "Debug" EnableASPDebugging = "false" @@ -13,7 +13,7 @@ StartAction = "Program" StartArguments = '"..\Nunit_AtomsFramework.nunit"' StartPage = "" - StartProgram = "C:\Program Files\NUnit 2.2.2\bin\nunit-gui.exe" + StartProgram = "C:\Program Files\NUnit 2.2\bin\nunit-gui.exe" StartURL = "" StartWorkingDirectory = "" StartWithIE = "true" |
From: Richard B. <rb...@us...> - 2005-03-01 20:51:49
|
Update of /cvsroot/jcframework/Nunit/StandardClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20247/StandardClasses Modified Files: NonInheritedTests.vb Log Message: Changed to use proper namespace name again (oops) Index: NonInheritedTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/StandardClasses/NonInheritedTests.vb,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- NonInheritedTests.vb 28 Feb 2005 23:05:49 -0000 1.6 +++ NonInheritedTests.vb 1 Mar 2005 20:51:34 -0000 1.7 @@ -1,4 +1,4 @@ -Imports Atoms.Framework +Imports AToMSFramework Imports NUnit.Framework Namespace StandardClasses |
From: Richard B. <rb...@us...> - 2005-03-01 20:51:49
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20247/InheritedClasses Modified Files: ManyToManyTests_v2.vb Log Message: Changed to use proper namespace name again (oops) Index: ManyToManyTests_v2.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/ManyToManyTests_v2.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ManyToManyTests_v2.vb 28 Feb 2005 23:05:49 -0000 1.4 +++ ManyToManyTests_v2.vb 1 Mar 2005 20:51:33 -0000 1.5 @@ -1,4 +1,4 @@ -Imports Atoms.Framework +Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses |
From: Richard B. <rb...@us...> - 2005-03-01 20:51:49
|
Update of /cvsroot/jcframework/Nunit/Interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20247/Interfaces Modified Files: EmployeeInterfaceTests.vb ManyToManyClasses.vb ManyToManyTests.vb ValidatedEmployee.vb Log Message: Changed to use proper namespace name again (oops) Index: ValidatedEmployee.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/ValidatedEmployee.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ValidatedEmployee.vb 1 Mar 2005 01:29:57 -0000 1.2 +++ ValidatedEmployee.vb 1 Mar 2005 20:51:33 -0000 1.3 @@ -2,7 +2,7 @@ Public Class ValidatedEmployee Inherits EmployeeClass - Implements Atoms.Framework.IValidation + Implements AToMSFramework.IValidation Private _allowValidation As Boolean @@ -15,11 +15,11 @@ End Set End Property - Public Function IsValid() As Boolean Implements Atoms.Framework.IValidation.IsValid + Public Function IsValid() As Boolean Implements AToMSFramework.IValidation.IsValid Return _allowValidation End Function - Public Function IsValidToDelete() As Boolean Implements Atoms.Framework.IValidation.IsValidToDelete + Public Function IsValidToDelete() As Boolean Implements AToMSFramework.IValidation.IsValidToDelete Return _allowValidation End Function End Class Index: ManyToManyClasses.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/ManyToManyClasses.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ManyToManyClasses.vb 28 Feb 2005 23:05:50 -0000 1.1 +++ ManyToManyClasses.vb 1 Mar 2005 20:51:33 -0000 1.2 @@ -1,4 +1,4 @@ -Imports Atoms.Framework +Imports AToMSFramework Namespace Interfaces @@ -134,20 +134,20 @@ #Region "Interface Factories" Public Class M2MAFactory - Implements Atoms.Framework.IClassFactory + Implements AToMSFramework.IClassFactory - Public Function CreateObject() As Object Implements Atoms.Framework.IClassFactory.CreateObject - Return New M2MA - End Function - End Class + Public Function CreateObject() As Object Implements AToMSFramework.IClassFactory.CreateObject + Return New M2MA + End Function + End Class Public Class M2MBFactory - Implements Atoms.Framework.IClassFactory + Implements AToMSFramework.IClassFactory - Public Function CreateObject() As Object Implements Atoms.Framework.IClassFactory.CreateObject - Return New M2MB - End Function - End Class + Public Function CreateObject() As Object Implements AToMSFramework.IClassFactory.CreateObject + Return New M2MB + End Function + End Class #End Region End Namespace Index: EmployeeInterfaceTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/EmployeeInterfaceTests.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- EmployeeInterfaceTests.vb 1 Mar 2005 01:29:56 -0000 1.4 +++ EmployeeInterfaceTests.vb 1 Mar 2005 20:51:33 -0000 1.5 @@ -1,4 +1,4 @@ -Imports Atoms.Framework +Imports AToMSFramework Imports NUnit.Framework Namespace Interfaces Index: ManyToManyTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/ManyToManyTests.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ManyToManyTests.vb 28 Feb 2005 23:05:50 -0000 1.1 +++ ManyToManyTests.vb 1 Mar 2005 20:51:33 -0000 1.2 @@ -1,4 +1,4 @@ -Imports Atoms.Framework +Imports AToMSFramework Imports NUnit.Framework Namespace Interfaces |
From: Richard B. <rb...@us...> - 2005-03-01 03:17:18
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24465 Modified Files: CPersistentCriteria.vb Log Message: Was missing where clause in SQL generated for CRetrieveCriteria when using shared tables and no wherecondition Index: CPersistentCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCriteria.vb,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- CPersistentCriteria.vb 2 Nov 2004 05:36:13 -0000 1.10 +++ CPersistentCriteria.vb 1 Mar 2005 03:16:57 -0000 1.11 @@ -21,7 +21,7 @@ End Interface '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CPersistentCriteria ''' '''----------------------------------------------------------------------------- @@ -269,6 +269,8 @@ If clauseConditionAdded Then statement.addSqlClause(" " & cm.RelationalDatabase.getClauseStringAnd & " ") clauseConditionAdded = True +else + statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringWhere & " ") End If statement.addSqlClause(CType(cm.Tables(1), CTableMap).Name & "." & cm.SharedTableField & cm.RelationalDatabase.getClauseStringEqualTo(cm.RelationalDatabase.getValueFor(cm.SharedTableValue))) End If |
From: Richard B. <rb...@us...> - 2005-03-01 01:30:16
|
Update of /cvsroot/jcframework/Nunit/Interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25464/Interfaces Modified Files: EmployeeInterfaceTests.vb ValidatedEmployee.vb Log Message: Added test for IsValidToDelete Index: ValidatedEmployee.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/ValidatedEmployee.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ValidatedEmployee.vb 6 Dec 2004 01:01:13 -0000 1.1 +++ ValidatedEmployee.vb 1 Mar 2005 01:29:57 -0000 1.2 @@ -2,7 +2,7 @@ Public Class ValidatedEmployee Inherits EmployeeClass - Implements AToMSFramework.IValidation + Implements Atoms.Framework.IValidation Private _allowValidation As Boolean @@ -15,7 +15,11 @@ End Set End Property - Public Function IsValid() As Boolean Implements AToMSFramework.IValidation.IsValid + Public Function IsValid() As Boolean Implements Atoms.Framework.IValidation.IsValid + Return _allowValidation + End Function + + Public Function IsValidToDelete() As Boolean Implements Atoms.Framework.IValidation.IsValidToDelete Return _allowValidation End Function End Class Index: EmployeeInterfaceTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/Interfaces/EmployeeInterfaceTests.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- EmployeeInterfaceTests.vb 21 Dec 2004 22:00:01 -0000 1.3 +++ EmployeeInterfaceTests.vb 1 Mar 2005 01:29:56 -0000 1.4 @@ -1,4 +1,4 @@ -Imports AToMSFramework +Imports Atoms.Framework Imports NUnit.Framework Namespace Interfaces @@ -91,5 +91,23 @@ Assert.IsTrue(emp.ReportsTo Is Nothing) End Sub + <Test()> Public Sub SaveAndDeleteValidEmp1() + Dim emp2 As ValidatedEmployee + emp2 = New ValidatedEmployee + emp2.AllowValidation = True + emp2.Name = "validCheck" + pbroker.FindObject(emp2) + Assert.IsFalse(pbroker.getInjectedObject(emp2).Persistent) + pbroker.PersistChanges(emp2) + emp2.AllowValidation = False + pbroker.MarkForDeletion(emp2) + pbroker.PersistChanges() + pbroker.ClearCache() + emp2 = New ValidatedEmployee + emp2.Name = "validCheck" + pbroker.GetObject(emp2) + Assert.IsTrue(pbroker.getInjectedObject(emp2).Persistent) + End Sub + End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-03-01 01:28:33
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24860 Modified Files: CPersistenceBroker.vb CPersistentObject.vb IPersistentObject.vb Log Message: Added IsValidToDelete to IValidation interface Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.96 retrieving revision 1.97 diff -u -d -r1.96 -r1.97 --- CPersistenceBroker.vb 28 Feb 2005 23:07:53 -0000 1.96 +++ CPersistenceBroker.vb 1 Mar 2005 01:28:19 -0000 1.97 @@ -1141,6 +1141,14 @@ clMap = obj.GetClassMap cm = clMap + + If GetType(IValidation).IsInstanceOfType(obj.GetSourceObject) Then + If Not CType(obj.GetSourceObject, IValidation).IsValidToDelete Then + Debug.WriteLine("Not valid to delete object") + Return 'Do not delete if object + End If + End If + Debug.WriteLine("Deleting object " & cm.Name) Dim myKeys(cm.AssociationMaps.Count) As String cm.AssociationMaps.Keys.CopyTo(myKeys, 0) Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- IPersistentObject.vb 6 Dec 2004 00:57:06 -0000 1.8 +++ IPersistentObject.vb 1 Mar 2005 01:28:19 -0000 1.9 @@ -66,4 +66,5 @@ Public Interface IValidation Function IsValid() As Boolean + Function IsValidToDelete() As Boolean End Interface \ No newline at end of file Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.56 retrieving revision 1.57 diff -u -d -r1.56 -r1.57 --- CPersistentObject.vb 28 Feb 2005 23:07:54 -0000 1.56 +++ CPersistentObject.vb 1 Mar 2005 01:28:19 -0000 1.57 @@ -1156,6 +1156,26 @@ '''----------------------------------------------------------------------------- ''' <summary> + ''' Checks that an object can be deleted + ''' </summary> + ''' <returns>Boolean indicating wether the object is may be deleted</returns> + ''' <remarks>This function indicates wether + ''' the object is in a state where it can be deleted from the database or not. + ''' <para>This can also be a place for object association integrity checks to occur</para> + ''' <para>Returning a false will prevent the object from being deleted when the delete + ''' method is called. True allows to the object to be deleted and is the normal + ''' behaviour unless the method is overridden.</para> + ''' </remarks> + ''' <history> + ''' [rbanks] 26/11/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Overridable Function IsValidToDelete() As Boolean Implements IValidation.IsValidToDelete + Return True + End Function + + '''----------------------------------------------------------------------------- + ''' <summary> ''' Determines wether two objects are equivalent by comparing their key values. ''' </summary> ''' <param name="obj">The second object to be compared</param> |
From: Richard B. <rb...@us...> - 2005-02-28 23:08:07
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16713 Modified Files: CCacheEntry.vb CClassMap.vb CCursor.vb CInjectedObject.vb CInjectedObjects.vb CMultiRetrieveCriteria.vb CPersistenceBroker.vb CPersistentObject.vb Log Message: Added ability to use many-to-many associations on non-inherited classes/interfaces Fixed numerous bugs in the injection cache Added restriction that injected obejcts must have key values populated before they can be tracked. Fixes a few other minor issues. Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- CPersistenceBroker.vb 14 Feb 2005 02:23:10 -0000 1.95 +++ CPersistenceBroker.vb 28 Feb 2005 23:07:53 -0000 1.96 @@ -8,7 +8,7 @@ Imports System.Text '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CPersistenceBroker ''' '''----------------------------------------------------------------------------- @@ -35,7 +35,8 @@ Private m_cache As CCacheCollection 'object collection cache - stores persistent objects Private m_useCache As Boolean Private m_loaded As Boolean - Private m_injectedObjects As New CInjectedObjects + Private m_injectedObjects As New CInjectedObjectCache + Private m_objectsToDelete As New ArrayList Public Event LoginDetailsNeeded(ByVal sender As Object, ByRef User As String, ByRef Password As String) @@ -181,7 +182,7 @@ conn = cm.RelationalDatabase.getConnection(Nothing) conn.AutoCommit = False Try - retrieveObject = retrievePrivateObject(obj, conn, useFind, useCache) + obj.Persistent = retrievePrivateObject(obj, conn, useFind, useCache) Catch ex As Exception x = New RetrieveException(ex.Message, ex) Finally @@ -196,6 +197,7 @@ Throw x End If End Try + Return obj.Persistent End SyncLock End Function @@ -497,10 +499,12 @@ 'Object doesn't exist - let's create it 'See if the assembly path is specified targetobj = udamap.ToClass.CreateObjectInstance - If Not targetobj Is Nothing Then cm2.populateObject(cm2, targetobj, rs, mapName) If targetobj.Persistent Then + If TypeOf (targetobj) Is CInjectedObject Then + StartTracking(targetobj) + End If tmpObj = m_cache.Item(targetobj) If Not (tmpObj Is Nothing) Then targetobj = tmpObj @@ -549,6 +553,16 @@ fromClass = udamap.ToClass End If End If + 'When retrieving we need to make sure the collection is cleared before + 'we go an load objects. + ' Under normal circumstances this will be the case, however when the + 'collection is in a many-to-many associations it is possible for + 'one side to be cleared, but for the other object to still + 'have the reference in place. (see the unit tests for an example) + If i = 0 Then + 'Obviously we don't want to clear it each time through ;-) + col.Clear() + End If 'Check whether the object is of child type If toClass.ChildrenMaps.Count > 0 Then @@ -580,7 +594,7 @@ If tmpColObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then tmpObj = tmpColObj Else - tmpObj = LocateOrCreateInjObject(tmpColObj) + tmpObj = getInjectedObject(tmpColObj) End If If tmpObj.Equals(targetobj) Then gotValue = True @@ -610,6 +624,9 @@ rw = rs.ResultSet.Tables(0).Rows(i) cm2.populateObject(cm2, targetobj, rw, mapName) If targetobj.Persistent Then + If TypeOf (targetobj) Is CInjectedObject Then + StartTracking(targetobj) + End If tmpObj = m_cache.Item(targetobj) If Not (tmpObj Is Nothing) Then targetobj = tmpObj @@ -632,7 +649,7 @@ If tmpColObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then tmpObj = tmpColObj Else - tmpObj = LocateOrCreateInjObject(tmpColObj) + tmpObj = getInjectedObject(tmpColObj) End If If tmpObj.Equals(targetobj) Then gotValue = True @@ -657,7 +674,7 @@ End If End If End If - End If + End If End If Next Next @@ -1139,6 +1156,9 @@ PCSQLHits.Increment() Catch End Try + If TypeOf (obj) Is CInjectedObject Then + m_objectsToDelete.Add(obj) + End If conn.processStatement(statement) If deleteSuperClass Then cm = cm.SuperClass @@ -2070,7 +2090,7 @@ ''' information. ''' </summary> ''' <param name="pAsm">The assembly being processed</param> - ''' <remarks>The assembly is scanned for an of the AtomsFramework custom attributes and + ''' <remarks>The assembly is scanned for an of the Atoms.Framework custom attributes and ''' should any be found they are processed and the O/R mappings generated. ''' <para>This method is called once the XML file has been processed</para> ''' </remarks> @@ -2827,36 +2847,33 @@ Public Sub GetObject(ByRef obj As Object) Dim injObj As CInjectedObject - If injObj Is Nothing Then - injObj = New CInjectedObject(obj) - retrieveObject(injObj, False, True) - m_injectedObjects.Add(injObj) - obj = injObj.GetSourceObject - Else - obj = injObj.GetSourceObject - End If + injObj = LocateOrCacheInjObject(obj) + retrieveObject(injObj, False, True) + obj = injObj.GetSourceObject End Sub Public Sub FindObject(ByRef obj As Object) + Dim needToAdd As Boolean = False Dim injObj As CInjectedObject - injObj = m_injectedObjects.LocateObject(obj) + injObj = m_injectedObjects.Find(obj, True) If injObj Is Nothing Then injObj = New CInjectedObject(obj) - retrieveObject(injObj, True, True) - m_injectedObjects.Add(injObj) - obj = injObj.GetSourceObject - Else - obj = injObj.GetSourceObject + 'Being a find we will not have key values until after the retrieve completes + needToAdd = True + End If + retrieveObject(injObj, True, True) + If needToAdd Then + Try + m_injectedObjects.Add(injObj) + Catch ex As Exception + End Try End If + obj = injObj.GetSourceObject End Sub Public Function getInjectedObject(ByVal obj As Object) As CInjectedObject - Return m_injectedObjects.LocateObject(obj) - End Function - - Public Function LocateOrCreateInjObject(ByVal obj As Object) As CInjectedObject Dim injObj As CInjectedObject - injObj = m_injectedObjects.LocateObject(obj) + injObj = m_injectedObjects.Find(obj) If injObj Is Nothing Then injObj = New CInjectedObject(obj) End If @@ -2865,7 +2882,7 @@ Public Function LocateOrCacheInjObject(ByVal obj As Object) As CInjectedObject Dim injObj As CInjectedObject - injObj = m_injectedObjects.LocateObject(obj) + injObj = m_injectedObjects.Find(obj) If injObj Is Nothing Then injObj = New CInjectedObject(obj) m_injectedObjects.Add(injObj) @@ -2874,9 +2891,13 @@ End Function Public Sub StartTracking(ByVal obj As Object) - Dim injObj As CInjectedObject - injObj = New CInjectedObject(obj) - m_injectedObjects.Add(injObj) + If Not TypeOf (obj) Is CInjectedObject Then + Dim injObj As CInjectedObject + injObj = New CInjectedObject(obj) + m_injectedObjects.Add(injObj) + Else + m_injectedObjects.Add(obj) + End If End Sub Public Function ObjectIsTracked(ByVal obj) As Boolean @@ -2890,7 +2911,7 @@ Public Sub MarkForDeletion(ByVal obj As Object, ByVal deleteParents As Boolean) Dim injObj As CInjectedObject - injObj = m_injectedObjects.LocateObject(obj) + injObj = m_injectedObjects.Find(obj) If injObj Is Nothing Then 'Nothing to do Else @@ -2909,16 +2930,31 @@ Dim injObj As CInjectedObject m_inPersistChangesLoop = True 'Need to copy the injected object cache as saving objects may result - 'in new objects being added to the cache (via the object hierarchy) - Dim objectsToPersist As New CInjectedObjects + 'in the collection being modified which would break the for/each loop. + Dim objectsToPersist As New CInjectedObjectCache For Each de As DictionaryEntry In m_injectedObjects objectsToPersist.Add(de.Key, de.Value) Next + 'We will try to save/create objects first and then we will process deletes + 'This will prevent us trying to update objects that have been + 'autodeleted by another object (which would throw an exception) For Each de As DictionaryEntry In objectsToPersist injObj = de.Value - PersistChanges(injObj.ReferencedObject) + If Not injObj.MarkedForDeletion Then + PersistChanges(injObj.ReferencedObject) + End If + Next + For Each de As DictionaryEntry In objectsToPersist + injObj = de.Value + If injObj.MarkedForDeletion And injObj.Persistent Then + PersistChanges(injObj.ReferencedObject) + End If Next m_inPersistChangesLoop = False + For Each obj As CInjectedObject In m_objectsToDelete + m_injectedObjects.Remove(obj) + Next + m_objectsToDelete.Clear() Me.commit() Catch ex As Exception m_inPersistChangesLoop = False @@ -2933,20 +2969,23 @@ 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 As CInjectedObject Dim ckey As CCacheKey Dim savedKeys As New ArrayList - injObj = m_injectedObjects.LocateObject(obj) - If injObj Is Nothing Then - injObj = New CInjectedObject(obj) - End If + 'If for some reason the object isn't being tracked for changes yet, we will start + 'tracking it now. + injObj = LocateOrCacheInjObject(obj) If injObj.MarkedForDeletion Then deleteObject(injObj, injObj.WillDeleteParents) If Not m_inPersistChangesLoop Then - m_injectedObjects.Remove(obj) + For Each xobj As CInjectedObject In m_objectsToDelete + m_injectedObjects.Remove(xobj) + Next + m_objectsToDelete.Clear() End If Else queue = getObjectsToSave(injObj, True, checkAssociationsRecursively) @@ -2954,17 +2993,23 @@ If queue.Count > 0 Then startTransaction() Do While queue.Count > 0 - value = queue.Dequeue() + qObject = queue.Dequeue() Try - 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") + If GetType(CAssociationObject).IsInstanceOfType(qObject) Then + saveAssociationObject(qObject) Else - saveObject(value) - 'Recalculate key value - required when identity columns are used + value = qObject 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 + saveObject(value) + 'Recalculate key value - required when identity columns are used + ckey = New CCacheKey(value) + savedKeys.Add(ckey) + End If + value.IsDirty = False End If Catch ex As Exception 'After an error remove the cached object so that the next retrieve @@ -2974,25 +3019,24 @@ rollback() Throw New SaveException(ex.Message, ex) End Try - value.IsDirty = False Loop commit() End If End If End Sub - Friend Property InjectedObjects() As CInjectedObjects + Friend Property InjectedObjects() As CInjectedObjectCache Get Return m_injectedObjects End Get - Set(ByVal Value As CInjectedObjects) + Set(ByVal Value As CInjectedObjectCache) m_injectedObjects = Value End Set End Property Friend Sub InitPerformanceCounters() Try - If Not PerformanceCounterCategory.Exists("AtomsFramework") Then + If Not PerformanceCounterCategory.Exists("Atoms.Framework") Then Dim CCDC As New CounterCreationDataCollection @@ -3057,22 +3101,22 @@ CCDC.Add(BaseAvgOpTimeCount64) ' Create the category. - PerformanceCounterCategory.Create("AtomsFramework", "Performance Counters for the AtomsFramework", CCDC) + PerformanceCounterCategory.Create("Atoms.Framework", "Performance Counters for the Atoms.Framework", CCDC) End If Dim instanceName As String instanceName = System.Diagnostics.Process.GetCurrentProcess.ProcessName ' Create the counters. - PCSQLHits = New PerformanceCounter("AtomsFramework", "PCSQLHits", False) - PCCacheHits = New PerformanceCounter("AtomsFramework", "PCCacheHits", False) - PCInserts = New PerformanceCounter("AtomsFramework", "PCInserts", False) - PCUpdates = New PerformanceCounter("AtomsFramework", "PCUpdates", False) - PCReads = New PerformanceCounter("AtomsFramework", "PCReads", False) - PCDeletes = New PerformanceCounter("AtomsFramework", "PCDeletes", False) - PCCriteria = New PerformanceCounter("AtomsFramework", "PCCriteria", False) - PCCacheSize = New PerformanceCounter("AtomsFramework", "PCCacheSize", False) - PCAverageTime = New PerformanceCounter("AtomsFramework", "PCAverageTime", False) - PCAverageTimeBase = New PerformanceCounter("AtomsFramework", "PCAverageTimeBase", False) + PCSQLHits = New PerformanceCounter("Atoms.Framework", "PCSQLHits", False) + PCCacheHits = New PerformanceCounter("Atoms.Framework", "PCCacheHits", False) + PCInserts = New PerformanceCounter("Atoms.Framework", "PCInserts", False) + PCUpdates = New PerformanceCounter("Atoms.Framework", "PCUpdates", False) + PCReads = New PerformanceCounter("Atoms.Framework", "PCReads", False) + PCDeletes = New PerformanceCounter("Atoms.Framework", "PCDeletes", False) + PCCriteria = New PerformanceCounter("Atoms.Framework", "PCCriteria", False) + PCCacheSize = New PerformanceCounter("Atoms.Framework", "PCCacheSize", False) + PCAverageTime = New PerformanceCounter("Atoms.Framework", "PCAverageTime", False) + PCAverageTimeBase = New PerformanceCounter("Atoms.Framework", "PCAverageTimeBase", False) PCSQLHits.RawValue = 0 PCCacheHits.RawValue = 0 @@ -3090,14 +3134,15 @@ End Try End Sub - Public Shared Sub CopyCollections(ByVal fromObject As IPersistableObject, ByRef toObject As IPersistableObject) - Dim t, iEnumerableType, iListType, iDicType As Type Dim fromColl, toColl, collItem As Object + Public Shared Sub CopyCollections(ByVal fromObject As Object, ByRef toObject As Object) + Dim t, iEnumerableType, iListType, iDicType As Type + Dim fromColl, toColl, collItem As Object Dim il As IList Dim id As IDictionary Dim f, fields() As FieldInfo Dim value As Object - t = fromObject.GetObjectType + t = fromObject.GetType fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) For Each f In fields iListType = f.FieldType.GetInterface("IList", True) @@ -3106,18 +3151,19 @@ Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) If Not ICloneType Is Nothing Then 'Getting the ICloneable interface from the object. - If Not f.GetValue(fromObject.GetSourceObject) Is Nothing Then - Dim IClone As ICloneable = CType(f.GetValue(fromObject.GetSourceObject), ICloneable) + If Not f.GetValue(fromObject) Is Nothing Then + Dim IClone As ICloneable = CType(f.GetValue(fromObject), ICloneable) toColl = IClone.Clone() Else toColl = Nothing End If Else - fromColl = f.GetValue(fromObject.GetSourceObject) + fromColl = f.GetValue(fromObject) If Not fromColl Is Nothing Then 'If the field doesn't support the ICloneable interface then just set it. t = f.FieldType - toColl = Activator.CreateInstance(t) 'need to copy references one-by-one + toColl = Activator.CreateInstance(t) + 'need to copy references one-by-one 'Also neeed to connect event handlers of new collection to new object based 'on event connections of the old collection and the old object Dim fColl, fieldsColl() As FieldInfo @@ -3134,7 +3180,7 @@ delArray = d.GetInvocationList For Each d In delArray If Not d.Target.GetType.GetInterface("IPersistableObject") Is Nothing Then - If CType(d.Target, IPersistableObject).Equals(fromObject.GetSourceObject) Then + If CType(d.Target, IPersistableObject).Equals(fromObject) Then newD = MulticastDelegate.CreateDelegate(fColl.FieldType, toObject, d.Method.Name) If collDel Is Nothing Then collDel = newD @@ -3169,7 +3215,15 @@ toColl = Nothing End If End If - f.SetValue(toObject.GetSourceObject, toColl) - End If Next + If Not toColl Is Nothing AndAlso f.FieldType Is GetType(CPersistentCollection) OrElse f.FieldType.IsSubclassOf(GetType(CPersistentCollection)) Then + Dim c As CPersistentCollection + c = CType(toColl, CPersistentCollection) + If Not c.ContainerObject Is Nothing AndAlso c.ContainerObject.Equals(fromObject) Then + c.ContainerObject = toObject + End If + End If + f.SetValue(toObject, toColl) + End If + Next End Sub End Class \ No newline at end of file Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- CCacheEntry.vb 14 Feb 2005 02:23:10 -0000 1.29 +++ CCacheEntry.vb 28 Feb 2005 23:07:43 -0000 1.30 @@ -4,7 +4,7 @@ Imports System.Reflection '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CCacheEntry ''' '''----------------------------------------------------------------------------- @@ -132,62 +132,6 @@ m_object = m_objectCopyAtTransactionStart End Sub - ' Public Sub CopyCollections() - ' Dim t, iEnumerableType, iListType, iDicType As Type ' Dim coll, obj As Object - ' Dim il As IList - ' Dim id As IDictionary - ' Dim f, fields() As FieldInfo - ' Dim value As Object - - ' 'We must precopy this collection into the collection copy ' 'A simple assignment would just copy a reference to the colletion, while ' 'we need to copy the collection itself, so that adding/removing elements ' 'of the original won't effect the copy - ' m_collectionCollection = New Specialized.HybridDictionary ' t = m_object.GetObjectType - ' fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - ' For Each f In fields - ' iListType = f.FieldType.GetInterface("IList", True) - ' iDicType = f.FieldType.GetInterface("IDictionary", True) - ' If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - ' Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) - ' If Not ICloneType Is Nothing Then - ' 'Getting the ICloneable interface from the object. - ' If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then - ' Dim IClone As ICloneable = CType(f.GetValue(m_object.GetSourceObject), ICloneable) - ' coll = IClone.Clone() - ' Else - ' coll = Nothing - ' End If - ' Else - ' If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then - ' 'If the field doesn't support the ICloneable interface then just set it. - ' coll = Activator.CreateInstance(f.FieldType) ' 'need to copy references one-by-one - ' If Not iListType Is Nothing Then - ' il = CType(coll, IList) - ' For Each obj In f.GetValue(m_object.GetSourceObject) - ' il.Add(obj) - ' Next - ' Else - ' id = CType(coll, IDictionary) - ' For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) - ' id.Add(de.Key, de.Value) - ' Next - ' End If - ' Else - ' coll = Nothing - ' End If - ' End If - ' m_collectionCollection.Add(f.Name, coll) ' End If ' Next - 'End Sub - - 'Public Sub RestoreCollections() - ' Dim t, iEnumerableType, iListType, iDicType As Type ' Dim f, fields() As FieldInfo - ' t = m_object.GetObjectType - ' fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - ' For Each f In fields - ' iListType = f.FieldType.GetInterface("IList", True) - ' iDicType = f.FieldType.GetInterface("IDictionary", True) - ' If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - ' 'We must restore this collection from the collection copy ' 'Just use a straight value assignment - no need to worry about cloning ' f.SetValue(m_object.GetSourceObject, m_collectionCollection.Item(f.Name)) ' End If ' Next - 'End Sub - Public Sub New(ByVal lifetime As Double) m_expiryTime = DateAdd(DateInterval.Minute, lifetime, Now) End Sub @@ -274,7 +218,7 @@ End Class '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CCacheKey ''' '''----------------------------------------------------------------------------- @@ -482,7 +426,7 @@ Return m_hashCode End Function - Private Sub CalculateHashCode(ByVal cachedObject) + Private Sub CalculateHashCode(ByVal cachedObject As Object) Dim i As Long Dim count As Integer Dim obj As Object @@ -552,7 +496,7 @@ End Class '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CCacheCollection ''' '''----------------------------------------------------------------------------- @@ -956,7 +900,6 @@ For Each x In Me ce = x.Value If ce.PersistentObject.GetClassMap.RelationalDatabase Is reldb Then - 'ce.CopyCollections() ce.CopyObject() End If Next Index: CMultiRetrieveCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiRetrieveCriteria.vb,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- CMultiRetrieveCriteria.vb 28 Oct 2004 00:16:12 -0000 1.18 +++ CMultiRetrieveCriteria.vb 28 Feb 2005 23:07:44 -0000 1.19 @@ -4,7 +4,7 @@ Imports System.Collections.Specialized '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CMultiRetrieveCriteria ''' '''----------------------------------------------------------------------------- @@ -140,7 +140,7 @@ Me.New() Dim injObj As CInjectedObject Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance - injObj = pbroker.LocateOrCreateInjObject(obj) + injObj = pbroker.getInjectedObject(obj) Me.addObjectToJoin(injObj, Nothing, "") Me.ClassMap = pbroker.getClassMap(obj.GetType) m_joins = New CJoin(Me.ClassMap, "t1") Index: CInjectedObjects.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObjects.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CInjectedObjects.vb 25 Oct 2004 07:12:31 -0000 1.3 +++ CInjectedObjects.vb 28 Feb 2005 23:07:44 -0000 1.4 @@ -1,3 +1,5 @@ +Imports System.Threading + 'Injected object keys are hashed on the object itself, not the value of the object '(unlike the persistence brokers cache which works via key values) @@ -11,7 +13,6 @@ NewInjObj(CType(obj, CInjectedObject)) Else m_keyvalues = New Collection - m_hashCode = obj.GetHashCode Dim injObj As New CInjectedObject(obj) populateKey(injObj) End If @@ -20,9 +21,7 @@ Public Sub NewInjObj(ByVal injobj As CInjectedObject) m_keyvalues = New Collection If injobj.ReferencedObject Is Nothing Then - m_hashCode = 0 - Else - m_hashCode = injobj.ReferencedObject.GetHashCode + Throw New Exception("Cannot track null objects") End If populateKey(injobj) End Sub @@ -31,6 +30,31 @@ Return m_hashCode End Function + Private Sub CalculateHashCode() + Dim i As Long + Dim count As Integer + Dim obj As Object + Dim t As Type + i = m_type.Name.GetHashCode + count = 1 + For Each obj In m_keyvalues + If Not obj Is Nothing Then + If TypeOf obj Is Integer Then + i += CInt(obj).GetHashCode + ElseIf TypeOf obj Is String Then + i += CStr(obj).GetHashCode + ElseIf TypeOf obj Is Double Then + i += CDbl(obj).GetHashCode + Else + t = obj.GetType + i += t.Name.GetHashCode + End If + count += 1 + End If + Next + m_hashCode = CInt(i / count) + End Sub + Protected Sub populateKey(ByVal injObj As IPersistableObject) Dim cm As CClassMap Dim i As Short @@ -43,8 +67,12 @@ For i = 1 To cm.getKeySize am = cm.getKeyAttributeMap(i) x = injObj.GetValueByAttribute(am.Name) + If x Is Nothing Then + Throw New Exception("Cannot have null key values") + End If m_keyvalues.Add(x) Next + CalculateHashCode() End Sub Public Overloads Shared Function Equals(ByVal obj1 As Object, ByVal obj2 As Object) As Boolean @@ -57,13 +85,14 @@ End Function Public Overloads Overrides Function Equals(ByVal obj1 As Object) As Boolean - Dim flag As Boolean Dim i As Integer Dim key As CInjectedObjectKey - key = CType(obj1, CInjectedObjectKey) - flag = False + key = obj1 + If Not (Me.m_type Is key.m_type) Then + Return False + End If For i = 1 To m_keyvalues.Count - If Me.GetHashCode <> key.GetHashCode Then + If m_keyvalues(i) <> key.m_keyvalues(i) Then Return False End If Next @@ -97,17 +126,23 @@ End Class -Public Class CInjectedObjects +Public Class CInjectedObjectCache Inherits System.Collections.Hashtable + Private m_lastFoundKey As CInjectedObjectKey + Public Overloads Sub Add(ByVal obj As CInjectedObject) Dim injKey As CInjectedObjectKey If obj.ReferencedObject Is Nothing Then - Exit Sub + Throw New Exception("Cannot track null objects") End If - injKey = New CInjectedObjectKey(obj) + Try + injKey = New CInjectedObjectKey(obj) + Catch ex As Exception + Throw New Exception("Cannot track objects with blank keys") + End Try If Not (MyBase.Item(injKey) Is Nothing) Then Debug.WriteLine("Object: " & obj.GetObjectType.ToString & " is already tracked with key(s):" & vbCrLf & injKey.ToString) Else @@ -116,21 +151,9 @@ End If End Sub - Public Function LocateObject(ByVal obj As Object) As CInjectedObject - Dim injKey As CInjectedObjectKey - Dim injObj As CInjectedObject - injKey = New CInjectedObjectKey(obj) - If Not (MyBase.Item(injKey) Is Nothing) Then - injObj = CType(MyBase.Item(injKey), CInjectedObject) - Return injObj - Else - Return Nothing - End If - End Function - Public Overloads Function isTracked(ByVal obj As Object) As Boolean Dim injObj As CInjectedObject - injObj = LocateObject(obj) + injObj = Find(obj) If injObj Is Nothing Then Return False Else @@ -139,20 +162,24 @@ End Function Public Overloads Function Exists(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As Boolean - If FindByValue(obj, useFindAttributes) Is Nothing Then + If Find(obj, useFindAttributes) Is Nothing Then Return False Else Return True End If End Function - Public Overloads Function FindByValue(ByVal obj As Object) As CInjectedObject + Public Overloads Function Find(ByVal obj As Object) As CInjectedObject + Return Find(obj, False) + End Function + + Public Overloads Function Find(ByVal obj As Object, ByVal useFindAttributes As Boolean) As CInjectedObject Dim injObj As CInjectedObject injObj = New CInjectedObject(obj) - Return FindByValue(injObj, False) + Return Find(injObj, useFindAttributes) End Function - Public Overloads Function FindByValue(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As CInjectedObject + Public Overloads Function Find(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As CInjectedObject Dim injObj As CInjectedObject Dim x As DictionaryEntry Dim attrmap As CAttributeMap @@ -163,6 +190,10 @@ Dim interval As Double Dim ikey As CInjectedObjectKey + 'We cannot use the dictionary key to find an object as changes to the key attributes + 'of an object will result in a different dictionary key being generated and an + 'we won't be able to find the object, even though it exists. + cm = obj.getClassMap 'We only check for objects of the same type @@ -174,29 +205,31 @@ 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 = CType(cm.FindAttributeMaps(i), CAttributeMap) - If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then - found = False - Exit For - End If - Next i - Else - For i = 1 To cm.getKeySize - attrmap = CType(cm.KeyAttributeMaps(i), CAttributeMap) - If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then - found = False - Exit For - End If - Next i - End If + Try + If useFindAttributes Then + For i = 1 To cm.getFindSize + attrmap = CType(cm.FindAttributeMaps(i), CAttributeMap) + If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then + found = False + Exit For + End If + Next i + Else + For i = 1 To cm.getKeySize + attrmap = CType(cm.KeyAttributeMaps(i), CAttributeMap) + If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then + found = False + Exit For + End If + Next i + End If + Catch ex As Exception + found = False + End Try If found Then - 'If ce.TransactionType = CCacheEntry.CacheTransaction.Deleted Then - ' Return Nothing - 'End If ikey = CType(x.Key, CInjectedObjectKey) Debug.WriteLine([String].Format("Injection Cache - getting object from cache. Key..." & vbCrLf & ikey.ToString)) + m_lastFoundKey = ikey Return injObj End If End If @@ -204,12 +237,19 @@ Return Nothing End Function - Public Overloads Sub Remove(ByVal obj As Object) + Public Overloads Sub Remove(ByVal obj As CInjectedObject) If obj Is Nothing Then Exit Sub End If - Dim injkey As New CInjectedObjectKey(obj) - MyBase.Remove(injkey) + Try + 'If key values have changed removing the object means we cannot just + 'generate an injection key and delete using the key - we must find it first + 'then delete it. + Dim injObj As CInjectedObject = Me.Find(obj, False) + If injObj Is Nothing Then Return + MyBase.Remove(m_lastFoundKey) + Catch + End Try End Sub Public Overrides Function ToString() As String @@ -233,4 +273,5 @@ outString &= ">>>> END TRACKED OBJECTS DUMP <<<<" Return outString End Function -End Class \ No newline at end of file +End Class + Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- CClassMap.vb 11 Feb 2005 02:51:35 -0000 1.50 +++ CClassMap.vb 28 Feb 2005 23:07:43 -0000 1.51 @@ -6,7 +6,7 @@ Imports System.Runtime.Remoting '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CClassMap ''' '''----------------------------------------------------------------------------- @@ -1407,7 +1407,7 @@ If checkForDuplicateAttributes Then Try 'If Not classMapToCheck.getAttributeMapByString(AttrMap.Name, False) Is Nothing Then - If Not classMapToCheck.getAttributeMapByString(AttrMap.Name, True) Is Nothing Then + If Not classMapToCheck.getAttributeMapByString(AttrMap.Name, False) Is Nothing Then skipAttribute = True End If Catch @@ -1502,7 +1502,7 @@ If checkForDuplicateAttributes Then Try 'If Not classMapToCheck.getAttributeMapByString(AttrMap.Name, False) Is Nothing Then - If Not classMapToCheck.getAttributeMapByString(AttrMap.Name, True) Is Nothing Then + If Not classMapToCheck.getAttributeMapByString(AttrMap.Name, False) Is Nothing Then skipAttribute = True End If Catch @@ -2106,7 +2106,7 @@ ip = CType(obj, IPersistableObject) Catch ex As Exception pbroker = getPersistenceBrokerInstance() - pbroker.StartTracking(obj) + 'pbroker.StartTracking(obj) ip = pbroker.getInjectedObject(obj) End Try Return ip @@ -2122,7 +2122,7 @@ ip = CType(obj, IPersistableObject) Catch ex As Exception pbroker = getPersistenceBrokerInstance() - pbroker.StartTracking(obj) + 'pbroker.StartTracking(obj) ip = pbroker.getInjectedObject(obj) End Try Return ip Index: CCursor.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCursor.vb,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- CCursor.vb 9 Nov 2004 11:46:04 -0000 1.14 +++ CCursor.vb 28 Feb 2005 23:07:44 -0000 1.15 @@ -2,24 +2,24 @@ Option Explicit On '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CCursor ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Holds the current position within a CResultSet. ''' </summary> -''' <remarks>The CCursor class references an position within a <see cref="T:AToMSFramework.CResultset"/> -''' that has been returned by either a <see cref="T:AToMSFramework.CRetrieveCriteria"/> or -''' a <see cref="T:AToMSFramework.CMultiRetrieveCriteria"/>. -''' <para>Objects can be instantiated from a CCursor using the <see cref="M:AToMSFramework.CCursor.LoadObject"/> method +''' <remarks>The CCursor class references an position within a <see cref="T:Atoms.Framework.CResultset"/> +''' that has been returned by either a <see cref="T:Atoms.Framework.CRetrieveCriteria"/> or +''' a <see cref="T:Atoms.Framework.CMultiRetrieveCriteria"/>. +''' <para>Objects can be instantiated from a CCursor using the <see cref="M:Atoms.Framework.CCursor.LoadObject"/> method ''' and will either be proxy objects or ''' full objects depending on the way the retrieve criteria was used.</para> ''' <para>A CCursor should only be created through the perform methods of the various ''' retrieve criteria, and once created it will contain information on the data retrieved.</para> -''' <para>Use the <see cref="M:AToMSFramework.CCursor.hasElements"/> method to determine -''' if the cursor contains any data, and use the <see cref="M:AToMSFramework.CCursor.previousCursor"/> and -''' <see cref="M:AToMSFramework.CCursor.nextCursor"/> methods to moved the cursor to the previous or next +''' <para>Use the <see cref="M:Atoms.Framework.CCursor.hasElements"/> method to determine +''' if the cursor contains any data, and use the <see cref="M:Atoms.Framework.CCursor.previousCursor"/> and +''' <see cref="M:Atoms.Framework.CCursor.nextCursor"/> methods to moved the cursor to the previous or next ''' record in the result set.</para> ''' </remarks> ''' <history> @@ -254,7 +254,7 @@ Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance Dim injObj As CInjectedObject - injObj = pbroker.LocateOrCreateInjObject(obj) + injObj = pbroker.getInjectedObject(obj) If Not m_parentCriteria Is Nothing Then If m_parentCriteria.GetType Is GetType(CMultiRetrieveCriteria) Then mr = m_parentCriteria @@ -461,7 +461,7 @@ Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance Dim injObj As CInjectedObject - injObj = pbroker.LocateOrCreateInjObject(obj) + injObj = pbroker.getInjectedObject(obj) If Not m_parentCriteria Is Nothing Then If m_parentCriteria.GetType Is GetType(CMultiRetrieveCriteria) Then cm = m_parentCriteria Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- CInjectedObject.vb 14 Feb 2005 02:23:10 -0000 1.13 +++ CInjectedObject.vb 28 Feb 2005 23:07:44 -0000 1.14 @@ -29,8 +29,7 @@ Public Sub New(ByVal obj As Object) MyBase.New() m_object = obj - m_originalObject = Activator.CreateInstance(m_object.GetType) - 'ReplaceValues(m_object, m_originalObject) + m_originalObject = Activator.CreateInstance(obj.GetType) End Sub Public Property ReferencedObject() As Object @@ -38,7 +37,7 @@ Return m_object End Get Set(ByVal Value As Object) - m_object = Value + m_object = New WeakReference(Value) End Set End Property @@ -102,92 +101,79 @@ End Sub Public Function getClassMap() As CClassMap Implements IPersistableObject.getClassMap - Dim ClassMap As CClassMap Dim tmpCMap As CClassMap - ClassMap = getClassMap(TypeName(m_object), m_object.GetType.FullName) - If ClassMap Is Nothing Then - 'try to find an interface that is mapped - first mapped interface we find will be used - Dim intType, tmpType, interfaces() As Type - interfaces = m_object.GetType.GetInterfaces - - '----------------------------------------- - Dim n, m As Integer - Dim super As CClassMap + If m_classmap Is Nothing Then + m_classmap = getClassMap(TypeName(m_object), m_object.GetType.FullName) + If m_classmap Is Nothing Then + 'try to find an interface that is mapped - first mapped interface we find will be used + Dim intType, tmpType, interfaces() As Type + interfaces = m_object.GetType.GetInterfaces - ' get the super class map if the object has multi-level inheritance - For n = 0 To interfaces.Length - 1 - ClassMap = getClassMap(interfaces(n).Name, interfaces(n).FullName) - If (Not ClassMap Is Nothing) AndAlso ClassMap.SuperClass Is Nothing Then - super = ClassMap - For m = n To interfaces.Length - 2 - interfaces(m) = interfaces(m + 1) - Next - If interfaces.Length > 1 Then - interfaces(m) = Nothing - End If - Exit For - End If - Next + '----------------------------------------- + Dim n, m As Integer + Dim super As CClassMap - 'get actual interface which is the bottom level of inheritance - n = 0 - While n < interfaces.Length - 1 - If Not interfaces(n) Is Nothing Then - tmpCMap = getClassMap(interfaces(n).Name, interfaces(n).FullName) - If (Not tmpCMap Is Nothing) AndAlso tmpCMap.SuperClass Is super Then - super = tmpCMap - ClassMap = super + ' get the super class map if the object has multi-level inheritance + For n = 0 To interfaces.Length - 1 + m_classmap = getClassMap(interfaces(n).Name, interfaces(n).FullName) + If (Not m_classmap Is Nothing) AndAlso m_classmap.SuperClass Is Nothing Then + super = m_classmap For m = n To interfaces.Length - 2 interfaces(m) = interfaces(m + 1) Next - interfaces(m) = Nothing + If interfaces.Length > 1 Then + interfaces(m) = Nothing + End If + Exit For + End If + Next - If interfaces(0) Is Nothing Then - ClassMap = tmpCMap - Exit While + 'get actual interface which is the bottom level of inheritance + n = 0 + While n < interfaces.Length - 1 + If Not interfaces(n) Is Nothing Then + tmpCMap = getClassMap(interfaces(n).Name, interfaces(n).FullName) + If (Not tmpCMap Is Nothing) AndAlso tmpCMap.SuperClass Is super Then + super = tmpCMap + m_classmap = super + For m = n To interfaces.Length - 2 + interfaces(m) = interfaces(m + 1) + Next + interfaces(m) = Nothing + + If interfaces(0) Is Nothing Then + m_classmap = tmpCMap + Exit While + End If + n = 0 + Else + n = n + 1 End If - n = 0 Else n = n + 1 End If - Else - n = n + 1 - End If - End While - '----------------------------------------- - - 'For Each intType In interfaces - ' tmpCMap = getClassMap(intType.Name, intType.FullName) - ' 'If this class has children, iterate through other class maps to see if - ' 'the object inherits a child class, otherwise we can get the wrong class map - ' 'returned. - ' If Not tmpCMap Is Nothing Then - ' If ClassMap Is Nothing Then ClassMap = tmpCMap - ' If tmpCMap.ChildrenMaps.Count = 0 Then - ' ClassMap = tmpCMap - ' Exit For - ' End If - ' End If - 'Next - End If - If (ClassMap Is Nothing) Then - Throw New NoClassMapException("No class map for " & m_object.GetType.FullName) + End While + End If + If (m_classmap Is Nothing) Then + Throw New NoClassMapException("No class map for " & m_object.GetType.FullName) + End If End If - Return ClassMap + Return m_classmap End Function Private Function getClassMap(ByVal name As String, ByVal fullname As String) As CClassMap - Dim ClassMap As CClassMap - Dim persistenceBroker As CPersistenceBroker - persistenceBroker = getPersistenceBrokerInstance() - ClassMap = persistenceBroker.getClassMap(name) - If ClassMap Is Nothing Then - ClassMap = persistenceBroker.getClassMap(fullname) - End If - If (ClassMap Is Nothing) Then - Return Nothing + If m_classmap Is Nothing Then + Dim persistenceBroker As CPersistenceBroker + persistenceBroker = getPersistenceBrokerInstance() + m_classmap = persistenceBroker.getClassMap(name) + If m_classmap Is Nothing Then + m_classmap = persistenceBroker.getClassMap(fullname) + End If + If (m_classmap Is Nothing) Then + Return Nothing + End If End If - Return ClassMap + Return m_classmap End Function Public Function GetObjectType() As Type Implements IPersistableObject.GetObjectType @@ -307,32 +293,58 @@ If Not sourceObject.GetType Is targetObject.GetType Then Return False End If - Dim f, fields() As FieldInfo + + Dim cmap As CClassMap Dim value As Object, value1 As Object - Dim t As Type - Try - t = sourceObject.GetType - While Not t Is Nothing - fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) - 'Note that this will copy event handlers as well - For Each f In fields - value = f.GetValue(sourceObject) - value1 = f.GetValue(targetObject) + + cmap = Me.getClassMap() + + 'Do equality checks only on attributes that will be persisted + 'Everything else is ignorable since it's only the database mapped fields + 'that are important + While Not cmap Is Nothing + For Each att As CAttributeMap In m_classmap.AttributeMaps + If Not att.ColumnMap Is Nothing Then + value = getValueByAttribute(att.Name) + value1 = getOriginalValueByAttribute(att.Name) If Not Equals(value, value1) Then Return True End If - Next - If Not t.BaseType Is Nothing Then - t = t.BaseType - Else - t = Nothing End If - End While - Catch ex As Exception - Debug.WriteLine(ex.Message) - Return False - End Try + Next + If Not cmap.SuperClass Is Nothing Then + cmap = cmap.SuperClass + Else + cmap = Nothing + End If + End While Return False + + 'Dim f, fields() As FieldInfo + 'Dim t As Type + 'Try + ' t = sourceObject.GetType + ' While Not t Is Nothing + ' fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + ' 'Note that this will copy event handlers as well + ' For Each f In fields + ' value = f.GetValue(sourceObject) + ' value1 = f.GetValue(targetObject) + ' If Not Equals(value, value1) Then + ' Return True + ' End If + ' Next + ' If Not t.BaseType Is Nothing Then + ' t = t.BaseType + ' Else + ' t = Nothing + ' End If + ' End While + 'Catch ex As Exception + ' Debug.WriteLine(ex.Message) + ' Return False + 'End Try + 'Return False End Function Public Property IsDirty() As Boolean Implements IPersistableObject.IsDirty @@ -558,7 +570,7 @@ 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, injobj) + CPersistenceBroker.CopyCollections(Me.GetSourceObject, injobj.GetSourceObject) Return injobj End Function Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.55 retrieving revision 1.56 diff -u -d -r1.55 -r1.56 --- CPersistentObject.vb 14 Feb 2005 02:23:11 -0000 1.55 +++ CPersistentObject.vb 28 Feb 2005 23:07:54 -0000 1.56 @@ -6,7 +6,7 @@ Imports System.Runtime.Remoting '''----------------------------------------------------------------------------- -''' Project : AToMSFramework +''' Project : Atoms.Framework ''' Class : CPersistentObject ''' '''----------------------------------------------------------------------------- @@ -39,11 +39,11 @@ Private m_originalModDate, m_blankDate As Date Private m_cacheExpiry As Double Private m_associationsLoaded As Boolean - Private m_guid As Guid - Private m_isLoading As Boolean = False + Private m_guid As Guid + Private m_isLoading As Boolean = False Private m_isQueued As Boolean = False Private m_checkingAssociations As Boolean - Private m_isNew As Boolean + Private m_isNew As Boolean Private m_editing As Boolean <NonSerialized()> Private m_classmap As CClassMap @@ -181,7 +181,7 @@ ''' </summary> ''' <value>Boolean indicating that the object has been modified</value> ''' <remarks>This flag must be set by the object whenever one of it's properties changes. - ''' Failing to do so will prevent the AtomsFramework from updating the database when + ''' Failing to do so will prevent the Atoms.Framework from updating the database when ''' the save method is performed. ''' <para>When an object is initially received this flag will be False.</para> ''' <para>Note: Changes to objects in a CPersistentCollection can result in this flag being set.</para></remarks> @@ -603,7 +603,7 @@ ''' <returns>An object of the subclasses type</returns> ''' <remarks>This is used internally by the framework and must be implemented by objects that ''' inherit the CPersistentObject. A typical example of this would be - ''' <code> Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject + ''' <code> Public Overrides Function getNewObject() As Atoms.Framework.CPersistentObject ''' Return New CEmployee ''' End Function</code> ''' </remarks> @@ -643,7 +643,7 @@ Return True End If Next - Return False + Return False End Function '''----------------------------------------------------------------------------- @@ -675,7 +675,7 @@ Return CallByName(o, propertyName, CallType.Get) End If Catch err As Exception - Throw New Exception("getCollectionByAttribute failed for class " & me.getclassmap.name & " attribute: " & " " & pname, err) + Throw New Exception("getCollectionByAttribute failed for class " & Me.getclassmap.name & " attribute: " & " " & pname, err) End Try End Function @@ -1122,15 +1122,15 @@ Static eventRaised As Boolean If m_persistent = True Then m_modifiedDate = Now 'Only set modified if the object is already persistent - 'Set milliseconds to zero to avoid issues with millisecond inconsistencies in SQL db's + 'Set milliseconds to zero to avoid issues with millisecond inconsistencies in MSSQL db's m_modifiedDate = m_modifiedDate.AddMilliseconds(-m_modifiedDate.Millisecond) - If m_dirty = False Then - If Not eventRaised Then - 'Was getting stack overflow with direct many-to-many associations due to circular event raising - eventRaised = True - RaiseEvent MarkedAsDirty(Me, New EventArgs) - eventRaised = False - End If + End If + If m_dirty = False Then + If Not eventRaised Then + 'Was getting stack overflow with direct many-to-many associations due to circular event raising + eventRaised = True + RaiseEvent MarkedAsDirty(Me, New EventArgs) + eventRaised = False End If End If m_dirty = True @@ -1240,12 +1240,7 @@ Dim obj As CPersistentObject obj = Me.getClassMap.CreateObjectInstance obj.ReplaceWith(Me) - 'obj = CType(Me.MemberwiseClone, CPersistentObject) - 'Because memberwise clone only reference copies collections we should also - 'copy the collections as well, since failing to do so can corrupt the cache. - 'This will also connect events from the collections to the new object based on - 'existing event handlers in "Me" - 'CPersistenceBroker.CopyCollections(Me, obj) Return obj + Return obj End Function '''----------------------------------------------------------------------------- @@ -1394,12 +1389,12 @@ Public Overridable Function getAll(ByVal pOrderCol As Collection, ByVal pOrderAscCol As Collection) As CPersistentCollection Dim obj As Object Dim obCol As CPersistentCollection - Dim obRC As AToMSFramework.CRetrieveCriteria - Dim obCursor As AToMSFramework.CCursor + Dim obRC As CRetrieveCriteria + Dim obCursor As CCursor Dim inIndex As Integer Dim boAscend As Boolean - obRC = New AToMSFramework.CRetrieveCriteria + obRC = New CRetrieveCriteria obRC.ClassMap = Me.getClassMap obRC.ReturnFullObjects = True @@ -1795,7 +1790,7 @@ ''' </history> ''' ----------------------------------------------------------------------------- <Browsable(False), EditorBrowsable(EditorBrowsableState.Advanced)> _ - Public Overridable ReadOnly Property [Error]() As String Implements System.ComponentModel.IDataErrorInfo.Error + Public Overridable ReadOnly Property [Error]() As String Implements System.ComponentModel.IDataErrorInfo.Error Get If Me.IsValid Then Return "" |
From: Richard B. <rb...@us...> - 2005-02-28 23:06:00
|
Update of /cvsroot/jcframework/Nunit/StandardClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16284/StandardClasses Modified Files: NonInheritedTests.vb Log Message: New unit tests for many-to-many associations for non-inherited objects. Changed a few unit tests to work under new restrictrions for injected (tracked) objects. Index: NonInheritedTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/StandardClasses/NonInheritedTests.vb,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- NonInheritedTests.vb 21 Dec 2004 22:00:02 -0000 1.5 +++ NonInheritedTests.vb 28 Feb 2005 23:05:49 -0000 1.6 @@ -1,4 +1,4 @@ -Imports AToMSFramework +Imports Atoms.Framework Imports NUnit.Framework Namespace StandardClasses @@ -51,9 +51,13 @@ Assert.AreEqual("basic", job.Description) End Sub - <Test()> Public Sub SaveJob_a2() + <Test(), ExpectedException(GetType(System.Exception))> Public Sub CheckForError() pbroker.StartTracking(job) + End Sub + + <Test()> Public Sub SaveJob_a2() job.Id = "a2" + pbroker.StartTracking(job) job.Description = "SomeJob" Assert.IsTrue(pbroker.getInjectedObject(job).IsDirty) pbroker.PersistChanges(job) @@ -61,25 +65,28 @@ End Sub <Test()> Public Sub DeleteAJob() - pbroker.StartTracking(job) job.Id = "a3" + pbroker.StartTracking(job) job.Description = "SomeJob3" pbroker.PersistChanges(job) pbroker.MarkForDeletion(job) pbroker.PersistChanges(job) Assert.IsFalse(pbroker.ObjectIsTracked(job)) - Assert.IsNull(pbroker.getInjectedObject(job)) End Sub <Test()> Public Sub CheckInjectionCache() Dim job2 As New NPJob - pbroker.StartTracking(job) - pbroker.StartTracking(job2) - Assert.IsTrue(pbroker.ObjectIsTracked(job)) + Try + pbroker.StartTracking(job) + Catch + End Try + Assert.IsFalse(pbroker.ObjectIsTracked(job)) job.Id = "1" + pbroker.StartTracking(job) job.Description = "a" Assert.IsTrue(pbroker.ObjectIsTracked(job)) job2.Id = "2" + pbroker.StartTracking(job2) job2.Description = "b" pbroker.PersistChanges(job) pbroker.PersistChanges(job2) @@ -154,7 +161,6 @@ Assert.AreEqual(emp.Name, "new") pbroker.MarkForDeletion(emp) pbroker.PersistChanges(emp) - Assert.IsNull(pbroker.getInjectedObject(emp)) emp = New NPEmployee emp.Name = "new" pbroker.FindObject(emp) @@ -178,7 +184,6 @@ Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) pbroker.MarkForDeletion(emp) pbroker.PersistChanges(emp) - Assert.IsNull(pbroker.getInjectedObject(emp)) emp = New NPEmployee emp.Name = "Changed" pbroker.FindObject(emp) @@ -192,8 +197,8 @@ <Test()> Public Sub saveHierarchy() Dim emp2 As New NPEmployee Dim emp3 As New NPEmployee - pbroker.StartTracking(emp) emp.Name = "theBoss" + pbroker.StartTracking(emp) emp2.Name = "middleMgr" emp3.Name = "slave" emp.Workers.Add(emp2) |
From: Richard B. <rb...@us...> - 2005-02-28 23:06:00
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16284 Modified Files: AtomsFramework.xml Nunit_AtomsFramework.vbproj Nunit_AtomsFramework.vbproj.user Log Message: New unit tests for many-to-many associations for non-inherited objects. Changed a few unit tests to work under new restrictrions for injected (tracked) objects. Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- Nunit_AtomsFramework.vbproj 14 Feb 2005 02:24:11 -0000 1.17 +++ Nunit_AtomsFramework.vbproj 28 Feb 2005 23:05:47 -0000 1.18 @@ -86,9 +86,9 @@ HintPath = "..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll" /> <Reference - Name = "AToMSFramework" - Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" - Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" + Name = "Atoms.Framework" + AssemblyName = "Atoms.Framework" + HintPath = "..\bin\Atoms.Framework.dll" /> </References> <Imports> @@ -215,6 +215,16 @@ BuildAction = "Compile" /> <File + RelPath = "Interfaces\ManyToManyClasses.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Interfaces\ManyToManyTests.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Interfaces\ValidatedEmployee.vb" SubType = "Code" BuildAction = "Compile" Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- AtomsFramework.xml 14 Feb 2005 02:24:11 -0000 1.18 +++ AtomsFramework.xml 28 Feb 2005 23:05:47 -0000 1.19 @@ -1,6 +1,6 @@ <?xml version="1.0" ?> <map> - <database name="MSA" provider="C:\Projects\MMM\Atoms_Framework\Providers\AF_OLEDB\bin\AF_OLEDB.dll"> + <database name="MSA" provider="bin\AF_OLEDB.dll"> <parameter name="name" value=".\db1.mdb" /> <parameter name="user" value="anyuser" /> <parameter name="password" value="anypassword" /> @@ -345,4 +345,26 @@ </association> + <class name="iM2MA" table="ManyToManyA" database="MSA" namespace="NunitTests.Interfaces" factory="M2MAFactory"> + <attribute name="GUIDValue" column="GuidValue" key="primary"/> + <attribute name="Description" column="description" /> + <attribute name="M2MBCollection" /> + </class> + <class name="iM2MB" table="ManyToManyB" database="MSA" namespace="NunitTests.Interfaces" factory="M2MBFactory"> + <attribute name="GUIDValue" column="GuidValue" key="primary"/> + <attribute name="Description" column="description" /> + <attribute name="M2MACollection" /> + </class> + <association fromClass="NunitTests.Interfaces.iM2MA" + toClass="NunitTests.Interfaces.iM2MB" + cardinality="ManyToMany" + fromClassTarget="M2MBCollection" + toClassTarget="M2MACollection" + retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="true"> + <associationTable name="ManyToManyAB"> + <fromClassKey name="GUIDValue" column="AGuidValue" /> + <toClassKey name="GUIDValue" column="BGuidValue" /> + </associationTable> + </association> + </map> \ No newline at end of file Index: Nunit_AtomsFramework.vbproj.user =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj.user,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Nunit_AtomsFramework.vbproj.user 9 Feb 2005 06:20:47 -0000 1.2 +++ Nunit_AtomsFramework.vbproj.user 28 Feb 2005 23:05:47 -0000 1.3 @@ -1,7 +1,7 @@ <VisualStudioProject> <VisualBasic LastOpenVersion = "7.10.3077" > <Build> - <Settings ReferencePath = "C:\Projects\MMM\Atoms_Framework\bin\" > + <Settings ReferencePath = "C:\Projects\MMM\Atoms_Framework\bin\;C:\Projects\Atoms.NET\Framework\bin\" > <Config Name = "Debug" EnableASPDebugging = "false" |
From: Richard B. <rb...@us...> - 2005-02-28 23:06:00
|
Update of /cvsroot/jcframework/Nunit/Interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16284/Interfaces Added Files: ManyToManyClasses.vb ManyToManyTests.vb Log Message: New unit tests for many-to-many associations for non-inherited objects. Changed a few unit tests to work under new restrictrions for injected (tracked) objects. --- NEW FILE: ManyToManyClasses.vb --- Imports Atoms.Framework Namespace Interfaces #Region "Interface Definitions" Public Interface iM2MA Property GUIDValue() As String Property Description() As String Property M2MBCollection() As M2MBCollection End Interface Public Interface iM2MB Property GUIDValue() As String Property Description() As String Property M2MACollection() As M2MACollection End Interface #End Region #Region "Realizations" Public Class M2MA Implements iM2MA Private _guid As Guid Private _description As String Private _bCol As M2MBCollection Public Property Description() As String Implements iM2MA.Description Get Return _description End Get Set(ByVal Value As String) _description = Value End Set End Property Public Property M2MBCollection() As M2MBCollection Implements iM2MA.M2MBCollection Get Return _bCol End Get Set(ByVal Value As M2MBCollection) _bCol = Value End Set End Property Public Sub New() _bCol = New M2MBCollection End Sub Public Property GUIDValue() As String Implements iM2MA.GUIDValue Get If _guid.Equals(Guid.Empty) Then _guid = Guid.NewGuid End If Return _guid.ToString("N") End Get Set(ByVal value As String) _guid = New Guid(value) End Set End Property End Class Public Class M2MB Implements iM2MB Private _guid As Guid Private _description As String Private _aCol As M2MACollection Public Property Description() As String Implements iM2MB.Description Get Return _description End Get Set(ByVal Value As String) _description = Value End Set End Property Public Property M2MACollection() As M2MACollection Implements iM2MB.M2MaCollection Get Return _aCol End Get Set(ByVal Value As M2MACollection) _aCol = Value End Set End Property Public Property GUIDValue() As String Implements iM2MB.GUIDValue Get If _guid.Equals(Guid.Empty) Then _guid = Guid.NewGuid End If Return _guid.ToString("N") End Get Set(ByVal value As String) _guid = New Guid(value) End Set End Property Public Sub New() _aCol = New M2MACollection End Sub End Class #End Region #Region "M2MACollection" Public Class M2MACollection Inherits CollectionBase Public Overloads Sub Add(ByVal a As iM2MA) list.Add(a) End Sub Public Shadows Function Item(ByVal index As Integer) As iM2MA Return CType(list(index), iM2MA) End Function End Class #End Region #Region "M2MBCollection" Public Class M2MBCollection Inherits CollectionBase Public Overloads Sub Add(ByVal b As iM2MB) list.Add(b) End Sub Public Shadows Function Item(ByVal index As Integer) As iM2MB Return CType(list(index), M2MB) End Function End Class #End Region #Region "Interface Factories" Public Class M2MAFactory Implements Atoms.Framework.IClassFactory Public Function CreateObject() As Object Implements Atoms.Framework.IClassFactory.CreateObject Return New M2MA End Function End Class Public Class M2MBFactory Implements Atoms.Framework.IClassFactory Public Function CreateObject() As Object Implements Atoms.Framework.IClassFactory.CreateObject Return New M2MB End Function End Class #End Region End Namespace --- NEW FILE: ManyToManyTests.vb --- Imports Atoms.Framework Imports NUnit.Framework Namespace Interfaces <TestFixture()> Public Class ManyToManyTests Private pbroker As CPersistenceBroker Private A As iM2MA Private B As iM2MB <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory Dim retry As Boolean = True While retry = True Try 'Remove any existing test database System.IO.File.Delete(".\db1.mdb") retry = False Catch iox As IO.IOException 'file is in use - so we will loop around until it is released GC.Collect() Catch ex As Exception retry = False End Try End While System.IO.File.Copy(".\original db1.mdb", ".\db1.mdb") pbroker = New CPersistenceBroker pbroker.init() End Sub <TestFixtureTearDown()> Public Sub Dispose() pbroker.Dispose() pbroker = Nothing End Sub <Test()> Public Sub SaveThenRetrieve() Dim gval As String Dim x As Integer, y As Integer A = New M2MA pbroker.StartTracking(A) A.Description = "A-one" gval = A.GUIDValue B = New M2MB B.Description = "B-one" A.M2MBCollection.Add(B) B.M2MACollection.Add(A) Dim B2 As iM2MB = New M2MB B2.Description = "B-two" A.M2MBCollection.Add(B2) Dim A2 As iM2MA = New M2MA A2.Description = "A-two" B2.M2MACollection.Add(A2) pbroker.PersistChanges() pbroker.ClearCache() A = New M2MA A.GUIDValue = gval pbroker.GetObject(A) Assert.AreEqual(2, A.M2MBCollection.Count) 'Order of guids can affect order of the collection If A.M2MBCollection.Item(0).M2MACollection.Count = 1 Then x = 0 y = 1 Else x = 1 y = 0 End If B = A.M2MBCollection.Item(x) Assert.IsNotNull(B) Assert.AreEqual("B-one", B.Description) Assert.AreEqual(1, B.M2MACollection.Count) Assert.AreEqual(A.GUIDValue, B.M2MACollection.Item(0).GUIDValue) B = A.M2MBCollection.Item(y) Assert.IsNotNull(B) Assert.AreEqual("B-two", B.Description) Assert.AreEqual(2, B.M2MACollection.Count) End Sub <Test()> Public Sub SaveThenDelete() Dim gval As String Dim x As Integer, y As Integer A = New M2MA pbroker.StartTracking(A) A.Description = "A1" gval = A.GUIDValue B = New M2MB B.Description = "B1" A.M2MBCollection.Add(B) B.M2MACollection.Add(A) Dim B2 As M2MB = New M2MB B2.Description = "B2" A.M2MBCollection.Add(B2) B2.M2MACollection.Add(A) Dim A2 As M2MA = New M2MA A2.Description = "A2" B2.M2MACollection.Add(A2) pbroker.PersistChanges() pbroker.ClearCache() A = New M2MA A.GUIDValue = gval pbroker.GetObject(A) Assert.AreEqual(2, A.M2MBCollection.Count) 'Order of guids can affect order of the collection If A.M2MBCollection.Item(0).M2MACollection.Count = 1 Then x = 0 y = 1 Else x = 1 y = 0 End If B = A.M2MBCollection.Item(x) Assert.IsNotNull(B) Assert.AreEqual("B1", B.Description) Assert.AreEqual(1, B.M2MACollection.Count) Assert.AreEqual(A.GUIDValue, B.M2MACollection.Item(0).GUIDValue) B = A.M2MBCollection.Item(y) Assert.IsNotNull(B) Assert.AreEqual("B2", B.Description) Assert.AreEqual(2, B.M2MACollection.Count) 'Now delete B2 - because of autodelete, allobjects should be deleted pbroker.MarkForDeletion(B) pbroker.PersistChanges() A = New M2MA A.GUIDValue = gval pbroker.GetObject(A) Assert.IsFalse(pbroker.getInjectedObject(A).Persistent, "Object A is still persistent") End Sub <Test()> Public Sub SaveThenChangeKeyValues() Dim gvalA, gvalB As String Dim s As String A = New M2MA pbroker.StartTracking(A) A.Description = "A1" gvalA = A.GUIDValue B = New M2MB B.Description = "B1" gvalB = B.GUIDValue A.M2MBCollection.Add(B) B.M2MACollection.Add(A) pbroker.PersistChanges() A.GUIDValue = Guid.NewGuid.ToString("N") pbroker.PersistChanges(A) s = "select * from ManyToManyAB where AGuidValue = """ & gvalA & """ and BGuidValue = """ & gvalB & """" Dim c As CCursor = pbroker.ProcessPureSQL(s, pbroker.getClassMap(GetType(NunitTests.Interfaces.iM2MA)).RelationalDatabase.getConnection(Nothing)) Assert.AreEqual(0, c.ResultSet.ResultSet.Tables(0).Rows.Count) End Sub <Test()> Public Sub RemoveFromCollection() Dim gvalA, gvalB As String Dim s As String A = New M2MA pbroker.StartTracking(A) A.Description = "A1" gvalA = A.GUIDValue B = New M2MB B.Description = "B1" gvalB = B.GUIDValue A.M2MBCollection.Add(B) B.M2MACollection.Add(A) pbroker.PersistChanges() pbroker.ClearCache() A = New M2MA A.GUIDValue = gvalA pbroker.GetObject(A) Assert.IsTrue(pbroker.getInjectedObject(A).Persistent) 'Being bi-directional this should result in both A/B objects having empty collections A.M2MBCollection.RemoveAt(0) pbroker.PersistChanges(A) pbroker.ClearCache() A = New M2MA A.GUIDValue = gvalA pbroker.GetObject(A) B = New M2MB B.GUIDValue = gvalB pbroker.GetObject(B) Assert.IsTrue(pbroker.getInjectedObject(A).Persistent) Assert.IsTrue(pbroker.getInjectedObject(B).Persistent) Assert.AreEqual(0, A.M2MBCollection.Count) Assert.AreEqual(0, B.M2MACollection.Count) End Sub End Class End Namespace |