project BLF > class Persistence (Progress) > method ReleaseInstance

Description

Release an instance in the fcInstance table after it was locked by a LoadInstance action, but without saving the instance data, so the instance can be re-opened at a later moment.


Parameters


ihClassinputhandle
iiInstanceIDinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/progress.p)

do transaction on error undo, throw:

    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.
    vhInstanceQuery:query-prepare
     ("for each fcInstance where ":U +
      "fcInstance.InstanceSeq = 1 and ":U +
      "fcInstance.Instance_ID = ":U + string(iiInstanceId)).
    vhInstanceQuery:query-open().
    
    do while true:
    
        vhInstanceQuery:get-next(exclusive-lock, no-wait).
        if vhInstanceBuffer:available = no
        then leave.
        
        if vhInstanceBuffer:locked
        then assign oiReturnStatus = -3.
        else do:
            if vhInstanceBuffer::InstanceIsInUse = no
            then do:
                assign oiReturnStatus = -3.
                <M-2 run ErrorMessage
                   (input  #T-1'Instance is already closed.':255(93)T-1# (icMessage), 
                    input  '' (icArguments), 
                    input  '' (icFieldName), 
                    input  '' (icFieldValue), 
                    input  '' (icRowid), 
                    input  ? (ihClass)) in Progress>
                return.
            end.
        
            assign vhInstanceBuffer::InstanceIsInUse = no.
        end.
    end.
end.

finally:
    if vhInstanceQuery <> ? then vhInstanceQuery:query-close().
end finally.