project BLF > class Persistence (Progress) > method CleanupStateOnline

Description

Clears all records form the database that hold state information, except for active sessions.


Parameters


ihClassinputhandle
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/progress.p)

if com.qad.qra.config.QraConfig:IsEnabled
then do:
    <I-4 {tFcStartAndOpenInstance
         &CLASS                = "PAuthenticationQRA"
         &SESSIONID            = "viPAuthenticationSessionId"}>
    
    vhPAuthentication1Inst = vhPAuthenticationQRA1Inst.
    viPAuthentication1ID = viPAuthenticationQRA1ID.
    viPAuthentication1OC = viPAuthenticationQRA1OC.
end.
else do:
    <I-39 {tFcStartAndOpenInstance
         &CLASS                = "PAuthentication"
         &SESSIONID            = "viPAuthenticationSessionId"}>
end.

if not (valid-handle(vhInstanceQuery) and
        viInstanceUID = vhInstanceQuery:unique-id)
then do:
    create buffer vhInstanceBuffer for table "fcInstance":U in widget-pool "persistent".
    create query vhInstanceQuery in widget-pool "persistent".
    vhInstanceQuery:forward-only = yes.
    vhInstanceQuery:set-buffers(vhInstanceBuffer).
    vhInstanceQuery:private-data = "Persistent".    /* do not ever delete this query */
    viInstanceUID = vhInstanceQuery:unique-id.
end.

create buffer vhInstanceSessionBuffer for table "fcInstance":U in widget-pool "non-persistent".
create query vhInstanceSessionQuery in widget-pool "non-persistent".
vhInstanceSessionQuery:forward-only = yes.
vhInstanceSessionQuery:set-buffers(vhInstanceSessionBuffer).
vhInstanceSessionQuery:query-prepare ("for each fcInstance where fcInstance.InstanceSeq = 0":U).
vhInstanceSessionQuery:query-open().

repeat transaction on error undo, throw:

    vhInstanceSessionQuery:get-next(no-lock).
    if vhInstanceSessionQuery:query-off-end
    then leave.

    vat = vhInstanceSessionBuffer::InstanceData.
    vcValue = get-string(vat,1).
    vinsessionID = ?.
    vinsessionID = integer(vcValue) no-error.
    if vinsessionID = ? then next.
    
    /* skip active sessions */
    Assign vcWhere = "for each fcSession where fcSession.SessionInstance_ID = " + string(vinsessionID).
    <M-8 run ReadDirect
       (input  'fcSession' (icTableName), 
        input  vcWhere (icPrepare), 
        input  'GlobalSessionId' (icFieldList), 
        output vcValue (ocValueList), 
        input  ihClass (ihClass), 
        output viFcReturnSuper (oiReturnStatus)) in Progress>
    if viFcReturnSuper = 0
    then do:
        <M-6 run KeepAlive
           (input  vcValue (icGlobalSessionId), 
            input  no (ilUpdateSession), 
            output vlFcOk (olIsActive), 
            output viFcReturnSuper (oiReturnStatus)) in PAuthentication>
        if  vlFcOk = yes
        and viFcReturnSuper = 0
        then next.
        
        <M-7 run WriteDirect
           (input  'fcSession' (icTableName), 
            input  vcWhere (icPrepare), 
            input  '' (icFieldList), 
            input  '' (icFieldListDataTypes), 
            input  '' (icAbsolute), 
            input  '' (icIncremental), 
            input  ihClass (ihClass), 
            input  '' (icUserLogin), 
            output viFcReturnSuper (oiReturnStatus)) in Progress>
    end.
    
    /* release numbers */
    vhInstanceQuery:query-prepare ("for each fcInstance where fcInstance.Instance_ID = ":U + string(vhInstanceSessionBuffer::Instance_ID) +
                                   " and fcInstance.InstanceSeq < 0").
    vhInstanceQuery:query-open().
    vhInstanceQuery:get-first(no-lock).
    do while not vhInstanceQuery:query-off-end:
        vat = vhInstanceBuffer::InstanceData.
        vcValue = get-string(vat,1).
        if num-entries(vcValue) = 4
        then do:
            vcWhere = "for each  Numbr where Numbr.Company_ID = ":U + entry(1,vcValue)
                    + " and Numbr.NumbrYear = ":U + entry(2,vcValue)
                    + " and Numbr.NumbrType = '":U + entry(3,vcValue)
                    + "' and Numbr.Numbr = ":U + entry(4,vcValue).
            <M-9 run WriteDirect
               (input  'Numbr' (icTableName), 
                input  vcWhere (icPrepare), 
                input  'NumbrStatus' (icFieldList), 
                input  'c' (icFieldListDataTypes), 
                input  {&NUMBERSTATUS-RELEASED} (icAbsolute), 
                input  '' (icIncremental), 
                input  ihClass (ihClass), 
                input  '' (icUserLogin), 
                output viFcReturnSuper (oiReturnStatus)) in Progress>
        end.
        vhInstanceQuery:get-next(no-lock).
    end.
    vhInstanceQuery:query-close().
    
    /* delete instance data */
    <M-3 run DeleteInstance
       (input  vhInstanceSessionBuffer::Instance_ID (iiInstanceID), 
        input  ihClass (ihClass), 
        input  vhInstanceSessionBuffer::InstanceClassName (icClassName), 
        output viFcReturnSuper (oiReturnStatus)) in Progress>
end.

vhInstanceSessionQuery:query-close().
delete object vhInstanceSessionQuery.
delete object vhInstanceSessionBuffer.

<I-5 {tFcCloseAndStopInstance
     &CLASS           = "PAuthentication"}>