project BLF > class Session > method ExitInstance

Description

This method can be extended with code to execute when an instance of a business class is stopped.

Standard functionality in this method is
- Clean up instance data in the fcInstance table.
- Create or update a draft instance if applicable.

PreCondition

This method is executed when :
- A business instance is stopped (release object + delete instance data)
(icDraftReference = "" + viCurrentDraftInstanceId = 0)
- A business instance is saved as a draft (release object + create draft)
(icDraftReference <> "")
- A draft instance is stopped (release object, delete copy of draft, release original draft)
(icDraftReference = "" + viCurrentDraftInstanceId <> 0)

This method is NOT run when a business instance is only closed (release object + keep instance data).


Parameters


icDraftReferenceinputcharacterDescription for the draft instance.
This parameter will have a value when creating a draft instance.
icDraftFormNameinputcharacterThis parameter will have a value when creating a draft instance.
ilDraftIsSharedinputlogicalThis parameter will have a value when creating a draft instance.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/session.p)

If oiReturnStatus = 0
Then Assign oiReturnStatus = -98.

Empty Temp-table tLogoutSessionTokenCaller.
Empty Temp-table tResponseCodeCaller.

If vlDoLogOut = True            And
   icDraftReference = "":U      And 
   viCurrentDraftInstanceId = 0 And
  (vcUserFromUIShell = '':U     Or
   vcUserFromUIShell = ?)
Then Do:    
    <Q-18 run FcSessionByAll (all) (Read) (NoCache)
       (input viFcCurrentInstanceId, (SessionInstanceId)
        input ?, (GlobalSessionNeedsUpdate)
        output dataset tqFcSessionByAll) in BFcSession>

    find first tqFcSessionByAll no-error.

    if available tqFcSessionByAll and tqFcSessionByAll.tiSessionTimeOut = 0
    then do:
        Create tLogoutSessionTokenCaller.
        Assign tLogoutSessionTokenCaller.tcMfgSessionId = vcGlobalSessionId.
    
        <I-1 {bFcStartAndOpenInstance
             &CLASS                = "PAuthentication"}>
             
        <M-4 run Logout
           (input  tLogoutSessionTokenCaller (tLogoutSessionToken), 
            output tResponseCodeCaller (tResponseCode), 
            output viFcReturnSuper (oiReturnStatus)) in PAuthentication>
        
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.

        if viFcReturnSuper < 0
        then Do:
            <I-10 {bFcCloseAndStopInstance
                 &CLASS           = "PAuthentication"}>
            return.
        End.
        
        For Each tResponseCodeCaller Where
                 tResponseCodeCaller.tcResponseCode <> '0':U:

            assign vcMsg = <M-5 GetMessage
                              (input  tResponseCodeCaller.tcResponseCode (icErrorCode)) in PAuthentication>
                   oiReturnStatus = -1.           

            <M-6 run SetMessage
               (input  vcMsg (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'BLF-397':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in Session>

        End. /*For Each tControlFlagsCall:*/
        
        <I-9 {bFcCloseAndStopInstance
             &CLASS           = "PAuthentication"}>
             
        If oiReturnStatus < 0 And
           oiReturnStatus <> -98
        Then Return.

    end. /* if available tqFcSessionByAll and tqFcSessionByAll.tiSessionTimeOut = 0 */

End. /* if */

If icDraftReference = "":U      And 
   viCurrentDraftInstanceId = 0 And
   vlDeleteFcSession = true
Then Do:   
    <M-15 run StartPersistence
       (output vhFcComponent (ohPersistence), 
        output viFcReturnSuper (oiReturnStatus)) in Session>        
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    /*delete the record*/
    Assign vcQuery = "for each fcSession where fcSession.SessionInstance_ID = ":U + String(viSessionID).
    <M-16 run WriteDirect
       (input  'fcSession':U (icTableName), 
        input  vcQuery (icPrepare), 
        input  '' (icFieldList), 
        input  '' (icFieldListDataTypes), 
        input  '' (icAbsolute), 
        input  '' (icIncremental), 
        input  {&TARGETPROCEDURE} (ihClass), 
        input  vcUserLogin (icUserLogin), 
        output viFcReturnSuper (oiReturnStatus)) in persistence>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return. 

    Assign vlDeleteFcSession = FALSE.
End.

If oiReturnStatus = -98
Then Assign oiReturnStatus = 0.

<ANCESTOR-CODE>

<M-17 run SetDebugLevel  (input  0 (iiDebugLevel)) in Session>

empty temp-table tDataItems.
empty temp-table tFilterVariable.

/* Invalidate the cached data of this session. */
<M-59 run StartCacher
    (output vhFcComponent (ohCacher), 
     output viFcReturnSuper (oiReturnStatus)) in Session>
<M-12 run ClearCache  (output viFcReturnSuper (oiReturnStatus)) in Cacher>