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...> - 2004-10-20 06:44:34
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31641 Modified Files: CCursor.vb CInjectedObject.vb CPersistenceBroker.vb CPersistentCriteria.vb CPersistentObject.vb IPersistentObject.vb Log Message: Fixes for bugs in saving object hierarchies Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.69 retrieving revision 1.70 diff -u -d -r1.69 -r1.70 --- CPersistenceBroker.vb 19 Oct 2004 03:32:08 -0000 1.69 +++ CPersistenceBroker.vb 20 Oct 2004 06:44:23 -0000 1.70 @@ -2123,9 +2123,20 @@ Dim i, k As Integer Dim tmpObj As Object - 'Determine if the object needs saving + If obj.IsQueued Then + 'if an object has already been added to the save queue, there is no need to add + 'it again (could result in infinite recursion) + Return queue + End If + If Not checkAssociationsRecursivly Then - If Not obj.IsDirty Then Return queue 'Do not save if nothing changed + If includeBaseObject Then + 'This will be on when we start saving a normal object. Recursive calls + 'to this method while processing parent class maps will turn this off. + 'Note that parent objects will not be dirty so in this case so we cannot + 'do the normal IsDirty check. + If Not obj.IsDirty Then Return queue 'Do not save if nothing changed + End If If obj.IsProxy Then Return queue 'Do not save if object is proxied If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then If Not CType(obj, CPersistentObject).IsValid Then Return queue 'Do not save if object is not valid @@ -2139,6 +2150,7 @@ If includeBaseObject Then obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) + obj.IsQueued = True End If Else 'Determine if the object needs saving @@ -2146,13 +2158,15 @@ If includeBaseObject AndAlso _ (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.IsReadOnly AndAlso Not obj.IsModifyOnly) Then If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then - If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid + If CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) + obj.IsQueued = True End If Else obj.IsDirty = False queue.Enqueue(obj) + obj.IsQueued = True End If End If End If @@ -2168,13 +2182,11 @@ udamap = cm.getStraightAssociationMap(i) If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - tmpObj = obj.GetObjectByAttribute(udamap.Target) - If Not tmpObj Is Nothing Then - If Not value Is Nothing Then - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - End If + value = obj.GetObjectByAttribute(udamap.Target) + If Not value Is Nothing Then + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then col = obj.GetCollectionByAttribute(udamap.Target) @@ -2182,7 +2194,7 @@ For k = 0 To col.Count() - 1 tmpObj = col.Item(k) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2199,13 +2211,11 @@ udamap = cm.getInverseAssociationMap(i) If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - tmpObj = obj.GetObjectByAttribute(udamap.Target) - If Not tmpObj Is Nothing Then - If Not value Is Nothing Then - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next - End If + value = obj.GetObjectByAttribute(udamap.Target) + If Not value Is Nothing Then + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then col = obj.GetCollectionByAttribute(udamap.Target) @@ -2213,7 +2223,7 @@ For k = 0 To col.Count() - 1 tmpObj = col.Item(k) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2234,7 +2244,7 @@ If Not cm.SuperClass Is Nothing Then tmpObj = obj.GetObjectByClassMap(cm.SuperClass) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2248,7 +2258,7 @@ If Not cm.SuperClass Is Nothing Then tmpObj = obj.GetObjectByClassMap(cm.SuperClass) If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then - value = LocateOrCreateInjObject(tmpObj) + value = LocateOrCacheInjObject(tmpObj) Else value = tmpObj End If @@ -2397,6 +2407,16 @@ Return injObj End Function + Public Function LocateOrCacheInjObject(ByVal obj As Object) As CInjectedObject + Dim injObj As CInjectedObject + injObj = m_injectedObjects.LocateObject(obj) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) + m_injectedObjects.Add(injObj) + End If + Return injObj + End Function + Public Sub StartTracking(ByVal obj As Object) Dim injObj As CInjectedObject injObj = New CInjectedObject(obj) Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- IPersistentObject.vb 15 Oct 2004 06:42:56 -0000 1.4 +++ IPersistentObject.vb 20 Oct 2004 06:44:23 -0000 1.5 @@ -10,6 +10,7 @@ Property OriginalModifiedDate() As Date Property AssociationsLoaded() As Boolean Property IsLoading() As Boolean + Property IsQueued() As Boolean ReadOnly Property IsReadOnly() As Boolean ReadOnly Property IsModifyOnly() As Boolean Property OriginalCacheKey() As CCacheKey Index: CPersistentCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCriteria.vb,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CPersistentCriteria.vb 21 Jul 2004 02:55:38 -0000 1.7 +++ CPersistentCriteria.vb 20 Oct 2004 06:44:23 -0000 1.8 @@ -244,9 +244,11 @@ If m_Associations.Count() > 0 Then If clauseConditionAdded Then statement.addSqlClause(" " & Me.ClassMap.RelationalDatabase.getClauseStringAnd & " ") + clauseConditionAdded = False End If End If - ElseIf m_WhereCondition.getSize > 0 Then + End If + If m_WhereCondition.getSize > 0 Then statement.addSqlClause(" ") If clauseConditionAdded Then statement.addSqlClause(Me.ClassMap.RelationalDatabase.getClauseStringAnd & " ") Index: CCursor.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCursor.vb,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- CCursor.vb 18 Oct 2004 03:31:51 -0000 1.11 +++ CCursor.vb 20 Oct 2004 06:44:23 -0000 1.12 @@ -296,7 +296,7 @@ End Sub Public Sub loadPersistentObject(ByRef obj As CPersistentObject) - loadObject(obj, 0) + loadPersistentObject(obj, 0) End Sub '''----------------------------------------------------------------------------- Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CInjectedObject.vb 18 Oct 2004 01:36:43 -0000 1.3 +++ CInjectedObject.vb 20 Oct 2004 06:44:23 -0000 1.4 @@ -21,6 +21,7 @@ Private m_persistent As Boolean Private m_retrievedCacheKey As CCacheKey Private m_loading As Boolean + Private m_queued As Boolean Private m_proxy As Boolean Private m_markedForDeletion As Boolean Private m_deleteParents As Boolean @@ -292,6 +293,15 @@ End Set End Property + Public Property IsQueued() As Boolean Implements IPersistableObject.IsQueued + Get + Return m_queued + End Get + Set(ByVal Value As Boolean) + m_queued = Value + End Set + End Property + Public ReadOnly Property isModifyOnly() As Boolean Implements IPersistableObject.isModifyOnly Get Return getClassMap.isModifyOnly Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- CPersistentObject.vb 19 Oct 2004 03:32:08 -0000 1.44 +++ CPersistentObject.vb 20 Oct 2004 06:44:23 -0000 1.45 @@ -40,7 +40,8 @@ Private m_associationsLoaded As Boolean Private m_guid As Guid Private m_isLoading As Boolean = False - Private m_checkingAssociations As Boolean + Private m_isQueued As Boolean = False + Private m_checkingAssociations As Boolean Private m_isNew As Boolean Private m_editing As Boolean <NonSerialized()> Private m_classmap As CClassMap @@ -435,6 +436,15 @@ End Set End Property + <Browsable(False)> Public Property IsQueued() As Boolean Implements IPersistentObject.IsQueued + Get + Return m_isQueued + End Get + Set(ByVal Value As Boolean) + m_isQueued = Value + End Set + End Property + <Browsable(False)> Friend Property OriginalCacheKey() As CCacheKey Implements IPersistableObject.OriginalCacheKey Get Return m_retrievedCacheKey |
From: Richard B. <rb...@us...> - 2004-10-20 06:43:52
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31302 Modified Files: AtomsFramework.xml Nunit_AtomsFramework.vbproj original db1.mdb Log Message: New tests for multiple inheritance, and multilevel subclassing Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Nunit_AtomsFramework.vbproj 19 Oct 2004 03:30:41 -0000 1.9 +++ Nunit_AtomsFramework.vbproj 20 Oct 2004 06:43:40 -0000 1.10 @@ -160,11 +160,21 @@ BuildAction = "Compile" /> <File + RelPath = "InheritedClasses\SuperClassTests.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "InheritedClasses\TableA_B.vb" SubType = "Code" BuildAction = "Compile" /> <File + RelPath = "InheritedClasses\tblAtoKClasses.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Interfaces\EmployeeInterfaceTests.vb" SubType = "Code" BuildAction = "Compile" Index: original db1.mdb =================================================================== RCS file: /cvsroot/jcframework/Nunit/original db1.mdb,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 Binary files /tmp/cvsW9HF5f and /tmp/cvszlZIJ6 differ Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- AtomsFramework.xml 19 Oct 2004 03:30:41 -0000 1.7 +++ AtomsFramework.xml 20 Oct 2004 06:43:40 -0000 1.8 @@ -8,138 +8,233 @@ </database> <class name="SharedParent" table="SharedClasses" database="MSA" namespace="NunitTests.InheritedClasses"> - <attribute name="OIDValue" column="oid" key="primary"/> - <attribute name="CreatedDate" column="created" timestamp="true"/> - <attribute name="ModifiedDate" column="modified" timestamp="true"/> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="CreatedDate" column="created" timestamp="true"/> + <attribute name="ModifiedDate" column="modified" timestamp="true"/> </class> - <class name="SharedChild" table="SharedClasses" superclass="SharedParent" database="MSA" sharedtablefield="IType" sharedtablevalue="PLN" namespace="NunitTests.InheritedClasses"> </class> <class name="NPJob" table="NPJobs" database="MSA" namespace="NunitTests.StandardClasses"> - <attribute name="Id" column="id" key="primary"/> - <attribute name="Description" column="description"/> + <attribute name="Id" column="id" key="primary"/> + <attribute name="Description" column="description"/> </class> - <class name="NPJobWithOIDValue" table="jobs" database="MSA" namespace="NunitTests.StandardClasses"> - <attribute name="OIDValue" column="oidvalue" key="primary"/> - <attribute name="Description" column="description" find="true"/> + <attribute name="OIDValue" column="oidvalue" key="primary"/> + <attribute name="Description" column="description" find="true"/> </class> - - <class name="NPEmployee" table="employee" database="MSA" namespace="NunitTests.StandardClasses"> - <attribute name="OIDValue" column="oid" key="primary"/> - <attribute name="Name" column="name" find="true"/> - <attribute name="ReportsToOID" column="parentoid" /> - <attribute name="TeamOID" column="teamoid" /> - <attribute name="Team" /> - <attribute name="ReportsTo" /> - <attribute name="Workers" /> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="Name" column="name" find="true"/> + <attribute name="ReportsToOID" column="parentoid" /> + <attribute name="TeamOID" column="teamoid" /> + <attribute name="Team" /> + <attribute name="ReportsTo" /> + <attribute name="Workers" /> </class> - - <association fromClass="NunitTests.StandardClasses.NPEmployee" toClass="NunitTests.StandardClasses.NPEmployee" target="ReportsTo" cardinality="OneToOne" +<class name="NPTeam" table="teams" database="MSA" namespace="NunitTests.StandardClasses"> + <attribute name="OIDValue" column="oidvalue" key="primary"/> + <attribute name="Name" column="teamname" find="true"/> + <attribute name="TeamLeaderOID" column="teamleader" /> + <attribute name="jobOID" column="joboidvalue" /> + <attribute name="TeamLeader" /> + <attribute name="Job" /> +</class> +<association fromClass="NunitTests.StandardClasses.NPEmployee" toClass="NunitTests.StandardClasses.NPEmployee" target="ReportsTo" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="ReportsToOID" toAttribute="OIDValue"/> - </association> - - <association fromClass="NunitTests.StandardClasses.NPEmployee" toClass="NunitTests.StandardClasses.NPEmployee" target="Workers" cardinality="OneToMany" +</association> +<association fromClass="NunitTests.StandardClasses.NPEmployee" toClass="NunitTests.StandardClasses.NPEmployee" target="Workers" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> - </association> - -<class name="NPTeam" table="teams" database="MSA" namespace="NunitTests.StandardClasses"> - <attribute name="OIDValue" column="oidvalue" key="primary"/> - <attribute name="Name" column="teamname" find="true"/> - <attribute name="TeamLeaderOID" column="teamleader" /> - <attribute name="jobOID" column="joboidvalue" /> - <attribute name="TeamLeader" /> - <attribute name="Job" /> -</class> - - <association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPEmployee" target="TeamLeader" cardinality="OneToOne" +</association> +<association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPEmployee" target="TeamLeader" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> <entry fromAttribute="TeamLeaderOID" toAttribute="OIDValue"/> - </association> - - <association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPJobWithOIDValue" target="Job" cardinality="OneToOne" +</association> +<association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPJobWithOIDValue" target="Job" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> <entry fromAttribute="jobOID" toAttribute="OIDValue"/> - </association> - - <association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPEmployee" target="Members" cardinality="OneToMany" +</association> +<association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPEmployee" target="Members" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> <entry fromAttribute="OIDValue" toAttribute="TeamOID"/> - </association> +</association> + <class name="IEmployee" table="employee" database="MSA" factory="IEmployeeFactory" namespace="NunitTests.Interfaces"> - <attribute name="OIDValue" column="oid" key="primary"/> - <attribute name="Name" column="name" find="true"/> - <attribute name="ReportsToOID" column="parentoid" /> - <attribute name="TeamOID" column="teamoid" /> - <attribute name="Team" /> - <attribute name="ReportsTo" /> - <attribute name="Workers" /> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="Name" column="name" find="true"/> + <attribute name="ReportsToOID" column="parentoid" /> + <attribute name="TeamOID" column="teamoid" /> + <attribute name="Team" /> + <attribute name="ReportsTo" /> + <attribute name="Workers" /> </class> - - <association fromClass="NunitTests.Interfaces.IEmployee" toClass="NunitTests.Interfaces.IEmployee" target="ReportsTo" cardinality="OneToOne" +<association fromClass="NunitTests.Interfaces.IEmployee" toClass="NunitTests.Interfaces.IEmployee" target="ReportsTo" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="ReportsToOID" toAttribute="OIDValue"/> - </association> - - <association fromClass="NunitTests.Interfaces.IEmployee" toClass="NunitTests.Interfaces.IEmployee" target="Workers" cardinality="OneToMany" +</association> +<association fromClass="NunitTests.Interfaces.IEmployee" toClass="NunitTests.Interfaces.IEmployee" target="Workers" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> - </association> +</association> <class name="mr1" table="mr1" database="MSA" namespace="NunitTests.InheritedClasses"> - <attribute name="id" column="id" key="primary"/> - <attribute name="field1" column="field1" /> - <attribute name="field2" column="field2" /> - <attribute name="mr2_id" column="mr2_id" /> - <attribute name="mr2" /> + <attribute name="id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="field2" column="field2" /> + <attribute name="mr2_id" column="mr2_id" /> + <attribute name="mr2" /> </class> - <class name="mr2" table="mr2" database="MSA" namespace="NunitTests.InheritedClasses"> - <attribute name="id" column="id" key="primary"/> - <attribute name="field1" column="field1" /> - <attribute name="field2" column="field2" /> - <attribute name="mr3_id" column="mr3_id" /> - <attribute name="mr3" /> + <attribute name="id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="field2" column="field2" /> + <attribute name="mr3_id" column="mr3_id" /> + <attribute name="mr3" /> </class> - <class name="mr3" table="mr3" database="MSA" namespace="NunitTests.InheritedClasses"> - <attribute name="id" column="id" key="primary"/> - <attribute name="field1" column="field1" /> - <attribute name="field2" column="field2" /> + <attribute name="id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="field2" column="field2" /> </class> - - <association fromClass="NunitTests.InheritedClasses.mr1" toClass="NunitTests.InheritedClasses.mr2" target="mr2" cardinality="OneToOne" +<association fromClass="NunitTests.InheritedClasses.mr1" toClass="NunitTests.InheritedClasses.mr2" target="mr2" cardinality="OneToOne" retrieveAutomatic="false" saveAutomatic="false" deleteAutomatic="false" inverse="false" name="mr1tomr2"> <entry fromAttribute="mr2_id" toAttribute="id"/> - </association> - - <association fromClass="NunitTests.InheritedClasses.mr2" toClass="NunitTests.InheritedClasses.mr3" target="mr3" cardinality="OneToOne" +</association> +<association fromClass="NunitTests.InheritedClasses.mr2" toClass="NunitTests.InheritedClasses.mr3" target="mr3" cardinality="OneToOne" retrieveAutomatic="false" saveAutomatic="false" deleteAutomatic="false" inverse="false" name="mr2tomr3"> <entry fromAttribute="mr3_id" toAttribute="id"/> - </association> +</association> <class name="TableA" table="tableA" database="MSA" namespace="NunitTests.InheritedClasses"> - <attribute name="Id" column="id" key="primary"/> - <attribute name="field1" column="field1" /> - <attribute name="TableBCollection" /> + <attribute name="Id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="TableBCollection" /> </class> <class name="TableB" table="TableB" database="MSA" namespace="NunitTests.InheritedClasses"> - <attribute name="Id" column="id" key="primary"/> - <attribute name="field1" column="field1" /> - <attribute name="AId" column="a_id" /> - <attrbute name="TableA" /> + <attribute name="Id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="AId" column="a_id" /> + <attrbute name="TableA" /> </class> - - <association fromClass="NunitTests.InheritedClasses.TableA" toClass="NunitTests.InheritedClasses.TableB" target="TableBCollection" cardinality="OneToMany" +<association fromClass="NunitTests.InheritedClasses.TableA" toClass="NunitTests.InheritedClasses.TableB" target="TableBCollection" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="true" inverse="false" name="AtoB"> <entry fromAttribute="Id" toAttribute="AId"/> - </association> +</association> + + <class name="A" table="tblA" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="BCol" /> + <attribute name="C" /> + <attribute name="COID" column="cOID"/> + </class> + <class name="B" table="tblB" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true"/> + <attribute name="Text" column="textCol"/> + <attribute name="A" /> + <attribute name="AOID" column="aOID"/> + </class> + <class name="C" table="tblC" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true"/> + <attribute name="Text" column="textCol"/> + </class> + <class name="D" table="tblD" database="MSA" superclass="B" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true" /> + <attribute name="Str" column="str"/> + </class> + <class name="E" table="tblE" database="MSA" superclass="B" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true"/> + <attribute name="Str" column="str"/> + </class> + <class name="F" table="tblF" database="MSA" superclass="E" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true"/> + <attribute name="I" column="i"/> + </class> + <class name="G" table="tblG" database="MSA" superclass="E" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true" /> + <attribute name="I" column="i"/> + </class> + <class name="H" table="tblH" database="MSA" superclass="C" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true" /> + <attribute name="Str" column="str"/> + </class> + <class name="I" table="tblI" database="MSA" superclass="C" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true" /> + <attribute name="Str" column="str"/> + </class> + <class name="J" table="tblJ" database="MSA" superclass="H" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true" /> + <attribute name="I" column="i"/> + </class> + <class name="K" table="tblK" database="MSA" superclass="H" namespace="NunitTests.InheritedClasses"> + <attribute name="OIDValue" column="oid" key="primary" reference="OIDValue"/> + <attribute name="CreatedDate" column="CreatedDate" timestamp="true"/> + <attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/> + <attribute name="Id" column="id" find="true" /> + <attribute name="I" column="i"/> + </class> + <association fromClass="NunitTests.InheritedClasses.A" + toClass="NunitTests.InheritedClasses.B" + cardinality="oneToMany" + target="BCol" + retrieveAutomatic="true" + deleteAutomatic="true" + saveAutomatic="true" + inverse="false"> + <entry fromAttribute="OIDValue" toAttribute="AOID"/> + </association> + <association fromClass="NunitTests.InheritedClasses.B" + toClass="NunitTests.InheritedClasses.A" + cardinality="oneToOne" + target="A" + retrieveAutomatic="true" + deleteAutomatic="false" + saveAutomatic="false" + inverse="false"> + <entry fromAttribute="AOID" toAttribute="OIDValue"/> + </association> + <association fromClass="NunitTests.InheritedClasses.A" + toClass="NunitTests.InheritedClasses.C" + cardinality="oneToOne" + target="C" + retrieveAutomatic="true" + saveAutomatic="true" + deleteAutomatic="true" + inverse="false"> + <entry fromAttribute="COID" toAttribute="OIDValue"/> + </association> </map> \ No newline at end of file |
From: Richard B. <rb...@us...> - 2004-10-20 06:43:52
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31302/InheritedClasses Added Files: SuperClassTests.vb tblAtoKClasses.vb Log Message: New tests for multiple inheritance, and multilevel subclassing --- NEW FILE: tblAtoKClasses.vb --- Imports AToMSFramework Namespace InheritedClasses Public Class A Inherits CPersistentObject Public _id As Integer = 0 Public _text As String = String.Empty Public _c As C Public _cOID As String Public _bCol As CPersistentCollection Public Sub New() _bCol = New CPersistentCollection _bCol.ContainerObject = Me Me.SetDirtyFlag() End Sub Public Property Id() As Integer Get Return _id End Get Set(ByVal value As Integer) If (_id <> value) Then _id = value SetDirtyFlag() End If End Set End Property Public Property Text() As String Get Return _text End Get Set(ByVal Value As String) If (_text <> Value) Then _text = Value SetDirtyFlag() End If End Set End Property Public Property C() As C Get If _c Is Nothing Then _c = New C _c.OIDValue = _cOID _c.Retrieve() End If Return _c End Get Set(ByVal Value As C) If Not CPersistentObject.Equals(_c, Value) Then _c = Value If Value Is Nothing Then _cOID = "" Else _cOID = Value.OIDValue End If SetDirtyFlag() End If End Set End Property Public Property COID() As String Get If Not _c Is Nothing Then Return _c.OIDValue Else Return _cOID End If End Get Set(ByVal Value As String) _cOID = Value End Set End Property Public Property BCol() As CPersistentCollection Get Return _bCol End Get Set(ByVal Value As CPersistentCollection) If _bCol.Equals(Value) Then _bCol = Value For Each _b As B In _bCol _b.A = Me Next SetDirtyFlag() End If End Set End Property Public Overrides Function getNewObject() As CPersistentObject Return New A End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class Public Class B Inherits CPersistentObject Public Sub New() End Sub Public _id As Integer = 0 Public _text As String = String.Empty Public _a As A = Nothing Public _aOID As String = Nothing Public Property Id() As Integer Get Return Me._id End Get Set(ByVal Value As Integer) If Not (Me._id = Value) Then Me._id = Value Me.SetDirtyFlag() End If End Set End Property Public Property Text() As String Get Return Me._text End Get Set(ByVal Value As String) If Not (Me._text = Value) Then Me._text = Value Me.SetDirtyFlag() End If End Set End Property Public Property A() As A Get Return Me._a End Get Set(ByVal Value As A) If Me._a Is Nothing AndAlso Not (Value Is Nothing) Then Me._a = Value Me._aOID = Value.OIDValue Else If Value Is Nothing Then Me._a = Nothing Me._aOID = Nothing Else If Not Me._a.Equals(Value) Then Me._a = Value Me._aOID = Value.OIDValue End If End If End If Me.SetDirtyFlag() End Set End Property Public Property AOID() As String Get If Not (Me._a Is Nothing) Then Return Me._a.OIDValue Else Return Me._aOID End If End Get Set(ByVal Value As String) If Not (Me._a Is Nothing) Then If Not (Me._a.OIDValue = Value) Then Me._a.OIDValue = Value Me.SetDirtyFlag() End If End If Me._aOID = Value End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New B End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class C Inherits CPersistentObject Public Sub New() End Sub Private _id As Integer = 0 Private _text As String = String.Empty Public Property Id() As Integer Get Return Me._id End Get Set(ByVal Value As Integer) If Not (Me._id = value) Then Me._id = value Me.SetDirtyFlag() End If End Set End Property Public Property Text() As String Get Return Me._text End Get Set(ByVal Value As String) If Not (Me._text = value) Then Me._text = value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New C End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class D Inherits B Public Sub New() End Sub Private _str As String = String.Empty Public Property Str() As String Get Return Me._str End Get Set(ByVal Value As String) If Not (Me._str = Value) Then Me._str = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New D End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class E Inherits B Public Sub New() End Sub Private _str As String = String.Empty Public Property Str() As String Get Return Me._str End Get Set(ByVal Value As String) If Not (Me._str = Value) Then Me._str = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New E End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class F Inherits E Public Sub New() End Sub Private _i As Integer = 0 Public Property I() As Integer Get Return Me._i End Get Set(ByVal Value As Integer) If Not (Me._i = Value) Then Me._i = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New F End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class G Inherits E Public Sub New() End Sub Private _i As Integer = 0 Public Property I() As Integer Get Return Me._i End Get Set(ByVal Value As Integer) If Not (Me._i = Value) Then Me._i = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New G End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class H Inherits C Public Sub New() End Sub Private _str As String = String.Empty Public Property Str() As String Get Return Me._str End Get Set(ByVal Value As String) If Not (Me._str = Value) Then Me._str = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New H End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class I Inherits C Public Sub New() End Sub Private _str As String = String.Empty Public Property Str() As String Get Return Me._str End Get Set(ByVal Value As String) If Not (Me._str = Value) Then Me._str = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New I End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class J Inherits H Public Sub New() End Sub Private _i As Integer = 0 Public Property I() As Integer Get Return Me._i End Get Set(ByVal Value As Integer) If Not (Me._i = Value) Then Me._i = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New J End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class Public Class K Inherits H Public Sub New() End Sub Private _i As Integer = 0 Public Property I() As Integer Get Return Me._i End Get Set(ByVal Value As Integer) If Not (Me._i = Value) Then Me._i = Value Me.SetDirtyFlag() End If End Set End Property Public Overloads Overrides Function getNewObject() As CPersistentObject Return New K End Function Public Overloads Overrides Function IsValid() As Boolean Return True End Function End Class End Namespace --- NEW FILE: SuperClassTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class SuperClassTests Private pbroker As CPersistenceBroker <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 GC.Collect() 'file is in use - so we will loop around until it is released 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 <SetUp()> Public Sub TestInit() End Sub <Test()> Public Sub CheckMultiInheritance1() Dim root As New A root.Id = 1 root.Text = "Root object" root.BCol = New CPersistentCollection ' create G and add it to the collection Dim g As New G g.Id = 5 g.Text = "Child class of E" g.Str = "Added to collection" g.I = 555 g.A = root root.BCol.Add(g) ' create oneToOne object (K) and add it to root Dim k As New K k.Id = 6 k.Text = "Child of class H" k.Str = "Added to oneToOne association" k.I = 666 root.C = k '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"); Dim col As CPersistentCollection Dim cpo As CPersistentObject = New A col = cpo.getAll(True) Assert.IsTrue(col.Count > 0) For Each a As A In col Assert.IsTrue(a.C.GetType Is GetType(K)) For Each b As B In a.BCol Assert.IsTrue(b.GetType Is GetType(G)) Next Next End Sub <Test()> Public Sub RetrievalViaParentAttributes() Dim j As New J j.I = 1 j.Id = 123 j.Text = "Class C Text" j.Str = "Class H Str" j.Save() j = New J Dim rc As New CRetrieveCriteria rc.ClassMap = j.getClassMap Dim condition As New CCriteriaCondition condition.ClassMap = j.getClassMap condition.Tables = rc.Tables condition.addSelectEqualTo("Text", "Class C Text") rc.WhereCondition = condition Dim cursor As CCursor = rc.perform Assert.IsTrue(cursor.hasElements) Assert.AreEqual(1, cursor.TotalRows) cursor.loadObject(j) Assert.AreEqual("Class C Text", j.Text) Assert.AreEqual("Class H Str", j.Str) assert.AreEqual(123,j.Id) End Sub <Test()> Public Sub RetrievalViaParentAttributes2() Dim j As New J j.I = 1 j.Id = 124 j.Text = "Class C Text1" j.Str = "Class H Str" j.Save() j = New J Dim rc As New CRetrieveCriteria rc.ClassMap = j.getClassMap rc.WhereCondition.addSelectEqualTo("Text", "Class C Text1") Dim cursor As CCursor = rc.perform Assert.IsTrue(cursor.hasElements) Assert.AreEqual(1, cursor.TotalRows) cursor.loadObject(j) Assert.AreEqual("Class C Text1", j.Text) Assert.AreEqual("Class H Str", j.Str) Assert.AreEqual(124, j.Id) End Sub End Class End Namespace |
From: Richard B. <rb...@us...> - 2004-10-19 03:32:18
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1140 Modified Files: AssemblyInfo.vb CJoin.vb CMultiRetrieveCriteria.vb CPersistenceBroker.vb CPersistentObject.vb Log Message: Fix problem with joins in MultiRetrieveCriteria, and problems with saveAutomatic Assembly Version number changed to 2.0.0.0 Index: AssemblyInfo.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/AssemblyInfo.vb,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- AssemblyInfo.vb 27 Sep 2004 02:39:31 -0000 1.12 +++ AssemblyInfo.vb 19 Oct 2004 03:32:08 -0000 1.13 @@ -25,7 +25,7 @@ ' by using the '*' as shown below -<Assembly: AssemblyVersion("1.24.0.0")> +<Assembly: AssemblyVersion("2.0.0.0")> ''' ----------------------------------------------------------------------------- ''' Project : AToMSFramework Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.68 retrieving revision 1.69 diff -u -d -r1.68 -r1.69 --- CPersistenceBroker.vb 18 Oct 2004 03:31:51 -0000 1.68 +++ CPersistenceBroker.vb 19 Oct 2004 03:32:08 -0000 1.69 @@ -2127,7 +2127,7 @@ If Not checkAssociationsRecursivly Then If Not obj.IsDirty Then Return queue 'Do not save if nothing changed If obj.IsProxy Then Return queue 'Do not save if object is proxied - If TypeOf (obj) Is CPersistentObject Then + If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then If Not CType(obj, CPersistentObject).IsValid Then Return queue 'Do not save if object is not valid End If If obj.IsReadOnly Then @@ -2145,7 +2145,7 @@ '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 TypeOf (obj) Is CPersistentObject Then + If obj.GetObjectType.IsSubclassOf(GetType(CPersistentObject)) Then If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) @@ -2181,7 +2181,7 @@ If Not col Is Nothing Then For k = 0 To col.Count() - 1 tmpObj = col.Item(k) - If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then value = LocateOrCreateInjObject(tmpObj) Else value = tmpObj @@ -2212,7 +2212,7 @@ If Not col Is Nothing Then For k = 0 To col.Count() - 1 tmpObj = col.Item(k) - If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then value = LocateOrCreateInjObject(tmpObj) Else value = tmpObj @@ -2233,7 +2233,7 @@ If cm.SharedTableField Is Nothing Then If Not cm.SuperClass Is Nothing Then tmpObj = obj.GetObjectByClassMap(cm.SuperClass) - If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then value = LocateOrCreateInjObject(tmpObj) Else value = tmpObj @@ -2247,7 +2247,7 @@ Else If Not cm.SuperClass Is Nothing Then tmpObj = obj.GetObjectByClassMap(cm.SuperClass) - If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + If Not tmpObj.GetType.IsSubclassOf(GetType(CPersistentObject)) Then value = LocateOrCreateInjObject(tmpObj) Else value = tmpObj Index: CMultiRetrieveCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiRetrieveCriteria.vb,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- CMultiRetrieveCriteria.vb 19 Oct 2004 01:59:57 -0000 1.16 +++ CMultiRetrieveCriteria.vb 19 Oct 2004 03:32:08 -0000 1.17 @@ -270,9 +270,7 @@ 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 Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- CPersistentObject.vb 15 Oct 2004 06:42:56 -0000 1.43 +++ CPersistentObject.vb 19 Oct 2004 03:32:08 -0000 1.44 @@ -852,7 +852,7 @@ '''----------------------------------------------------------------------------- Public Overridable Sub Save(ByVal obj As CPersistentObject, ByVal checkAssociationsRecursivly As Boolean) Implements IPersistentObject.save Dim persistentBroker As CPersistenceBroker - Dim value As CPersistentObject + Dim value As IPersistableObject Dim queue As Queue persistentBroker = getPersistenceBrokerInstance() Index: CJoin.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CJoin.vb,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CJoin.vb 19 Oct 2004 01:59:57 -0000 1.7 +++ CJoin.vb 19 Oct 2004 03:32:08 -0000 1.8 @@ -152,6 +152,12 @@ '''----------------------------------------------------------------------------- Public Property LeftTableAlias() As String Get + If m_leftTableAlias Is Nothing OrElse m_leftTableAlias.Length = 0 Then + If LeftSide Is Nothing Then + Return TableAlias + End If + Return LeftSide.RootTableAlias + End If Return m_leftTableAlias End Get Set(ByVal Value As String) |
From: Richard B. <rb...@us...> - 2004-10-19 03:30:52
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv767 Modified Files: AtomsFramework.xml Nunit_AtomsFramework.vbproj original db1.mdb Log Message: Extra tests for retrieve criteria, auto save and auto delete. Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Nunit_AtomsFramework.vbproj 19 Oct 2004 00:13:37 -0000 1.8 +++ Nunit_AtomsFramework.vbproj 19 Oct 2004 03:30:41 -0000 1.9 @@ -140,6 +140,16 @@ BuildAction = "Compile" /> <File + RelPath = "InheritedClasses\MultiRetrieveTestClasses.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "InheritedClasses\MultiRetrieveTests.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "InheritedClasses\RetrieveCriteriaTests.vb" SubType = "Code" BuildAction = "Compile" @@ -150,6 +160,11 @@ BuildAction = "Compile" /> <File + RelPath = "InheritedClasses\TableA_B.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Interfaces\EmployeeInterfaceTests.vb" SubType = "Code" BuildAction = "Compile" Index: original db1.mdb =================================================================== RCS file: /cvsroot/jcframework/Nunit/original db1.mdb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 Binary files /tmp/cvsBOphG7 and /tmp/cvsgzMoRC differ Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- AtomsFramework.xml 19 Oct 2004 00:13:37 -0000 1.6 +++ AtomsFramework.xml 19 Oct 2004 03:30:41 -0000 1.7 @@ -91,4 +91,55 @@ <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> </association> + +<class name="mr1" table="mr1" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="field2" column="field2" /> + <attribute name="mr2_id" column="mr2_id" /> + <attribute name="mr2" /> +</class> + +<class name="mr2" table="mr2" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="field2" column="field2" /> + <attribute name="mr3_id" column="mr3_id" /> + <attribute name="mr3" /> +</class> + +<class name="mr3" table="mr3" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="field2" column="field2" /> +</class> + + <association fromClass="NunitTests.InheritedClasses.mr1" toClass="NunitTests.InheritedClasses.mr2" target="mr2" cardinality="OneToOne" + retrieveAutomatic="false" saveAutomatic="false" deleteAutomatic="false" inverse="false" name="mr1tomr2"> + <entry fromAttribute="mr2_id" toAttribute="id"/> + </association> + + <association fromClass="NunitTests.InheritedClasses.mr2" toClass="NunitTests.InheritedClasses.mr3" target="mr3" cardinality="OneToOne" + retrieveAutomatic="false" saveAutomatic="false" deleteAutomatic="false" inverse="false" name="mr2tomr3"> + <entry fromAttribute="mr3_id" toAttribute="id"/> + </association> + + +<class name="TableA" table="tableA" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="Id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="TableBCollection" /> +</class> +<class name="TableB" table="TableB" database="MSA" namespace="NunitTests.InheritedClasses"> + <attribute name="Id" column="id" key="primary"/> + <attribute name="field1" column="field1" /> + <attribute name="AId" column="a_id" /> + <attrbute name="TableA" /> +</class> + + <association fromClass="NunitTests.InheritedClasses.TableA" toClass="NunitTests.InheritedClasses.TableB" target="TableBCollection" cardinality="OneToMany" + retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="true" inverse="false" name="AtoB"> + <entry fromAttribute="Id" toAttribute="AId"/> + </association> + </map> \ No newline at end of file |
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv767/InheritedClasses Modified Files: AtomsFrameworkTests.vb RetrieveCriteriaTests.vb SharedTests.vb Added Files: MultiRetrieveTestClasses.vb MultiRetrieveTests.vb TableA_B.vb Log Message: Extra tests for retrieve criteria, auto save and auto delete. Index: SharedTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/SharedTests.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SharedTests.vb 19 Oct 2004 00:13:38 -0000 1.1 +++ SharedTests.vb 19 Oct 2004 03:30:42 -0000 1.2 @@ -18,6 +18,7 @@ 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 --- NEW FILE: MultiRetrieveTestClasses.vb --- Imports AToMSFramework Namespace InheritedClasses Public Class mr1 Inherits CPersistentObject Private _id As String Private _mr2_id As String Private _mr2 As mr2 Private _field1 As String Private _field2 As Integer Public Property id() As String Get Return _id End Get Set(ByVal Value As String) _id = Value SetDirtyFlag() End Set End Property Public Property mr2_id() As String Get If Not _mr2 Is Nothing Then Return _mr2.id End If Return _mr2_id End Get Set(ByVal Value As String) _mr2_id = Value SetDirtyFlag() End Set End Property Public Property mr2() As mr2 Get Return _mr2 End Get Set(ByVal Value As mr2) _mr2 = Value SetDirtyFlag() End Set End Property Public Property field1() As String Get Return _field1 End Get Set(ByVal Value As String) _field1 = Value End Set End Property Public Property field2() As Integer Get Return _field2 End Get Set(ByVal Value As Integer) _field2 = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New mr1 End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class Public Class mr2 Inherits CPersistentObject Private _id As String Public Property id() As String Get Return _id End Get Set(ByVal Value As String) _id = Value SetDirtyFlag() End Set End Property Private _field1 As String Public Property field1() As String Get Return _field1 End Get Set(ByVal Value As String) _field1 = Value End Set End Property Private _field2 As Integer Public Property field2() As Integer Get Return _field2 End Get Set(ByVal Value As Integer) _field1 = Value End Set End Property Private _mr3_id As String Private _mr3 As mr3 Public Property mr3_id() As String Get If Not _mr3 Is Nothing Then Return _mr3.id End If Return _mr3_id End Get Set(ByVal Value As String) _mr3_id = Value SetDirtyFlag() End Set End Property Public Property mr3() As mr3 Get Return _mr3 End Get Set(ByVal Value As mr3) _mr3 = Value SetDirtyFlag() End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New mr2 End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class Public Class mr3 Inherits CPersistentObject Private _id As String Public Property id() As String Get Return _id End Get Set(ByVal Value As String) _id = Value SetDirtyFlag() End Set End Property Private _field1 As String Public Property field1() As String Get Return _field1 End Get Set(ByVal Value As String) _field1 = Value End Set End Property Private _field2 As Integer Public Property field2() As Integer Get Return _field2 End Get Set(ByVal Value As Integer) _field1 = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New mr3 End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class End Namespace --- NEW FILE: TableA_B.vb --- Imports AToMSFramework Namespace InheritedClasses Public Class TableA Inherits CPersistentObject Private _id As String Public Property Id() As String Get Return _id End Get Set(ByVal Value As String) _id = Value SetDirtyFlag() End Set End Property Private _field1 As String Public Property field1() As String Get Return _field1 End Get Set(ByVal Value As String) _field1 = Value SetDirtyFlag() End Set End Property Private _tableBCol As New CPersistentCollection Public Property TableBCollection() As CPersistentCollection Get Return _tableBCol End Get Set(ByVal Value As CPersistentCollection) _tableBCol = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New TableA End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class Public Class TableB Inherits CPersistentObject Private _id As String Public Property Id() As String Get Return _id End Get Set(ByVal Value As String) _id = Value SetDirtyFlag() End Set End Property Private _field1 As String Public Property field1() As String Get Return _field1 End Get Set(ByVal Value As String) _field1 = Value SetDirtyFlag() End Set End Property Private _a As TableA Private _a_id As String Public Property TableA() As TableA Get Return _a End Get Set(ByVal Value As TableA) _a = Value SetDirtyFlag() End Set End Property Public Property AId() As String Get If _a Is Nothing Then Return _a_id End If Return _a.Id End Get Set(ByVal Value As String) _a_id = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New TableA End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class End Namespace Index: RetrieveCriteriaTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/RetrieveCriteriaTests.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RetrieveCriteriaTests.vb 19 Oct 2004 00:13:38 -0000 1.1 +++ RetrieveCriteriaTests.vb 19 Oct 2004 03:30:42 -0000 1.2 @@ -20,6 +20,7 @@ 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 @@ -143,8 +144,6 @@ Assert.AreEqual(emp.Name, "ab") c.nextCursor() End While - End Sub - End Class End Namespace \ No newline at end of file --- NEW FILE: MultiRetrieveTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class MultiRetrieveTests Private pbroker As CPersistenceBroker Private mr1 As mr1 Private mrc As CMultiRetrieveCriteria Private c As CCursor <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 ChainedClasses() 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.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 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 End Class End Namespace Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/AtomsFrameworkTests.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- AtomsFrameworkTests.vb 19 Oct 2004 00:13:38 -0000 1.1 +++ AtomsFrameworkTests.vb 19 Oct 2004 03:30:42 -0000 1.2 @@ -18,6 +18,7 @@ System.IO.File.Delete(".\db1.mdb") retry = False Catch iox As IO.IOException + GC.Collect() 'file is in use - so we will loop around until it is released Catch ex As Exception retry = False @@ -183,5 +184,39 @@ emp.Find() Assert.IsTrue(emp.Persistent) End Sub + + <Test()> Public Sub AutoDelete() + Dim a As New TableA + Dim b As New TableB + Dim cc As CCursor + a.Id = "a1" + a.Retrieve() + Assert.IsTrue(a.Persistent) + Assert.AreEqual(2, a.TableBCollection.Count) + a.Delete() + Dim rc As New CRetrieveCriteria + rc.ClassMap = b.getClassMap + rc.WhereCondition.addSelectEqualTo("AId", "a1") + cc = rc.perform() + Assert.AreEqual(0, cc.TotalRows) + Assert.IsFalse(cc.hasElements) + End Sub + + <Test()> Public Sub AutoSave() + Dim a As New TableA + Dim b As New TableB + Dim cc As CCursor + a.Id = "a3" + b.Id = "b33" + b.TableA = a + a.TableBCollection.Add(b) + a.Save() + Dim rc As New CRetrieveCriteria + rc.ClassMap = b.getClassMap + rc.WhereCondition.addSelectEqualTo("AId", "a3") + cc = rc.perform() + Assert.AreEqual(1, cc.TotalRows) + Assert.IsTrue(cc.hasElements) + End Sub End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2004-10-19 02:00:12
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13072 Modified Files: CJoin.vb CMultiRetrieveCriteria.vb CXMLConfigLoader.vb Log Message: Fix problem with joins in MultiRetrieveCriteria (bug #1046405) Index: CMultiRetrieveCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiRetrieveCriteria.vb,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- CMultiRetrieveCriteria.vb 18 Oct 2004 00:08:10 -0000 1.15 +++ CMultiRetrieveCriteria.vb 19 Oct 2004 01:59:57 -0000 1.16 @@ -175,7 +175,7 @@ ''' </history> '''----------------------------------------------------------------------------- Public Sub addObjectToJoin(ByVal obj As IPersistableObject, ByVal fromObj As IPersistableObject, ByVal assocName As String) - Dim mapName As String + Dim mapName, sourceMapName As String Dim persobj As IPersistableObject Dim bfound As Boolean = False Dim cm, cm2 As CClassMap @@ -222,9 +222,10 @@ i = m_fromCMaps.Count mapName = "t" & i.ToString m_objectsToJoin.Add(mapName, obj) + sourceMapName = m_joins.GetTableAlias(cm2) m_joins = New CJoin(m_joins, cm, mapName, am) - mapName = "t" & (i - 1).ToString - m_joins.LeftTableAlias = mapName + 'mapName = "t" & (i - 1).ToString + m_joins.LeftTableAlias = sourceMapName cm = cm.SuperClass While Not cm Is Nothing i += 1 Index: CXMLConfigLoader.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CXMLConfigLoader.vb,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- CXMLConfigLoader.vb 18 Oct 2004 01:36:44 -0000 1.24 +++ CXMLConfigLoader.vb 19 Oct 2004 01:59:57 -0000 1.25 @@ -284,11 +284,20 @@ If ((Not attrClassName Is Nothing) And (Not attrDatabase Is Nothing)) Then ClassMap = New CClassMap ClassMap.Name = attrClassName.Value + If Not attrClassNameSpace Is Nothing Then + ClassMap.ClassNameSpace = attrClassNameSpace.Value + End If If Not attrSuperClassName Is Nothing Then If Not attrSuperClassNameSpace Is Nothing Then ClassMap.SuperClass = m_classMap.Item(attrSuperClassNameSpace.Value & "." & attrSuperClassName.Value) + ClassMap.SuperClassNameSpace = attrSuperClassNameSpace.Value Else - ClassMap.SuperClass = m_classMap.Item(attrSuperClassName.Value) + If Not attrClassNameSpace Is Nothing Then + ClassMap.SuperClass = m_classMap.Item(ClassMap.ClassNameSpace & "." & attrSuperClassName.Value) + ClassMap.SuperClassNameSpace = attrClassNameSpace.Value + Else + ClassMap.SuperClass = m_classMap.Item(attrSuperClassName.Value) + End If End If ClassMap.SuperClass.addChildrenMap(ClassMap) If Not attrSharedValue Is Nothing Then @@ -324,12 +333,6 @@ If Not attrAssemblyPath Is Nothing Then ClassMap.AssemblyPath = attrAssemblyPath.Value End If - If Not attrClassNameSpace Is Nothing Then - ClassMap.ClassNameSpace = attrClassNameSpace.Value - End If - If Not attrSuperClassNameSpace Is Nothing Then - ClassMap.SuperClassNameSpace = attrSuperClassNameSpace.Value - End If If Not attrClassFactory Is Nothing Then ClassMap.IClassFactoryName = attrClassFactory.Value End If Index: CJoin.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CJoin.vb,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CJoin.vb 28 Sep 2004 04:18:54 -0000 1.6 +++ CJoin.vb 19 Oct 2004 01:59:57 -0000 1.7 @@ -282,13 +282,15 @@ End If tm = RightSide.Tables.Item(1) s = leftBracket & LeftSide.GetSQLString & " " & db.getClauseStringLeftJoin _ - & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " + & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " For i = 1 To cm.getReferenceSize If i > 1 Then s = s & " " & db.getClauseStringAnd & " " End If - s = s & cm.getReferenceAttributeMap(i).ColumnMap.getAliasQualifiedName(LeftSide.RootTableAlias) _ - & " = " & cm.getReferenceAttributeMap(i).AttributeMap.ColumnMap.getAliasQualifiedName(TableAlias) + 's = s & cm.getReferenceAttributeMap(i).ColumnMap.getAliasQualifiedName(LeftSide.RootTableAlias) _ + ' & " = " & cm.getReferenceAttributeMap(i).AttributeMap.ColumnMap.getAliasQualifiedName(TableAlias) + s = s & cm.getReferenceAttributeMap(i).ColumnMap.getAliasQualifiedName(LeftTableAlias) _ + & " = " & cm.getReferenceAttributeMap(i).AttributeMap.ColumnMap.getAliasQualifiedName(TableAlias) Next i s = s & rightBracket ElseIf Association Is Nothing Then @@ -318,14 +320,16 @@ End If tm = cm.Tables.Item(1) s = leftBracket & LeftSide.GetSQLString & " " & db.getClauseStringLeftJoin _ - & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " + & " " & db.getClauseStringTableAlias(tm.Name, tm.TableOwner, TableAlias) & " " & db.getClauseStringOn & " " For i = 1 To Association.Entries.Count If i > 1 Then s = s & " " & db.getClauseStringAnd & " " End If udaEntry = Association.getEntry(i) - s = s & udaEntry.FromAttrMap.ColumnMap.getAliasQualifiedName(LeftSide.RootTableAlias) & " = " _ - & udaEntry.ToAttrMap.ColumnMap.getAliasQualifiedName(TableAlias) + 's = s & udaEntry.FromAttrMap.ColumnMap.getAliasQualifiedName(LeftSide.RootTableAlias) & " = " _ + '& udaEntry.ToAttrMap.ColumnMap.getAliasQualifiedName(TableAlias) + s = s & udaEntry.FromAttrMap.ColumnMap.getAliasQualifiedName(LeftTableAlias) & " = " _ + & udaEntry.ToAttrMap.ColumnMap.getAliasQualifiedName(TableAlias) Next i s = s & rightBracket End If |
From: Richard B. <rb...@us...> - 2004-10-19 00:13:48
|
Update of /cvsroot/jcframework/Nunit/StandardClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19366/StandardClasses Added Files: NPEmployee.vb NPJob.vb NPTeam.vb NonInheritedRetreiveCriteria.vb NonInheritedTests.vb Log Message: Rearrange unit test structure (extra namespaces and folders) --- NEW FILE: NPEmployee.vb --- Namespace StandardClasses Public Class NPEmployee Private m_name As String Private m_parentoid As String Private m_parent As NPEmployee Private m_children As ArrayList Private m_team As InheritedClasses.CTeam Private m_teamoid As String Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Property ReportsTo() As NPEmployee Get Return m_parent End Get Set(ByVal Value As NPEmployee) If Not Value Is Nothing Then m_parent = Value m_parentoid = Value.OIDValue End If End Set End Property Public Property ReportsToOID() As String Get If m_parent Is Nothing Then Return m_parentoid Else Return (m_parent.OIDValue) End If End Get Set(ByVal Value As String) m_parentoid = Value End Set End Property Public Property Workers() As ArrayList Get Return m_children End Get Set(ByVal Value As ArrayList) m_children = Value End Set End Property Public Property Team() As InheritedClasses.CTeam Get Return m_team End Get Set(ByVal Value As InheritedClasses.CTeam) If Not Value Is Nothing Then m_team = Value m_teamoid = Value.OIDValue End If End Set End Property Public Property TeamOID() As String Get If m_team Is Nothing Then Return m_teamoid Else Return (m_team.OIDValue) End If End Get Set(ByVal Value As String) m_teamoid = Value End Set End Property Public Sub New() MyBase.New() m_children = New ArrayList End Sub End Class End Namespace --- NEW FILE: NPJob.vb --- Namespace StandardClasses Public Class NPJob Private m_id As String Private m_description As String Public Property Id() As String Get Return m_id End Get Set(ByVal Value As String) m_id = Value End Set End Property Public Property Description() As String Get Return m_description End Get Set(ByVal Value As String) m_description = Value End Set End Property End Class Public Class NPJobWithOIDValue Inherits NPJob Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property End Class End Namespace --- NEW FILE: NPTeam.vb --- Namespace StandardClasses Public Class NPTeam Private m_leader As NPEmployee Private m_leaderoid As String Private m_name As String Private m_job As NPJobWithOIDValue Private m_joboid As String Private m_members As ArrayList Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property Public Property TeamLeader() As NPEmployee Get Return m_leader End Get Set(ByVal Value As NPEmployee) m_leader = Value m_leaderoid = Value.OIDValue End Set End Property Public Property TeamLeaderOID() As String Get If m_leader Is Nothing Then Return m_leaderoid Else Return (m_leader.OIDValue) End If End Get Set(ByVal Value As String) m_leaderoid = Value End Set End Property Public Property Job() As NPJobWithOIDValue Get Return m_job End Get Set(ByVal Value As NPJobWithOIDValue) m_job = Value m_joboid = Value.OIDValue End Set End Property Public Property jobOID() As String Get If m_job Is Nothing Then Return m_joboid Else Return (m_job.OIDValue) End If End Get Set(ByVal Value As String) m_joboid = Value End Set End Property Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Property Members() As ArrayList Get Return m_members End Get Set(ByVal Value As ArrayList) m_members = Value End Set End Property Public Sub New() MyBase.new() m_members = New ArrayList End Sub End Class End Namespace --- NEW FILE: NonInheritedTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace StandardClasses <TestFixture()> Public Class NonInheritedTests Private pbroker As CPersistenceBroker Private job As NPJob Private emp As NPEmployee <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 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 <SetUp()> Public Sub TestInit() job = New NPJob emp = New NPEmployee End Sub <Test()> Public Sub LoadJob_a1() job.Id = "a1" pbroker.GetObject(job) Assert.IsTrue(pbroker.getInjectedObject(job).Persistent) Assert.AreEqual("basic", job.Description) End Sub <Test()> Public Sub FindJob_basic() Dim job As New NPJobWithOIDValue job.Description = "basic" pbroker.FindObject(job) Assert.AreEqual("000000160002", job.OIDValue) Assert.AreEqual("basic", job.Description) End Sub <Test()> Public Sub SaveJob_a2() pbroker.StartTracking(job) job.Id = "a2" job.Description = "SomeJob" Assert.IsTrue(pbroker.getInjectedObject(job).IsDirty) pbroker.PersistChanges(job) Assert.IsFalse(pbroker.getInjectedObject(job).IsDirty) End Sub <Test()> Public Sub DeleteAJob() pbroker.StartTracking(job) job.Id = "a3" job.Description = "SomeJob3" pbroker.PersistChanges(job) pbroker.MarkForDeletion(job) pbroker.PersistChanges(job) Assert.IsTrue(pbroker.ObjectIsTracked(job)) Assert.IsFalse(pbroker.getInjectedObject(job).Persistent) End Sub <Test()> Public Sub CheckInjectionCache() Dim job2 As New NPJob pbroker.StartTracking(job) pbroker.StartTracking(job2) Assert.IsTrue(pbroker.ObjectIsTracked(job)) job.Id = "1" job.Description = "a" Assert.IsTrue(pbroker.ObjectIsTracked(job)) job2.Id = "2" job2.Description = "b" pbroker.PersistChanges(job) pbroker.PersistChanges(job2) End Sub <Test()> Public Sub CheckInjectionCache2() Dim job2 As New NPJob job.Id = "3" job2.Id = "4" pbroker.StartTracking(job) pbroker.StartTracking(job2) job.Description = "c" job2.Description = "d" Assert.IsFalse(pbroker.getInjectedObject(job).Persistent) pbroker.PersistChanges() Assert.IsTrue(pbroker.getInjectedObject(job).Persistent) End Sub <Test()> Public Sub LoadEmployee_a() emp.Name = "a" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.Workers.Count, 0) Assert.IsTrue(Not emp.ReportsTo Is Nothing) Assert.AreEqual(emp.ReportsTo.Name, "c") Dim emp2 As NPEmployee emp2 = emp.ReportsTo.Workers(0) Assert.AreEqual(emp2.Name, emp.Name) Assert.AreEqual(emp2.OIDValue, emp.OIDValue) Assert.AreSame(emp2, emp) End Sub <Test()> Public Sub LoadEmployee_ac() emp.Name = "ac" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.Workers.Count, 3) emp = emp.Workers.Item(1) Assert.AreEqual(emp.Name, "aa") Assert.AreEqual(emp.ReportsTo.Name, "ac") End Sub <Test()> Public Sub CheckSchemaBasedProperties() emp.Name = "ac" pbroker.FindObject(emp) Assert.AreEqual(50, pbroker.getInjectedObject(emp).getFieldLengthByName("Name")) Assert.IsTrue(pbroker.getInjectedObject(emp).getFieldTypeByName("Name") Is GetType([String])) End Sub <Test()> Public Sub PersistentObjectEquality() Dim emp2 As NPEmployee emp.Name = "ac" pbroker.FindObject(emp) emp2 = New NPEmployee emp2.Name = "aa" pbroker.FindObject(emp2) Assert.IsTrue(emp.Equals(emp2.ReportsTo)) Assert.AreEqual(3, emp2.ReportsTo.Workers.Count) End Sub <Test()> Public Sub LoadSaveandDeleteEmployee() Dim oidvalue As String emp.Name = "new" pbroker.FindObject(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) oidvalue = emp.OIDValue pbroker.PersistChanges(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.IsTrue(emp.ReportsTo Is Nothing) Debug.WriteLine(pbroker.DumpCacheDetails) emp = New NPEmployee emp.Name = "new" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.OIDValue, oidvalue) Assert.AreEqual(emp.Name, "new") pbroker.MarkForDeletion(emp) pbroker.PersistChanges(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) emp = New NPEmployee emp.Name = "new" pbroker.FindObject(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) Assert.IsTrue(emp.OIDValue <> oidvalue) End Sub <Test()> Public Sub ChangeFindFieldValue() Dim oidvalue As String emp.Name = "SaveThenChange" pbroker.FindObject(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) oidvalue = emp.OIDValue pbroker.PersistChanges(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.IsTrue(emp.ReportsTo Is Nothing) emp = New NPEmployee emp.Name = "SaveThenChange" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.OIDValue, oidvalue) Assert.AreEqual(emp.Name, "SaveThenChange") emp.Name = "Changed" pbroker.PersistChanges(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) pbroker.MarkForDeletion(emp) pbroker.PersistChanges(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) emp = New NPEmployee emp.Name = "Changed" pbroker.FindObject(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) emp = New NPEmployee emp.Name = "SaveThenChange" pbroker.FindObject(emp) Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) End Sub <Test()> Public Sub saveHierarchy() Dim emp2 As New NPEmployee Dim emp3 As New NPEmployee pbroker.StartTracking(emp) emp.Name = "theBoss" emp2.Name = "middleMgr" emp3.Name = "slave" emp.Workers.Add(emp2) emp2.ReportsTo = emp emp2.Workers.Add(emp3) emp3.ReportsTo = emp2 pbroker.PersistChanges(emp) pbroker.ClearCache() emp = New NPEmployee emp.Name = "slave" pbroker.FindObject(emp) Assert.AreEqual("middleMgr", emp.ReportsTo.Name) Assert.AreEqual("theBoss", emp.ReportsTo.ReportsTo.Name) emp2 = emp.ReportsTo.Workers(0) Assert.AreEqual("slave", emp2.Name) End Sub End Class End Namespace --- NEW FILE: NonInheritedRetreiveCriteria.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace StandardClasses <TestFixture()> Public Class NonInheritedRetreiveCriteria Private pbroker As CPersistenceBroker Private emp As NPEmployee Private r As CRetrieveCriteria Private mr As CMultiRetrieveCriteria Private c As CCursor Private injObj As CInjectedObject <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 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 <SetUp()> Public Sub testInit() emp = New NPEmployee End Sub <Test()> Public Sub SingleClassRetrieve() r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(GetType(NPEmployee)) c = r.perform Assert.IsTrue(c.hasElements) Assert.IsTrue(Not c.EOF) Assert.IsTrue(c.HoldsProxies) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 6) End Sub <Test()> Public Sub LoadFullObjects() r = New CRetrieveCriteria r.ReturnFullObjects = True r.ClassMap = pbroker.getClassMap(emp.GetType) c = r.perform Assert.IsFalse(c.HoldsProxies) 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() End While c.SetCursor(0) emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "ab") End Sub <Test()> Public Sub SimpleOrCriteria() r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(emp.GetType) r.WhereCondition.addSelectEqualTo("Name", "aa") r.WhereCondition.addSelectEqualTo("Name", "b", True) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 2) c.loadObject(emp) Assert.AreEqual(emp.Name, "aa") c.nextCursor() emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "b") End Sub <Test()> Public Sub SelectInList() Dim al As New ArrayList al.Add("aa") al.Add("b") r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(emp.GetType) r.WhereCondition.addSelectInList("Name", al) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 2) c.loadObject(emp) Assert.AreEqual(emp.Name, "aa") c.nextCursor() emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "b") End Sub <Test()> Public Sub SubCriteria() Dim xx_1 As New CCriteriaCondition Dim xx_2 As New CCriteriaCondition Dim xx_3 As New CCriteriaCondition Dim xx_4 As New CCriteriaCondition r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(emp.GetType) xx_1.ClassMap = r.ClassMap xx_2.ClassMap = r.ClassMap xx_3.ClassMap = r.ClassMap xx_4.ClassMap = r.ClassMap xx_1.addSelectEqualTo("Name", "aa") xx_2.addSelectEqualTo("Name", "ab") xx_1.addSubCriteria(xx_2, True) xx_3.addSelectEqualTo("Name", "ab") xx_4.addSelectEqualTo("Name", "ac") xx_3.addSubCriteria(xx_4, True) r.WhereCondition.addSubCriteria(xx_1, True) r.WhereCondition.addSubCriteria(xx_3, False) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 1) While c.hasElements And Not c.EOF emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "ab") c.nextCursor() End While End Sub <Test()> Public Sub MultiRetrieveTest1() Dim si As CSelectInCriteria mr = New CMultiRetrieveCriteria(emp) mr.WhereCondition.addSelectEqualTo("Name", "ac") si = New CSelectInCriteria(emp) si.WhereCondition.addSelectEqualTo("Name", "ac") si.SetSelectAttribute("Name") mr.WhereCondition.addSelectNotIn("Name", si) c = mr.perform Assert.IsFalse(c.hasElements) Assert.IsTrue(c.EOF) End Sub End Class End Namespace |
From: Richard B. <rb...@us...> - 2004-10-19 00:13:48
|
Update of /cvsroot/jcframework/Nunit/Interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19366/Interfaces Added Files: EmployeeInterfaceTests.vb IEmployee.vb Log Message: Rearrange unit test structure (extra namespaces and folders) --- NEW FILE: EmployeeInterfaceTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace Interfaces <TestFixture()> Public Class EmployeeInterfaceTests Private pbroker As CPersistenceBroker Private emp As IEmployee <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 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 <SetUp()> Public Sub TestInit() emp = New EmployeeClass End Sub <Test()> Public Sub LoadEmployee_a() emp.Name = "a" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.Workers.Count, 0) Assert.IsTrue(Not emp.ReportsTo Is Nothing) Assert.AreEqual(emp.ReportsTo.Name, "c") Dim emp2 As IEmployee emp2 = emp.ReportsTo.Workers(0) Assert.AreEqual(emp2.Name, emp.Name) Assert.AreEqual(emp2.OIDValue, emp.OIDValue) Assert.AreSame(emp2, emp) End Sub <Test()> Public Sub LoadEmployee_ac() emp.Name = "ac" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.Workers.Count, 3) emp = emp.Workers.Item(1) Assert.AreEqual(emp.Name, "aa") Assert.AreEqual(emp.ReportsTo.Name, "ac") End Sub <Test()> Public Sub CheckSchemaBasedProperties() emp.Name = "ac" pbroker.FindObject(emp) Assert.AreEqual(50, pbroker.getInjectedObject(emp).getFieldLengthByName("Name")) Assert.IsTrue(pbroker.getInjectedObject(emp).getFieldTypeByName("Name") Is GetType([String])) End Sub End Class End Namespace --- NEW FILE: IEmployee.vb --- Namespace Interfaces Public Interface IEmployee Property OIDValue() As String Property Name() As String Property ReportsTo() As IEmployee Property ReportsToOID() As String Property Workers() As ArrayList Property Team() As InheritedClasses.CTeam Property TeamOID() As String End Interface Public Class EmployeeClass Implements IEmployee Private m_name As String Private m_parentoid As String Private m_parent As IEmployee Private m_children As ArrayList Private m_team As InheritedClasses.CTeam Private m_teamoid As String Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Implements IEmployee.OIDValue Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property Public Property Name() As String Implements IEmployee.Name Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Property ReportsTo() As IEmployee Implements IEmployee.ReportsTo Get Return m_parent End Get Set(ByVal Value As IEmployee) If Not Value Is Nothing Then m_parent = Value m_parentoid = Value.OIDValue End If End Set End Property Public Property ReportsToOID() As String Implements IEmployee.ReportsToOID Get If m_parent Is Nothing Then Return m_parentoid Else Return (m_parent.OIDValue) End If End Get Set(ByVal Value As String) m_parentoid = Value End Set End Property Public Property Workers() As ArrayList Implements IEmployee.Workers Get Return m_children End Get Set(ByVal Value As ArrayList) m_children = Value End Set End Property Public Property Team() As InheritedClasses.CTeam Implements IEmployee.Team Get Return m_team End Get Set(ByVal Value As InheritedClasses.CTeam) If Not Value Is Nothing Then m_team = Value m_teamoid = Value.OIDValue End If End Set End Property Public Property TeamOID() As String Implements IEmployee.TeamOID Get If m_team Is Nothing Then Return m_teamoid Else Return (m_team.OIDValue) End If End Get Set(ByVal Value As String) m_teamoid = Value End Set End Property Public Sub New() MyBase.New() m_children = New ArrayList End Sub End Class Public Class IEmployeeFactory Implements AToMSFramework.IClassFactory Public Function CreateObject() As Object Implements AToMSFramework.IClassFactory.CreateObject Return New EmployeeClass End Function End Class End Namespace |
From: Richard B. <rb...@us...> - 2004-10-19 00:13:48
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19366/InheritedClasses Added Files: AtomsFrameworkTests.vb CEmployee.vb CJob.vb CSharedClasses.vb CStudent.vb CTeam.vb CWorker.vb RetrieveCriteriaTests.vb SharedTests.vb Log Message: Rearrange unit test structure (extra namespaces and folders) --- NEW FILE: CJob.vb --- Imports AToMSFramework Namespace InheritedClasses <AFTable("jobs", "MSA", AFTableAttribute.KeyType.useOIDValue, OIDcolumn:="oidvalue")> _ Public Class CJob Inherits CPersistentObject Private m_description As String <AFColumn("description", Find:=True)> _ Public Property Description() As String Get Return m_description End Get Set(ByVal Value As String) m_description = Value SetDirtyFlag() End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New CJob End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class End Namespace --- NEW FILE: SharedTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class SharedTests Private pbroker As CPersistenceBroker Dim sc As SharedChild Dim sp As SharedParent <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 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 <SetUp()> Public Sub testInit() sc = New SharedChild sp = New SharedParent End Sub <Test()> Public Sub SaveAndRetrieveSharedChild() Dim result As Boolean Dim origOid As String = String.Empty Dim newOid As String = String.Empty sc.IsDirty = True sc.Save() origOid = sc.OIDValue sc = New SharedChild newOid = sc.OIDValue sc.OIDValue = origOid result = sc.Retrieve(sc) Assert.IsTrue(sc.OIDValue = origOid) Assert.IsTrue(origOid <> newOid) Assert.IsTrue(result) Assert.IsFalse(sc.IsDirty) sc.IsDirty = True sc.Save() End Sub <Test()> Public Sub SaveChildAndRetrieveParent() Dim result As Boolean Dim origOid As String = String.Empty sc.IsDirty = True sc.Save() origOid = sc.OIDValue sp.OIDValue = origOid result = sp.Retrieve(sp) Assert.IsTrue(sp.OIDValue = origOid) Assert.IsTrue(result) Assert.IsFalse(sp.IsDirty) Assert.IsFalse(sp.GetType Is GetType(SharedChild)) End Sub End Class End Namespace --- NEW FILE: CSharedClasses.vb --- Imports AToMSFramework Namespace InheritedClasses Public Class SharedParent Inherits CPersistentObject Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New SharedParent End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class Public Class SharedChild Inherits SharedParent Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New SharedChild End Function End Class End Namespace --- NEW FILE: CTeam.vb --- Imports AToMSFramework Namespace InheritedClasses <AFTable("teams", "MSA", AFTableAttribute.KeyType.useOIDValue, oidcolumn:="oidvalue"), _ AFAssociation(GetType(CEmployee), "TeamLeader", CUDAMap.CardinalityEnum.ONE_TO_ONE, Retrieve:=True), _ AFAssociationEntry("TeamLeader", "TeamLeaderOID", "OIDValue"), _ AFAssociation(GetType(CJob), "Job", CUDAMap.CardinalityEnum.ONE_TO_ONE, Retrieve:=True), _ AFAssociationEntry("Job", "jobOID", "OIDValue"), _ AFAssociation(GetType(CEmployee), "Members", CUDAMap.CardinalityEnum.ONE_TO_MANY, Retrieve:=True, Save:=False), _ AFAssociationEntry("Members", "OIDValue", "TeamOID")> _ Public Class CTeam Inherits CPersistentObject Private m_leader As CEmployee Private m_leaderoid As String Private m_name As String Private m_job As CJob Private m_joboid As String Private m_members As CPersistentCollection Public Property TeamLeader() As CEmployee Get Return m_leader End Get Set(ByVal Value As CEmployee) m_leader = Value m_leaderoid = Value.OIDValue SetDirtyFlag() End Set End Property <AFColumn("teamleader")> _ Public Property TeamLeaderOID() As String Get If m_leader Is Nothing Then Return m_leaderoid Else Return (m_leader.OIDValue) End If End Get Set(ByVal Value As String) m_leaderoid = Value SetDirtyFlag() End Set End Property Public Property Job() As CJob Get Return m_job End Get Set(ByVal Value As CJob) m_job = Value m_joboid = Value.OIDValue SetDirtyFlag() End Set End Property <AFColumn("joboidvalue")> _ Public Property jobOID() As String Get If m_job Is Nothing Then Return m_joboid Else Return (m_job.OIDValue) End If End Get Set(ByVal Value As String) m_joboid = Value SetDirtyFlag() End Set End Property <AFColumn("teamname", Find:=True)> _ Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value SetDirtyFlag() End Set End Property Public Property Members() As CPersistentCollection Get Return m_members End Get Set(ByVal Value As CPersistentCollection) m_members = Value SetDirtyFlag() End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New CTeam End Function Public Overrides Function IsValid() As Boolean Return True End Function Public Sub New() MyBase.new() m_members = New CPersistentCollection End Sub Protected Overrides Sub Finalize() m_members = Nothing MyBase.Finalize() End Sub End Class End Namespace --- NEW FILE: RetrieveCriteriaTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class RetrieveCriteriaTests Private pbroker As CPersistenceBroker Private emp As CEmployee Private r As CRetrieveCriteria Private mr As CMultiRetrieveCriteria Private c As CCursor <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 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 <SetUp()> Public Sub testInit() emp = New CEmployee End Sub <Test()> Public Sub SingleClassRetrieve() r = New CRetrieveCriteria r.ClassMap = emp.getClassMap c = r.perform Assert.IsTrue(c.hasElements) Assert.IsTrue(Not c.EOF) Assert.IsTrue(c.HoldsProxies) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 6) End Sub <Test()> Public Sub MultiRetrieveTest1() Dim si As CSelectInCriteria mr = New CMultiRetrieveCriteria(emp) mr.WhereCondition.addSelectEqualTo("Name", "ac") si = New CSelectInCriteria(emp) si.WhereCondition.addSelectEqualTo("Name", "ac") si.SetSelectAttribute("Name") mr.WhereCondition.addSelectNotIn("Name", si) c = mr.perform Assert.IsFalse(c.hasElements) Assert.IsTrue(c.EOF) End Sub <Test()> Public Sub LoadFullObjects() r = New CRetrieveCriteria r.ReturnFullObjects = True c = r.perform(emp) Assert.IsFalse(c.HoldsProxies) 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 c.SetCursor(0) emp = New CEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "ab") End Sub <Test()> Public Sub SimpleOrCriteria() r = New CRetrieveCriteria r.ClassMap = emp.getClassMap r.WhereCondition.addSelectEqualTo("Name", "aa") r.WhereCondition.addSelectEqualTo("Name", "b", True) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 2) c.loadObject(emp) Assert.AreEqual(emp.Name, "aa") c.nextCursor() emp = New CEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "b") End Sub <Test()> Public Sub SelectInList() Dim al As New ArrayList al.Add("aa") al.Add("b") r = New CRetrieveCriteria r.ClassMap = emp.getClassMap r.WhereCondition.addSelectInList("Name", al) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 2) c.loadObject(emp) Assert.AreEqual(emp.Name, "aa") c.nextCursor() emp = New CEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "b") End Sub <Test()> Public Sub SubCriteria() Dim xx_1 As New CCriteriaCondition Dim xx_2 As New CCriteriaCondition Dim xx_3 As New CCriteriaCondition Dim xx_4 As New CCriteriaCondition r = New CRetrieveCriteria r.ClassMap = emp.getClassMap xx_1.ClassMap = r.ClassMap xx_2.ClassMap = r.ClassMap xx_3.ClassMap = r.ClassMap xx_4.ClassMap = r.ClassMap xx_1.addSelectEqualTo("Name", "aa") xx_2.addSelectEqualTo("Name", "ab") xx_1.addSubCriteria(xx_2, True) xx_3.addSelectEqualTo("Name", "ab") xx_4.addSelectEqualTo("Name", "ac") xx_3.addSubCriteria(xx_4, True) r.WhereCondition.addSubCriteria(xx_1, True) r.WhereCondition.addSubCriteria(xx_3, False) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 1) While c.hasElements And Not c.EOF emp = New CEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "ab") c.nextCursor() End While End Sub End Class End Namespace --- NEW FILE: CStudent.vb --- Namespace InheritedClasses Public Class CStudent Inherits CEmployee Private m_course As String Public Property Course() As String Get Return m_course End Get Set(ByVal Value As String) m_course = Value End Set End Property End Class End Namespace --- NEW FILE: CWorker.vb --- Namespace InheritedClasses Public Class CWorker Inherits CEmployee Private m_job As String Public Property Job() As String Get Return m_job End Get Set(ByVal Value As String) m_job = Value End Set End Property End Class End Namespace --- NEW FILE: CEmployee.vb --- Imports AToMSFramework Namespace InheritedClasses <AFTable("employee", "MSA", AFTableAttribute.KeyType.useOIDValue, OIDColumn:="oid"), _ AFAssociation(GetType(CEmployee), "ReportsTo", CUDAMap.CardinalityEnum.ONE_TO_ONE, Name:="boss", Retrieve:=True), _ AFAssociationEntry("boss", "ReportsToOID", "OIDValue"), _ AFAssociation(GetType(CEmployee), "Workers", CUDAMap.CardinalityEnum.ONE_TO_MANY, Retrieve:=True), _ AFAssociationEntry("Workers", "OIDValue", "ReportsToOID")> _ Public Class CEmployee Inherits CPersistentObject Private m_name As String Private m_parentoid As String Private m_parent As CEmployee Private m_children As CPersistentCollection Private m_team As CTeam Private m_teamoid As String <AFColumn("name", Find:=True)> _ Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value SetDirtyFlag() End Set End Property Public Property ReportsTo() As CEmployee Get Return m_parent End Get Set(ByVal Value As CEmployee) If Not Value Is Nothing Then m_parent = Value m_parentoid = Value.OIDValue SetDirtyFlag() End If End Set End Property <AFColumn("parentoid")> _ Public Property ReportsToOID() As String Get If m_parent Is Nothing Then Return m_parentoid Else Return (m_parent.OIDValue) End If End Get Set(ByVal Value As String) m_parentoid = Value SetDirtyFlag() End Set End Property Public Property Workers() As CPersistentCollection Get Return m_children End Get Set(ByVal Value As CPersistentCollection) m_children = Value SetDirtyFlag() End Set End Property Public Property Team() As CTeam Get Return m_team End Get Set(ByVal Value As CTeam) If Not Value Is Nothing Then m_team = Value m_teamoid = Value.OIDValue SetDirtyFlag() End If End Set End Property <AFColumn("teamoid")> _ Public Property TeamOID() As String Get If m_team Is Nothing Then Return m_teamoid Else Return (m_team.OIDValue) End If End Get Set(ByVal Value As String) m_teamoid = Value SetDirtyFlag() End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New CEmployee End Function Public Overrides Function IsValid() As Boolean Return True End Function Public Sub New() MyBase.New() m_children = New CPersistentCollection m_children.ContainerObject = Me End Sub End Class End Namespace --- NEW FILE: AtomsFrameworkTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class _BasicTests Private pbroker As CPersistenceBroker Private emp As CEmployee Private job As CJob Private team As CTeam <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" 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 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 <SetUp()> Public Sub TestInit() emp = New CEmployee job = New CJob team = New CTeam End Sub <Test()> Public Sub LoadSaveandDeleteEmployee() Dim oidvalue As String emp.Name = "new" emp.Find() Assert.IsFalse(emp.Persistent) oidvalue = emp.OIDValue emp.Save() Assert.IsTrue(emp.Persistent) Assert.IsTrue(emp.ReportsTo Is Nothing) Assert.IsFalse(emp.IsReferenced) emp = New CEmployee emp.Name = "new" emp.Find() Assert.IsTrue(emp.Persistent) Assert.AreEqual(emp.OIDValue, oidvalue) Assert.AreEqual(emp.Name, "new") emp.Delete() Assert.IsFalse(emp.Persistent) emp = New CEmployee emp.Name = "new" emp.Find() Assert.IsFalse(emp.Persistent) Assert.IsTrue(emp.OIDValue <> oidvalue) End Sub <Test()> Public Sub ChangeFindFieldValue() Dim oidvalue As String emp.Name = "SaveThenChange" emp.Find() Assert.IsFalse(emp.Persistent) oidvalue = emp.OIDValue emp.Save() Assert.IsTrue(emp.Persistent) Assert.IsTrue(emp.ReportsTo Is Nothing) Assert.IsFalse(emp.IsReferenced) emp = New CEmployee emp.Name = "SaveThenChange" emp.Find() Assert.IsTrue(emp.Persistent) Assert.AreEqual(emp.OIDValue, oidvalue) Assert.AreEqual(emp.Name, "SaveThenChange") emp.Name = "Changed" emp.Save() Assert.IsTrue(emp.Persistent) emp.Delete() Assert.IsFalse(emp.Persistent) emp = New CEmployee emp.Name = "Changed" emp.Find() Assert.IsFalse(emp.Persistent) emp = New CEmployee emp.Name = "SaveThenChange" emp.Find() Assert.IsFalse(emp.Persistent) End Sub <Test()> Public Sub DeleteMultipleEmployees() emp.Name = "DeleteMe1" emp.Save() emp = New CEmployee emp.Name = "DeleteMe2" emp.Save() emp = New CEmployee emp.Name = "DeleteMe3" emp.Save() Dim dc As CDeleteCriteria dc = New CDeleteCriteria dc.ClassMap = emp.getClassMap dc.WhereCondition.addSelectLike("Name", "DeleteMe%") Dim i As Integer = dc.perform() Assert.AreEqual(i, 3) emp = New CEmployee emp.Name = "DeleteMe1" emp.Find() Assert.IsFalse(emp.Persistent) End Sub <Test()> Public Sub LoadEmployee_ac() emp.Name = "ac" emp.Find() Assert.IsTrue(emp.Persistent) Assert.AreEqual(emp.Workers.Count, 3) emp = emp.Workers.Item(1) Assert.AreEqual(emp.Name, "aa") Assert.AreEqual(emp.ReportsTo.Name, "ac") End Sub <Test()> Public Sub LoadEmployee_a() emp.Name = "a" emp.Find() Assert.IsTrue(emp.Persistent) Assert.AreEqual(emp.Workers.Count, 0) Assert.IsTrue(Not emp.ReportsTo Is Nothing) Assert.AreEqual(emp.ReportsTo.Name, "c") End Sub <Test(), ExpectedException(GetType(AssertionException))> _ Public Sub CheckCacheCopiesAreDifferent() Dim emp2 As CEmployee emp.Name = "ac" emp.Find() emp2 = New CEmployee emp2.Find() Assert.AreSame(emp2, emp) End Sub <Test()> Public Sub PersistentObjectEquality() Dim emp2 As CEmployee emp.Name = "ac" emp.Find() emp2 = New CEmployee emp2.Name = "aa" emp2.Find() Assert.IsTrue(CPersistentObject.Equals(emp2.ReportsTo, emp)) Assert.IsTrue(emp.Equals(emp2.ReportsTo)) End Sub <Test()> Public Sub CheckSchemaBasedProperties() emp.Name = "ac" emp.Find() Assert.AreEqual(emp.getFieldLengthByName("Name"), 50) Assert.IsTrue(emp.getFieldTypeByName("Name") Is GetType([String])) End Sub <Test()> Public Sub CacheTest() emp.Name = "Initial" emp.Find() Assert.IsFalse(emp.Persistent) emp.Save() pbroker.ClearCache() emp = New CEmployee emp.Name = "Initial" emp.Find() emp.Name = "Final" emp.Save() Assert.AreEqual("Final", emp.Name) emp = New CEmployee emp.Name = "Initial" emp.Find() Assert.IsFalse(emp.Persistent) emp.Name = "Final" emp.Find() Assert.IsTrue(emp.Persistent) End Sub End Class End Namespace |
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19366 Modified Files: AtomsFramework.xml Nunit_AtomsFramework.vbproj Removed Files: AtomsFrameworkTests.vb CEmployee.vb CJob.vb CSharedClasses.vb CStudent.vb CTeam.vb CWorker.vb EmployeeInterfaceTests.vb IEmployee.vb NPEmployee.vb NPJob.vb NPTeam.vb NonInheritedRetreiveCriteria.vb NonInheritedTests.vb RetrieveCriteriaTests.vb SharedTests.vb Log Message: Rearrange unit test structure (extra namespaces and folders) --- CJob.vb DELETED --- --- NPJob.vb DELETED --- --- IEmployee.vb DELETED --- --- NonInheritedTests.vb DELETED --- --- RetrieveCriteriaTests.vb DELETED --- --- CStudent.vb DELETED --- --- AtomsFrameworkTests.vb DELETED --- --- CWorker.vb DELETED --- --- NPTeam.vb DELETED --- --- CSharedClasses.vb DELETED --- --- NPEmployee.vb DELETED --- --- SharedTests.vb DELETED --- Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Nunit_AtomsFramework.vbproj 18 Oct 2004 01:38:39 -0000 1.7 +++ Nunit_AtomsFramework.vbproj 19 Oct 2004 00:13:37 -0000 1.8 @@ -20,8 +20,8 @@ OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" - RootNamespace = "Nunit_AtomsFramework" - StartupObject = "" + RootNamespace = "NunitTests" + StartupObject = "NunitTests.(None)" > <Config Name = "Debug" @@ -105,82 +105,82 @@ BuildAction = "Content" /> <File - RelPath = "AtomsFrameworkTests.vb" + RelPath = "InheritedClasses\AtomsFrameworkTests.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "CEmployee.vb" + RelPath = "InheritedClasses\CEmployee.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "CJob.vb" + RelPath = "InheritedClasses\CJob.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "CSharedClasses.vb" + RelPath = "InheritedClasses\CSharedClasses.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "CStudent.vb" + RelPath = "InheritedClasses\CStudent.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "CTeam.vb" + RelPath = "InheritedClasses\CTeam.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "CWorker.vb" + RelPath = "InheritedClasses\CWorker.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "EmployeeInterfaceTests.vb" + RelPath = "InheritedClasses\RetrieveCriteriaTests.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "IEmployee.vb" + RelPath = "InheritedClasses\SharedTests.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "NonInheritedRetreiveCriteria.vb" + RelPath = "Interfaces\EmployeeInterfaceTests.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "NonInheritedTests.vb" + RelPath = "Interfaces\IEmployee.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "NPEmployee.vb" + RelPath = "StandardClasses\NonInheritedRetreiveCriteria.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "NPJob.vb" + RelPath = "StandardClasses\NonInheritedTests.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "NPTeam.vb" + RelPath = "StandardClasses\NPEmployee.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "RetrieveCriteriaTests.vb" + RelPath = "StandardClasses\NPJob.vb" SubType = "Code" BuildAction = "Compile" /> <File - RelPath = "SharedTests.vb" + RelPath = "StandardClasses\NPTeam.vb" SubType = "Code" BuildAction = "Compile" /> --- CTeam.vb DELETED --- --- CEmployee.vb DELETED --- --- EmployeeInterfaceTests.vb DELETED --- Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- AtomsFramework.xml 18 Oct 2004 01:38:39 -0000 1.5 +++ AtomsFramework.xml 19 Oct 2004 00:13:37 -0000 1.6 @@ -7,27 +7,27 @@ <parameter name="OIDTable" value="OID"/> </database> -<class name="SharedParent" table="SharedClasses" database="MSA"> +<class name="SharedParent" table="SharedClasses" database="MSA" namespace="NunitTests.InheritedClasses"> <attribute name="OIDValue" column="oid" key="primary"/> <attribute name="CreatedDate" column="created" timestamp="true"/> <attribute name="ModifiedDate" column="modified" timestamp="true"/> </class> -<class name="SharedChild" table="SharedClasses" superclass="SharedParent" database="MSA" sharedtablefield="IType" sharedtablevalue="PLN"> +<class name="SharedChild" table="SharedClasses" superclass="SharedParent" database="MSA" sharedtablefield="IType" sharedtablevalue="PLN" namespace="NunitTests.InheritedClasses"> </class> -<class name="NPJob" table="NPJobs" database="MSA"> +<class name="NPJob" table="NPJobs" database="MSA" namespace="NunitTests.StandardClasses"> <attribute name="Id" column="id" key="primary"/> <attribute name="Description" column="description"/> </class> -<class name="NPJobWithOIDValue" table="jobs" database="MSA"> +<class name="NPJobWithOIDValue" table="jobs" database="MSA" namespace="NunitTests.StandardClasses"> <attribute name="OIDValue" column="oidvalue" key="primary"/> <attribute name="Description" column="description" find="true"/> </class> -<class name="NPEmployee" table="employee" database="MSA"> +<class name="NPEmployee" table="employee" database="MSA" namespace="NunitTests.StandardClasses"> <attribute name="OIDValue" column="oid" key="primary"/> <attribute name="Name" column="name" find="true"/> <attribute name="ReportsToOID" column="parentoid" /> @@ -37,17 +37,17 @@ <attribute name="Workers" /> </class> - <association fromClass="NPEmployee" toClass="NPEmployee" target="ReportsTo" cardinality="OneToOne" + <association fromClass="NunitTests.StandardClasses.NPEmployee" toClass="NunitTests.StandardClasses.NPEmployee" target="ReportsTo" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="ReportsToOID" toAttribute="OIDValue"/> </association> - <association fromClass="NPEmployee" toClass="NPEmployee" target="Workers" cardinality="OneToMany" + <association fromClass="NunitTests.StandardClasses.NPEmployee" toClass="NunitTests.StandardClasses.NPEmployee" target="Workers" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> </association> -<class name="NPTeam" table="teams" database="MSA"> +<class name="NPTeam" table="teams" database="MSA" namespace="NunitTests.StandardClasses"> <attribute name="OIDValue" column="oidvalue" key="primary"/> <attribute name="Name" column="teamname" find="true"/> <attribute name="TeamLeaderOID" column="teamleader" /> @@ -56,22 +56,22 @@ <attribute name="Job" /> </class> - <association fromClass="NPTeam" toClass="NPEmployee" target="TeamLeader" cardinality="OneToOne" + <association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPEmployee" target="TeamLeader" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> <entry fromAttribute="TeamLeaderOID" toAttribute="OIDValue"/> </association> - <association fromClass="NPTeam" toClass="NPJobWithOIDValue" target="Job" cardinality="OneToOne" + <association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPJobWithOIDValue" target="Job" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> <entry fromAttribute="jobOID" toAttribute="OIDValue"/> </association> - <association fromClass="NPTeam" toClass="NPEmployee" target="Members" cardinality="OneToMany" + <association fromClass="NunitTests.StandardClasses.NPTeam" toClass="NunitTests.StandardClasses.NPEmployee" target="Members" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> <entry fromAttribute="OIDValue" toAttribute="TeamOID"/> </association> -<class name="IEmployee" table="employee" database="MSA" factory="IEmployeeFactory"> +<class name="IEmployee" table="employee" database="MSA" factory="IEmployeeFactory" namespace="NunitTests.Interfaces"> <attribute name="OIDValue" column="oid" key="primary"/> <attribute name="Name" column="name" find="true"/> <attribute name="ReportsToOID" column="parentoid" /> @@ -81,12 +81,12 @@ <attribute name="Workers" /> </class> - <association fromClass="IEmployee" toClass="IEmployee" target="ReportsTo" cardinality="OneToOne" + <association fromClass="NunitTests.Interfaces.IEmployee" toClass="NunitTests.Interfaces.IEmployee" target="ReportsTo" cardinality="OneToOne" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="ReportsToOID" toAttribute="OIDValue"/> </association> - <association fromClass="IEmployee" toClass="IEmployee" target="Workers" cardinality="OneToMany" + <association fromClass="NunitTests.Interfaces.IEmployee" toClass="NunitTests.Interfaces.IEmployee" target="Workers" cardinality="OneToMany" retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> </association> --- NonInheritedRetreiveCriteria.vb DELETED --- |
From: Richard B. <rb...@us...> - 2004-10-19 00:12:41
|
Update of /cvsroot/jcframework/Nunit/StandardClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19152/StandardClasses Log Message: Directory /cvsroot/jcframework/Nunit/StandardClasses added to the repository |
From: Richard B. <rb...@us...> - 2004-10-19 00:12:41
|
Update of /cvsroot/jcframework/Nunit/Interfaces In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19152/Interfaces Log Message: Directory /cvsroot/jcframework/Nunit/Interfaces added to the repository |
From: Richard B. <rb...@us...> - 2004-10-19 00:12:41
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19152/InheritedClasses Log Message: Directory /cvsroot/jcframework/Nunit/InheritedClasses added to the repository |
From: Richard B. <rb...@us...> - 2004-10-18 22:31:26
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25410 Added Files: IClassFactory.vb Log Message: Oops - missed this in the last update :-( --- NEW FILE: IClassFactory.vb --- Public Interface IClassFactory Function CreateObject() As Object End Interface |
From: Richard B. <rb...@us...> - 2004-10-18 03:32:02
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15129 Modified Files: CClassMap.vb CConnection.vb CCursor.vb CMsAccessDatabase.vb CMsSqlDatabase.vb CMySqlDatabase.vb CODBCDatabase.vb CPersistenceBroker.vb CRelationalDatabase.vb CSqlStatement.vb Log Message: Fixed for ANSI Null behaviour. New parameter in Db config called "ansinulls" to control behaviour of the system when generating SQL for NULL values in the where clause. (bug 1046809) Index: CRelationalDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CRelationalDatabase.vb,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- CRelationalDatabase.vb 28 Sep 2004 07:30:33 -0000 1.19 +++ CRelationalDatabase.vb 18 Oct 2004 03:31:51 -0000 1.20 @@ -49,6 +49,7 @@ ''' </history> '''----------------------------------------------------------------------------- Property ConnectionPool() As Stack + Property UseANSINulls() As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' Releases a connection @@ -582,6 +583,7 @@ Private m_connectionPool As Stack Private m_name As String Private m_oidTablename As String + Private m_useAnsiNulls As Boolean Protected m_disposed As Boolean '''----------------------------------------------------------------------------- @@ -641,6 +643,15 @@ End Set End Property + Public Property UseANSINulls() As Boolean Implements _CRelationalDatabase.UseANSINulls + Get + Return m_useAnsiNulls + End Get + Set(ByVal Value As Boolean) + m_useAnsiNulls = Value + End Set + End Property + Public Sub New() MyBase.New() m_connectionPool = New Stack Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- CPersistenceBroker.vb 18 Oct 2004 01:36:43 -0000 1.67 +++ CPersistenceBroker.vb 18 Oct 2004 03:31:51 -0000 1.68 @@ -298,28 +298,28 @@ End If obj.IsLoading = True - Dim statement As CSqlStatement - If useFind Then - statement = cm.getSQLFind(Me, Nothing) - Else - statement = cm.getSQLRetrieve(Me, Nothing) - End If + Dim statement As New CSqlStatement cm2 = cm Do If useFind Then For i = 1 To cm2.getFindSize am = cm2.FindAttributeMaps(i) - statement.addSqlParameter(i, obj.getValueByAttribute(am.Name), am.ColumnMap) + statement.addSqlParameter(i, obj.GetValueByAttribute(am.Name), am.ColumnMap) Next i cm2 = cm2.SuperClass Else For i = 1 To cm2.getKeySize am = cm2.getKeyAttributeMap(i) - statement.addSqlParameter(i, obj.getValueByAttribute(am.Name), am.ColumnMap) + statement.addSqlParameter(i, obj.GetValueByAttribute(am.Name), am.ColumnMap) Next i cm2 = Nothing End If Loop While Not cm2 Is Nothing + If useFind Then + statement.SqlString = cm.getSQLFind(Me, statement.Parameters) + Else + statement.SqlString = cm.getSQLRetrieve(Me, statement.Parameters) + End If joins = cm.Joins @@ -377,11 +377,11 @@ '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 - targetobj = obj.getObjectByAttribute(udamap.Target) + targetobj = obj.GetObjectByAttribute(udamap.Target) If Not targetobj Is Nothing Then 'if the class as child classes then check if the targetobj is of type child If cm2.ChildrenMaps.Count > 0 Then - cm3 = targetobj.getClassMap() + cm3 = targetobj.GetClassMap() cm2.retrieveObject(cm3, targetobj, rs, joins.GetTableAlias(cm3)) Else cm2.retrieveObject(cm2, targetobj, rs, mapName) @@ -455,7 +455,7 @@ End If End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then - col = obj.getCollectionByAttribute(udamap.Target) + col = obj.GetCollectionByAttribute(udamap.Target) 'Check whether the object is of child type If udamap.ForClass.ChildrenMaps.Count > 0 Then Index: CCursor.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCursor.vb,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- CCursor.vb 18 Oct 2004 00:08:10 -0000 1.10 +++ CCursor.vb 18 Oct 2004 03:31:51 -0000 1.11 @@ -236,17 +236,25 @@ ''' </history> '''----------------------------------------------------------------------------- Public Sub loadObject(ByRef obj As Object) - loadObject(obj, 0) + If obj.GetType.IsSubclassOf(GetType(CPersistentObject)) OrElse TypeOf (obj) Is CPersistentObject Then + loadPersistentObject(obj) + Else + loadObject(obj, 0) + End If End Sub Public Sub loadObject(ByRef obj As Object, ByVal offset As Integer) + If obj.GetType.IsSubclassOf(GetType(CPersistentObject)) OrElse TypeOf (obj) Is CPersistentObject Then + loadPersistentObject(obj, offset) + Exit Sub + End If Dim _alias As String = "" Dim mr As CMultiRetrieveCriteria Dim clMap As CClassMap Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance Dim injObj As CInjectedObject - injobj = pbroker.LocateOrCreateInjObject(obj) + injObj = pbroker.LocateOrCreateInjObject(obj) If Not m_parentCriteria Is Nothing Then If m_parentCriteria.GetType Is GetType(CMultiRetrieveCriteria) Then mr = m_parentCriteria @@ -272,11 +280,11 @@ clMap = pbroker.getClassMap(obj.GetType) If Not m_holdsProxies Then - clMap.retrieveObject(injobj, m_row) + clMap.retrieveObject(injObj, m_row) If clMap.AssociationMapCount > 0 Then - injobj.AssociationsLoaded = False + injObj.AssociationsLoaded = False Else - injobj.AssociationsLoaded = True + injObj.AssociationsLoaded = True End If pbroker.InjectedObjects.Add(injObj) Else @@ -287,7 +295,7 @@ End If End Sub - Public Sub loadObject(ByRef obj As CPersistentObject) + Public Sub loadPersistentObject(ByRef obj As CPersistentObject) loadObject(obj, 0) End Sub @@ -314,7 +322,7 @@ ''' [rbanks] 4/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub loadObject(ByRef obj As CPersistentObject, ByVal offset As Integer) + Public Sub loadPersistentObject(ByRef obj As CPersistentObject, ByVal offset As Integer) 'TO DO: Handle errors Dim _alias As String = "" Dim cm As CMultiRetrieveCriteria Index: CMsSqlDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMsSqlDatabase.vb,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- CMsSqlDatabase.vb 11 Oct 2004 23:03:38 -0000 1.18 +++ CMsSqlDatabase.vb 18 Oct 2004 03:31:51 -0000 1.19 @@ -99,6 +99,11 @@ m_serverName = properties.Item("serverName") m_user = properties.Item("user") m_password = properties.Item("password") + If properties.Item("ansinulls") Is Nothing Then + UseANSINulls = False + Else + UseANSINulls = properties.Item("ansinulls") + End If MyBase.OIDTable = properties.Item("OIDTable") End Sub Index: CConnection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CConnection.vb,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- CConnection.vb 6 Oct 2004 23:42:24 -0000 1.26 +++ CConnection.vb 18 Oct 2004 03:31:51 -0000 1.27 @@ -413,11 +413,13 @@ m_command.CommandText = statement.SqlString 'new bit for parameters For Each cp In statement.Parameters - param = New OleDbParameter - param.ParameterName = cp.Name - param.OleDbType = CType(cp.Column.ProviderType, System.Data.OleDb.OleDbType) - param.Value = cp.Value - m_command.Parameters.Add(param) + If Not cp.Ignore Then + param = New OleDbParameter + param.ParameterName = cp.Name + param.OleDbType = CType(cp.Column.ProviderType, System.Data.OleDb.OleDbType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If Next m_command.Transaction = m_transaction @@ -455,11 +457,13 @@ m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters - param = New OleDbParameter - param.ParameterName = cp.Name - param.OleDbType = CType(cp.Column.ProviderType, OleDbType) - param.Value = cp.Value - m_command.Parameters.Add(param) + If Not cp.Ignore Then + param = New OleDbParameter + param.ParameterName = cp.Name + param.OleDbType = CType(cp.Column.ProviderType, OleDbType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If Next Try @@ -866,20 +870,22 @@ m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters - param = New SqlParameter - param.ParameterName = cp.Name - param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) - If TypeOf (cp.Value) Is DateTime Then - dd = cp.Value - If dd.Ticks = 0 Then - dd = DateAdd(DateInterval.Year, 1899, dd) - Else - dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) + If Not cp.Ignore Then + param = New SqlParameter + param.ParameterName = cp.Name + param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) + If TypeOf (cp.Value) Is DateTime Then + dd = cp.Value + If dd.Ticks = 0 Then + dd = DateAdd(DateInterval.Year, 1899, dd) + Else + dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) + End If + cp.Value = dd End If - cp.Value = dd + param.Value = cp.Value + m_command.Parameters.Add(param) End If - param.Value = cp.Value - m_command.Parameters.Add(param) Next m_command.Transaction = m_transaction Debug.WriteLine(m_command.CommandText) @@ -920,20 +926,22 @@ m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters - param = New SqlParameter - param.ParameterName = cp.Name - param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) - If TypeOf (cp.Value) Is DateTime Then - dd = cp.Value - If dd.Ticks = 0 Then - dd = DateAdd(DateInterval.Year, 1899, dd) - Else - dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) + If Not cp.Ignore Then + param = New SqlParameter + param.ParameterName = cp.Name + param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) + If TypeOf (cp.Value) Is DateTime Then + dd = cp.Value + If dd.Ticks = 0 Then + dd = DateAdd(DateInterval.Year, 1899, dd) + Else + dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) + End If + cp.Value = dd End If - cp.Value = dd + param.Value = cp.Value + m_command.Parameters.Add(param) End If - param.Value = cp.Value - m_command.Parameters.Add(param) Next Try @@ -1370,11 +1378,13 @@ m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters - param = New MySqlParameter - param.ParameterName = cp.Name - param.MySqlDbType = CType(cp.Column.ProviderType, MySqlDbType) - param.Value = cp.Value - m_command.Parameters.Add(param) + If Not cp.Ignore Then + param = New MySqlParameter + param.ParameterName = cp.Name + param.MySqlDbType = CType(cp.Column.ProviderType, MySqlDbType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If Next m_command.Transaction = m_transaction m_recordcount = m_command.ExecuteNonQuery() @@ -1414,11 +1424,13 @@ m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters - param = New MySqlParameter - param.ParameterName = cp.Name - param.MySqlDbType = CType(cp.Column.ProviderType, MySqlDbType) - param.Value = cp.Value - m_command.Parameters.Add(param) + If Not cp.Ignore Then + param = New MySqlParameter + param.ParameterName = cp.Name + param.MySqlDbType = CType(cp.Column.ProviderType, MySqlDbType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If Next Try @@ -1793,11 +1805,13 @@ m_command.CommandText = statement.SqlString 'new bit for parameters For Each cp In statement.Parameters - param = New OdbcParameter - param.ParameterName = cp.Name - param.OdbcType = CType(cp.Column.ProviderType, System.Data.odbc.OdbcType) - param.Value = cp.Value - m_command.Parameters.Add(param) + If Not cp.Ignore Then + param = New OdbcParameter + param.ParameterName = cp.Name + param.OdbcType = CType(cp.Column.ProviderType, System.Data.odbc.OdbcType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If Next m_command.Transaction = m_transaction @@ -1834,11 +1848,13 @@ m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters - param = New OdbcParameter - param.ParameterName = cp.Name - param.OdbcType = CType(cp.Column.ProviderType, System.Data.odbc.OdbcType) - param.Value = cp.Value - m_command.Parameters.Add(param) + If Not cp.Ignore Then + param = New OdbcParameter + param.ParameterName = cp.Name + param.OdbcType = CType(cp.Column.ProviderType, System.Data.odbc.OdbcType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If Next Try Index: CODBCDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CODBCDatabase.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CODBCDatabase.vb 28 Sep 2004 07:30:32 -0000 1.4 +++ CODBCDatabase.vb 18 Oct 2004 03:31:51 -0000 1.5 @@ -51,6 +51,11 @@ '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As HybridDictionary) m_connectionString = properties.Item("name") + If properties.Item("ansinulls") Is Nothing Then + UseANSINulls = False + Else + UseANSINulls = properties.Item("ansinulls") + End If MyBase.OIDTable = properties.Item("OIDTable") End Sub Index: CMySqlDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMySqlDatabase.vb,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- CMySqlDatabase.vb 28 Sep 2004 07:30:32 -0000 1.19 +++ CMySqlDatabase.vb 18 Oct 2004 03:31:51 -0000 1.20 @@ -120,6 +120,11 @@ m_password = properties.Item("password") m_portNumber = properties.Item("portNumber") m_option = properties.Item("option") + If properties.Item("ansinulls") Is Nothing Then + UseANSINulls = False + Else + UseANSINulls = properties.Item("ansinulls") + End If MyBase.OIDTable = properties.Item("OIDTable") End Sub Index: CMsAccessDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMsAccessDatabase.vb,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- CMsAccessDatabase.vb 28 Sep 2004 07:30:32 -0000 1.17 +++ CMsAccessDatabase.vb 18 Oct 2004 03:31:51 -0000 1.18 @@ -55,6 +55,11 @@ m_name = properties.Item("name") m_user = properties.Item("user") m_password = properties.Item("password") + If properties.Item("ansinulls") Is Nothing Then + UseANSINulls = False + Else + UseANSINulls = properties.Item("ansinulls") + End If MyBase.OIDTable = properties.Item("OIDTable") End Sub Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- CClassMap.vb 18 Oct 2004 01:36:43 -0000 1.35 +++ CClassMap.vb 18 Oct 2004 03:31:51 -0000 1.36 @@ -63,6 +63,8 @@ Private m_joinSet As CJoin Private m_sqlFindStatement As CSqlStatement Private m_sqlRetrieveStatement As CSqlStatement + Private m_updateWhereParamPosition As Integer + Private m_insertWhereParamPosition As Integer Private m_classFactoryName As String Private m_classFactory As IClassFactory @@ -777,17 +779,33 @@ m_deleteStatement.addSqlClause(Me.RelationalDatabase.getClauseStringWhere & " ") For i = 1 To Me.getKeySize map = Me.getKeyAttributeMap(i) - If i = 1 Then - 'm_deleteStatement.addSqlClause(map.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(map.Name)))) - m_deleteStatement.addSqlClause(map.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(i)) - Else - 'm_deleteStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & map.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(map.Name)))) - m_deleteStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & map.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(i)) + If i > 1 Then + m_deleteStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " ") End If + 'm_deleteStatement.addSqlClause(map.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(map.Name)))) + 'm_deleteStatement.addSqlClause(map.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(i)) + m_deleteStatement.addSqlClause(map.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo("_" & i.ToString & "_")) m_deleteStatement.addSqlParameter(i, obj.GetValueByAttribute(map.Name), map.ColumnMap) Next i End If - getDeleteSqlFor = m_deleteStatement + + Dim x As String = m_deleteStatement.SqlString + Dim p As CSQLParameter + For i = 1 To Me.getKeySize + p = m_deleteStatement.Parameters.Item(i) + If IsNullAlias(p.Value) Then + If Me.RelationalDatabase.UseANSINulls = False Then + x = x.Replace(" = _" & i.ToString & "_", " is NULL") + p.Ignore = True + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) + End If + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) + End If + Next + m_deleteStatement.SqlString = x + Return m_deleteStatement End Function '''----------------------------------------------------------------------------- @@ -1216,107 +1234,122 @@ ''' </history> '''----------------------------------------------------------------------------- Public Function getUpdateSqlFor(ByVal obj As IPersistableObject) As CSqlStatement - If Not m_updateStatement Is Nothing Then - m_updateStatement = Nothing - End If + Dim AttrMap As CAttributeMap Dim i As Short, paramCount As Short Dim isFirst As Boolean - If m_updateStatement Is Nothing Then - 'New statement - m_updateStatement = New CSqlStatement - 'Add UPDATE clause - 'Use the save query to improve speed if it exists - If m_sqlUpdateStub.Length > 0 Then - m_updateStatement.addSqlClause(m_sqlUpdateStub) - Else - m_updateStatement.addSqlClause(RelationalDatabase.getClauseStringUpdate & " ") - AttrMap = getAttributeMap(1) - If Not AttrMap Is Nothing Then - m_updateStatement.addSqlClause(AttrMap.ColumnMap.TableMap.Name & " ") - End If - 'add each field - m_updateStatement.addSqlClause(RelationalDatabase.getClauseStringSet & " ") - isFirst = True - For i = 1 To Me.getSize - AttrMap = Me.getAttributeMap(i) - If Not AttrMap.ColumnMap.IsIdentity Then - If Not isFirst Then - m_updateStatement.addSqlClause(", " & Me.getAttributeMap(i).ColumnMap.Name & "=" & m_relationalDatabase.getParamHolder(i)) - Else - 'This is the first attribute - m_updateStatement.addSqlClause("" & Me.getAttributeMap(i).ColumnMap.Name & "=" & m_relationalDatabase.getParamHolder(i)) - isFirst = False - End If - End If - Next i - m_sqlUpdateStub = m_updateStatement.SqlString + m_updateStatement = New CSqlStatement + 'Add UPDATE clause + 'Use the save query to improve speed if it exists + If m_sqlUpdateStub.Length > 0 Then + m_updateStatement.addSqlClause(m_sqlUpdateStub) + Else + m_updateStatement.addSqlClause(RelationalDatabase.getClauseStringUpdate & " ") + AttrMap = getAttributeMap(1) + If Not AttrMap Is Nothing Then + m_updateStatement.addSqlClause(AttrMap.ColumnMap.TableMap.Name & " ") End If - - 'Add Parameter values + 'add each field + m_updateStatement.addSqlClause(RelationalDatabase.getClauseStringSet & " ") + isFirst = True For i = 1 To Me.getSize AttrMap = Me.getAttributeMap(i) If Not AttrMap.ColumnMap.IsIdentity Then - m_updateStatement.addSqlParameter(i, obj.GetValueByAttribute(AttrMap.Name), AttrMap.ColumnMap) + If Not isFirst Then + m_updateStatement.addSqlClause(", " & Me.getAttributeMap(i).ColumnMap.Name & "=" & m_relationalDatabase.getParamHolder(i)) + Else + 'This is the first attribute + m_updateStatement.addSqlClause("" & Me.getAttributeMap(i).ColumnMap.Name & "=" & m_relationalDatabase.getParamHolder(i)) + isFirst = False + End If End If Next i - paramCount = Me.getSize - 'Add WHERE clause - m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringWhere & " ") - isFirst = True + m_sqlUpdateStub = m_updateStatement.SqlString + End If + m_updateWhereParamPosition = Me.getSize - 'Need to set where clause based on original values for key fields, - 'not on the current values, otherwise the update statement - 'may reference a non-existant column, or a wrong record. - 'Note: this would only occur if the key values for an object were changed - Dim keyValuesCol As New Collection - If Not obj.OriginalCacheKey Is Nothing Then - For i = 1 To Me.getKeySize - AttrMap = Me.getKeyAttributeMap(i) - 'keyValuesCol.Add(m_relationalDatabase.getValueFor(obj.OriginalCacheKey.GetKeyValue(i))) - keyValuesCol.Add(obj.OriginalCacheKey.GetKeyValue(i)) - Next - Else - For i = 1 To Me.getKeySize - AttrMap = Me.getKeyAttributeMap(i) - 'keyValuesCol.Add(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name))) - keyValuesCol.Add(obj.GetValueByAttribute(AttrMap.Name)) - Next + 'Add Parameter values + For i = 1 To Me.getSize + AttrMap = Me.getAttributeMap(i) + If Not AttrMap.ColumnMap.IsIdentity Then + m_updateStatement.addSqlParameter(i, obj.GetValueByAttribute(AttrMap.Name), AttrMap.ColumnMap) End If + Next i + paramCount = Me.getSize + 'Add WHERE clause + m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringWhere & " ") + isFirst = True + 'Need to set where clause based on original values for key fields, + 'not on the current values, otherwise the update statement + 'may reference a non-existant column, or a wrong record. + 'Note: this would only occur if the key values for an object were changed + Dim keyValuesCol As New Collection + If Not obj.OriginalCacheKey Is Nothing Then For i = 1 To Me.getKeySize AttrMap = Me.getKeyAttributeMap(i) + 'keyValuesCol.Add(m_relationalDatabase.getValueFor(obj.OriginalCacheKey.GetKeyValue(i))) + keyValuesCol.Add(obj.OriginalCacheKey.GetKeyValue(i)) + Next + Else + For i = 1 To Me.getKeySize + AttrMap = Me.getKeyAttributeMap(i) + 'keyValuesCol.Add(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name))) + keyValuesCol.Add(obj.GetValueByAttribute(AttrMap.Name)) + Next + End If + + For i = 1 To Me.getKeySize + AttrMap = Me.getKeyAttributeMap(i) + paramCount += 1 + If Not isFirst Then + 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(keyValuesCol.Item(i)))) + 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & AttrMap.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) + m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd) + End If + 'm_updateStatement.addSqlClause("" & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(keyValuesCol.Item(i)))) + 'm_updateStatement.addSqlClause(AttrMap.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) + m_updateStatement.addSqlClause(" " & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo("_" & paramCount.ToString & "_")) + isFirst = False + m_updateStatement.addSqlParameter(paramCount, keyValuesCol.Item(i), AttrMap.ColumnMap) + Next i + If Not Me.SharedTableField Is Nothing Then + If Not isFirst Then + m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.SharedTableField & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(Me.SharedTableValue))) + Else + m_updateStatement.addSqlClause("" & RelationalDatabase.getClauseStringAnd & " " & Me.SharedTableField & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(Me.SharedTableValue))) + isFirst = False + End If + End If + For i = 1 To Me.getSize + 'process timestamp attributes + If Me.getAttributeMap(i).isTimeStamp Then paramCount += 1 - If Not isFirst Then - 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(keyValuesCol.Item(i)))) - m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & AttrMap.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) - Else - 'm_updateStatement.addSqlClause("" & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(keyValuesCol.Item(i)))) - m_updateStatement.addSqlClause("" & AttrMap.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) - isFirst = False - End If - m_updateStatement.addSqlParameter(paramCount, keyValuesCol.Item(i), AttrMap.ColumnMap) - Next i - If Not Me.SharedTableField Is Nothing Then - If Not isFirst Then - m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.SharedTableField & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(Me.SharedTableValue))) + 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute("Original" & Me.getAttributeMap(i).Name)))) + 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) + m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo("_" & paramCount.ToString & "_")) + m_updateStatement.addSqlParameter(paramCount, obj.GetValueByAttribute("Original" & Me.getAttributeMap(i).Name), Me.getAttributeMap(i).ColumnMap) + End If + Next i + + Dim x As String = m_updateStatement.SqlString + Dim p As CSQLParameter + For i = m_updateWhereParamPosition To m_updateStatement.Parameters.Count + p = m_updateStatement.Parameters.Item(i) + If IsNullAlias(p.Value) Then + If Me.RelationalDatabase.UseANSINulls = False Then + x = x.Replace(" = _" & i.ToString & "_", " is NULL") + p.Ignore = True Else - m_updateStatement.addSqlClause("" & RelationalDatabase.getClauseStringAnd & " " & Me.SharedTableField & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(Me.SharedTableValue))) - isFirst = False + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) End If + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) End If - For i = 1 To Me.getSize - 'process timestamp attributes - If Me.getAttributeMap(i).isTimeStamp Then - paramCount += 1 - 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute("Original" & Me.getAttributeMap(i).Name)))) - m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) - m_updateStatement.addSqlParameter(paramCount, obj.GetValueByAttribute("Original" & Me.getAttributeMap(i).Name), Me.getAttributeMap(i).ColumnMap) - End If - Next i - End If - getUpdateSqlFor = m_updateStatement + Next + m_updateStatement.SqlString = x + Return m_updateStatement End Function '''----------------------------------------------------------------------------- @@ -1740,23 +1773,26 @@ Return False End Function - Public Function getSQLRetrieve(ByRef pbroker As CPersistenceBroker, ByVal args As ArrayList) As CSqlStatement + Public Function getSQLRetrieve(ByRef pbroker As CPersistenceBroker, ByVal params As Collection) As String Dim statement As New CSqlStatement Dim i As Integer = 1 If m_sqlRetrieveStub.Length > 0 Then - statement.SqlString = m_sqlRetrieveStub - Return statement - 'Dim x As String = m_sqlRetrieveStub - 'For Each s As String In args - ' If s = "NULL" Then - ' x = x.Replace(" = _" & i.ToString & "_", " is NULL") - ' Else - ' x = x.Replace("_" & i.ToString & "_", s) - ' End If - ' i += 1 - 'Next - 'statement.SqlString = x - 'Return statement + Dim x As String = m_sqlRetrieveStub + Dim o As CSQLParameter + For i = 1 To params.Count + o = params.Item(i) + If IsNullAlias(o.Value) Then + If Me.RelationalDatabase.UseANSINulls = True Then + x = x.Replace(" = _" & i.ToString & "_", " is NULL") + o.Ignore = True + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) + End If + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) + End If + Next + Return x End If Dim rMaps As New HybridDictionary @@ -1843,10 +1879,10 @@ Else isfirst = False End If - 'statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - ' & cm2.RelationalDatabase.getClauseStringEqualTo("_" & i.ToString & "_")) statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - & " = " & cm2.RelationalDatabase.getParamHolder(i)) + & 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 @@ -1854,26 +1890,30 @@ m_sqlRetrieveStub = statement.SqlString 'Now that we've built the string we need to fill in the values - Return getSQLRetrieve(pbroker, args) + Return getSQLRetrieve(pbroker, params) End Function - Public Function getSQLFind(ByRef pbroker As CPersistenceBroker, ByVal args As ArrayList) As CSqlStatement + Public Function getSQLFind(ByRef pbroker As CPersistenceBroker, ByVal params As Collection) As String Dim statement As New CSqlStatement Dim i As Integer = 1 + If m_sqlFindStub.Length > 0 Then - statement.SqlString = m_sqlFindStub - Return statement - 'Dim x As String = m_sqlFindStub - 'For Each s As String In args - ' If s = "NULL" Then - ' x = x.Replace(" = _" & i.ToString & "_", " is NULL") - ' Else - ' x = x.Replace("_" & i.ToString & "_", s) - ' End If - ' i += 1 - 'Next - 'statement.SqlString = x - 'Return statement + Dim x As String = m_sqlFindStub + Dim o As Object + For i = 1 To params.Count + o = params.Item(i) + If IsNullAlias(o.value) Then + If Me.RelationalDatabase.UseANSINulls = False Then + x = x.Replace(" = _" & i.ToString & "_", " is NULL") + o.Ignore = True + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) + End If + Else + x = x.Replace("_" & i.ToString & "_", Me.RelationalDatabase.getParamHolder(i)) + End If + Next + Return x End If Dim rMaps As New HybridDictionary @@ -1962,10 +2002,10 @@ Else isfirst = False End If - 'statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - ' & cm2.RelationalDatabase.getClauseStringEqualTo("_" & i.ToString & "_")) statement.addSqlClause(" " & am.ColumnMap.getAliasQualifiedName(mapName) _ - & " = " & cm2.RelationalDatabase.getParamHolder(i)) + & 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 @@ -1973,7 +2013,7 @@ m_sqlFindStub = statement.SqlString 'Now that we've built the string we need to fill in the values - Return getSQLFind(pbroker, args) + Return getSQLFind(pbroker, params) End Function Public ReadOnly Property Joins() As CJoin Index: CSqlStatement.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CSqlStatement.vb,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- CSqlStatement.vb 7 Oct 2004 05:57:33 -0000 1.10 +++ CSqlStatement.vb 18 Oct 2004 03:31:51 -0000 1.11 @@ -171,9 +171,10 @@ ''' </history> '''----------------------------------------------------------------------------- Friend Class CSQLParameter - Public m_Name As String - Public m_Column As CColumnMap - Public m_Value As Object + Private m_Name As String + Private m_Column As CColumnMap + Private m_Value As Object + Private m_ignore As Boolean '''----------------------------------------------------------------------------- ''' <summary> @@ -230,5 +231,14 @@ Set(ByVal InValue As Object) m_Value = InValue End Set - End Property + End Property + + Public Property Ignore() As Boolean + Get + Return m_ignore + End Get + Set(ByVal Value As Boolean) + m_ignore = Value + End Set + End Property End Class |
From: Richard B. <rb...@us...> - 2004-10-18 01:38:48
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23134 Modified Files: AtomsFramework.xml Nunit_AtomsFramework.vbproj Added Files: EmployeeInterfaceTests.vb IEmployee.vb Log Message: Tests for interface persistence Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Nunit_AtomsFramework.vbproj 18 Oct 2004 00:07:09 -0000 1.6 +++ Nunit_AtomsFramework.vbproj 18 Oct 2004 01:38:39 -0000 1.7 @@ -140,6 +140,16 @@ BuildAction = "Compile" /> <File + RelPath = "EmployeeInterfaceTests.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "IEmployee.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NonInheritedRetreiveCriteria.vb" SubType = "Code" BuildAction = "Compile" --- NEW FILE: EmployeeInterfaceTests.vb --- Imports AToMSFramework Imports NUnit.Framework <TestFixture()> Public Class EmployeeInterfaceTests Private pbroker As CPersistenceBroker Private emp As IEmployee <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" Try 'Remove any existing test database System.IO.File.Delete(".\db1.mdb") Catch ex As Exception End Try 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 <SetUp()> Public Sub TestInit() emp = New EmployeeClass End Sub <Test()> Public Sub LoadEmployee_a() emp.Name = "a" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.Workers.Count, 0) Assert.IsTrue(Not emp.ReportsTo Is Nothing) Assert.AreEqual(emp.ReportsTo.Name, "c") Dim emp2 As IEmployee emp2 = emp.ReportsTo.Workers(0) Assert.AreEqual(emp2.Name, emp.Name) Assert.AreEqual(emp2.OIDValue, emp.OIDValue) Assert.AreSame(emp2, emp) End Sub <Test()> Public Sub LoadEmployee_ac() emp.Name = "ac" pbroker.FindObject(emp) Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) Assert.AreEqual(emp.Workers.Count, 3) emp = emp.Workers.Item(1) Assert.AreEqual(emp.Name, "aa") Assert.AreEqual(emp.ReportsTo.Name, "ac") End Sub <Test()> Public Sub CheckSchemaBasedProperties() emp.Name = "ac" pbroker.FindObject(emp) Assert.AreEqual(50, pbroker.getInjectedObject(emp).getFieldLengthByName("Name")) Assert.IsTrue(pbroker.getInjectedObject(emp).getFieldTypeByName("Name") Is GetType([String])) End Sub End Class --- NEW FILE: IEmployee.vb --- Public Interface IEmployee Property OIDValue() As String Property Name() As String Property ReportsTo() As IEmployee Property ReportsToOID() As String Property Workers() As ArrayList Property Team() As CTeam Property TeamOID() As String End Interface Public Class EmployeeClass Implements IEmployee Private m_name As String Private m_parentoid As String Private m_parent As IEmployee Private m_children As ArrayList Private m_team As CTeam Private m_teamoid As String Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Implements IEmployee.OIDValue Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property Public Property Name() As String Implements IEmployee.Name Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Property ReportsTo() As IEmployee Implements IEmployee.ReportsTo Get Return m_parent End Get Set(ByVal Value As IEmployee) If Not Value Is Nothing Then m_parent = Value m_parentoid = Value.OIDValue End If End Set End Property Public Property ReportsToOID() As String Implements IEmployee.ReportsToOID Get If m_parent Is Nothing Then Return m_parentoid Else Return (m_parent.OIDValue) End If End Get Set(ByVal Value As String) m_parentoid = Value End Set End Property Public Property Workers() As ArrayList Implements IEmployee.Workers Get Return m_children End Get Set(ByVal Value As ArrayList) m_children = Value End Set End Property Public Property Team() As CTeam Implements IEmployee.Team Get Return m_team End Get Set(ByVal Value As CTeam) If Not Value Is Nothing Then m_team = Value m_teamoid = Value.OIDValue End If End Set End Property Public Property TeamOID() As String Implements IEmployee.TeamOID Get If m_team Is Nothing Then Return m_teamoid Else Return (m_team.OIDValue) End If End Get Set(ByVal Value As String) m_teamoid = Value End Set End Property Public Sub New() MyBase.New() m_children = New ArrayList End Sub End Class Public Class IEmployeeFactory Implements AToMSFramework.IClassFactory Public Function CreateObject() As Object Implements AToMSFramework.IClassFactory.CreateObject Return New EmployeeClass End Function End Class Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- AtomsFramework.xml 15 Oct 2004 06:47:04 -0000 1.4 +++ AtomsFramework.xml 18 Oct 2004 01:38:39 -0000 1.5 @@ -71,4 +71,24 @@ <entry fromAttribute="OIDValue" toAttribute="TeamOID"/> </association> +<class name="IEmployee" table="employee" database="MSA" factory="IEmployeeFactory"> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="Name" column="name" find="true"/> + <attribute name="ReportsToOID" column="parentoid" /> + <attribute name="TeamOID" column="teamoid" /> + <attribute name="Team" /> + <attribute name="ReportsTo" /> + <attribute name="Workers" /> +</class> + + <association fromClass="IEmployee" toClass="IEmployee" target="ReportsTo" cardinality="OneToOne" + retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="ReportsToOID" toAttribute="OIDValue"/> + </association> + + <association fromClass="IEmployee" toClass="IEmployee" target="Workers" cardinality="OneToMany" + retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> + </association> + </map> \ No newline at end of file |
From: Richard B. <rb...@us...> - 2004-10-18 01:36:55
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22604 Modified Files: AToMSFramework.vbproj CClassMap.vb CInjectedObject.vb CPersistenceBroker.vb CXMLConfigLoader.vb Log Message: It's now possible to persist interfaces instead of concrete classes. Must provide a factory name that implements IClassFactory (XML config only) Index: AToMSFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/dotnet/AToMSFramework.vbproj,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- AToMSFramework.vbproj 14 Oct 2004 05:25:02 -0000 1.18 +++ AToMSFramework.vbproj 18 Oct 2004 01:36:43 -0000 1.19 @@ -359,6 +359,11 @@ BuildAction = "Compile" /> <File + RelPath = "IClassFactory.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "IConfigLoader.vb" SubType = "Code" BuildAction = "Compile" Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- CPersistenceBroker.vb 18 Oct 2004 00:08:10 -0000 1.66 +++ CPersistenceBroker.vb 18 Oct 2004 01:36:43 -0000 1.67 @@ -956,9 +956,16 @@ Public Function getClassMap(ByVal pType As Type) As CClassMap Dim ClassMap As CClassMap - ClassMap = m_classMaps.Item(pType.Name) + ClassMap = getClassMapByTypeName(pType.Name, pType.FullName) If ClassMap Is Nothing Then - ClassMap = m_classMaps.Item(pType.FullName) + 'try to find an interface that is mapped - first mapped interface we find will be used + Dim intType, interfaces() As Type + For Each intType In pType.GetInterfaces() + ClassMap = getClassMapByTypeName(intType.Name, intType.FullName) + If Not ClassMap Is Nothing Then + Exit For + End If + Next End If If (ClassMap Is Nothing) Then Throw New NoClassMapException("No class map for " & pType.FullName) @@ -966,6 +973,18 @@ Return ClassMap End Function + Private Function getClassMapByTypeName(ByVal name As String, ByVal fullname As String) As CClassMap + Dim ClassMap As CClassMap + ClassMap = m_classMaps.Item(name) + If ClassMap Is Nothing Then + ClassMap = m_classMaps.Item(fullname) + End If + If (ClassMap Is Nothing) Then + Return Nothing + End If + Return ClassMap + End Function + '''----------------------------------------------------------------------------- ''' <summary> ''' Retrieves a _CRelationalDatabase object by name Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CInjectedObject.vb 15 Oct 2004 06:42:56 -0000 1.2 +++ CInjectedObject.vb 18 Oct 2004 01:36:43 -0000 1.3 @@ -98,14 +98,33 @@ Public Function getClassMap() As CClassMap Implements IPersistableObject.getClassMap Dim ClassMap 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, interfaces() As Type + For Each intType In m_object.GetType.GetInterfaces() + ClassMap = getClassMap(intType.Name, intType.FullName) + If Not ClassMap Is Nothing Then + Exit For + End If + Next + End If + If (ClassMap Is Nothing) Then + Throw New NoClassMapException("No class map for " & m_object.GetType.FullName) + End If + Return 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(TypeName(m_object)) + ClassMap = persistenceBroker.getClassMap(name) If ClassMap Is Nothing Then - ClassMap = persistenceBroker.getClassMap(m_object.GetType.FullName) + ClassMap = persistenceBroker.getClassMap(fullname) End If If (ClassMap Is Nothing) Then - Throw New NoClassMapException("No class map for " & m_object.GetType.FullName) + Return Nothing End If Return ClassMap End Function Index: CXMLConfigLoader.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CXMLConfigLoader.vb,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- CXMLConfigLoader.vb 7 Oct 2004 05:57:33 -0000 1.23 +++ CXMLConfigLoader.vb 18 Oct 2004 01:36:44 -0000 1.24 @@ -261,6 +261,7 @@ Dim attrDatabase As XmlAttribute, attrSuperClassName As XmlAttribute, attrReadOnly As XmlAttribute, attrModifyOnly As XmlAttribute Dim attrClassNameSpace, attrAssemblyPath, attrSuperClassNameSpace As XmlAttribute Dim attrSharedField As XmlAttribute, attrSharedValue As XmlAttribute + Dim attrClassFactory As XmlAttribute attrClassName = node.GetAttributeNode("name") attrTable = node.GetAttributeNode("table") attrDatabase = node.GetAttributeNode("database") @@ -273,6 +274,7 @@ attrClassNameSpace = node.GetAttributeNode("namespace") attrAssemblyPath = node.GetAttributeNode("assemblypath") attrSuperClassNameSpace = node.GetAttributeNode("superclassnamespace") + attrClassFactory = node.GetAttributeNode("factory") Dim ClassMap As CClassMap Dim dbMap As CDatabaseMap Dim tblMap As CTableMap @@ -328,6 +330,9 @@ If Not attrSuperClassNameSpace Is Nothing Then ClassMap.SuperClassNameSpace = attrSuperClassNameSpace.Value End If + If Not attrClassFactory Is Nothing Then + ClassMap.IClassFactoryName = attrClassFactory.Value + End If dbMap = New CDatabaseMap dbMap.Name = attrDatabase.Value tblMap = New CTableMap Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- CClassMap.vb 18 Oct 2004 00:08:10 -0000 1.34 +++ CClassMap.vb 18 Oct 2004 01:36:43 -0000 1.35 @@ -64,6 +64,9 @@ Private m_sqlFindStatement As CSqlStatement Private m_sqlRetrieveStatement As CSqlStatement + Private m_classFactoryName As String + Private m_classFactory As IClassFactory + '''----------------------------------------------------------------------------- ''' <summary> ''' The name of the class being mapped @@ -602,6 +605,15 @@ End Set End Property + Public Property IClassFactoryName() As String + Get + Return m_classFactoryName + End Get + Set(ByVal Value As String) + m_classFactoryName = Value + End Set + End Property + '''----------------------------------------------------------------------------- ''' <summary> ''' Initializes a new instance the of CClassMap class. @@ -772,7 +784,7 @@ 'm_deleteStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & map.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(map.Name)))) m_deleteStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & map.ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(i)) End If - m_deleteStatement.addSqlParameter(i, obj.getValueByAttribute(map.Name), map.ColumnMap) + m_deleteStatement.addSqlParameter(i, obj.GetValueByAttribute(map.Name), map.ColumnMap) Next i End If getDeleteSqlFor = m_deleteStatement @@ -1045,10 +1057,10 @@ For i = 1 To ClassMap.getFindSize AttrMap = ClassMap.FindAttributeMaps(i) If isFirst Then - m_selectStatement.addSqlClause("" & ClassMap.getFindAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name)))) + m_selectStatement.addSqlClause("" & ClassMap.getFindAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.GetValueByAttribute(AttrMap.Name)))) isFirst = False Else - m_selectStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & ClassMap.getFindAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name)))) + m_selectStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & ClassMap.getFindAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.GetValueByAttribute(AttrMap.Name)))) End If Next i ClassMap = ClassMap.SuperClass @@ -1057,9 +1069,9 @@ For i = 1 To Me.getKeySize AttrMap = Me.getKeyAttributeMap(i) If i > 1 Then - m_selectStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name)))) + m_selectStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.GetValueByAttribute(AttrMap.Name)))) Else - m_selectStatement.addSqlClause("" & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name)))) + m_selectStatement.addSqlClause("" & AttrMap.ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.GetValueByAttribute(AttrMap.Name)))) End If Next i End If @@ -1113,7 +1125,7 @@ AttrMap = getIdentityAttributeMap(1) If Not AttrMap Is Nothing Then 'Identity columns must be integers. A zero value means it is not set. - If CInt(RelationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name))) <> 0 Then + If CInt(RelationalDatabase.getValueFor(obj.GetValueByAttribute(AttrMap.Name))) <> 0 Then includeIdentity = True End If End If @@ -1181,7 +1193,7 @@ For i = 1 To Me.getSize AttrMap = Me.getAttributeMap(i) If Not AttrMap.ColumnMap.IsIdentity Then - m_insertStatement.addSqlParameter(i, obj.getValueByAttribute(AttrMap.Name), AttrMap.ColumnMap) + m_insertStatement.addSqlParameter(i, obj.GetValueByAttribute(AttrMap.Name), AttrMap.ColumnMap) End If Next i If Not Me.SharedTableValue Is Nothing Then @@ -1246,7 +1258,7 @@ For i = 1 To Me.getSize AttrMap = Me.getAttributeMap(i) If Not AttrMap.ColumnMap.IsIdentity Then - m_updateStatement.addSqlParameter(i, obj.getValueByAttribute(AttrMap.Name), AttrMap.ColumnMap) + m_updateStatement.addSqlParameter(i, obj.GetValueByAttribute(AttrMap.Name), AttrMap.ColumnMap) End If Next i paramCount = Me.getSize @@ -1269,7 +1281,7 @@ For i = 1 To Me.getKeySize AttrMap = Me.getKeyAttributeMap(i) 'keyValuesCol.Add(m_relationalDatabase.getValueFor(obj.getValueByAttribute(AttrMap.Name))) - keyValuesCol.Add(obj.getValueByAttribute(AttrMap.Name)) + keyValuesCol.Add(obj.GetValueByAttribute(AttrMap.Name)) Next End If @@ -1300,7 +1312,7 @@ paramCount += 1 'm_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & m_relationalDatabase.getClauseStringEqualTo(m_relationalDatabase.getValueFor(obj.getValueByAttribute("Original" & Me.getAttributeMap(i).Name)))) m_updateStatement.addSqlClause(" " & RelationalDatabase.getClauseStringAnd & " " & Me.getAttributeMap(i).ColumnMap.getFullyQualifiedName & "=" & m_relationalDatabase.getParamHolder(paramCount)) - m_updateStatement.addSqlParameter(paramCount, obj.getValueByAttribute("Original" & Me.getAttributeMap(i).Name), Me.getAttributeMap(i).ColumnMap) + m_updateStatement.addSqlParameter(paramCount, obj.GetValueByAttribute("Original" & Me.getAttributeMap(i).Name), Me.getAttributeMap(i).ColumnMap) End If Next i End If @@ -1378,7 +1390,7 @@ End If Catch ex As Exception End Try - obj.setAttributeValue(AttrMap.Name, val) + obj.SetAttributeValue(AttrMap.Name, val) If Not IsDBNull(val) And Not val Is Nothing Then obj.Persistent = True End If @@ -1457,7 +1469,7 @@ Catch ex As Exception End Try - obj.setAttributeValue(AttrMap.Name, tmpObj) + obj.SetAttributeValue(AttrMap.Name, tmpObj) If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then obj.Persistent = True End If @@ -1971,6 +1983,54 @@ End Property Public Function CreateObjectInstance() As IPersistableObject + If m_classFactoryName Is Nothing Then + Return CreateObjectInstanceNoFactory() + End If + + 'Try to locate the object factory + Dim obj As Object + Dim pbroker As CPersistenceBroker + If m_classFactory Is Nothing Then + Try + If AssemblyPath <> String.Empty Then + 'For late loading assemblies + Dim objHdl As ObjectHandle + If ClassNameSpace = String.Empty Then + objHdl = Activator.CreateInstanceFrom(AssemblyPath, m_classFactoryName) + Else + objHdl = Activator.CreateInstanceFrom(AssemblyPath, ClassNameSpace & "." & m_classFactoryName) + End If + obj = CType(objHdl.Unwrap, Object) + Else + Dim t As Type + Dim asmArray As [Assembly]() = AppDomain.CurrentDomain.GetAssemblies + For Each asm As [Assembly] In asmArray + Try + If ClassNameSpace = String.Empty Then + For Each tt As Type In asm.GetTypes() + If tt.Name = m_classFactoryName Then + t = tt + Exit For + End If + Next + Else + t = asm.GetType(ClassNameSpace & "." & m_classFactoryName) + End If + Catch + End Try + If Not t Is Nothing Then Exit For + Next + obj = Activator.CreateInstance(t) + End If + Catch ex As Exception + Throw New XMLMappingException("The factory for class " & Name & " could not be found") + End Try + m_classFactory = CType(obj, IClassFactory) + End If + Return CreateObjectInstanceViaFactory() + End Function + + Private Function CreateObjectInstanceNoFactory() As IPersistableObject Dim obj As Object Dim ip As IPersistableObject Dim pbroker As CPersistenceBroker @@ -2016,4 +2076,19 @@ Return ip End Function + Public Function CreateObjectInstanceViaFactory() As IPersistableObject + Dim obj As Object + Dim ip As IPersistableObject + Dim pbroker As CPersistenceBroker + + obj = m_classFactory.CreateObject + Try + ip = CType(obj, IPersistableObject) + Catch ex As Exception + pbroker = getPersistenceBrokerInstance() + pbroker.StartTracking(obj) + ip = pbroker.getInjectedObject(obj) + End Try + Return ip + End Function End Class \ No newline at end of file |
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31996 Modified Files: CClassMap.vb CCursor.vb CMultiRetrieveCriteria.vb CMultiSummaryCriteria.vb CPersistenceBroker.vb CSelectInCriteria.vb CSummaryCriteria.vb Log Message: Retrieve criteria now handle objects that don't inherit from CPersistentObject Index: CMultiSummaryCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiSummaryCriteria.vb,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- CMultiSummaryCriteria.vb 21 Jul 2004 02:55:38 -0000 1.10 +++ CMultiSummaryCriteria.vb 18 Oct 2004 00:08:10 -0000 1.11 @@ -107,7 +107,7 @@ ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public ReadOnly Property getFirstObject() As CPersistentObject + Public ReadOnly Property getFirstObject() As IPersistableObject Get If m_objectsToJoin.Count = 0 Then Return Nothing @@ -138,6 +138,14 @@ Me.ClassMap = obj.getClassMap(obj) End Sub + Public Sub New(ByVal obj As Object) + Me.New() + Dim injObj As CInjectedObject + injObj = New CInjectedObject(obj) + Me.addObjectToJoin(injObj, Nothing, "") + Me.ClassMap = injObj.getClassMap + End Sub + Protected Overrides Sub Finalize() m_objectsToJoin = Nothing m_groupAttributes = Nothing @@ -168,20 +176,20 @@ ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub addObjectToJoin(ByVal obj As CPersistentObject, ByVal fromObj As CPersistentObject, ByVal assocName As String) + Public Sub addObjectToJoin(ByVal obj As IPersistableObject, ByVal fromObj As IPersistableObject, ByVal assocName As String) Dim mapName As String - Dim persobj As CPersistentObject + Dim persobj As IPersistableObject Dim bfound As Boolean = False Dim cm, cm2 As CClassMap Dim am As CUDAMap Dim i As Integer If m_objectsToJoin.Count = 0 Then - m_joins = New CJoin(obj.getClassMap(obj), "t1") - Me.ClassMap = obj.getClassMap(obj) + m_joins = New CJoin(obj.GetClassMap, "t1") + Me.ClassMap = obj.GetClassMap m_fromCMaps.Add(Me.ClassMap) m_objectsToJoin.Add(obj) - cm = obj.getClassMap(obj).SuperClass + cm = obj.GetClassMap.SuperClass i = 2 While Not cm Is Nothing m_fromCMaps.Add(cm) @@ -194,8 +202,8 @@ End While Exit Sub End If - cm = fromObj.getClassMap(fromObj) - i = 0 'Used to track the index of the from object + cm = fromObj.GetClassMap + i = 0 'Used to track the index of the from object For Each cm2 In m_fromCMaps i += 1 If cm2.Name = cm.Name Then @@ -208,7 +216,7 @@ Exit Sub End If - cm2 = fromObj.getClassMap(fromObj) + cm2 = fromObj.GetClassMap am = cm2.GetAssociationMapByName(assocName) If am Is Nothing Then Throw New NoAssociationException("Invalid association " & assocName & " selected - no such association exists") @@ -362,7 +370,7 @@ Public Function getSqlStatementParameters() As CSqlStatement Dim statement As New CSqlStatement Dim i As Short - Dim persObj As CPersistentObject + Dim persObj As IPersistableObject Dim cm As CClassMap Dim isFirst As Boolean = True Dim s As String Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.65 retrieving revision 1.66 diff -u -d -r1.65 -r1.66 --- CPersistenceBroker.vb 15 Oct 2004 06:42:56 -0000 1.65 +++ CPersistenceBroker.vb 18 Oct 2004 00:08:10 -0000 1.66 @@ -954,6 +954,18 @@ getClassMap = ClassMap End Function + Public Function getClassMap(ByVal pType As Type) As CClassMap + Dim ClassMap As CClassMap + ClassMap = m_classMaps.Item(pType.Name) + If ClassMap Is Nothing Then + ClassMap = m_classMaps.Item(pType.FullName) + End If + If (ClassMap Is Nothing) Then + Throw New NoClassMapException("No class map for " & pType.FullName) + End If + Return ClassMap + End Function + '''----------------------------------------------------------------------------- ''' <summary> ''' Retrieves a _CRelationalDatabase object by name @@ -1290,7 +1302,7 @@ '''----------------------------------------------------------------------------- Public Function processMultiRetrieveCriteria(ByRef pCriteria As CMultiRetrieveCriteria, ByVal fullObjects As Boolean) As CCursor Dim clMap As CClassMap - clMap = pCriteria.getFirstObject.getClassMap(pCriteria.getFirstObject) + clMap = pCriteria.getFirstObject.GetClassMap Dim conn As _CConnection conn = clMap.RelationalDatabase.getConnection(Nothing) @@ -1334,7 +1346,7 @@ '''----------------------------------------------------------------------------- Public Function processMultiSummaryCriteria(ByRef pCriteria As CMultiSummaryCriteria) As CCursor Dim clMap As CClassMap - clMap = pCriteria.getFirstObject.getClassMap(pCriteria.getFirstObject) + clMap = pCriteria.getFirstObject.GetClassMap Dim conn As _CConnection conn = clMap.RelationalDatabase.getConnection(Nothing) @@ -2099,10 +2111,10 @@ If TypeOf (obj) Is CPersistentObject Then If Not CType(obj, CPersistentObject).IsValid Then Return queue 'Do not save if object is not valid End If - If obj.isReadOnly Then + If obj.IsReadOnly Then Return queue End If - If (Not obj.Persistent) And obj.isModifyOnly Then + If (Not obj.Persistent) And obj.IsModifyOnly Then Return queue End If If includeBaseObject Then @@ -2113,7 +2125,7 @@ '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 + (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.IsReadOnly AndAlso Not obj.IsModifyOnly) Then If TypeOf (obj) Is CPersistentObject Then If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid obj.IsDirty = False 'Added to queue so clear dirty flag @@ -2131,7 +2143,7 @@ 'obj.IsDirty = False 'Now process the object associations to see what else needs saving - cm = obj.getClassMap() + cm = obj.GetClassMap() For i = 1 To cm.getStraightAssociationMapSize udamap = cm.getStraightAssociationMap(i) @@ -2451,4 +2463,12 @@ End If End Sub + Friend Property InjectedObjects() As CInjectedObjects + Get + Return m_injectedObjects + End Get + Set(ByVal Value As CInjectedObjects) + m_injectedObjects = Value + End Set + End Property End Class \ No newline at end of file Index: CMultiRetrieveCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CMultiRetrieveCriteria.vb,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- CMultiRetrieveCriteria.vb 7 Oct 2004 23:15:10 -0000 1.14 +++ CMultiRetrieveCriteria.vb 18 Oct 2004 00:08:10 -0000 1.15 @@ -106,7 +106,7 @@ ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public ReadOnly Property getFirstObject() As CPersistentObject + Public ReadOnly Property getFirstObject() As IPersistableObject Get If m_objectsToJoin.Count = 0 Then Return Nothing @@ -126,7 +126,7 @@ m_offset = -1 m_rows = -1 m_Having = Nothing - m_fullObjects = False 'default to proxy objects only + m_fullObjects = False 'default to proxy objects only End Sub Public Sub New(ByVal obj As CPersistentObject) @@ -136,6 +136,16 @@ m_joins = New CJoin(obj.getClassMap(obj), "t1") End Sub + Public Sub New(ByVal obj As Object) + Me.New() + Dim injObj As CInjectedObject + Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance + injObj = pbroker.LocateOrCreateInjObject(obj) + Me.addObjectToJoin(injObj, Nothing, "") + Me.ClassMap = pbroker.getClassMap(obj.GetType) + m_joins = New CJoin(Me.ClassMap, "t1") + End Sub + Protected Overrides Sub Finalize() m_objectsToJoin = Nothing m_groupAttributes = Nothing @@ -164,20 +174,20 @@ ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub addObjectToJoin(ByVal obj As CPersistentObject, ByVal fromObj As CPersistentObject, ByVal assocName As String) + Public Sub addObjectToJoin(ByVal obj As IPersistableObject, ByVal fromObj As IPersistableObject, ByVal assocName As String) Dim mapName As String - Dim persobj As CPersistentObject + Dim persobj As IPersistableObject Dim bfound As Boolean = False Dim cm, cm2 As CClassMap Dim am As CUDAMap Dim i As Integer If m_objectsToJoin.Count = 0 Then - m_joins = New CJoin(obj.getClassMap(obj), "t1") - Me.ClassMap = obj.getClassMap(obj) + m_joins = New CJoin(obj.GetClassMap, "t1") + Me.ClassMap = obj.GetClassMap m_fromCMaps.Add(Me.ClassMap) m_objectsToJoin.Add("t1", obj) - cm = obj.getClassMap(obj).SuperClass + cm = obj.GetClassMap.SuperClass i = 2 While Not cm Is Nothing m_fromCMaps.Add(cm) @@ -190,8 +200,8 @@ End While Exit Sub End If - cm = fromObj.getClassMap(fromObj) - i = 0 'Used to track the index of the from object + cm = fromObj.GetClassMap + i = 0 'Used to track the index of the from object For Each cm2 In m_fromCMaps i += 1 If cm2.Name = cm.Name Then @@ -207,7 +217,7 @@ If am Is Nothing Then Throw New NoAssociationException("Invalid association " & assocName & " selected - no such association exists") End If - cm = obj.getClassMap(obj) + cm = obj.GetClassMap m_fromCMaps.Add(cm) i = m_fromCMaps.Count mapName = "t" & i.ToString @@ -331,7 +341,7 @@ Dim statement As New CSqlStatement Dim i As Short Dim j As Short - Dim persObj As CPersistentObject + Dim persObj As IPersistableObject Dim cm As CClassMap Dim isFirst As Boolean = True Dim mapName As String @@ -361,7 +371,7 @@ statement.addSqlClause(", ") End If statement.addSqlClause(cm.getAttributeMap(i).ColumnMap.getAliasQualifiedName(mapName) & _ - Me.ClassMap.RelationalDatabase.getClauseStringAs & cm.getAttributeMap(i).ColumnMap.getAliasName(mapName)) + Me.ClassMap.RelationalDatabase.getClauseStringAs & cm.getAttributeMap(i).ColumnMap.getAliasName(mapName)) End If Next i Next @@ -476,7 +486,7 @@ ''' [rbanks] 19/05/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- - Public Function getObjectAlias(ByVal obj As CPersistentObject) As String + Public Function getObjectAlias(ByVal obj As IPersistableObject) As String Return getObjectAlias(obj, 0) End Function @@ -494,10 +504,10 @@ ''' [rbanks] 19/05/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- - Public Function getObjectAlias(ByVal obj As CPersistentObject, ByVal offset As Integer) As String + Public Function getObjectAlias(ByVal obj As IPersistableObject, ByVal offset As Integer) As String Dim i As Integer = 0 For Each o As DictionaryEntry In m_objectsToJoin - If o.Value.GetType Is obj.GetType Then + If o.Value.GetType Is obj.GetSourceObject.GetType Then If i = offset Then Return o.Key Else Index: CSelectInCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CSelectInCriteria.vb,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- CSelectInCriteria.vb 21 Jul 2004 02:55:38 -0000 1.5 +++ CSelectInCriteria.vb 18 Oct 2004 00:08:10 -0000 1.6 @@ -80,7 +80,7 @@ ''' [rbanks] 17/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public ReadOnly Property getFirstObject() As CPersistentObject + Public ReadOnly Property getFirstObject() As IPersistableObject Get If m_objectsToJoin.Count = 0 Then Return Nothing @@ -126,6 +126,16 @@ ' m_joins = New CJoin(obj.getClassMap(obj), m_SQC.ToString & "s1") End Sub + Public Sub New(ByVal obj As Object) + Me.New() + Dim injObj As CInjectedObject + Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance + injObj = New CInjectedObject(obj) + Me.addObjectToJoin(injObj, Nothing, "") + Me.ClassMap = injObj.getClassMap + ' m_joins = New CJoin(obj.getClassMap(obj), m_SQC.ToString & "s1") + End Sub + Protected Overrides Sub Finalize() m_objectsToJoin = Nothing m_joins = Nothing @@ -145,20 +155,20 @@ ''' [rbanks] 17/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub addObjectToJoin(ByVal obj As CPersistentObject, ByVal fromObj As CPersistentObject, ByVal assocName As String) + Public Sub addObjectToJoin(ByVal obj As IPersistableObject, ByVal fromObj As IPersistableObject, ByVal assocName As String) Dim mapName As String - Dim persobj As CPersistentObject + Dim persobj As IPersistableObject Dim bfound As Boolean = False Dim cm, cm2 As CClassMap Dim am As CUDAMap Dim i As Integer If m_objectsToJoin.Count = 0 Then - m_joins = New CJoin(obj.getClassMap(obj), "s" & m_SQC.ToString & "1") - Me.ClassMap = obj.getClassMap(obj) + m_joins = New CJoin(obj.GetClassMap, "s" & m_SQC.ToString & "1") + Me.ClassMap = obj.GetClassMap m_fromCMaps.Add(Me.ClassMap) m_objectsToJoin.Add(obj) - cm = obj.getClassMap(obj).SuperClass + cm = obj.GetClassMap.SuperClass i = 2 While Not cm Is Nothing m_fromCMaps.Add(cm) @@ -171,8 +181,8 @@ End While Exit Sub End If - cm = fromObj.getClassMap(fromObj) - i = 0 'Used to track the index of the from object + cm = fromObj.GetClassMap + i = 0 'Used to track the index of the from object For Each cm2 In m_fromCMaps i += 1 If cm2.Name = cm.Name Then @@ -189,7 +199,7 @@ If am Is Nothing Then Throw New NoAssociationException("Invalid association selected - no such association exists") End If - cm = obj.getClassMap(obj) + cm = obj.GetClassMap m_fromCMaps.Add(cm) i = m_fromCMaps.Count mapName = "s" & m_SQC.ToString & i.ToString @@ -244,7 +254,7 @@ Dim statement As New CSqlStatement Dim i As Short Dim j As Short - Dim persObj As CPersistentObject + Dim persObj As IPersistableObject Dim cm As CClassMap Dim isFirst As Boolean = True Dim mapName As String Index: CCursor.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCursor.vb,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- CCursor.vb 7 Sep 2004 00:36:34 -0000 1.9 +++ CCursor.vb 18 Oct 2004 00:08:10 -0000 1.10 @@ -235,6 +235,58 @@ ''' [rbanks] 4/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- + Public Sub loadObject(ByRef obj As Object) + loadObject(obj, 0) + End Sub + + Public Sub loadObject(ByRef obj As Object, ByVal offset As Integer) + Dim _alias As String = "" + Dim mr As CMultiRetrieveCriteria + Dim clMap As CClassMap + Dim pbroker As CPersistenceBroker = modPersistenceBrokerSingleton.getPersistenceBrokerInstance + Dim injObj As CInjectedObject + + injobj = pbroker.LocateOrCreateInjObject(obj) + If Not m_parentCriteria Is Nothing Then + If m_parentCriteria.GetType Is GetType(CMultiRetrieveCriteria) Then + mr = m_parentCriteria + _alias = mr.getObjectAlias(injObj, offset) + clMap = pbroker.getClassMap(obj.GetType) + If Not m_holdsProxies Then + clMap.retrieveObject(clMap, injObj, m_row, _alias) + If clMap.AssociationMapCount > 0 Then + injObj.AssociationsLoaded = False + Else + injObj.AssociationsLoaded = True + End If + pbroker.InjectedObjects.Add(injObj) + Else + 'need to retrieve the proxy and then load the object + clMap.retrieveProxy(injObj, m_row, _alias) + pbroker.retrieveObject(injObj, False, True) + pbroker.InjectedObjects.Add(injObj) + End If + Exit Sub + End If + End If + + clMap = pbroker.getClassMap(obj.GetType) + If Not m_holdsProxies Then + clMap.retrieveObject(injobj, m_row) + If clMap.AssociationMapCount > 0 Then + injobj.AssociationsLoaded = False + Else + injobj.AssociationsLoaded = True + End If + pbroker.InjectedObjects.Add(injObj) + Else + 'need to retrieve the proxy and then load the object + clMap.retrieveProxy(injObj, m_row) + pbroker.retrieveObject(injObj, False, True) + pbroker.InjectedObjects.Add(injObj) + End If + End Sub + Public Sub loadObject(ByRef obj As CPersistentObject) loadObject(obj, 0) End Sub @@ -357,7 +409,7 @@ 'TO DO: Handle errors If Not m_holdsProxies Then obj.getClassMap(obj).retrieveObject(obj, m_row) - obj.IsDirty = False 'Clear the dirty flag after initial loading of the object + obj.IsDirty = False 'Clear the dirty flag after initial loading of the object 'Add object to cache broker.addToCache(obj) broker.retrieveAssociations(obj, obj.getClassMap(obj).RelationalDatabase.getConnection(Nothing), m_classMap, True) Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- CClassMap.vb 15 Oct 2004 06:42:56 -0000 1.33 +++ CClassMap.vb 18 Oct 2004 00:08:10 -0000 1.34 @@ -1476,9 +1476,9 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub retrieveProxy(ByRef obj As CPersistentObject, ByVal rw As DataRow) + Public Sub retrieveProxy(ByRef obj As IPersistableObject, ByVal rw As DataRow) Dim tm As CTableMap - tm = obj.getClassMap(obj).Tables.Item(1) + tm = obj.GetClassMap.Tables.Item(1) Call retrieveProxy(obj, rw, tm.Name) End Sub @@ -1495,11 +1495,11 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub retrieveProxy(ByRef obj As CPersistentObject, ByVal rw As DataRow, ByVal pAlias As String) + Public Sub retrieveProxy(ByRef obj As IPersistableObject, ByVal rw As DataRow, ByVal pAlias As String) Dim ClassMap As CClassMap Dim tmpObj As Object If obj Is Nothing Then - Throw New RetrieveException("Source object has not been instantiated yet") + Throw New RetrieveException("Target object has not been instantiated yet") End If ClassMap = Me Dim i As Short @@ -1519,7 +1519,7 @@ End If Catch ex As Exception End Try - obj.setAttributeValue(AttrMap.Name, tmpObj) + obj.SetAttributeValue(AttrMap.Name, tmpObj) End If Next i ClassMap = ClassMap.SuperClass @@ -1552,7 +1552,7 @@ End If Catch ex As Exception End Try - obj.setAttributeValue(AttrMap.Name, tmpObj) + obj.SetAttributeValue(AttrMap.Name, tmpObj) If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then obj.Persistent = True End If Index: CSummaryCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CSummaryCriteria.vb,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- CSummaryCriteria.vb 21 Jul 2004 02:55:38 -0000 1.8 +++ CSummaryCriteria.vb 18 Oct 2004 00:08:10 -0000 1.9 @@ -323,7 +323,7 @@ ''' [rbanks] 17/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function perform(ByVal obj As CPersistentObject) As CCursor + Public Function perform(ByVal obj As IPersistableObject) As CCursor Static persistentBroker As CPersistenceBroker persistentBroker = getPersistenceBrokerInstance() perform = persistentBroker.Instance.processSummaryCriteria(obj, Me) |
From: Richard B. <rb...@us...> - 2004-10-18 00:07:33
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31816 Modified Files: Nunit_AtomsFramework.vbproj Added Files: NonInheritedRetreiveCriteria.vb Nunit_AtomsFramework.vbproj.user Log Message: Unit tests for retrieve criteria based on non-persistence-inherited objects Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Nunit_AtomsFramework.vbproj 15 Oct 2004 06:47:15 -0000 1.5 +++ Nunit_AtomsFramework.vbproj 18 Oct 2004 00:07:09 -0000 1.6 @@ -140,6 +140,11 @@ BuildAction = "Compile" /> <File + RelPath = "NonInheritedRetreiveCriteria.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NonInheritedTests.vb" SubType = "Code" BuildAction = "Compile" --- NEW FILE: NonInheritedRetreiveCriteria.vb --- Imports AToMSFramework Imports NUnit.Framework <TestFixture()> Public Class NonInheritedRetreiveCriteria Private pbroker As CPersistenceBroker Private emp As NPEmployee Private r As CRetrieveCriteria Private mr As CMultiRetrieveCriteria Private c As CCursor Private injObj As CInjectedObject <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" Try 'Remove any existing test database System.IO.File.Delete(".\db1.mdb") Catch ex As Exception End Try 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 <SetUp()> Public Sub testInit() emp = New NPEmployee End Sub <Test()> Public Sub SingleClassRetrieve() r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(GetType(NPEmployee)) c = r.perform Assert.IsTrue(c.hasElements) Assert.IsTrue(Not c.EOF) Assert.IsTrue(c.HoldsProxies) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 6) End Sub <Test()> Public Sub LoadFullObjects() r = New CRetrieveCriteria r.ReturnFullObjects = True r.ClassMap = pbroker.getClassMap(emp.GetType) c = r.perform Assert.IsFalse(c.HoldsProxies) 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() End While c.SetCursor(0) emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "ab") End Sub <Test()> Public Sub SimpleOrCriteria() r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(emp.GetType) r.WhereCondition.addSelectEqualTo("Name", "aa") r.WhereCondition.addSelectEqualTo("Name", "b", True) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 2) c.loadObject(emp) Assert.AreEqual(emp.Name, "aa") c.nextCursor() emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "b") End Sub <Test()> Public Sub SelectInList() Dim al As New ArrayList al.Add("aa") al.Add("b") r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(emp.GetType) r.WhereCondition.addSelectInList("Name", al) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 2) c.loadObject(emp) Assert.AreEqual(emp.Name, "aa") c.nextCursor() emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "b") End Sub <Test()> Public Sub SubCriteria() Dim xx_1 As New CCriteriaCondition Dim xx_2 As New CCriteriaCondition Dim xx_3 As New CCriteriaCondition Dim xx_4 As New CCriteriaCondition r = New CRetrieveCriteria r.ClassMap = pbroker.getClassMap(emp.GetType) xx_1.ClassMap = r.ClassMap xx_2.ClassMap = r.ClassMap xx_3.ClassMap = r.ClassMap xx_4.ClassMap = r.ClassMap xx_1.addSelectEqualTo("Name", "aa") xx_2.addSelectEqualTo("Name", "ab") xx_1.addSubCriteria(xx_2, True) xx_3.addSelectEqualTo("Name", "ab") xx_4.addSelectEqualTo("Name", "ac") xx_3.addSubCriteria(xx_4, True) r.WhereCondition.addSubCriteria(xx_1, True) r.WhereCondition.addSubCriteria(xx_3, False) c = r.perform Assert.IsTrue(c.hasElements) Assert.AreEqual(c.ResultSet.ResultSet.Tables(0).Rows.Count, 1) While c.hasElements And Not c.EOF emp = New NPEmployee c.loadObject(emp) Assert.AreEqual(emp.Name, "ab") c.nextCursor() End While End Sub <Test()> Public Sub MultiRetrieveTest1() Dim si As CSelectInCriteria mr = New CMultiRetrieveCriteria(emp) mr.WhereCondition.addSelectEqualTo("Name", "ac") si = New CSelectInCriteria(emp) si.WhereCondition.addSelectEqualTo("Name", "ac") si.SetSelectAttribute("Name") mr.WhereCondition.addSelectNotIn("Name", si) c = mr.perform Assert.IsFalse(c.hasElements) Assert.IsTrue(c.EOF) End Sub End Class --- NEW FILE: Nunit_AtomsFramework.vbproj.user --- <VisualStudioProject> <VisualBasic LastOpenVersion = "7.10.3077" > <Build> <Settings ReferencePath = "C:\Projects\MMM\Atoms_Framework\bin\" > <Config Name = "Debug" EnableASPDebugging = "false" EnableASPXDebugging = "false" EnableUnmanagedDebugging = "false" EnableSQLServerDebugging = "false" RemoteDebugEnabled = "false" RemoteDebugMachine = "" StartAction = "Program" StartArguments = '"..\Nunit_AtomsFramework.nunit"' StartPage = "" StartProgram = "C:\Program Files\NUnit 2.2\bin\nunit-gui.exe" StartURL = "" StartWorkingDirectory = "" StartWithIE = "true" /> <Config Name = "Release" EnableASPDebugging = "false" EnableASPXDebugging = "false" EnableUnmanagedDebugging = "false" EnableSQLServerDebugging = "false" RemoteDebugEnabled = "false" RemoteDebugMachine = "" StartAction = "Project" StartArguments = "" StartPage = "" StartProgram = "" StartURL = "" StartWorkingDirectory = "" StartWithIE = "false" /> </Settings> </Build> <OtherProjectSettings CopyProjectDestinationFolder = "" CopyProjectUncPath = "" CopyProjectOption = "0" ProjectView = "ProjectFiles" ProjectTrust = "0" /> </VisualBasic> </VisualStudioProject> |
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27874 Modified Files: AtomsFramework.xml AtomsFrameworkTests.vb NonInheritedTests.vb Nunit_AtomsFramework.vbproj original db1.mdb Added Files: NPEmployee.vb NPTeam.vb Log Message: More units tests for persistence of non-inherited objects --- NEW FILE: NPEmployee.vb --- Public Class NPEmployee Private m_name As String Private m_parentoid As String Private m_parent As NPEmployee Private m_children As ArrayList Private m_team As CTeam Private m_teamoid As String Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Property ReportsTo() As NPEmployee Get Return m_parent End Get Set(ByVal Value As NPEmployee) If Not Value Is Nothing Then m_parent = Value m_parentoid = Value.OIDValue End If End Set End Property Public Property ReportsToOID() As String Get If m_parent Is Nothing Then Return m_parentoid Else Return (m_parent.OIDValue) End If End Get Set(ByVal Value As String) m_parentoid = Value End Set End Property Public Property Workers() As ArrayList Get Return m_children End Get Set(ByVal Value As ArrayList) m_children = Value End Set End Property Public Property Team() As CTeam Get Return m_team End Get Set(ByVal Value As CTeam) If Not Value Is Nothing Then m_team = Value m_teamoid = Value.OIDValue End If End Set End Property Public Property TeamOID() As String Get If m_team Is Nothing Then Return m_teamoid Else Return (m_team.OIDValue) End If End Get Set(ByVal Value As String) m_teamoid = Value End Set End Property Public Sub New() MyBase.New() m_children = New ArrayList End Sub End Class Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Nunit_AtomsFramework.vbproj 14 Oct 2004 05:23:48 -0000 1.4 +++ Nunit_AtomsFramework.vbproj 15 Oct 2004 06:47:15 -0000 1.5 @@ -145,11 +145,21 @@ BuildAction = "Compile" /> <File + RelPath = "NPEmployee.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NPJob.vb" SubType = "Code" BuildAction = "Compile" /> <File + RelPath = "NPTeam.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "RetrieveCriteriaTests.vb" SubType = "Code" BuildAction = "Compile" Index: NonInheritedTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/NonInheritedTests.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- NonInheritedTests.vb 14 Oct 2004 05:23:48 -0000 1.1 +++ NonInheritedTests.vb 15 Oct 2004 06:47:15 -0000 1.2 @@ -5,6 +5,7 @@ Private pbroker As CPersistenceBroker Private job As NPJob + Private emp As NPEmployee <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" @@ -25,12 +26,13 @@ <SetUp()> Public Sub TestInit() job = New NPJob + emp = New NPEmployee End Sub <Test()> Public Sub LoadJob_a1() job.Id = "a1" pbroker.GetObject(job) - Assert.AreEqual(cinjectedobject.state.loaded, pbroker.getcurrentstate(job)) + Assert.IsTrue(pbroker.getInjectedObject(job).Persistent) Assert.AreEqual("basic", job.Description) End Sub @@ -47,15 +49,168 @@ pbroker.StartTracking(job) job.Id = "a2" job.Description = "SomeJob" + Assert.IsTrue(pbroker.getInjectedObject(job).IsDirty) pbroker.PersistChanges(job) + Assert.IsFalse(pbroker.getInjectedObject(job).IsDirty) End Sub <Test()> Public Sub DeleteAJob() - 'pbroker.StartTracking(job) - 'job.Id = "a3" - 'job.Description = "SomeJob3" - 'pbroker.PersistChanges(job) - 'pbroker.MarkForDeletion(job) - 'pbroker.PersistChanges(job) + pbroker.StartTracking(job) + job.Id = "a3" + job.Description = "SomeJob3" + pbroker.PersistChanges(job) + pbroker.MarkForDeletion(job) + pbroker.PersistChanges(job) + Assert.IsTrue(pbroker.ObjectIsTracked(job)) + Assert.IsFalse(pbroker.getInjectedObject(job).Persistent) End Sub + + <Test()> Public Sub CheckInjectionCache() + Dim job2 As New NPJob + pbroker.StartTracking(job) + pbroker.StartTracking(job2) + Assert.IsTrue(pbroker.objectistracked(job)) + job.Id = "1" + job.Description = "a" + Assert.IsTrue(pbroker.ObjectIsTracked(job)) + job2.Id = "2" + job2.Description = "b" + pbroker.PersistChanges(job) + pbroker.PersistChanges(job2) + End Sub + + <Test()> Public Sub CheckInjectionCache2() + Dim job2 As New NPJob + job.Id = "3" + job2.Id = "4" + pbroker.StartTracking(job) + pbroker.StartTracking(job2) + job.Description = "c" + job2.Description = "d" + Assert.IsFalse(pbroker.getInjectedObject(job).Persistent) + pbroker.PersistChanges() + Assert.IsTrue(pbroker.getInjectedObject(job).Persistent) + End Sub + + <Test()> Public Sub LoadEmployee_a() + emp.Name = "a" + pbroker.FindObject(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + Assert.AreEqual(emp.Workers.Count, 0) + Assert.IsTrue(Not emp.ReportsTo Is Nothing) + Assert.AreEqual(emp.ReportsTo.Name, "c") + Dim emp2 As NPEmployee + emp2 = emp.ReportsTo.Workers(0) + Assert.AreEqual(emp2.Name, emp.Name) + Assert.AreEqual(emp2.OIDValue, emp.OIDValue) + Assert.AreSame(emp2, emp) + End Sub + + <Test()> Public Sub LoadEmployee_ac() + emp.Name = "ac" + pbroker.FindObject(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + Assert.AreEqual(emp.Workers.Count, 3) + emp = emp.Workers.Item(1) + Assert.AreEqual(emp.Name, "aa") + Assert.AreEqual(emp.ReportsTo.Name, "ac") + End Sub + + <Test()> Public Sub CheckSchemaBasedProperties() + emp.Name = "ac" + pbroker.FindObject(emp) + Assert.AreEqual(50, pbroker.getInjectedObject(emp).getFieldLengthByName("Name")) + Assert.IsTrue(pbroker.getInjectedObject(emp).getFieldTypeByName("Name") Is GetType([String])) + End Sub + + <Test()> Public Sub PersistentObjectEquality() + Dim emp2 As NPEmployee + emp.Name = "ac" + pbroker.FindObject(emp) + emp2 = New NPEmployee + emp2.Name = "aa" + pbroker.FindObject(emp2) + Assert.IsTrue(emp.Equals(emp2.ReportsTo)) + Assert.AreEqual(3, emp2.ReportsTo.Workers.Count) + End Sub + + <Test()> Public Sub LoadSaveandDeleteEmployee() + Dim oidvalue As String + emp.Name = "new" + pbroker.FindObject(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + oidvalue = emp.OIDValue + pbroker.PersistChanges(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + Assert.IsTrue(emp.ReportsTo Is Nothing) + Debug.WriteLine(pbroker.DumpCacheDetails) + emp = New NPEmployee + emp.Name = "new" + pbroker.FindObject(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + Assert.AreEqual(emp.OIDValue, oidvalue) + Assert.AreEqual(emp.Name, "new") + pbroker.MarkForDeletion(emp) + pbroker.PersistChanges(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + emp = New NPEmployee + emp.Name = "new" + pbroker.FindObject(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + Assert.IsTrue(emp.OIDValue <> oidvalue) + End Sub + + <Test()> Public Sub ChangeFindFieldValue() + Dim oidvalue As String + emp.Name = "SaveThenChange" + pbroker.FindObject(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + oidvalue = emp.OIDValue + pbroker.PersistChanges(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + Assert.IsTrue(emp.ReportsTo Is Nothing) + emp = New NPEmployee + emp.Name = "SaveThenChange" + pbroker.FindObject(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + Assert.AreEqual(emp.OIDValue, oidvalue) + Assert.AreEqual(emp.Name, "SaveThenChange") + emp.Name = "Changed" + pbroker.PersistChanges(emp) + Assert.IsTrue(pbroker.getInjectedObject(emp).Persistent) + pbroker.MarkForDeletion(emp) + pbroker.PersistChanges(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + emp = New NPEmployee + emp.Name = "Changed" + pbroker.FindObject(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + emp = New NPEmployee + emp.Name = "SaveThenChange" + pbroker.FindObject(emp) + Assert.IsFalse(pbroker.getInjectedObject(emp).Persistent) + End Sub + + <Test()> Public Sub saveHierarchy() + Dim emp2 As New NPEmployee + Dim emp3 As New NPEmployee + pbroker.StartTracking(emp) + emp.Name = "theBoss" + emp2.Name = "middleMgr" + emp3.Name = "slave" + emp.Workers.Add(emp2) + emp2.ReportsTo = emp + emp2.Workers.Add(emp3) + emp3.ReportsTo = emp2 + pbroker.PersistChanges(emp) + pbroker.ClearCache() + emp = New NPEmployee + emp.Name = "slave" + pbroker.FindObject(emp) + Assert.AreEqual("middleMgr", emp.ReportsTo.Name) + Assert.AreEqual("theBoss", emp.ReportsTo.ReportsTo.Name) + emp2 = emp.ReportsTo.Workers(0) + Assert.AreEqual("slave", emp2.Name) + End Sub + End Class Index: original db1.mdb =================================================================== RCS file: /cvsroot/jcframework/Nunit/original db1.mdb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 Binary files /tmp/cvs3fYzaj and /tmp/cvsiZibQ6 differ --- NEW FILE: NPTeam.vb --- Public Class NPTeam Private m_leader As NPEmployee Private m_leaderoid As String Private m_name As String Private m_job As NPJobWithOIDValue Private m_joboid As String Private m_members As ArrayList Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property Public Property TeamLeader() As NPEmployee Get Return m_leader End Get Set(ByVal Value As NPEmployee) m_leader = Value m_leaderoid = Value.OIDValue End Set End Property Public Property TeamLeaderOID() As String Get If m_leader Is Nothing Then Return m_leaderoid Else Return (m_leader.OIDValue) End If End Get Set(ByVal Value As String) m_leaderoid = Value End Set End Property Public Property Job() As NPJobWithOIDValue Get Return m_job End Get Set(ByVal Value As NPJobWithOIDValue) m_job = Value m_joboid = Value.OIDValue End Set End Property Public Property jobOID() As String Get If m_job Is Nothing Then Return m_joboid Else Return (m_job.OIDValue) End If End Get Set(ByVal Value As String) m_joboid = Value End Set End Property Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Property Members() As ArrayList Get Return m_members End Get Set(ByVal Value As ArrayList) m_members = Value End Set End Property Public Sub New() MyBase.new() m_members = New ArrayList End Sub End Class Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- AtomsFramework.xml 14 Oct 2004 05:23:48 -0000 1.3 +++ AtomsFramework.xml 15 Oct 2004 06:47:04 -0000 1.4 @@ -26,4 +26,49 @@ <attribute name="Description" column="description" find="true"/> </class> + +<class name="NPEmployee" table="employee" database="MSA"> + <attribute name="OIDValue" column="oid" key="primary"/> + <attribute name="Name" column="name" find="true"/> + <attribute name="ReportsToOID" column="parentoid" /> + <attribute name="TeamOID" column="teamoid" /> + <attribute name="Team" /> + <attribute name="ReportsTo" /> + <attribute name="Workers" /> +</class> + + <association fromClass="NPEmployee" toClass="NPEmployee" target="ReportsTo" cardinality="OneToOne" + retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="ReportsToOID" toAttribute="OIDValue"/> + </association> + + <association fromClass="NPEmployee" toClass="NPEmployee" target="Workers" cardinality="OneToMany" + retrieveAutomatic="true" saveAutomatic="true" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="OIDValue" toAttribute="ReportsToOID"/> + </association> + +<class name="NPTeam" table="teams" database="MSA"> + <attribute name="OIDValue" column="oidvalue" key="primary"/> + <attribute name="Name" column="teamname" find="true"/> + <attribute name="TeamLeaderOID" column="teamleader" /> + <attribute name="jobOID" column="joboidvalue" /> + <attribute name="TeamLeader" /> + <attribute name="Job" /> +</class> + + <association fromClass="NPTeam" toClass="NPEmployee" target="TeamLeader" cardinality="OneToOne" + retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="TeamLeaderOID" toAttribute="OIDValue"/> + </association> + + <association fromClass="NPTeam" toClass="NPJobWithOIDValue" target="Job" cardinality="OneToOne" + retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="jobOID" toAttribute="OIDValue"/> + </association> + + <association fromClass="NPTeam" toClass="NPEmployee" target="Members" cardinality="OneToMany" + retrieveAutomatic="true" saveAutomatic="false" deleteAutomatic="false" inverse="false"> + <entry fromAttribute="OIDValue" toAttribute="TeamOID"/> + </association> + </map> \ No newline at end of file Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFrameworkTests.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- AtomsFrameworkTests.vb 8 Oct 2004 00:09:58 -0000 1.4 +++ AtomsFrameworkTests.vb 15 Oct 2004 06:47:15 -0000 1.5 @@ -134,7 +134,7 @@ emp.Find() emp2 = New CEmployee emp2.Find() - Assert.ReferenceEquals(emp2, emp) + Assert.AreSame(emp2, emp) End Sub <Test()> Public Sub PersistentObjectEquality() @@ -155,4 +155,24 @@ Assert.IsTrue(emp.getFieldTypeByName("Name") Is GetType([String])) End Sub + <Test()> Public Sub CacheTest() + emp.Name = "Initial" + emp.Find() + Assert.IsFalse(emp.Persistent) + emp.Save() + pbroker.ClearCache() + emp = New CEmployee + emp.Name = "Initial" + emp.Find() + emp.Name = "Final" + emp.Save() + Assert.AreEqual("Final", emp.Name) + emp = New CEmployee + emp.Name = "Initial" + emp.Find() + Assert.IsFalse(emp.Persistent) + emp.Name = "Final" + emp.Find() + Assert.IsTrue(emp.Persistent) + End Sub End Class |
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26911 Modified Files: CCacheEntry.vb CClassMap.vb CInjectedObject.vb CInjectedObjects.vb CPersistenceBroker.vb CPersistentObject.vb IPersistentObject.vb Log Message: More changes to persist non-inherited objects. Object hierarchies are now persistable Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- CPersistenceBroker.vb 14 Oct 2004 05:25:02 -0000 1.64 +++ CPersistenceBroker.vb 15 Oct 2004 06:42:56 -0000 1.65 @@ -394,7 +394,7 @@ ' All objects are loaded to the cache regardless of applications cache usage m_cache.Add(targetobj) End If - obj.setAttributeValue(udamap.Target, targetobj) + obj.SetAttributeValue(udamap.Target, targetobj.GetSourceObject) If Not targetobj.AssociationsLoaded Then retrievePrivateObject(targetobj, conn, False, False) Else @@ -426,7 +426,7 @@ targetobj.IsDirty = False targetobj.OriginalCacheKey = New CCacheKey(targetobj) End If - obj.setAttributeValue(udamap.Target, targetobj) + obj.SetAttributeValue(udamap.Target, targetobj.GetSourceObject) End If Else 'Object doesn't exist - let's create it @@ -449,7 +449,7 @@ targetobj.IsDirty = False targetobj.OriginalCacheKey = New CCacheKey(targetobj) End If - obj.setAttributeValue(udamap.Target, targetobj) + obj.SetAttributeValue(udamap.Target, targetobj.GetSourceObject) End If End If End If @@ -475,7 +475,12 @@ 'Need to determine if new object is already in the collection '(prevents duplicates when multiple one-to-many associations exist) gotValue = False - For Each tmpObj In col + For Each tmpColObj As Object In col + If Not tmpColObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + tmpObj = LocateOrCreateInjObject(tmpColObj) + Else + tmpObj = tmpColObj + End If If tmpObj.Equals(targetobj) Then gotValue = True End If @@ -489,7 +494,7 @@ targetobj.OriginalCacheKey = New CCacheKey(targetobj) End If If targetobj.AssociationsLoaded Then - col.Add(targetobj) + col.Add(targetobj.GetSourceObject) 'the object is found and added to the collection ' Exit For End If @@ -511,7 +516,12 @@ 'Need to determine if new object is already in the collection '(prevents duplicates when multiple one-to-many associations exist) gotValue = False - For Each tmpObj In col + For Each tmpColObj As Object In col + If Not tmpColObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + tmpObj = LocateOrCreateInjObject(tmpColObj) + Else + tmpObj = tmpColObj + End If If tmpObj.Equals(targetobj) Then gotValue = True End If @@ -524,7 +534,7 @@ targetobj.OriginalCacheKey = New CCacheKey(targetobj) End If If targetobj.AssociationsLoaded Then - col.Add(targetobj) + col.Add(targetobj.GetSourceObject) End If End If End If @@ -600,7 +610,7 @@ End If Value.IsDirty = False Value.OriginalCacheKey = New CCacheKey(Value) - obj.setAttributeValue(udaMap.Target, Value) + obj.setAttributeValue(udaMap.Target, Value.GetSourceObject) gotValue = True End If End If @@ -627,7 +637,7 @@ End If Value.IsDirty = False 'After populating a new object Value.OriginalCacheKey = New CCacheKey(Value) - obj.setAttributeValue(udaMap.Target, Value) + obj.setAttributeValue(udaMap.Target, Value.GetSourceObject) End If End If ElseIf udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then @@ -695,9 +705,6 @@ conn.startTransaction() conn.AutoCommit = False savePrivateObject(obj, conn) - 'If m_useCache Then - ' m_cache.Add(obj) 'Add to the cache - 'End If conn.commit() Catch ex As Exception conn.rollback() @@ -784,7 +791,7 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub deleteObject(ByVal obj As CPersistentObject) + Public Sub deleteObject(ByVal obj As IPersistableObject) Call deleteObject(obj, False) End Sub @@ -800,11 +807,11 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub deleteObject(ByVal obj As CPersistentObject, ByVal deleteSuperClass As Boolean) + Public Sub deleteObject(ByVal obj As IPersistableObject, ByVal deleteSuperClass As Boolean) SyncLock GetType(CPersistenceBroker) Dim cm As CClassMap Dim x As DeleteException - cm = obj.getClassMap(obj) + cm = obj.getClassMap Dim conn As _CConnection conn = cm.RelationalDatabase.getConnection(Nothing) conn.startTransaction() @@ -835,7 +842,7 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub deleteCachedObject(ByVal obj As CPersistentObject) + Public Sub deleteCachedObject(ByVal obj As IPersistableObject) If m_useCache Then m_cache.Remove(obj) End If @@ -858,9 +865,9 @@ ''' child objects are deleted ''' </history> '''----------------------------------------------------------------------------- - Private Sub deletePrivateObject(ByRef obj As CPersistentObject, ByVal conn As _CConnection, ByVal deleteSuperClass As Boolean) + Private Sub deletePrivateObject(ByRef obj As IPersistableObject, ByVal conn As _CConnection, ByVal deleteSuperClass As Boolean) Dim clMap As CClassMap - clMap = obj.getClassMap(obj) + clMap = obj.getClassMap Dim cm As CClassMap cm = clMap @@ -870,9 +877,9 @@ Dim udaMap As CUDAMap Dim aCriteria As CRetrieveCriteria Dim cursor As CCursor - Dim Value As CPersistentObject + Dim Value As IPersistableObject Dim ValueVar As String - Dim col As CPersistentCollection + Dim col As IList Dim colCriteriaParameters As New Collection Dim i As Short, j As Short, k As Short Dim myKeys(cm.AssociationMaps.Count) As String @@ -885,7 +892,8 @@ If udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then Value = obj.getObjectByAttribute(udaMap.Target) If Not Value Is Nothing Then - If Value.Retrieve() Then + If retrieveObject(Value, False, True) Then + 'If Value.Retrieve() Then deletePrivateObject(Value, conn, deleteSuperClass) End If End If @@ -894,7 +902,8 @@ If Not col Is Nothing Then For k = 0 To col.Count - 1 Value = col.Item(k) - If Value.Retrieve Then + If retrieveObject(Value, False, True) Then + 'If Value.Retrieve Then deletePrivateObject(Value, conn, deleteSuperClass) End If Next k @@ -905,25 +914,6 @@ End If Next i - 'Delete any objects that inherit from this one - 'Dim delCriteria As CDeleteCriteria - 'For Each cm In clMap.ChildrenMaps - ' 'No need to delete if the child data is in the same record as the parent (ie shared tables) - ' If cm.SharedTableField Is Nothing Then - ' delCriteria = New CDeleteCriteria - ' delCriteria.ClassMap = cm - ' For Each am As CAttributeMap In cm.ReferenceAttributeMaps - ' ValueVar = cm.getValueForRelationalDatabase(obj.getValueByAttribute(am.AttributeMap.Name)) - ' aCriteria.WhereCondition.addSelectEqualTo(am.Name, ValueVar) - ' Next am - ' Try - ' delCriteria.perform() - ' Catch ex As Exception - ' End Try - ' delCriteria = Nothing - ' End If - 'Next cm - Dim statement As CSqlStatement statement = clMap.getDeleteSqlFor(obj) conn.processStatement(statement) @@ -933,7 +923,8 @@ If Not cm Is Nothing Then 'delete super class and its associations Value = obj.getObjectByClassMap(cm) - If Value.Retrieve() Then + If retrieveObject(Value, False, True) Then + 'If Value.Retrieve() Then deletePrivateObject(Value, conn, True) End If End If @@ -1247,7 +1238,7 @@ Dim i As Integer Dim t As Type Dim outString As String - Dim obj As CPersistentObject + Dim obj As IPersistableObject Dim ck As CCacheKey outString = ">>>> START CACHE DUMP <<<<" & vbCrLf @@ -1255,7 +1246,7 @@ For Each x In m_cache ce = x.Value obj = ce.PersistentObject - t = obj.GetType + t = obj.GetObjectType ck = x.Key outString &= i.ToString & "> " & t.ToString & " Dirty:" & obj.IsDirty.ToString & _ " Persistent:" & obj.Persistent.ToString & _ @@ -2099,6 +2090,7 @@ 'Dim stack As New Stack Dim queue As New Queue Dim i, k As Integer + Dim tmpObj As Object 'Determine if the object needs saving If Not checkAssociationsRecursivly Then @@ -2123,8 +2115,8 @@ If includeBaseObject AndAlso _ (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.isReadOnly AndAlso Not obj.isModifyOnly) Then If TypeOf (obj) Is CPersistentObject Then - If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid - obj.IsDirty = False 'Added to queue so clear dirty flag + If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid + obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) End If Else @@ -2145,17 +2137,24 @@ udamap = cm.getStraightAssociationMap(i) If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - value = obj.getObjectByAttribute(udamap.Target) - If Not value Is Nothing Then - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next + tmpObj = obj.GetObjectByAttribute(udamap.Target) + If Not tmpObj Is Nothing Then + If Not value Is Nothing Then + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next + End If End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then - col = obj.getCollectionByAttribute(udamap.Target) + col = obj.GetCollectionByAttribute(udamap.Target) If Not col Is Nothing Then For k = 0 To col.Count() - 1 - value = col.Item(k) + tmpObj = col.Item(k) + If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + value = LocateOrCreateInjObject(tmpObj) + Else + value = tmpObj + End If For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) queue.Enqueue(o) Next @@ -2169,17 +2168,24 @@ udamap = cm.getInverseAssociationMap(i) If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - value = obj.getObjectByAttribute(udamap.Target) - If Not value Is Nothing Then - For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) - queue.Enqueue(o) - Next + tmpObj = obj.GetObjectByAttribute(udamap.Target) + If Not tmpObj Is Nothing Then + If Not value Is Nothing Then + For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) + queue.Enqueue(o) + Next + End If End If ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then - col = obj.getCollectionByAttribute(udamap.Target) + col = obj.GetCollectionByAttribute(udamap.Target) If Not col Is Nothing Then For k = 0 To col.Count() - 1 - value = col.Item(k) + tmpObj = col.Item(k) + If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + value = LocateOrCreateInjObject(tmpObj) + Else + value = tmpObj + End If For Each o In getObjectsToSave(value, True, checkAssociationsRecursivly) queue.Enqueue(o) Next @@ -2195,7 +2201,12 @@ '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 - value = obj.getObjectByClassMap(cm.SuperClass) + tmpObj = obj.GetObjectByClassMap(cm.SuperClass) + If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + value = LocateOrCreateInjObject(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) @@ -2204,7 +2215,12 @@ End If Else If Not cm.SuperClass Is Nothing Then - value = obj.getObjectByClassMap(cm.SuperClass) + tmpObj = obj.GetObjectByClassMap(cm.SuperClass) + If Not tmpObj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + value = LocateOrCreateInjObject(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) @@ -2312,29 +2328,42 @@ m_cache.Clear() End Sub - Public Sub GetObject(ByVal obj As Object) + Public Sub GetObject(ByRef obj As Object) Dim injObj As CInjectedObject - injObj = New CInjectedObject(obj) - If m_injectedObjects.Exists(obj) Then - Return - Else + 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 End Sub - Public Sub FindObject(ByVal obj As Object) + Public Sub FindObject(ByRef obj As Object) Dim injObj As CInjectedObject - injObj = New CInjectedObject(obj) - If m_injectedObjects.Exists(obj) Then - Return - Else + injObj = m_injectedObjects.LocateObject(obj) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) retrieveObject(injObj, True, True) m_injectedObjects.Add(injObj) + obj = injObj.GetSourceObject + Else + obj = injObj.GetSourceObject End If End Sub Public Function getInjectedObject(ByVal obj As Object) As CInjectedObject - Return m_injectedObjects.Find(obj) + 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) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) + End If + Return injObj End Function Public Sub StartTracking(ByVal obj As Object) @@ -2343,18 +2372,43 @@ m_injectedObjects.Add(injObj) End Sub - Public Function GetCurrentState(ByVal obj As Object) As CInjectedObject.State + 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) + MarkForDeletion(obj, False) + End Sub + + Public Sub MarkForDeletion(ByVal obj As Object, ByVal deleteParents As Boolean) Dim injObj As CInjectedObject - injObj = m_injectedObjects.Find(obj) - If Not injObj Is Nothing Then - Return injObj.CurrentState + injObj = m_injectedObjects.LocateObject(obj) + If injObj Is Nothing Then + 'Nothing to do Else - Return CInjectedObject.State.NotLoaded + injObj.MarkedForDeletion = True + injObj.WillDeleteParents = deleteParents End If - End Function + End Sub - Public Sub MarkForDeletion(ByVal obj As Object) + Public Sub PersistChanges() + PersistChanges(True) + End Sub + Public Sub PersistChanges(ByVal checkAssociationsRecursively As Boolean) + Me.startTransaction() + Try + Dim injObj As CInjectedObject + For Each de As DictionaryEntry In m_injectedObjects + injObj = de.Value + PersistChanges(injObj.ReferencedObject) + Next + Me.commit() + Catch ex As Exception + Me.rollback() + Throw ex + End Try End Sub Public Sub PersistChanges(ByVal obj As Object) @@ -2364,33 +2418,37 @@ Public Sub PersistChanges(ByVal obj As Object, ByVal checkAssociationsRecursively As Boolean) Dim value As IPersistableObject Dim queue As Queue - Dim injObj As CInjectedObject - injObj = m_injectedObjects.Find(obj) + + injObj = m_injectedObjects.LocateObject(obj) If injObj Is Nothing Then injObj = New CInjectedObject(obj) End If - 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 - value = queue.Dequeue() - Try - saveObject(value) - 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 - value.IsDirty = False - Loop - commit() + If injObj.MarkedForDeletion Then + deleteObject(injObj, injObj.WillDeleteParents) + 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 + value = queue.Dequeue() + Try + saveObject(value) + 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 + value.IsDirty = False + Loop + commit() + End If End If End Sub + End Class \ No newline at end of file Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- IPersistentObject.vb 14 Oct 2004 05:25:02 -0000 1.3 +++ IPersistentObject.vb 15 Oct 2004 06:42:56 -0000 1.4 @@ -10,25 +10,26 @@ Property OriginalModifiedDate() As Date Property AssociationsLoaded() As Boolean Property IsLoading() As Boolean - ReadOnly Property isReadOnly() As Boolean - ReadOnly Property isModifyOnly() As Boolean + ReadOnly Property IsReadOnly() As Boolean + ReadOnly Property IsModifyOnly() As Boolean Property OriginalCacheKey() As CCacheKey - Function getClassMap() As CClassMap - Function getFieldLengthByName(ByVal x As String) As Integer - Function getFieldTypeByName(ByVal x As String) As Type + Function GetClassMap() As CClassMap + Function GetFieldLengthByName(ByVal x As String) As Integer + Function GetFieldTypeByName(ByVal x As String) As Type - Function getCollectionByAttribute(ByVal pName As String) As IList - Function getObjectByAttribute(ByVal pName As String) As IPersistableObject - Function getValueByAttribute(ByVal pName As String) As Object - Sub setAttributeValue(ByVal pName As String, ByRef Value As Object) + Function GetCollectionByAttribute(ByVal pName As String) As IList + Function GetObjectByAttribute(ByVal pName As String) As IPersistableObject + Function GetValueByAttribute(ByVal pName As String) As Object + Sub SetAttributeValue(ByVal pName As String, ByRef Value As Object) Function GetObjectType() As Type Function Equals(ByVal obj As IPersistableObject) As Boolean Function Copy() As IPersistableObject Sub ReplaceWith(ByVal obj As IPersistableObject) Sub ResetOriginalDates() - Function getObjectByClassMap(ByVal classMap As CClassMap) As IPersistableObject + Function GetObjectByClassMap(ByVal classMap As CClassMap) As IPersistableObject + Function GetSourceObject() As Object End Interface Index: CInjectedObjects.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObjects.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CInjectedObjects.vb 14 Oct 2004 05:25:02 -0000 1.1 +++ CInjectedObjects.vb 15 Oct 2004 06:42:56 -0000 1.2 @@ -1,10 +1,95 @@ +'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) + Public Class CInjectedObjectKey - Inherits CCacheKey + Private m_hashCode As Integer + Private m_type As Type + Private m_keyvalues As Collection + + Public Sub New(ByVal obj As Object) + m_keyvalues = New Collection + m_hashCode = obj.GetHashCode + Dim injObj As New CInjectedObject(obj) + populateKey(injObj) + End Sub Public Sub New(ByVal obj As CInjectedObject) - MyBase.new() - populateWith(obj) + m_keyvalues = New Collection + If obj.ReferencedObject Is Nothing Then + m_hashCode = 0 + Else + m_hashCode = obj.ReferencedObject.GetHashCode + End If + populateKey(obj) End Sub + + Public Overrides Function GetHashCode() As Integer + Return m_hashCode + End Function + + Protected Sub populateKey(ByVal obj As IPersistableObject) + Dim cm As CClassMap + Dim i As Integer + Dim am As CAttributeMap + Dim x As Object + + m_keyvalues = New Collection + m_type = obj.GetObjectType + cm = obj.getClassMap + For i = 1 To cm.getKeySize + am = cm.getKeyAttributeMap(i) + x = obj.getValueByAttribute(am.Name) + m_keyvalues.Add(x) + Next + End Sub + + Public Overloads Shared Function Equals(ByVal obj1 As Object, ByVal obj2 As Object) As Boolean + Dim flag As Boolean + Dim i As Integer + Dim key1, key2 As CInjectedObjectKey + key1 = obj1 + key2 = obj2 + Return key1.Equals(key2) + 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 = obj1 + flag = False + For i = 1 To m_keyvalues.Count + If Me.GetHashCode <> key.GetHashCode Then + Return False + End If + Next + Return True + End Function + + Public Overrides Function ToString() As String + Dim s As String + Dim obj As Object + Dim i As Integer + + s = "" + i = 0 + For Each obj In m_keyvalues + If s.Length > 0 Then + s = s & vbCrLf + End If + i += 1 + Try + s = s & vbTab & i.ToString & ") " & obj.GetType.ToString & ": " & obj.ToString + Catch x As Exception + If obj Is Nothing Then + s = s & vbTab & i.ToString & ") --Null Reference--: " & "Nothing" + Else + s = s & vbTab & i.ToString & ") " & obj.GetType.ToString & ": Unprintable Data" + End If + End Try + Next + Return s + End Function End Class @@ -19,42 +104,51 @@ End If injKey = New CInjectedObjectKey(obj) - 'If Not injKey.hasLegitValues Then - ' Exit Sub - 'End If - If injKey.hasLegitValues AndAlso Not (MyBase.Item(injKey) Is Nothing) Then - 'Replace values if possible, otherwise delete and add new + If Not (MyBase.Item(injKey) Is Nothing) Then Debug.WriteLine("Object: " & obj.GetObjectType.ToString & " is already tracked with key(s):" & vbCrLf & injKey.ToString) Else Debug.WriteLine("Started Tracking " & obj.GetObjectType.ToString & " with keys:" & vbCrLf & injKey.ToString) - 'If obj.getClassMap.RelationalDatabase.getConnection(Nothing).Started Then - ' obj.CurrentState = CInjectedObject.State.Loaded - 'End If MyBase.Add(injKey, obj) End If End Sub - Public Overloads Function Exists(ByVal obj As Object) As Boolean + Public Function LocateObject(ByVal obj As Object) As CInjectedObject + Dim injKey As CInjectedObjectKey Dim injObj As CInjectedObject - injObj = New CInjectedObject(obj) - Return Exists(injObj, False) + injKey = New CInjectedObjectKey(obj) + If Not (MyBase.Item(injKey) Is Nothing) Then + injObj = MyBase.Item(injKey) + 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) + If injObj Is Nothing Then + Return False + Else + Return True + End If End Function Public Overloads Function Exists(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As Boolean - If Find(obj, useFindAttributes) Is Nothing Then + If FindByValue(obj, useFindAttributes) Is Nothing Then Return False Else Return True End If End Function - Public Overloads Function Find(ByVal obj As Object) As CInjectedObject + Public Overloads Function FindByValue(ByVal obj As Object) As CInjectedObject Dim injObj As CInjectedObject injObj = New CInjectedObject(obj) - Return Find(injObj, False) + Return FindByValue(injObj, False) End Function - Public Overloads Function Find(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As CInjectedObject + Public Overloads Function FindByValue(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As CInjectedObject Dim injObj As CInjectedObject Dim x As DictionaryEntry Dim attrmap As CAttributeMap @@ -105,22 +199,32 @@ End Function Public Overloads Sub Remove(ByVal obj As Object) - Dim injObj As CInjectedObject If obj Is Nothing Then Exit Sub End If - injObj = New CInjectedObject(obj) - Dim injkey As New CInjectedObjectKey(injObj) - If Not injkey.hasLegitValues Then - Exit Sub - End If - 'If injObj.getClassMap.RelationalDatabase.getConnection(Nothing).Started Then - ' ce = MyBase.Item(ckey) - ' If Not (ce Is Nothing) Then - ' ce.TransactionType = CCacheEntry.CacheTransaction.Deleted - ' End If - 'Else + Dim injkey As New CInjectedObjectKey(obj) MyBase.Remove(injkey) - 'End If End Sub + + Public Overrides Function ToString() As String + Dim x As DictionaryEntry + Dim injObj As CInjectedObject + Dim i As Integer + Dim t As Type + Dim outString As String + Dim obj As IPersistableObject + Dim key As CInjectedObjectKey + + outString = ">>>> START TRACKED OBJECTS DUMP <<<<" & vbCrLf + i = 1 + For Each x In Me + injObj = x.Value + t = injObj.GetObjectType + key = x.Key + outString &= i.ToString & "> " & t.ToString & vbCrLf & injObj.ToString & vbCrLf + i += 1 + Next x + outString &= ">>>> END TRACKED OBJECTS DUMP <<<<" + Return outString + End Function End Class \ No newline at end of file Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- CClassMap.vb 14 Oct 2004 05:25:02 -0000 1.32 +++ CClassMap.vb 15 Oct 2004 06:42:56 -0000 1.33 @@ -1971,6 +1971,10 @@ End Property Public Function CreateObjectInstance() As IPersistableObject + Dim obj As Object + Dim ip As IPersistableObject + Dim pbroker As CPersistenceBroker + If AssemblyPath <> String.Empty Then 'For late loading assemblies Dim objHdl As ObjectHandle @@ -1979,7 +1983,7 @@ Else objHdl = Activator.CreateInstanceFrom(AssemblyPath, ClassNameSpace & "." & Name) End If - Return CType(objHdl.Unwrap(), IPersistableObject) + obj = CType(objHdl.Unwrap, Object) Else Dim t As Type Dim asmArray As [Assembly]() = AppDomain.CurrentDomain.GetAssemblies @@ -2000,8 +2004,16 @@ If Not t Is Nothing Then Exit For Next If t Is Nothing Then Return Nothing - Return Activator.CreateInstance(t) + obj = Activator.CreateInstance(t) End If + Try + ip = CType(obj, IPersistableObject) + Catch ex As Exception + pbroker = getPersistenceBrokerInstance() + pbroker.StartTracking(obj) + ip = pbroker.getInjectedObject(obj) + End Try + Return ip End Function End Class \ No newline at end of file Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- CCacheEntry.vb 14 Oct 2004 05:25:02 -0000 1.18 +++ CCacheEntry.vb 15 Oct 2004 06:42:55 -0000 1.19 @@ -153,6 +153,7 @@ Private m_type As Type Private m_keyvalues As Collection Private m_hasLegitValues As Boolean + Protected m_hashCode As Integer '''----------------------------------------------------------------------------- ''' <summary> @@ -169,6 +170,7 @@ Public Sub New() m_keyvalues = New Collection m_hasLegitValues = False + m_hashCode = 0 End Sub Public Sub New(ByVal obj As IPersistableObject) @@ -194,25 +196,7 @@ End If m_keyvalues.Add(x) Next - End Sub - - '''----------------------------------------------------------------------------- - ''' <summary> - ''' Creates a new instance of a CCacheKey object - ''' </summary> - ''' <param name="oid">The Object ID of the CPersistentObject that will be cached.</param> - ''' <remarks>This will create a new cache key based on a ObjectID value. It is slightly - ''' faster than the other constructor as it does not have to determine and explore the objects key - ''' fields.</remarks> - ''' <history> - ''' [rbanks] 27/11/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub New(ByVal oid As COID) - m_type = oid.GetType - m_keyvalues = New Collection - m_keyvalues.Add(oid.OID) - m_hasLegitValues = True + CalculateHashCode(obj) End Sub '''----------------------------------------------------------------------------- @@ -350,29 +334,37 @@ ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function GetHashCode() As Integer + Return m_hashCode + End Function + + Private Sub CalculateHashCode(ByVal cachedObject) 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 + If m_hasLegitValues Then + 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 - count += 1 - End If - Next - Return CInt(i / count) - End Function + Next + m_hashCode = CInt(i / count) + Else + m_hashCode = cachedObject.GetHashCode + End If + End Sub ''' ----------------------------------------------------------------------------- ''' <summary> @@ -465,19 +457,11 @@ Dim ckey As CCacheKey If obj Is Nothing Then - 'Debug.WriteLine("Rejected attempt to add empty object to cache") Exit Sub End If If obj.IsProxy Then - 'Debug.WriteLine("Rejected attempt to add proxy object to cache") Exit Sub End If - 'If obj.ExpiryInterval > 0 Then - ' ce = New CCacheEntry(obj.ExpiryInterval) - 'Else - ' ce = New CCacheEntry(m_expiryInterval) - 'End If - ' ce.PersistentObject = obj.Copy ckey = New CCacheKey(obj) If Not ckey.hasLegitValues Then Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CInjectedObject.vb 14 Oct 2004 05:25:02 -0000 1.1 +++ CInjectedObject.vb 15 Oct 2004 06:42:56 -0000 1.2 @@ -1,4 +1,5 @@ Imports System.Reflection +Imports System.Runtime.Remoting 'Class to manage objects injected into the persistence broker 'These will be objects that do not inherit from the cperistentobject class, but which @@ -7,18 +8,9 @@ Public Class CInjectedObject Implements IPersistableObject - Public Enum State - Loaded - Modified - Deleted - Added - NotLoaded - End Enum - Private m_object As Object - Private m_objectState As State Private m_originalObject As Object - Private m_associationsLoaded As Object + Private m_associationsLoaded As Boolean Private m_oid As COID Private m_createdDate As Date 'Set when object is created Private m_modifiedDate As Date 'Set when Dirty flag is set on persisted objects @@ -30,13 +22,14 @@ Private m_retrievedCacheKey As CCacheKey Private m_loading As Boolean Private m_proxy As Boolean + Private m_markedForDeletion As Boolean + Private m_deleteParents As Boolean Public Sub New(ByVal obj As Object) MyBase.New() m_object = obj - 'make a snapshot of the object as it currently exists m_originalObject = Activator.CreateInstance(m_object.GetType) - ReplaceValues(m_object, m_originalObject) + 'ReplaceValues(m_object, m_originalObject) End Sub Public Property ReferencedObject() As Object @@ -57,15 +50,6 @@ End Set End Property - Public Property CurrentState() As State - Get - Return m_objectState - End Get - Set(ByVal Value As State) - m_objectState = Value - End Set - End Property - Public Sub ResetToOriginal() ReplaceValues(m_originalObject, m_object) End Sub @@ -149,6 +133,22 @@ End If End Function + Public Function getOriginalValueByAttribute(ByVal pName As String) As Object + Dim dotPos As Integer + dotPos = pName.IndexOf(".") + If dotPos = -1 Then + Return CallByName(m_originalObject, pName, CallType.Get) + Else + Dim o As Object + Dim objName As String + Dim propertyName As String + objName = pName.Substring(0, dotPos) + propertyName = pName.Substring(dotPos + 1) + o = CallByName(m_originalObject, objName, CallType.Get) + Return CallByName(o, propertyName, CallType.Get) + End If + End Function + Public Property AssociationsLoaded() As Boolean Implements IPersistableObject.AssociationsLoaded Get Return m_associationsLoaded @@ -176,6 +176,24 @@ End Set End Property + Public Property MarkedForDeletion() As Boolean + Get + Return m_markedForDeletion + End Get + Set(ByVal Value As Boolean) + m_markedForDeletion = Value + End Set + End Property + + Public Property WillDeleteParents() As Boolean + Get + Return m_deleteParents + End Get + Set(ByVal Value As Boolean) + m_deleteParents = Value + End Set + End Property + Public Function getFieldLengthByName(ByVal x As String) As Integer Implements IPersistableObject.getFieldLengthByName Return getClassMap.getAttributeMapByString(x, True).ColumnMap.StorageSize() End Function @@ -236,7 +254,13 @@ Return ObjectsMatch(m_object, m_originalObject) End Get Set(ByVal Value As Boolean) - 'Do nothing + 'For injected objects this should only be called from the persistence broker and + 'will indicate that an object has finished loading, etc + 'Since we check for value differences to tell if an object is dirty, we need to + 'replace the original object values with the current ones. + If Value = False Then + ReplaceValues(m_object, m_originalObject) + End If End Set End Property @@ -327,9 +351,13 @@ Public Function getObjectByAttribute(ByVal pName As String) As IPersistableObject Implements IPersistableObject.getObjectByAttribute Dim dotPos As Integer + Dim obj As Object + Dim injobj As CInjectedObject + Dim pbroker As CPersistenceBroker + dotPos = pName.IndexOf(".") If dotPos = -1 Then - Return CallByName(m_object, pName, CallType.Get) + obj = CallByName(m_object, pName, CallType.Get) Else Dim o As Object Dim objName As String @@ -337,8 +365,20 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) - Return CallByName(o, propertyName, CallType.Get) + obj = CallByName(o, propertyName, CallType.Get) + End If + If obj Is Nothing Then Return Nothing + If obj.GetType.IsSubclassOf(GetType(IPersistableObject)) Then + injobj = obj + 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 Public Sub setAttributeValue(ByVal pName As String, ByRef Value As Object) Implements IPersistableObject.setAttributeValue @@ -399,10 +439,13 @@ End Function Public Function Copy() As IPersistableObject Implements IPersistableObject.Copy - Dim m_object2 As Object - m_object2 = Activator.CreateInstance(m_object.GetType) - ReplaceValues(m_object, m_object2) - Return New CInjectedObject(m_object2) + 'Dim m_object2 As Object + Dim injobj As CInjectedObject + injobj = Me.MemberwiseClone + 'm_object2 = Activator.CreateInstance(m_object.GetType) + 'ReplaceValues(m_object, m_object2) + 'injobj = New CInjectedObject(m_object2) + Return injobj End Function Friend Sub ResetOriginalDates() Implements IPersistableObject.ResetOriginalDates @@ -429,16 +472,16 @@ udamap = classMap.getStraightAssociationMap(i) 'If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - obj.setAttributeValue(udamap.Target, Me.getObjectByAttribute(udamap.Target)) + obj.SetAttributeValue(udamap.Target, Me.getObjectByAttribute(udamap.Target)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then - obj.setAttributeValue(udamap.Target, Me.getCollectionByAttribute(udamap.Target)) + obj.SetAttributeValue(udamap.Target, Me.getCollectionByAttribute(udamap.Target)) End If 'End If Next i 'set object's attributes For i = 1 To classMap.AttributeMaps.Count - obj.setAttributeValue(classMap.getAttributeMap(i).Name, Me.getValueByAttribute(classMap.getAttributeMap(i).Name)) + obj.SetAttributeValue(classMap.getAttributeMap(i).Name, Me.getValueByAttribute(classMap.getAttributeMap(i).Name)) Next 'if it has superclass add its attributes @@ -449,23 +492,23 @@ udamap = cm.getStraightAssociationMap(i) 'If udamap.SaveAutomatic Then If udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then - obj.setAttributeValue(udamap.Target, Me.getObjectByAttribute(udamap.Target)) + obj.SetAttributeValue(udamap.Target, Me.getObjectByAttribute(udamap.Target)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then - obj.setAttributeValue(udamap.Target, Me.getCollectionByAttribute(udamap.Target)) + obj.SetAttributeValue(udamap.Target, Me.getCollectionByAttribute(udamap.Target)) End If 'End If Next i 'set superclass's attributes For i = 1 To cm.AttributeMaps.Count - obj.setAttributeValue(cm.getAttributeMap(i).Name, Me.getValueByAttribute(cm.getAttributeMap(i).Name)) + obj.SetAttributeValue(cm.getAttributeMap(i).Name, Me.getValueByAttribute(cm.getAttributeMap(i).Name)) Next cm = cm.SuperClass End While 'copy the OriginalModifiedDate and the ModifiedDate from the child to the parent. 'if we don't do this the object won't get saved correctly on subsequent calls. - obj.setAttributeValue("ModifiedDate", Me.getValueByAttribute("ModifiedDate")) + obj.SetAttributeValue("ModifiedDate", Me.getValueByAttribute("ModifiedDate")) obj.OriginalModifiedDate = Me.OriginalModifiedDate obj.IsDirty = Me.IsDirty @@ -480,5 +523,60 @@ m_originalModDate = Value End Set End Property + + Public Overrides Function ToString() As String + Dim s As String + Dim i As Integer + Dim indent As Integer + Dim formatString As String + + Dim cm As CClassMap + Dim am As CAttributeMap + Dim x As Object + Dim y As Object + Dim xstring As String + Dim ystring As String + + If m_object Is Nothing Then + Return "No object" + End If + + s = Me.GetObjectType.ToString & ": " & vbCrLf + indent = s.Length + formatString = Space(s.Length) & "{0,-9}" & vbTab & "{1,-13}" & vbTab & "{2,-14}" & vbCrLf + s &= [String].Format(formatString, "Attribute", "Current Value", "Original Value") + s &= [String].Format(formatString, "---------", "-------------", "--------------") + i = 0 + cm = getClassMap() + For i = 1 To cm.getKeySize + am = cm.getKeyAttributeMap(i) + x = Me.getValueByAttribute(am.Name) + y = Me.getOriginalValueByAttribute(am.Name) + Try + xstring = x.ToString + Catch ex As Exception + If x Is Nothing Then + xstring = "Nothing" + Else + xstring = "Unprintable" + End If + End Try + Try + ystring = y.ToString + Catch ex As Exception + If y Is Nothing Then + ystring = "Nothing" + Else + ystring = "Unprintable" + End If + End Try + s &= [String].Format(formatString, am.Name, xstring, ystring) + Next + Return s + End Function + + Public Function GetSourceObject() As Object Implements IPersistableObject.GetSourceObject + Return m_object + End Function End Class Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- CPersistentObject.vb 14 Oct 2004 05:25:02 -0000 1.42 +++ CPersistentObject.vb 15 Oct 2004 06:42:56 -0000 1.43 @@ -1769,4 +1769,7 @@ Return Me.GetType End Function + Public Function GetSourceObject() As Object Implements IPersistableObject.GetSourceObject + Return Me + End Function End Class |
From: Richard B. <rb...@us...> - 2004-10-14 05:25:11
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21824 Modified Files: AToMSFramework.vbproj CCacheEntry.vb CClassMap.vb CPersistenceBroker.vb CPersistentObject.vb IPersistentObject.vb modPersistenceBrokerSingleton.vb Added Files: CInjectedObject.vb CInjectedObjects.vb Log Message: Allow the persistence of objects without having to inherit from CPeristentObject. At this stage only basic save and retrieve for a single object is working. Index: AToMSFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/dotnet/AToMSFramework.vbproj,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- AToMSFramework.vbproj 13 Oct 2004 01:36:34 -0000 1.17 +++ AToMSFramework.vbproj 14 Oct 2004 05:25:02 -0000 1.18 @@ -184,6 +184,16 @@ BuildAction = "Compile" /> <File + RelPath = "CInjectedObject.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CInjectedObjects.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "CJoin.vb" SubType = "Code" BuildAction = "Compile" Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- CPersistenceBroker.vb 13 Oct 2004 05:19:01 -0000 1.63 +++ CPersistenceBroker.vb 14 Oct 2004 05:25:02 -0000 1.64 @@ -35,6 +35,7 @@ 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 Public Event LoginDetailsNeeded(ByVal sender As Object, ByRef User As String, ByRef Password As String) @@ -155,12 +156,12 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function retrieveObject(ByRef obj As CPersistentObject, ByVal useFind As Boolean, ByVal useCache As Boolean) As Boolean + Public Function retrieveObject(ByRef obj As IPersistableObject, ByVal useFind As Boolean, ByVal useCache As Boolean) As Boolean SyncLock GetType(CPersistenceBroker) Dim cm As CClassMap Dim conn As _CConnection Dim x As RetrieveException - cm = obj.getClassMap(obj) + cm = obj.getClassMap conn = cm.RelationalDatabase.getConnection(Nothing) conn.AutoCommit = False Try @@ -247,8 +248,8 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Private Function retrievePrivateObject(ByRef obj As CPersistentObject, ByVal conn As _CConnection, ByVal useFind As Boolean, ByVal useCache As Boolean) As Boolean - Dim tmpObj As CPersistentObject + Private Function retrievePrivateObject(ByRef obj As IPersistableObject, ByVal conn As _CConnection, ByVal useFind As Boolean, ByVal useCache As Boolean) As Boolean + Dim tmpObj As IPersistableObject Dim cm As CClassMap Dim t As Type Dim resetLoadingFlag As Boolean @@ -266,7 +267,7 @@ Dim isfirst As Boolean = True Dim am As CAttributeMap - cm = obj.getClassMap(obj) + cm = obj.getClassMap Debug.WriteLine("retrievePrivateObject: " & cm.Name) @@ -280,8 +281,8 @@ End If End If If Not tmpObj Is Nothing Then - t = tmpObj.GetType - If t Is obj.GetType Or t.IsSubclassOf(obj.GetType) Then + t = tmpObj.GetObjectType + If t Is obj.GetObjectType Or t.IsSubclassOf(obj.GetObjectType) Then Debug.WriteLine("retrievePrivateObject: retreived from cache") obj = tmpObj Return True @@ -297,30 +298,6 @@ End If obj.IsLoading = True - 'Dim al As New ArrayList - 'cm2 = cm - 'Do - ' If useFind Then - ' For i = 1 To cm2.getFindSize - ' am = cm2.FindAttributeMaps(i) - ' al.Add(cm2.RelationalDatabase.getValueFor(obj.getValueByAttribute(am.Name))) - ' Next i - ' cm2 = cm2.SuperClass - ' Else - ' For i = 1 To cm2.getKeySize - ' am = cm2.getKeyAttributeMap(i) - ' al.Add(cm2.RelationalDatabase.getValueFor(obj.getValueByAttribute(am.Name))) - ' Next i - ' cm2 = Nothing - ' End If - 'Loop While Not cm2 Is Nothing - 'Dim statement As CSqlStatement - 'If useFind Then - ' statement = cm.getSQLFind(Me, al) - 'Else - ' statement = cm.getSQLRetrieve(Me, al) - 'End If - Dim statement As CSqlStatement If useFind Then statement = cm.getSQLFind(Me, Nothing) @@ -363,10 +340,10 @@ Return False End If - Dim targetobj, anObjPers As CPersistentObject + Dim targetobj, anObjPers As IPersistableObject Dim gotValue As Boolean Dim j As Integer - Dim col As CPersistentCollection + Dim col As IList 'Retrieve superclass details first classMapCount = 1 @@ -430,7 +407,7 @@ If Not gotValue Then 'Check whether the object is of child type If udamap.ForClass.ChildrenMaps.Count > 0 Then - targetobj = Me.createTargetObjectForMultipleInheritance(udamap.ForClass, obj.GetType, obj.GetType.Namespace, rs.ResultSet.Tables(0).Rows(i), joins, conn) + targetobj = Me.createTargetObjectForMultipleInheritance(udamap.ForClass, obj.GetObjectType, obj.GetObjectType.Namespace, rs.ResultSet.Tables(0).Rows(i), joins, conn) 'update classMapCount with the child count number classMapCount += Me.getChildCountForMultipleInheritance(udamap.ForClass) classMapCount -= 1 'This is because we added one in the beginning of the for loop @@ -482,7 +459,7 @@ 'Check whether the object is of child type If udamap.ForClass.ChildrenMaps.Count > 0 Then - targetobj = Me.createTargetObjectForMultipleInheritance(udamap.ForClass, obj.GetType, obj.GetType.Namespace, rs.ResultSet.Tables(0).Rows(i), joins, conn) + targetobj = Me.createTargetObjectForMultipleInheritance(udamap.ForClass, obj.GetObjectType, obj.GetObjectType.Namespace, rs.ResultSet.Tables(0).Rows(i), joins, conn) 'update classMapCount with the child count number classMapCount += Me.getChildCountForMultipleInheritance(udamap.ForClass) classMapCount -= 1 'This is because we added one in the beginning of the for loop @@ -708,11 +685,11 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub saveObject(ByRef obj As CPersistentObject) + Public Sub saveObject(ByRef obj As IPersistableObject) SyncLock GetType(CPersistenceBroker) Dim conn As _CConnection Dim cm As CClassMap - cm = obj.getClassMap(obj) + cm = obj.getClassMap conn = cm.RelationalDatabase.getConnection(Nothing) Try conn.startTransaction() @@ -748,13 +725,13 @@ ''' [rbanks] 16/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Private Sub savePrivateObject(ByRef obj As CPersistentObject, ByVal conn As _CConnection) + Private Sub savePrivateObject(ByRef obj As IPersistableObject, ByVal conn As _CConnection) Dim j, i, k As Integer Dim clMap As CClassMap Dim m As Short Dim udaMap As CUDAMap - Dim Value As CPersistentObject - Dim col As CPersistentCollection + Dim Value As IPersistableObject + Dim col As IList Dim SharedClassMapStack As New Stack Dim cm As CClassMap Dim tmpStatement As CSqlStatement @@ -764,7 +741,7 @@ Dim statement As CSqlStatement Dim rs As CResultset - clMap = obj.getClassMap(obj) + clMap = obj.getClassMap cm = clMap 'Clear dirty flag so that recursion in the class structure doesn't cause an infinite loop obj.IsDirty = False @@ -2113,12 +2090,12 @@ ''' [danmayer] 19/05/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- - Function getObjectsToSave(ByVal obj As CPersistentObject, ByVal includeBaseObject As Boolean, ByVal checkAssociationsRecursivly As Boolean) As Queue + Function getObjectsToSave(ByVal obj As IPersistableObject, ByVal includeBaseObject As Boolean, ByVal checkAssociationsRecursivly As Boolean) As Queue Dim cm As CClassMap Dim de As DictionaryEntry Dim udamap As CUDAMap - Dim value, o As CPersistentObject - Dim col As CPersistentCollection + Dim value, o As IPersistableObject + Dim col As IList 'Dim stack As New Stack Dim queue As New Queue Dim i, k As Integer @@ -2127,7 +2104,9 @@ If Not checkAssociationsRecursivly Then If Not obj.IsDirty Then Return queue 'Do not save if nothing changed If obj.IsProxy Then Return queue 'Do not save if object is proxied - If Not obj.IsValid Then Return queue 'Do not save if object is not valid + If TypeOf (obj) Is CPersistentObject Then + If Not CType(obj, CPersistentObject).IsValid Then Return queue 'Do not save if object is not valid + End If If obj.isReadOnly Then Return queue End If @@ -2135,16 +2114,23 @@ Return queue End If If includeBaseObject Then - obj.IsDirty = False 'Added to queue so clear dirty flag + obj.IsDirty = False 'Added to queue so clear dirty flag queue.Enqueue(obj) 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 obj.IsValid AndAlso Not obj.isReadOnly AndAlso Not obj.isModifyOnly) Then - obj.IsDirty = False 'Added to queue so clear dirty flag - queue.Enqueue(obj) + (obj.IsDirty AndAlso Not obj.IsProxy AndAlso Not obj.isReadOnly AndAlso Not obj.isModifyOnly) Then + If TypeOf (obj) Is CPersistentObject Then + If Not CType(obj, CPersistentObject).IsValid Then 'Do not save if object is not valid + obj.IsDirty = False 'Added to queue so clear dirty flag + queue.Enqueue(obj) + End If + Else + obj.IsDirty = False + queue.Enqueue(obj) + End If End If End If @@ -2211,20 +2197,11 @@ If Not cm.SuperClass Is Nothing Then value = obj.getObjectByClassMap(cm.SuperClass) queue.Enqueue(value) - value.IsDirty = False 'Added to queue so clear dirty flag + value.IsDirty = False 'Added to queue so clear dirty flag For Each o In getObjectsToSave(value, False, checkAssociationsRecursivly) queue.Enqueue(o) Next End If - 'cm = cm.SuperClass - 'While Not cm Is Nothing - ' value = obj.getObjectByClassMap(cm) - ' Stack.Push(value) - ' For Each o In getObjectsToSave(value, False) - ' Stack.Push(o) - ' Next - ' cm = cm.SuperClass - 'End While Else If Not cm.SuperClass Is Nothing Then value = obj.getObjectByClassMap(cm.SuperClass) @@ -2233,14 +2210,6 @@ queue.Enqueue(o) Next End If - 'cm = cm.SuperClass - 'While Not cm Is Nothing - ' value = obj.getObjectByClassMap(cm) - ' For Each o In getObjectsToSave(value, False) - ' Stack.Push(o) - ' Next - ' cm = cm.SuperClass - 'End While End If Return queue End Function @@ -2343,4 +2312,85 @@ m_cache.Clear() End Sub + Public Sub GetObject(ByVal obj As Object) + Dim injObj As CInjectedObject + injObj = New CInjectedObject(obj) + If m_injectedObjects.Exists(obj) Then + Return + Else + retrieveObject(injObj, False, True) + End If + End Sub + + Public Sub FindObject(ByVal obj As Object) + Dim injObj As CInjectedObject + injObj = New CInjectedObject(obj) + If m_injectedObjects.Exists(obj) Then + Return + Else + retrieveObject(injObj, True, True) + m_injectedObjects.Add(injObj) + End If + End Sub + + Public Function getInjectedObject(ByVal obj As Object) As CInjectedObject + Return m_injectedObjects.Find(obj) + End Function + + Public Sub StartTracking(ByVal obj As Object) + Dim injObj As CInjectedObject + injObj = New CInjectedObject(obj) + m_injectedObjects.Add(injObj) + End Sub + + Public Function GetCurrentState(ByVal obj As Object) As CInjectedObject.State + Dim injObj As CInjectedObject + injObj = m_injectedObjects.Find(obj) + If Not injObj Is Nothing Then + Return injObj.CurrentState + Else + Return CInjectedObject.State.NotLoaded + End If + End Function + + Public Sub MarkForDeletion(ByVal obj As Object) + + End Sub + + Public Sub PersistChanges(ByVal obj As Object) + PersistChanges(obj, True) + End Sub + + Public Sub PersistChanges(ByVal obj As Object, ByVal checkAssociationsRecursively As Boolean) + Dim value As IPersistableObject + Dim queue As Queue + + Dim injObj As CInjectedObject + injObj = m_injectedObjects.Find(obj) + If injObj Is Nothing Then + injObj = New CInjectedObject(obj) + End If + + 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 + value = queue.Dequeue() + Try + saveObject(value) + 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 + value.IsDirty = False + Loop + commit() + End If + End Sub End Class \ No newline at end of file Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IPersistentObject.vb 13 Oct 2004 05:19:01 -0000 1.2 +++ IPersistentObject.vb 14 Oct 2004 05:25:02 -0000 1.3 @@ -1,4 +1,4 @@ -Public Interface IPersistentObject +Public Interface IPersistableObject Property Persistent() As Boolean Property IsProxy() As Boolean Property IsDirty() As Boolean @@ -7,10 +7,33 @@ Property GUIDValue() As String Property CreatedDate() As Date Property ModifiedDate() As Date + Property OriginalModifiedDate() As Date Property AssociationsLoaded() As Boolean Property IsLoading() As Boolean ReadOnly Property isReadOnly() As Boolean ReadOnly Property isModifyOnly() As Boolean + Property OriginalCacheKey() As CCacheKey + + Function getClassMap() As CClassMap + Function getFieldLengthByName(ByVal x As String) As Integer + Function getFieldTypeByName(ByVal x As String) As Type + + Function getCollectionByAttribute(ByVal pName As String) As IList + Function getObjectByAttribute(ByVal pName As String) As IPersistableObject + Function getValueByAttribute(ByVal pName As String) As Object + Sub setAttributeValue(ByVal pName As String, ByRef Value As Object) + + Function GetObjectType() As Type + Function Equals(ByVal obj As IPersistableObject) As Boolean + Function Copy() As IPersistableObject + Sub ReplaceWith(ByVal obj As IPersistableObject) + Sub ResetOriginalDates() + Function getObjectByClassMap(ByVal classMap As CClassMap) As IPersistableObject + +End Interface + +Public Interface IPersistentObject + Inherits IPersistableObject Function Retrieve() As Boolean Function Retrieve(ByRef obj As CPersistentObject) As Boolean @@ -30,16 +53,10 @@ Sub Delete(ByVal obj As CPersistentObject, ByVal deleteSuperClass As Boolean) Sub DeleteAll() - Function Copy() As CPersistentObject Function IsValid() As Boolean Function IsReferenced() As Boolean Function getNewObject() As CPersistentObject - Function getClassMap() As CClassMap - Function getFieldLengthByName(ByVal x As String) As Integer - Function getFieldTypeByName(ByVal x As String) As Type - - Function Equals(ByVal obj As CPersistentObject) As Boolean Event MarkedAsDirty As EventHandler Event LoadStarted As EventHandler Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- CClassMap.vb 6 Oct 2004 23:42:23 -0000 1.31 +++ CClassMap.vb 14 Oct 2004 05:25:02 -0000 1.32 @@ -745,7 +745,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function getDeleteSqlFor(ByVal obj As CPersistentObject) As CSqlStatement + Public Function getDeleteSqlFor(ByVal obj As IPersistableObject) As CSqlStatement If Not m_deleteStatement Is Nothing Then m_deleteStatement = Nothing End If @@ -989,7 +989,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function getSelectSqlFor(ByVal obj As CPersistentObject) As CSqlStatement + Public Function getSelectSqlFor(ByVal obj As IPersistableObject) As CSqlStatement Return getSelectSqlFor(obj, False) End Function @@ -1005,7 +1005,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function getSelectSqlFor(ByVal obj As CPersistentObject, ByVal useFind As Boolean) As CSqlStatement + Public Function getSelectSqlFor(ByVal obj As IPersistableObject, ByVal useFind As Boolean) As CSqlStatement If Not m_selectStatement Is Nothing Then m_selectStatement = Nothing End If @@ -1089,7 +1089,7 @@ ''' [rbanks] 23/01/2004 Adjusted to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- - Public Function getInsertSqlFor(ByVal obj As CPersistentObject) As CSqlStatement + Public Function getInsertSqlFor(ByVal obj As IPersistableObject) As CSqlStatement ' ' Identity columns with null values should not be included in the insert statement. ' The database will populate them during the insert. @@ -1203,7 +1203,7 @@ ''' [rbanks] 23/01/2004 Adjusted to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- - Public Function getUpdateSqlFor(ByVal obj As CPersistentObject) As CSqlStatement + Public Function getUpdateSqlFor(ByVal obj As IPersistableObject) As CSqlStatement If Not m_updateStatement Is Nothing Then m_updateStatement = Nothing End If @@ -1323,7 +1323,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub retrieveObject(ByRef obj As CPersistentObject, ByVal rs As CResultset) + Public Sub retrieveObject(ByRef obj As IPersistableObject, ByVal rs As CResultset) Dim tm As CTableMap Dim ClassMap As CClassMap ClassMap = Me @@ -1355,7 +1355,7 @@ ''' </history> '''----------------------------------------------------------------------------- - Public Sub retrieveObject(ByRef cm As CClassMap, ByRef obj As CPersistentObject, ByVal rs As CResultset, ByVal pAlias As String) + Public Sub retrieveObject(ByRef cm As CClassMap, ByRef obj As IPersistableObject, ByVal rs As CResultset, ByVal pAlias As String) Dim i As Short Dim AttrMap As CAttributeMap Dim val As Object @@ -1403,7 +1403,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub retrieveObject(ByRef obj As CPersistentObject, ByVal rw As DataRow) + Public Sub retrieveObject(ByRef obj As IPersistableObject, ByVal rw As DataRow) Dim tm As CTableMap Dim ClassMap As CClassMap ClassMap = Me @@ -1434,7 +1434,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub retrieveObject(ByRef ClassMap As CClassMap, ByRef obj As CPersistentObject, ByVal rw As DataRow, ByVal pAlias As String) + Public Sub retrieveObject(ByRef ClassMap As CClassMap, ByRef obj As IPersistableObject, ByVal rw As DataRow, ByVal pAlias As String) Dim tmpObj As Object If obj Is Nothing Then Throw New RetrieveException("Source object not instantiated yet") @@ -1523,13 +1523,15 @@ End If Next i ClassMap = ClassMap.SuperClass + If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then + obj.Persistent = True + End If Loop While Not ClassMap Is Nothing - obj.Persistent = True obj.IsProxy = True obj.IsDirty = False End Sub - Public Sub retrieveKeys(ByRef ClassMap As CClassMap, ByRef obj As CPersistentObject, ByVal rw As DataRow, ByVal pAlias As String) + Public Sub retrieveKeys(ByRef ClassMap As CClassMap, ByRef obj As IPersistableObject, ByVal rw As DataRow, ByVal pAlias As String) Dim tmpObj As Object If obj Is Nothing Then Throw New RetrieveException("Source object has not been instantiated yet") @@ -1968,7 +1970,7 @@ End Get End Property - Public Function CreateObjectInstance() As CPersistentObject + Public Function CreateObjectInstance() As IPersistableObject If AssemblyPath <> String.Empty Then 'For late loading assemblies Dim objHdl As ObjectHandle @@ -1977,7 +1979,7 @@ Else objHdl = Activator.CreateInstanceFrom(AssemblyPath, ClassNameSpace & "." & Name) End If - Return CType(objHdl.Unwrap(), CPersistentObject) + Return CType(objHdl.Unwrap(), IPersistableObject) Else Dim t As Type Dim asmArray As [Assembly]() = AppDomain.CurrentDomain.GetAssemblies --- NEW FILE: CInjectedObjects.vb --- Public Class CInjectedObjectKey Inherits CCacheKey Public Sub New(ByVal obj As CInjectedObject) MyBase.new() populateWith(obj) End Sub End Class Public Class CInjectedObjects Inherits System.Collections.Hashtable Public Overloads Sub Add(ByVal obj As CInjectedObject) Dim injKey As CInjectedObjectKey If obj.ReferencedObject Is Nothing Then Exit Sub End If injKey = New CInjectedObjectKey(obj) 'If Not injKey.hasLegitValues Then ' Exit Sub 'End If If injKey.hasLegitValues AndAlso Not (MyBase.Item(injKey) Is Nothing) Then 'Replace values if possible, otherwise delete and add new Debug.WriteLine("Object: " & obj.GetObjectType.ToString & " is already tracked with key(s):" & vbCrLf & injKey.ToString) Else Debug.WriteLine("Started Tracking " & obj.GetObjectType.ToString & " with keys:" & vbCrLf & injKey.ToString) 'If obj.getClassMap.RelationalDatabase.getConnection(Nothing).Started Then ' obj.CurrentState = CInjectedObject.State.Loaded 'End If MyBase.Add(injKey, obj) End If End Sub Public Overloads Function Exists(ByVal obj As Object) As Boolean Dim injObj As CInjectedObject injObj = New CInjectedObject(obj) Return Exists(injObj, False) End Function Public Overloads Function Exists(ByVal obj As CInjectedObject, ByVal useFindAttributes As Boolean) As Boolean If Find(obj, useFindAttributes) Is Nothing Then Return False Else Return True End If End Function Public Overloads Function Find(ByVal obj As Object) As CInjectedObject Dim injObj As CInjectedObject injObj = New CInjectedObject(obj) Return Find(injObj, False) End Function 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 Dim i As Integer Dim found As Boolean Dim cm As CClassMap Dim t As Type Dim interval As Double cm = obj.getClassMap 'We only check for objects of the same type Dim m_Enumerator As Collections.IEnumerator = Me.GetEnumerator() While m_Enumerator.MoveNext() x = m_Enumerator.Current injObj = x.Value t = injObj.GetObjectType If t Is obj.GetObjectType Or t.IsSubclassOf(obj.GetObjectType) Then found = True If useFindAttributes Then For i = 1 To cm.getFindSize attrmap = cm.FindAttributeMaps(i) 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 = cm.KeyAttributeMaps(i) If Not obj.getValueByAttribute(attrmap.Name).Equals(injObj.getValueByAttribute(attrmap.Name)) Then found = False Exit For End If Next i End If If found Then 'If ce.TransactionType = CCacheEntry.CacheTransaction.Deleted Then ' Return Nothing 'End If Debug.WriteLine([String].Format("Injection Cache - getting {0} object from cache. Key..." & vbCrLf & x.Key.ToString, x.Key.ObjType.Name)) Return injObj End If End If End While Return Nothing End Function Public Overloads Sub Remove(ByVal obj As Object) Dim injObj As CInjectedObject If obj Is Nothing Then Exit Sub End If injObj = New CInjectedObject(obj) Dim injkey As New CInjectedObjectKey(injObj) If Not injkey.hasLegitValues Then Exit Sub End If 'If injObj.getClassMap.RelationalDatabase.getConnection(Nothing).Started Then ' ce = MyBase.Item(ckey) ' If Not (ce Is Nothing) Then ' ce.TransactionType = CCacheEntry.CacheTransaction.Deleted ' End If 'Else MyBase.Remove(injkey) 'End If End Sub End Class Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- CPersistentObject.vb 13 Oct 2004 05:19:01 -0000 1.41 +++ CPersistentObject.vb 14 Oct 2004 05:25:02 -0000 1.42 @@ -381,10 +381,13 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - <Browsable(False)> Public ReadOnly Property OriginalModifiedDate() As Date + <Browsable(False)> Public Property OriginalModifiedDate() As Date Implements IPersistentObject.OriginalModifiedDate Get Return m_originalModDate End Get + Set(ByVal Value As Date) + m_originalModDate = Value + End Set End Property '''----------------------------------------------------------------------------- @@ -432,7 +435,7 @@ End Set End Property - <Browsable(False)> Friend Property OriginalCacheKey() As CCacheKey + <Browsable(False)> Friend Property OriginalCacheKey() As CCacheKey Implements IPersistableObject.OriginalCacheKey Get Return m_retrievedCacheKey End Get @@ -456,7 +459,7 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Friend Sub ResetOriginalDates() + Friend Sub ResetOriginalDates() Implements IPersistentObject.ResetOriginalDates m_originalModDate = m_modifiedDate End Sub @@ -474,7 +477,7 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub setAttributeValue(ByVal pName As String, ByRef Value As Object) + Public Sub setAttributeValue(ByVal pName As String, ByRef Value As Object) Implements IPersistentObject.setAttributeValue If TypeOf (Value) Is System.DBNull Then Exit Sub @@ -523,7 +526,7 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function getValueByAttribute(ByVal pName As String) As Object + Public Function getValueByAttribute(ByVal pName As String) As Object Implements IPersistentObject.getValueByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") If dotPos = -1 Then @@ -552,7 +555,7 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function getObjectByAttribute(ByVal pName As String) As CPersistentObject + Public Function getObjectByAttribute(ByVal pName As String) As IPersistableObject Implements IPersistableObject.getObjectByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") If dotPos = -1 Then @@ -622,7 +625,7 @@ ''' [rbanks] 26/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function getCollectionByAttribute(ByVal pName As String) As CPersistentCollection + Public Overloads Function getCollectionByAttribute(ByVal pName As String) As IList Implements IPersistentObject.getCollectionByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") Try @@ -1114,7 +1117,7 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Overloads Function Equals(ByVal obj As CPersistentObject) As Boolean Implements IPersistentObject.Equals + Public Overloads Function Equals(ByVal obj As IPersistableObject) As Boolean Implements IPersistentObject.Equals Dim ck1, ck2 As CCacheKey If Me Is Nothing And Not obj Is Nothing Then Return False @@ -1174,7 +1177,7 @@ ''' [rbanks] 26/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Overridable Function Copy() As CPersistentObject Implements IPersistentObject.Copy + Public Overridable Function Copy() As IPersistableObject Implements IPersistentObject.Copy Return Me.MemberwiseClone End Function @@ -1190,10 +1193,10 @@ ''' [rbanks] 12/08/2004 Created ''' </history> '''----------------------------------------------------------------------------- - Public Overridable Sub ReplaceWith(ByVal obj As CPersistentObject) + Public Overridable Sub ReplaceWith(ByVal obj As IPersistableObject) Implements IPersistentObject.ReplaceWith 'Use reflection to copy all of the fields from Obj to me (by value) If obj Is Nothing Then Return - If Not obj.GetType Is Me.GetType Then + If Not obj.GetObjectType Is Me.GetObjectType Then Throw New Exception("Objects must be of the same type") End If Dim f, fields() As FieldInfo @@ -1545,7 +1548,7 @@ ''' [danymayer] 19/07/2004 Created ''' </history> '''----------------------------------------------------------------------------- - Function getObjectByClassMap(ByVal classMap As CClassMap) As CPersistentObject + Function getObjectByClassMap(ByVal classMap As CClassMap) As IPersistableObject Implements IPersistentObject.getObjectByClassMap Dim obj, Value As CPersistentObject Dim col As CPersistentCollection Dim i, k As Integer @@ -1762,4 +1765,8 @@ End Sub #End Region + Public Function GetObjectType() As System.Type Implements IPersistableObject.GetObjectType + Return Me.GetType + End Function + End Class Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- CCacheEntry.vb 9 Sep 2004 08:14:01 -0000 1.17 +++ CCacheEntry.vb 14 Oct 2004 05:25:02 -0000 1.18 @@ -26,11 +26,11 @@ Added End Enum - Private m_object As CPersistentObject - Private m_objectCopy As CPersistentObject + Private m_object As IPersistableObject + Private m_objectCopy As IPersistableObject Private m_transactionType As CCacheEntry.CacheTransaction Private m_expiryTime As Date - Private m_originalObject As CPersistentObject + Private m_originalObject As IPersistableObject '''----------------------------------------------------------------------------- ''' <summary> @@ -43,11 +43,11 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Property PersistentObject() As CPersistentObject + Public Property PersistentObject() As IPersistableObject Get Return m_object End Get - Set(ByVal Value As CPersistentObject) + Set(ByVal Value As IPersistableObject) m_object = Value End Set End Property @@ -74,11 +74,11 @@ 'Instead of returning a copy of the object we need to return the object itself 'Otherwise circular references during loading will refer to partial object copies instead of 'the real object. - Public Property OriginalObject() As CPersistentObject + Public Property OriginalObject() As IPersistableObject Get Return m_originalObject End Get - Set(ByVal Value As CPersistentObject) + Set(ByVal Value As IPersistableObject) m_originalObject = Value End Set End Property @@ -165,16 +165,26 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Sub New(ByVal obj As CPersistentObject) + + Public Sub New() + m_keyvalues = New Collection + m_hasLegitValues = False + End Sub + + Public Sub New(ByVal obj As IPersistableObject) + populateWith(obj) + End Sub + + Protected Sub populateWith(ByVal obj As IPersistableObject) Dim cm As CClassMap Dim i As Integer Dim am As CAttributeMap Dim x As Object m_keyvalues = New Collection - m_type = obj.GetType + m_type = obj.GetObjectType m_hasLegitValues = True - cm = obj.getClassMap(obj) + cm = obj.getClassMap For i = 1 To cm.getKeySize am = cm.getKeyAttributeMap(i) x = obj.getValueByAttribute(am.Name) @@ -347,17 +357,19 @@ i = m_type.Name.GetHashCode count = 1 For Each obj In m_keyvalues - 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 + 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 - count += 1 Next Return CInt(i / count) End Function @@ -390,7 +402,11 @@ Try s = s & vbTab & i.ToString & ") " & obj.GetType.ToString & ": " & obj.ToString Catch x As Exception - s = s & vbTab & i.ToString & ") " & obj.GetType.ToString & ": " & "unprintable data" + If obj Is Nothing Then + s = s & vbTab & i.ToString & ") --Null Reference--: " & "unprintable data" + Else + s = s & vbTab & i.ToString & ") " & obj.GetType.ToString & ": " & "unprintable data" + End If End Try Next Return s @@ -444,7 +460,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Overloads Sub Add(ByVal obj As CPersistentObject) + Public Overloads Sub Add(ByVal obj As IPersistableObject) Dim ce As CCacheEntry Dim ckey As CCacheKey @@ -470,7 +486,7 @@ End If If Not (MyBase.Item(ckey) Is Nothing) Then 'Replace values if possible, otherwise delete and add new - Debug.WriteLine("Cache - replacing existing " & obj.GetType.ToString & " object in cache with keys:" & vbCrLf & ckey.ToString) + Debug.WriteLine("Cache - replacing existing " & obj.GetObjectType.ToString & " object in cache with keys:" & vbCrLf & ckey.ToString) ce = MyBase.Item(ckey) If obj.ExpiryInterval > 0 Then ce.resetExpiry(obj.ExpiryInterval) @@ -489,7 +505,7 @@ MyBase.Add(ckey, ce) End Try Else - Debug.WriteLine("Cache - adding " & obj.GetType.ToString & " object with keys:" & vbCrLf & ckey.ToString) + Debug.WriteLine("Cache - adding " & obj.GetObjectType.ToString & " object with keys:" & vbCrLf & ckey.ToString) If obj.ExpiryInterval > 0 Then ce = New CCacheEntry(obj.ExpiryInterval) Else @@ -519,7 +535,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Function Find(ByVal obj As CPersistentObject) As CPersistentObject + Public Function Find(ByVal obj As IPersistableObject) As IPersistableObject Dim x As DictionaryEntry Dim ce As CCacheEntry Dim attrmap As CAttributeMap @@ -529,7 +545,7 @@ Dim t As Type Dim interval As Double - cm = obj.getClassMap(obj) + cm = obj.getClassMap 'Debug.WriteLine("Cache - Attempt to Find() <" & cm.Name & "> object in cache") @@ -543,13 +559,13 @@ While m_Enumerator.MoveNext() x = m_Enumerator.Current ce = x.Value - t = ce.PersistentObject.GetType - If t Is obj.GetType Or t.IsSubclassOf(obj.GetType) Then + t = ce.PersistentObject.GetObjectType + If t Is obj.GetObjectType Or t.IsSubclassOf(obj.GetObjectType) Then If ce.IsExpired() And Not ce.PersistentObject.IsDirty Then 'Debug.WriteLine("Cache - Removing expired object from cache during Find()") MyBase.Remove(x.Key) 'delete object from cache m_Enumerator = Me.GetEnumerator - m_Enumerator.Reset() 'Reset enumerator after removing item + m_Enumerator.Reset() 'Reset enumerator after removing item Else found = True For i = 1 To cm.getFindSize @@ -588,7 +604,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Default Public Overloads ReadOnly Property Item(ByVal OIDValue As String) As CPersistentObject + Default Public Overloads ReadOnly Property Item(ByVal OIDValue As String) As IPersistableObject Get Dim ce As CCacheEntry ce = MyBase.Item(OIDValue) @@ -621,7 +637,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Default Public Overloads ReadOnly Property Item(ByVal obj As CPersistentObject) As CPersistentObject + Default Public Overloads ReadOnly Property Item(ByVal obj As IPersistableObject) As IPersistableObject Get Dim ce As CCacheEntry Dim ckey As CCacheKey @@ -657,7 +673,7 @@ ''' [rbanks] 27/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Overloads Sub Remove(ByVal obj As CPersistentObject) + Public Overloads Sub Remove(ByVal obj As IPersistableObject) Dim ce As CCacheEntry If obj Is Nothing Then 'Debug.WriteLine("Rejected attempt to delete empty object from cache") @@ -781,12 +797,12 @@ End Set End Property - Private Function GetCachedObject(ByVal ce As CCacheEntry) As CPersistentObject + Private Function GetCachedObject(ByVal ce As CCacheEntry) As IPersistableObject If m_objectsLoading Then - Debug.WriteLine(" - returning original object " & ce.PersistentObject.GetType.Name) + Debug.WriteLine(" - returning original object " & ce.PersistentObject.GetObjectType.Name) Return ce.OriginalObject Else - Debug.WriteLine(" - returning copy of object " & ce.PersistentObject.GetType.Name) + Debug.WriteLine(" - returning copy of object " & ce.PersistentObject.GetObjectType.Name) Return ce.PersistentObject.Copy End If End Function --- NEW FILE: CInjectedObject.vb --- Imports System.Reflection 'Class to manage objects injected into the persistence broker 'These will be objects that do not inherit from the cperistentobject class, but which 'still need to be saved/retrieved from the database. Public Class CInjectedObject Implements IPersistableObject Public Enum State Loaded Modified Deleted Added NotLoaded End Enum Private m_object As Object Private m_objectState As State Private m_originalObject As Object Private m_associationsLoaded As Object Private m_oid As COID Private m_createdDate As Date 'Set when object is created Private m_modifiedDate As Date 'Set when Dirty flag is set on persisted objects Private m_originalModDate, m_blankDate As Date Private m_cacheExpiry As Double Private m_guid As Guid Private m_classmap As CClassMap Private m_persistent As Boolean Private m_retrievedCacheKey As CCacheKey Private m_loading As Boolean Private m_proxy As Boolean Public Sub New(ByVal obj As Object) MyBase.New() m_object = obj 'make a snapshot of the object as it currently exists m_originalObject = Activator.CreateInstance(m_object.GetType) ReplaceValues(m_object, m_originalObject) End Sub Public Property ReferencedObject() As Object Get Return m_object End Get Set(ByVal Value As Object) m_object = Value End Set End Property Public Property OriginalObject() As Object Get Return m_originalObject End Get Set(ByVal Value As Object) m_originalObject = Value End Set End Property Public Property CurrentState() As State Get Return m_objectState End Get Set(ByVal Value As State) m_objectState = Value End Set End Property Public Sub ResetToOriginal() ReplaceValues(m_originalObject, m_object) End Sub Sub ReplaceWith(ByVal obj As IPersistableObject) Implements IPersistableObject.ReplaceWith If Not obj.GetObjectType Is Me.GetObjectType Then Throw New Exception("Objects must be of the same type") End If Dim injObj As CInjectedObject If TypeOf (obj) Is CInjectedObject Then injObj = obj ReplaceValues(injObj.m_object, m_object) Else ReplaceValues(obj, m_object) End If End Sub Public Sub ReplaceValues(ByVal sourceObject As Object, ByVal targetObject As Object) 'Use reflection to copy all of the fields from sourceObj to targetobject (by value) If sourceObject Is Nothing OrElse targetObject Is Nothing Then Return If Not sourceObject.GetType Is targetObject.GetType Then Throw New Exception("Objects must be of the same type") End If Dim f, fields() As FieldInfo Dim value 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) f.SetValue(targetObject, value) 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) End Try End Sub Public Function getClassMap() As CClassMap Implements IPersistableObject.getClassMap Dim ClassMap As CClassMap Dim persistenceBroker As CPersistenceBroker persistenceBroker = getPersistenceBrokerInstance() ClassMap = persistenceBroker.getClassMap(TypeName(m_object)) If ClassMap Is Nothing Then ClassMap = persistenceBroker.getClassMap(m_object.GetType.FullName) End If If (ClassMap Is Nothing) Then Throw New NoClassMapException("No class map for " & m_object.GetType.FullName) End If Return ClassMap End Function Public Function GetObjectType() As Type Implements IPersistableObject.GetObjectType If m_object Is Nothing Then Return GetType(Object) End If Return m_object.GetType End Function Public Function getValueByAttribute(ByVal pName As String) As Object Implements IPersistableObject.getValueByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") If dotPos = -1 Then Return CallByName(m_object, pName, CallType.Get) Else Dim o As Object Dim objName As String Dim propertyName As String objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) Return CallByName(o, propertyName, CallType.Get) End If End Function Public Property AssociationsLoaded() As Boolean Implements IPersistableObject.AssociationsLoaded Get Return m_associationsLoaded End Get Set(ByVal Value As Boolean) m_associationsLoaded = Value End Set End Property Public Property CreatedDate() As Date Implements IPersistableObject.CreatedDate Get Return m_createdDate End Get Set(ByVal Value As Date) m_createdDate = Value End Set End Property Public Property ExpiryInterval() As Double Implements IPersistableObject.ExpiryInterval Get Return m_cacheExpiry End Get Set(ByVal Value As Double) m_cacheExpiry = Value End Set End Property Public Function getFieldLengthByName(ByVal x As String) As Integer Implements IPersistableObject.getFieldLengthByName Return getClassMap.getAttributeMapByString(x, True).ColumnMap.StorageSize() End Function Public Function getFieldTypeByName(ByVal x As String) As System.Type Implements IPersistableObject.getFieldTypeByName Return getClassMap.getAttributeMapByString(x, True).ColumnMap.StorageType End Function Public Property GUIDValue() As String Implements IPersistableObject.GUIDValue Get If m_guid.Equals(Guid.Empty) Then m_guid = Guid.NewGuid End If GUIDValue = m_guid.ToString("N") End Get Set(ByVal value As String) m_guid = New Guid(value) End Set End Property Public Function ObjectsMatch(ByVal sourceObject As Object, ByVal targetObject As Object) As Boolean 'Use reflection to compare all of the fields from sourceObj to targetobject (by value) If sourceObject Is Nothing AndAlso targetObject Is Nothing Then Return True If sourceObject Is Nothing OrElse targetObject Is Nothing Then Return False If Not sourceObject.GetType Is targetObject.GetType Then Return False End If Dim f, fields() As FieldInfo 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) 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 Get Return ObjectsMatch(m_object, m_originalObject) End Get Set(ByVal Value As Boolean) 'Do nothing End Set End Property Public Property IsLoading() As Boolean Implements IPersistableObject.IsLoading Get Return m_loading End Get Set(ByVal Value As Boolean) m_loading = Value End Set End Property Public ReadOnly Property isModifyOnly() As Boolean Implements IPersistableObject.isModifyOnly Get Return getClassMap.isModifyOnly End Get End Property Public Property IsProxy() As Boolean Implements IPersistableObject.IsProxy Get Return m_proxy End Get Set(ByVal Value As Boolean) m_proxy = Value End Set End Property Public ReadOnly Property isReadOnly() As Boolean Implements IPersistableObject.isReadOnly Get Return getClassMap.isReadOnly End Get End Property Public Property ModifiedDate() As Date Implements IPersistableObject.ModifiedDate Get Return m_modifiedDate End Get Set(ByVal Value As Date) m_modifiedDate = Value End Set End Property Public Property OIDValue() As String Implements IPersistableObject.OIDValue Get Dim oidfactory As COIDFactory If m_oid Is Nothing Then oidfactory = getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New COID End If m_oid.OID = value End Set End Property Public Property Persistent() As Boolean Implements IPersistableObject.Persistent Get Return m_persistent End Get Set(ByVal Value As Boolean) m_persistent = Value End Set End Property Public Function getCollectionByAttribute(ByVal pName As String) As IList Implements IPersistableObject.getCollectionByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") Try If dotPos = -1 Then Return CallByName(m_object, pName, CallType.Get) Else Dim o As Object Dim objName As String Dim propertyName As String objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) Return CallByName(o, propertyName, CallType.Get) End If Catch err As Exception Throw New Exception("getCollectionByAttribute failed", err) End Try End Function Public Function getObjectByAttribute(ByVal pName As String) As IPersistableObject Implements IPersistableObject.getObjectByAttribute Dim dotPos As Integer dotPos = pName.IndexOf(".") If dotPos = -1 Then Return CallByName(m_object, pName, CallType.Get) Else Dim o As Object Dim objName As String Dim propertyName As String objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) Return CallByName(o, propertyName, CallType.Get) End If End Function Public Sub setAttributeValue(ByVal pName As String, ByRef Value As Object) Implements IPersistableObject.setAttributeValue If TypeOf (Value) Is System.DBNull Then Exit Sub End If Dim dotPos As Integer dotPos = pName.IndexOf(".") Try If dotPos = -1 Then If TypeOf (Value) Is System.SByte Then CallByName(m_object, pName, CallType.Set, IIf(Value.ToString = "1", True, False)) Else CallByName(m_object, pName, CallType.Set, Value) End If Else Dim o As Object Dim objName As String Dim propertyName As String objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) If TypeOf (Value) Is System.SByte Then CallByName(o, propertyName, CallType.Set, IIf(Value.ToString = "1", True, False)) Else CallByName(o, propertyName, CallType.Set, Value) End If End If Catch ex As Exception Throw New AttributeValueException("Could not set attribute " & pName & " (Value Type: " _ & Value.GetType.Name & ") in CPersistentObject::SetAttributeValue." & vbCrLf & ex.Message, ex) End Try End Sub Friend Property OriginalCacheKey() As CCacheKey Implements IPersistableObject.OriginalCacheKey Get Return m_retrievedCacheKey End Get Set(ByVal Value As CCacheKey) m_retrievedCacheKey = Value End Set End Property Public Overloads Function Equals(ByVal obj As IPersistableObject) As Boolean Implements IPersistableObject.Equals Dim ck1, ck2 As CCacheKey If Me Is Nothing And Not obj Is Nothing Then Return False End If If obj Is Nothing And Not Me Is Nothing Then Return False End If ck1 = New CCacheKey(Me) ck2 = New CCacheKey(obj) Return ck1.Equals(ck2) And Me.Persistent = obj.Persistent End Function Public Function Copy() As IPersistableObject Implements IPersistableObject.Copy Dim m_object2 As Object m_object2 = Activator.CreateInstance(m_object.GetType) ReplaceValues(m_object, m_object2) Return New CInjectedObject(m_object2) End Function Friend Sub ResetOriginalDates() Implements IPersistableObject.ResetOriginalDates m_originalModDate = m_modifiedDate End Sub Function getObjectByClassMap(ByVal classMap As CClassMap) As IPersistableObject Implements IPersistableObject.getObjectByClassMap Dim obj, Value As IPersistableObject Dim col As IList Dim i, k As Integer Dim cm As CClassMap Dim de As DictionaryEntry Dim udamap As CUDAMap obj = classMap.CreateObjectInstance 'set persistent before populating the object since the dirty flag checks its validity If Me.Persistent Then obj.Persistent = True 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.Target, Me.getObjectByAttribute(udamap.Target)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then obj.setAttributeValue(udamap.Target, Me.getCollectionByAttribute(udamap.Target)) End If 'End If Next i 'set object's attributes For i = 1 To classMap.AttributeMaps.Count obj.setAttributeValue(classMap.getAttributeMap(i).Name, Me.getValueByAttribute(classMap.getAttributeMap(i).Name)) Next 'if it has superclass add its attributes cm = classMap.SuperClass While Not cm Is Nothing '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.Target, Me.getObjectByAttribute(udamap.Target)) ElseIf udamap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then obj.setAttributeValue(udamap.Target, Me.getCollectionByAttribute(udamap.Target)) End If 'End If Next i 'set superclass's attributes For i = 1 To cm.AttributeMaps.Count obj.setAttributeValue(cm.getAttributeMap(i).Name, Me.getValueByAttribute(cm.getAttributeMap(i).Name)) Next cm = cm.SuperClass End While 'copy the OriginalModifiedDate and the ModifiedDate from the child to the parent. 'if we don't do this the object won't get saved correctly on subsequent calls. obj.setAttributeValue("ModifiedDate", Me.getValueByAttribute("ModifiedDate")) obj.OriginalModifiedDate = Me.OriginalModifiedDate obj.IsDirty = Me.IsDirty Return obj End Function Public Property OriginalModifiedDate() As Date Implements IPersistableObject.OriginalModifiedDate Get Return m_originalModDate End Get Set(ByVal Value As Date) m_originalModDate = Value End Set End Property End Class Index: modPersistenceBrokerSingleton.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/modPersistenceBrokerSingleton.vb,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- modPersistenceBrokerSingleton.vb 28 Sep 2004 07:30:33 -0000 1.8 +++ modPersistenceBrokerSingleton.vb 14 Oct 2004 05:25:02 -0000 1.9 @@ -149,7 +149,7 @@ ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- -Module modOIDFactorySingleton +Public Module modOIDFactorySingleton '''----------------------------------------------------------------------------- ''' <summary> ''' Gets a reference to the COIDFactory instance. |
From: Richard B. <rb...@us...> - 2004-10-14 05:23:57
|
Update of /cvsroot/jcframework/Nunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21628 Modified Files: AtomsFramework.xml Nunit_AtomsFramework.vbproj original db1.mdb Added Files: NPJob.vb NonInheritedTests.vb Log Message: Tests for persistence of objects that don't inherit from CPersistentObject Index: Nunit_AtomsFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/Nunit/Nunit_AtomsFramework.vbproj,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Nunit_AtomsFramework.vbproj 28 Sep 2004 07:32:24 -0000 1.3 +++ Nunit_AtomsFramework.vbproj 14 Oct 2004 05:23:48 -0000 1.4 @@ -140,6 +140,16 @@ BuildAction = "Compile" /> <File + RelPath = "NonInheritedTests.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "NPJob.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "RetrieveCriteriaTests.vb" SubType = "Code" BuildAction = "Compile" --- NEW FILE: NPJob.vb --- Public Class NPJob Private m_id As String Private m_description As String Public Property Id() As String Get Return m_id End Get Set(ByVal Value As String) m_id = Value End Set End Property Public Property Description() As String Get Return m_description End Get Set(ByVal Value As String) m_description = Value End Set End Property End Class Public Class NPJobWithOIDValue Inherits NPJob Private m_oid As AToMSFramework.COID Public Property OIDValue() As String Get Dim oidfactory As AToMSFramework.COIDFactory If m_oid Is Nothing Then oidfactory = AToMSFramework.modoidfactorysingleton.getOIDFactoryInstance() m_oid = oidfactory.newOID End If OIDValue = m_oid.OID End Get Set(ByVal value As String) If m_oid Is Nothing Then m_oid = New AToMSFramework.COID End If m_oid.OID = value End Set End Property End Class Index: original db1.mdb =================================================================== RCS file: /cvsroot/jcframework/Nunit/original db1.mdb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 Binary files /tmp/cvs8HdDBl and /tmp/cvsj1kVDv differ Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/Nunit/AtomsFramework.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- AtomsFramework.xml 28 Sep 2004 07:32:24 -0000 1.2 +++ AtomsFramework.xml 14 Oct 2004 05:23:48 -0000 1.3 @@ -16,4 +16,14 @@ <class name="SharedChild" table="SharedClasses" superclass="SharedParent" database="MSA" sharedtablefield="IType" sharedtablevalue="PLN"> </class> +<class name="NPJob" table="NPJobs" database="MSA"> + <attribute name="Id" column="id" key="primary"/> + <attribute name="Description" column="description"/> +</class> + +<class name="NPJobWithOIDValue" table="jobs" database="MSA"> + <attribute name="OIDValue" column="oidvalue" key="primary"/> + <attribute name="Description" column="description" find="true"/> +</class> + </map> \ No newline at end of file --- NEW FILE: NonInheritedTests.vb --- Imports AToMSFramework Imports NUnit.Framework <TestFixture()> Public Class NonInheritedTests Private pbroker As CPersistenceBroker Private job As NPJob <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" Try 'Remove any existing test database System.IO.File.Delete(".\db1.mdb") Catch ex As Exception End Try 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 <SetUp()> Public Sub TestInit() job = New NPJob End Sub <Test()> Public Sub LoadJob_a1() job.Id = "a1" pbroker.GetObject(job) Assert.AreEqual(cinjectedobject.state.loaded, pbroker.getcurrentstate(job)) Assert.AreEqual("basic", job.Description) End Sub <Test()> Public Sub FindJob_basic() Dim job As New NPJobWithOIDValue job.Description = "basic" pbroker.FindObject(job) Assert.AreEqual("000000160002", job.OIDValue) Assert.AreEqual("basic", job.Description) End Sub <Test()> Public Sub SaveJob_a2() pbroker.StartTracking(job) job.Id = "a2" job.Description = "SomeJob" pbroker.PersistChanges(job) End Sub <Test()> Public Sub DeleteAJob() 'pbroker.StartTracking(job) 'job.Id = "a3" 'job.Description = "SomeJob3" 'pbroker.PersistChanges(job) 'pbroker.MarkForDeletion(job) 'pbroker.PersistChanges(job) End Sub End Class |
From: Richard B. <rb...@us...> - 2004-10-13 05:19:41
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4342 Modified Files: CPersistenceBroker.vb CPersistentObject.vb IPersistentObject.vb Log Message: Additions to IPersistentObject interface Added method to persistence broker to manually clear the cache Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.62 retrieving revision 1.63 diff -u -d -r1.62 -r1.63 --- CPersistenceBroker.vb 8 Oct 2004 00:06:25 -0000 1.62 +++ CPersistenceBroker.vb 13 Oct 2004 05:19:01 -0000 1.63 @@ -2338,4 +2338,9 @@ Return m_disposed End Get End Property + + Public Sub ClearCache() + m_cache.Clear() + End Sub + End Class \ No newline at end of file Index: IPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/IPersistentObject.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IPersistentObject.vb 13 Oct 2004 01:36:35 -0000 1.1 +++ IPersistentObject.vb 13 Oct 2004 05:19:01 -0000 1.2 @@ -39,6 +39,8 @@ Function getFieldLengthByName(ByVal x As String) As Integer Function getFieldTypeByName(ByVal x As String) As Type + Function Equals(ByVal obj As CPersistentObject) As Boolean + Event MarkedAsDirty As EventHandler Event LoadStarted As EventHandler Event LoadFinished As EventHandler Index: CPersistentObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentObject.vb,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- CPersistentObject.vb 13 Oct 2004 01:36:35 -0000 1.40 +++ CPersistentObject.vb 13 Oct 2004 05:19:01 -0000 1.41 @@ -1114,7 +1114,7 @@ ''' [rbanks] 25/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Overloads Function Equals(ByVal obj As CPersistentObject) As Boolean + Public Overloads Function Equals(ByVal obj As CPersistentObject) As Boolean Implements IPersistentObject.Equals Dim ck1, ck2 As CCacheKey If Me Is Nothing And Not obj Is Nothing Then Return False |