<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2014-7-14 下午03:09:37  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                       SELECT t.access_token
              FROM (SELECT v.record_id, v.access_token
                      FROM token_record_info v
                     where v.start_time <= sysdate
                       and v.over_time >= sysdate
                     order by v.record_id desc) t
             where rownum = 1
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                begin
                token_post_pkg.insert_token_recode(p_system_source      =>${@system_source},
                          p_expires_in   =>${@expires_in},
                          p_access_token  =>${@access_token},
                          p_user_id  => ${/session/@user_id}
                         );
                end;]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[begin
                   ${@check_token_valid}:= token_post_pkg.check_token_valid;
                end;]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="check_token_valid" output="true" outputPath="@check_token_valid"/>
            </bm:parameters>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
                begin
                    insert into token_response_logs
                        (
                        log_id,
                        response_json,
                        status,
                        created_by,
                        creation_date,
                        last_updated_by,
                        last_update_date
                  ) values
                  (token_response_logs_s.nextval,
                  ${@json},
                  ${@status},
                  ${/session/@user_id},
                  sysdate,
                  ${/session/@user_id},
                  sysdate
                  );
                  commit;
                end;]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="access_token"/>
    </bm:fields>
</bm:model>
