<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-9-27 下午02:47:06  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    m.mortgage_name,
                    m.mortgage_id,
                    'MORTGAGE' item_type,
                    m.mortgage_id item_id,
                    ${@content_id} content_id,
                    ca.content_asset_id,
                    (
                        CASE
                            WHEN ca.CONTENT_ID=${@content_id}
                            THEN 'Y'
                            ELSE 'N'
                        END) selected_flag
                FROM
                    hls_mortgage m,
                    con_contract c,
                    con_contract_content_asset ca #WHERE_CLAUSE#
                ORDER BY
                    m.mortgage_code
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="mortgage_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="MORTGAGE_NAME"/>
        <bm:field name="mortgage_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MORTGAGE_ID"/>
        <bm:field name="item_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ITEM_TYPE"/>
        <bm:field name="item_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ITEM_ID"/>
        <bm:field name="content_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTENT_ID"/>
        <bm:field name="content_asset_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTENT_ASSET_ID"/>
        <bm:field name="selected_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SELECTED_FLAG"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="mortgage_name" queryOperator="like"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="m.project_id = c.project_id and c.contract_id = ${@contract_id} and exists (select 1 from con_contract_bp d where d.record_id = ${@con_contract_bp_id} and d.bp_category = &apos;PLEDGER&apos;) and m.mortgage_id = ca.item_id(+)    and ca.item_type(+) = &apos;MORTGAGE&apos; and ca.content_id(+)=${@content_id}"/>
    </bm:data-filters>
</bm:model>
