I have retrieve about 3000 records from table.
It take many time or look like hang.
but when i change Code For retrieveObject Procedure in CClassMap class. it run faster
but i am not the following code is correct for any case
Public Sub retrieveObject(ByRef ClassMap As CClassMap, ByRef obj As CPersistentObject, ByVal rw As DataRow, ByVal pAlias As String)
Dim tmpObj As Object
If obj Is Nothing Then
Throw New Exception("source object not instantiated yet")
End If
Dim i As Short
Dim AttrMap As CAttributeMap
For i = 1 To ClassMap.getSize
AttrMap = ClassMap.getAttributeMap(i)
'Attempt to load column via alias first, then table qualified name then column name
tmpObj = Nothing
Try
If rw.Table.Columns.Contains(AttrMap.ColumnMap.getAliasName(pAlias)) Then
tmpObj = rw.Item(AttrMap.ColumnMap.getAliasName(pAlias))
ElseIf rw.Table.Columns.Contains(AttrMap.ColumnMap.getAliasQualifiedName(pAlias)) Then
tmpObj = rw.Item(AttrMap.ColumnMap.getAliasQualifiedName(pAlias))
ElseIf rw.Table.Columns.Contains(AttrMap.ColumnMap.Name) Then
tmpObj = rw.Item(AttrMap.ColumnMap.Name)
End If
Catch ex As Exception
Throw ex
End Try
' OLD CODE REMARK BY LENG
'Try
' 'Try column alias first
' tmpObj = rw.Item(AttrMap.ColumnMap.getAliasName(pAlias))
'Catch ex As Exception
' Try
' 'Try fully qualified name as second
' tmpObj = rw.Item(AttrMap.ColumnMap.getAliasQualifiedName(pAlias))
' Catch ex1 As Exception
' Try
' 'Try column name on it's own as third
' tmpObj = rw.Item(AttrMap.ColumnMap.Name)
' Catch ex2 As Exception
' tmpObj = Nothing
' End Try
' End Try
'End Try
obj.setAttributeValue(AttrMap.Name, tmpObj)
If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then
obj.Persistent = True
End If
Next i
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have retrieve about 3000 records from table.
It take many time or look like hang.
but when i change Code For retrieveObject Procedure in CClassMap class. it run faster
but i am not the following code is correct for any case
Public Sub retrieveObject(ByRef ClassMap As CClassMap, ByRef obj As CPersistentObject, ByVal rw As DataRow, ByVal pAlias As String)
Dim tmpObj As Object
If obj Is Nothing Then
Throw New Exception("source object not instantiated yet")
End If
Dim i As Short
Dim AttrMap As CAttributeMap
For i = 1 To ClassMap.getSize
AttrMap = ClassMap.getAttributeMap(i)
'Attempt to load column via alias first, then table qualified name then column name
tmpObj = Nothing
Try
If rw.Table.Columns.Contains(AttrMap.ColumnMap.getAliasName(pAlias)) Then
tmpObj = rw.Item(AttrMap.ColumnMap.getAliasName(pAlias))
ElseIf rw.Table.Columns.Contains(AttrMap.ColumnMap.getAliasQualifiedName(pAlias)) Then
tmpObj = rw.Item(AttrMap.ColumnMap.getAliasQualifiedName(pAlias))
ElseIf rw.Table.Columns.Contains(AttrMap.ColumnMap.Name) Then
tmpObj = rw.Item(AttrMap.ColumnMap.Name)
End If
Catch ex As Exception
Throw ex
End Try
' OLD CODE REMARK BY LENG
'Try
' 'Try column alias first
' tmpObj = rw.Item(AttrMap.ColumnMap.getAliasName(pAlias))
'Catch ex As Exception
' Try
' 'Try fully qualified name as second
' tmpObj = rw.Item(AttrMap.ColumnMap.getAliasQualifiedName(pAlias))
' Catch ex1 As Exception
' Try
' 'Try column name on it's own as third
' tmpObj = rw.Item(AttrMap.ColumnMap.Name)
' Catch ex2 As Exception
' tmpObj = Nothing
' End Try
' End Try
'End Try
obj.setAttributeValue(AttrMap.Name, tmpObj)
If Not IsDBNull(tmpObj) And Not tmpObj Is Nothing Then
obj.Persistent = True
End If
Next i
End Sub
Hi Leng,
Thanks for the code :-). I've made the changes and checked in the updates.
- Richard.