project BLF > class Database Component > 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.

plus transaction handling
- Remove the instance from the transaction if it was added to a transaction in InitInstance.
- Abort the transaction if one was started from inside the business code.

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/database.p)

if viCurrentDraftInstanceId = 0
then do:
    if  vlTransactionActive
    and icDraftReference = ""
    then do:
        /* Uncommitted transaction found */
        <I-2 {bFcOpenInstance
            &CLASS           = "Transaction"}>
        <M-4 run AbortTransaction
           (input  {&TARGETPROCEDURE} (ihParentInstance), 
            output vcDummy (ocInstances), 
            output viLocalReturn (oiReturnStatus)) in Transaction>
        <I-3 {bFcCloseAndStopInstance
            &CLASS           = "Transaction"}>
        assign vlTransactionActive = no.
        if viLocalReturn <> 0
        then oiReturnStatus = viLocalReturn.
        if viLocalReturn < 0
        then return.
    end.

    if  viTransactionId  <> 0
    and vlTransactionOpen = no
    then do:
        /* Remove this instance from the transaction,
           unless the instance is stopped by transaction itself of course. */
        <I-6 {bFcOpenInstance
            &CLASS           = "Transaction"}>
        <M-8 run RemoveInstance (input  viFcCurrentInstanceId (iiInstanceNr), 
                         output viLocalReturn (oiReturnStatus)) in Transaction>
        if viLocalReturn <> 0
        then oiReturnStatus = viLocalReturn.
        if viLocalReturn >= 0
        then do:
            <M-9 run StopExternalInstances
               (output viLocalReturn (oiReturnStatus)) in database>
            if viLocalReturn <> 0
            then oiReturnStatus = viLocalReturn.
        end.
        <I-7 {bFcCloseInstance
            &CLASS           = "Transaction"}>
        if viLocalReturn <> 0
        then oiReturnStatus = viLocalReturn.
        if viLocalReturn < 0
        then return.
    end.
end.

<ANCESTOR-CODE>

empty temp-table tFcRowidConvert.