to the Line Below "Remark By Leng"
because I found some case that
cursor.hasElements is true but cursor.EOF is false
if it is not correct please email me monsak@cpf.co.th
thank you
Private Sub deletePrivateObject(ByRef obj As CPersistentObject, ByVal conn As _CConnection)
Dim clMap As CClassMap
clMap = obj.getClassMap(obj)
Dim cm As CClassMap
cm = clMap
Debug.WriteLine("Deleting object " & cm.Name)
'Retrieve associations and delete if deleteAutomatic
Dim udaMap As CUDAMap
Dim aCriteria As CRetrieveCriteria
Dim cursor As CCursor
Dim Value As CPersistentObject
Dim ValueVar As String
Dim col As CPersistentCollection
Dim colCriteriaParameters As New Collection
Dim i, j As Short
Dim myKeys(cm.AssociationMaps.Count) As String
cm.AssociationMaps.Keys.CopyTo(myKeys, 0)
Dim anObjPers As CPersistentObject
For i = 0 To cm.AssociationMaps.Count - 1
udaMap = cm.AssociationMaps.Item(myKeys(i))
If udaMap.DeleteAutomatic Then
'Se agregan los parametros para los criterios
aCriteria = New CRetrieveCriteria
aCriteria.ClassMap = udaMap.ForClass
For j = 1 To udaMap.getSize
If udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then
Value = obj.getObjectByAttribute(udaMap.Target.Name)
If Not Value Is Nothing Then
Value.Retrieve(Value)
deletePrivateObject(Value, conn)
End If
ElseIf udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then
ValueVar = cm.getValueForRelationalDatabase(obj.getValueByAttribute(udaMap.getEntry(j).FromAttrMap.Name))
aCriteria.WhereCondition.addSelectEqualTo(udaMap.getEntry(j).ToAttrMap.Name, ValueVar)
' colCriteriaParameters.Add(ValueVar)
'Se obtiene el cursor dados todos los parametros y los criterios
cursor = processCriteria(aCriteria, colCriteriaParameters, conn)
'Se agregan los objetos a la coleccion
col = obj.getCollectionByAttribute(udaMap.Target.Name)
If Not col Is Nothing Then
If col.Count() > 0 Then
Value = col.Item(1)
'While cursor.hasElements Remark By Leng 20040426
While cursor.hasElements And Not cursor.EOF
Dim aa As [Assembly]
aa = aa.GetAssembly(Value.GetType)
anObjPers = Activator.CreateInstance(aa.GetType(aa.GetName.Name.Replace(" ", "_") & "." & udaMap.ForClass.Name))
' anObjPers = Value.getNewObject
cursor.loadObject(anObjPers)
deletePrivateObject(anObjPers, conn)
cursor.nextCursor()
End While
End If
col = Nothing
End If
End If
Next j
End If
Next i
Dim statement As CSqlStatement
Do
statement = cm.getDeleteSqlFor(obj)
conn.processStatement(statement)
cm = cm.SuperClass
Loop While Not cm Is Nothing
obj.Persistent = False
If m_useCache Then
m_cache.Remove(obj) 'remove from the cache
End If
colCriteriaParameters = Nothing
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm actually coming through Bangkok again on 24-25th May. I'll be staying in the Srinakarin area, but I don't know how much free time I'll have at this stage.
Email me offline with your details.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
to the Line Below "Remark By Leng"
because I found some case that
cursor.hasElements is true but cursor.EOF is false
if it is not correct please email me monsak@cpf.co.th
thank you
Private Sub deletePrivateObject(ByRef obj As CPersistentObject, ByVal conn As _CConnection)
Dim clMap As CClassMap
clMap = obj.getClassMap(obj)
Dim cm As CClassMap
cm = clMap
Debug.WriteLine("Deleting object " & cm.Name)
'Retrieve associations and delete if deleteAutomatic
Dim udaMap As CUDAMap
Dim aCriteria As CRetrieveCriteria
Dim cursor As CCursor
Dim Value As CPersistentObject
Dim ValueVar As String
Dim col As CPersistentCollection
Dim colCriteriaParameters As New Collection
Dim i, j As Short
Dim myKeys(cm.AssociationMaps.Count) As String
cm.AssociationMaps.Keys.CopyTo(myKeys, 0)
Dim anObjPers As CPersistentObject
For i = 0 To cm.AssociationMaps.Count - 1
udaMap = cm.AssociationMaps.Item(myKeys(i))
If udaMap.DeleteAutomatic Then
'Se agregan los parametros para los criterios
aCriteria = New CRetrieveCriteria
aCriteria.ClassMap = udaMap.ForClass
For j = 1 To udaMap.getSize
If udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_ONE Then
Value = obj.getObjectByAttribute(udaMap.Target.Name)
If Not Value Is Nothing Then
Value.Retrieve(Value)
deletePrivateObject(Value, conn)
End If
ElseIf udaMap.Cardinality = CUDAMap.CardinalityEnum.ONE_TO_MANY Then
ValueVar = cm.getValueForRelationalDatabase(obj.getValueByAttribute(udaMap.getEntry(j).FromAttrMap.Name))
aCriteria.WhereCondition.addSelectEqualTo(udaMap.getEntry(j).ToAttrMap.Name, ValueVar)
' colCriteriaParameters.Add(ValueVar)
'Se obtiene el cursor dados todos los parametros y los criterios
cursor = processCriteria(aCriteria, colCriteriaParameters, conn)
'Se agregan los objetos a la coleccion
col = obj.getCollectionByAttribute(udaMap.Target.Name)
If Not col Is Nothing Then
If col.Count() > 0 Then
Value = col.Item(1)
'While cursor.hasElements Remark By Leng 20040426
While cursor.hasElements And Not cursor.EOF
Dim aa As [Assembly]
aa = aa.GetAssembly(Value.GetType)
anObjPers = Activator.CreateInstance(aa.GetType(aa.GetName.Name.Replace(" ", "_") & "." & udaMap.ForClass.Name))
' anObjPers = Value.getNewObject
cursor.loadObject(anObjPers)
deletePrivateObject(anObjPers, conn)
cursor.nextCursor()
End While
End If
col = Nothing
End If
End If
Next j
End If
Next i
Dim statement As CSqlStatement
Do
statement = cm.getDeleteSqlFor(obj)
conn.processStatement(statement)
cm = cm.SuperClass
Loop While Not cm Is Nothing
obj.Persistent = False
If m_useCache Then
m_cache.Remove(obj) 'remove from the cache
End If
colCriteriaParameters = Nothing
End Sub
and the line above Remark By Leng 20040426
"Value = col.Item(1)"
Why You Use "1"
Can I Use "0" - Zero
I used 1 instead of 0 because I'm stupid :-)
Just a simple case of mixing up which lists are 1-based and which ones are 0-based.
Adding the .EOF check is also the right thing to do and should have been checked as part of the loop from the start.
Sorry for the delay in responding - I was in Thailand last week and had limited email access.
"I used 1 instead of 0 because I'm stupid "
I'm not blame you. Don't Serious.
Why Don't you Tell Me that You were in Thailand.
I Live In Bangkok (Thailand).
I wish to see you if you were in Bangkok.
Thank you
I'm actually coming through Bangkok again on 24-25th May. I'll be staying in the Srinakarin area, but I don't know how much free time I'll have at this stage.
Email me offline with your details.