project QadFinancials > class BSharedSetMerge > method MergeInit

Description

Initialize merge of two shared sets.


Parameters


ilIsLastMergeFinishedinputlogicalIndication, whether last merge finished succesfully
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program6/bsharedsetmerge.p)

/* =================================================================================================== */
/* Method      : MergeInit                                                                             */
/* Desc        : This method is used for initializing of merging of two shared sets                    */
/* =================================================================================================== */

assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do:
    /* =================================================================================================== */
    /* Create transaction for Init method                                                                  */
    /* =================================================================================================== */
    <I-15 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "false"
                &CLASS              = "Transaction"}>
    
    <M-16 run StartTransaction
       (output viFcReturnSuper (oiReturnStatus)) in Transaction>
    assign viExternalReturnStatus = viFcReturnSuper.
    
    /* ========================================================================================================================= */
    /* Normally we would here close the communication to class Transaction but we wont do it for performance reasons as this way */ 
    /* the transaction does not have to be re-open when other instances are added to the transactionthe instance to commit it.   */
    /* ========================================================================================================================= */
    
    if viExternalReturnStatus < 0 or viExternalReturnStatus > 0 and viLocalReturn = 0 then assign viLocalReturn = viExternalReturnStatus.
    if viLocalReturn          < 0 then leave MAIN_BLOCK.
    
    TRANSACTION_BLOCK:
    do:
        /* =================================================================================================== */
        /* Create record in shared set merge log file                                                          */
        /* =================================================================================================== */
        if  ilIsLastMergeFinished
        then do:
            <I-11 {bFcStartAndOpenInstance
                    &ADD-TO-TRANSACTION = "true"
                    &CLASS              = "BSharedSetMergeLog"}>
            
            <M-13 run LogStartMerge
               (input  vcMasterSharedSetCode (icMasterSharedSet), 
                input  vcRedundantSharedSetCode (icRedundantSharedSet), 
                output viFcReturnSuper (oiReturnStatus)) in BSharedSetMergeLog>
            assign viExternalReturnStatus = viFcReturnSuper.
            
            /* Close instance of BDomain component */
            <I-18 {bFcCloseInstance
                    &CLASS           = "BSharedSetMergeLog"}>
            if viExternalReturnStatus < 0 or viExternalReturnStatus > 0 and viLocalReturn = 0 then assign viLocalReturn = viExternalReturnStatus.
            if viLocalReturn          < 0 then leave TRANSACTION_BLOCK.
        end. /* if ilIsLastMergeFinished */
        
        /* =================================================================================================== */
        /* Remove redundant shared set from all referenced Domains and Companies and assign to master          */
        /* shared set                                                                                          */
        /* =================================================================================================== */
        /* Get list of all domains using redundant shared set */
        <Q-24 run DomainBySharedSetDomain (all) (Read) (NoCache)
           (input viRedundantSharedSetId, (SharedSetId)
            input 0, (DomainID)
            input '':U, (DomainCode)
            output dataset tqDomainBySharedSetDomain) in BDomain >
        
        empty temp-table tSharedSetMergeUpdateSharedSet.
        for each tqDomainBySharedSetDomain:
            create tSharedSetMergeUpdateSharedSet.
            assign tSharedSetMergeUpdateSharedSet.tiDomainID       = tqDomainBySharedSetDomain.tiDomain_ID
                   tSharedSetMergeUpdateSharedSet.tcSharedSetType  = vcSharedSetMergeSharedSetType
                   tSharedSetMergeUpdateSharedSet.tiNewSharedSetId = viMasterSharedSetId.
        end.
         
        if can-find(first tSharedSetMergeUpdateSharedSet)
        then do:
            /* Start Domain component */
            <I-10 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "true"
                &CLASS              = "BDomain"}>
            
            /* Execute assignment of new shared set for the domain */
            <M-7 run UpdateSharedSet
               (input  tSharedSetMergeUpdateSharedSet (tDomainUpdateSharedSet), 
                input  false (ilIsValSharedSetChangeActive), 
                output viFcReturnSuper (oiReturnStatus)) in BDomain>
            assign viExternalReturnStatus = viFcReturnSuper.
            
            if viExternalReturnStatus >= 0
            then do:
                <M-98 run ValidateBCAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDomain>
                if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viExternalReturnStatus = 0 then assign viExternalReturnStatus = viFcReturnSuper.
            end.
            
            /* Close instance of BDomain component */
            <I-19 {bFcCloseInstance
                &CLASS           = "BDomain"}>
                
            if viExternalReturnStatus < 0 or viExternalReturnStatus > 0 and viLocalReturn = 0 then assign viLocalReturn = viExternalReturnStatus.
            if viLocalReturn          < 0 then leave TRANSACTION_BLOCK.
        end. /* if can-find(fist tSharedSetMergeUpdateSharedSet) */
    end. /* of TRANSACTION_BLOCK */
    
    /* =================================================================================================== */
    /* Submit data and commit transation                                                                   */
    /* =================================================================================================== */
    <I-20 {bFcOpenInstance
                &CLASS           = "Transaction"}>
         
    if viLocalReturn >= 0
    then do:
        <M-21 run CommitTransaction
           (input  true (ilStop), 
            input  ? (ihParentInstance), 
            output vcDummy (ocInstances), 
            output viFcReturnSuper (oiReturnStatus)) in Transaction>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    end.
    else do:
        <M-25 run AbortTransaction
           (input  ? (ihParentInstance), 
            output vcDummy (ocInstances), 
            output viFcReturnSuper (oiReturnStatus)) in Transaction>
        if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    end.
    
    <I-22 {bFcCloseAndStopInstance
                &CLASS           = "Transaction"}>
    
    if viLocalReturn < 0 then leave MAIN_BLOCK.
    
    /* =================================================================================================== */
    /* Stop replication daemon                                                                             */
    /* =================================================================================================== */
    <I-31 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "no"
                &CLASS              = "BReplicaDaemon"}>
    
    <M-14 run APIStop
       (output viFcReturnSuper (oiReturnStatus)) in BReplicaDaemon>
    assign viExternalReturnStatus = viFcReturnSuper.
        
    <I-32 {bFcCloseAndStopInstance
                &CLASS           = "BReplicaDaemon"}>
         
    if viExternalReturnStatus < 0 or viExternalReturnStatus > 0 and viLocalReturn = 0 then assign viLocalReturn = viExternalReturnStatus.
    if viLocalReturn          < 0 then leave MAIN_BLOCK.
    
    /* =================================================================================================== */
    /* Load id's of all records from redundant shared set (used for controlling of execution)              */
    /* Following variables are stored in the component (instance dependant)                                */
    /*   - tSharedSetMergeData                                                                             */
    /* =================================================================================================== */
    <M-23 run MergeInitLoadSharedSetData
       (input  vcSharedSetMergeSharedSetType (icSharedSetTypeCode), 
        input  viRedundantSharedSetId (iiRedundantSharedSetId), 
        input  viMasterSharedSetId (iiMasterSharedSetId), 
        output tSharedSetMergeData (tSharedSetMergeData), 
        output viFcReturnSuper (oiReturnStatus)) in BSharedSetMerge>
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    if viLocalReturn   < 0 then leave MAIN_BLOCK.
    
    /* =================================================================================================== */
    /* Remove references between same table (eg. Debtor->Debtor). Existence of this reference can lead     */
    /* to fail of delete of element, to which other element is pointing                                    */
    /* =================================================================================================== */
    <M-30 run MergeInitClearReferencesSameTable
       (output viFcReturnSuper (oiReturnStatus)) in BSharedSetMerge>
    
    if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
    if viLocalReturn   < 0 then leave MAIN_BLOCK.
    
    /* =================================================================================================== */
    /* Read supportive data for merge                                                                      */
    /* =================================================================================================== */
    <Q-26 run DomainBySharedSetDomain (all) (Read) (NoCache)
       (input viMasterSharedSetId, (SharedSetId)
        input 0, (DomainID)
        input '':U, (DomainCode)
        output dataset tqDomainBySharedSetDomain) in BDomain >
    
    find first tqDomainBySharedSetDomain where
               tqDomainBySharedSetDomain.tlDomainIsActive = true no-error.
    if available tqDomainBySharedSetDomain
    then assign viMasterCompanyId = tqDomainBySharedSetDomain.tiPrimaryCompany_ID.
    else assign viMasterCompanyId = ?.
end. /* of MAIN_BLOCK */

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
assign oiReturnStatus = viLocalReturn.