Menu

CPersistentObject.getall with order

2004-08-09
2004-08-10
  • Marcos Flavio de Oliveira

      '''-----------------------------------------------------------------------------
      ''' <summary>
      ''' Returns all objects for a class in a CPersistentCollection.
      ''' </summary>
      ''' <param name="pOrderCol">Optional collection of attributes for ordering.</param>
      ''' <param name="pOrderAscCol">Optional collection which identify if attributes for ordering are ascendent or not.</param>
      ''' <returns>A CPersistentCollection containing all objects in the class.</returns>
      ''' <remarks>The objects returned by this method are all fully instantiated (ie
      ''' no proxy objects) and are returned in database order.</remarks>
      ''' <history>
      '''     [Marcos Flavio De Oliviera - mfo@cdtn.br]     17/12/2003    Created
      ''' </history>
      '''-----------------------------------------------------------------------------
      Public Overridable Function getAll(Optional ByVal pOrderCol As Collection = Nothing, Optional ByVal pOrderAscCol As Collection = Nothing) As CPersistentCollection
        Dim obj As Object
        Dim obCol As CPersistentCollection
        Dim obRC As AToMSFramework.CRetrieveCriteria
        Dim obCursor As AToMSFramework.CCursor
        Dim inIndex As Integer
        Dim boAscend As Boolean

        obRC = New AToMSFramework.CRetrieveCriteria
        obRC.ClassMap = Me.getClassMap

        ' If the collection isnt nothing.
        If Not IsNothing(pOrderCol) Then
          ' For each attribute in collection, add a order attribute in retrieve criteria.
          For inIndex = 1 To pOrderCol.Count
            boAscend = True
            ' If exists a value for index in a ascend collection.
            If Not IsNothing(pOrderAscCol) Then
              If inIndex <= pOrderAscCol.Count Then
                ' If the item for ascend is false.
                If Not pOrderAscCol(inIndex) Then
                  boAscend = False
                End If
              End If
            End If

            obRC.addOrderAttributeByAscend(pOrderCol(inIndex), boAscend)
          Next
        End If

        obCursor = obRC.perform(Me)
        obCursor.HoldsProxies = False
        obCol = New CPersistentCollection
        Do While Not obCursor.EOF
          obj = Me.getNewObject
          obCursor.loadObject(obj)
          obCol.Add(obj)
          obCursor.nextCursor()
        Loop
        Return obCol
      End Function

     
    • Richard Banks

      Richard Banks - 2004-08-10

      Hi Marcos,

      Thanks for the code.  I'll add it for the next release.

      - Richard.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.