project BLF > class Database Component > method PostSave

Description

Actions to take after writing current instance to the database, and before final commit of the transaction.
Use the field tc_status to test the status of the updated records:
'' = unchanged
'N' = new
'C' = changed
'D' = deleted


Parameters


oiReturnStatusoutputinteger


Internal usage


BLF
method database.DataSaveWorker


program code (program1/database.p)

/* ================================================================= */
/* On successfull save of draft instance data,                       */
/* the draft instance can be deleted.                                */
/* ================================================================= */
if viCurrentDraftInstanceId <> 0
then do:
    <M-6 run StartPersistence
       (output vhFcComponent (ohPersistence), 
        output viFcReturnSuper (oiReturnStatus)) in database>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    <M-7 run WriteDirect
       (input  'fcDraftInstance':U (icTableName), 
        input  'for each fcDraftInstance where fcDraftInstance.DraftInstance_Id = ':U + string(viCurrentDraftInstanceId) (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 viCurrentDraftInstanceId = 0.
end.

/* ================================================================= */
/* Lock published objects for external control                       */
/* ================================================================= */
if vcExternalControlItems <> ""
then do viCount = 1 to num-entries(vcExternalControlItems):
    <M-9 run StartPersistence
       (output vhFcComponent (ohPersistence), 
        output viFcReturnSuper (oiReturnStatus)) in database>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    <M-10 run MarkAsExternalControl
       (input  integer(entry(viCount,vcExternalControlItems)) (iiObjectId), 
        input  'PENDING':U (icExternal), 
        output viFcReturnSuper (oiReturnStatus)) in persistence>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
end.

/* ================================================================= */
/* Delete object security on deleted objects                         */
/* ================================================================= */
if vlObjectSecurityActive
then do:
    find first tFcDynRel where
               tFcDynRel.tcFcFrom = "" no-error.
    if available tFcDynRel
    then do:
        create query vhQuery in widget-pool "non-persistent".
        vhQuery:forward-only = yes.
        vhQuery:set-buffers(tFcDynRel.thFcBuffer).
        vhQuery:query-prepare ("for each ":U + tFcDynRel.thFcBuffer:name
             + " where ":U + tFcDynRel.thFcBuffer:name + ".tc_Status = 'D'":U).
        vhQuery:query-open().
        vhQuery:get-first().

        do while not vhQuery:query-off-end:
            <M-4 run GetPKValues
               (input  tFcDynRel.thFcBuffer (ihBuffer), 
                output vcPK (ocPKValue), 
                output viFcReturnSuper (oiReturnStatus)) in database>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.

            vcPK = "for each ObjectSecurity where ObjectSecurity.ObjectSecurityObjectRef = '":U + vcPK + "'":U.
            <M-11 run StartPersistence
               (output vhFcComponent (ohPersistence), 
                output viFcReturnSuper (oiReturnStatus)) in database>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.

            <M-5 run WriteDirect (input  'ObjectSecurity':U (icTableName), 
                      input  vcPK (icPrepare), 
                      input  '' (icFieldList), 
                      input  '' (icFieldListDataTypes), 
                      input  '' (icAbsolute), 
                      input  '' (icIncremental), 
                      input  {&TARGETPROCEDURE} (ihClass), 
                      input  vcUserLogin (icUserLogin), 
                      output viFcReturnSuper (oiReturnStatus)) in persistence>
            if viFcReturnSuper = -4
            then viFcReturnSuper = 0. /* ignore 'not found' error */
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.

            vhQuery:get-next().
        end.

        vhQuery:query-close().
        delete object vhQuery.
        vhQuery = ?.
    end.
end.

finally:
    if vhQuery <> ? then delete object vhQuery.
end finally.