<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="alfresco.qname">

    <!--                -->
    <!-- Type Defs      -->
    <!--                -->
    
    <typeAlias alias="Namespace" type="org.alfresco.repo.domain.qname.NamespaceEntity"/>
    <typeAlias alias="QName" type="org.alfresco.repo.domain.qname.QNameEntity"/>

    <!--                -->
    <!-- Result Maps    -->
    <!--                -->

    <resultMap id="result_Namespace" class="Namespace">
        <result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
        <result property="version" column="version" jdbcType="BIGINT" javaType="java.lang.Long"/>
        <result property="uri" column="uri" jdbcType="VARCHAR" javaType="java.lang.String"/>
    </resultMap>
  
    <resultMap id="result_QName" class="QName">
        <result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
        <result property="version" column="version" jdbcType="BIGINT" javaType="java.lang.Long"/>
        <result property="namespaceId" column="ns_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
        <result property="localName" column="local_name" jdbcType="VARCHAR" javaType="java.lang.String"/>
    </resultMap>
  
    <!--                -->
    <!-- Parameter Maps -->
    <!--                -->

    <parameterMap id="parameter_NamespaceId" class="Namespace">
        <parameter property="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
    </parameterMap>
  
    <parameterMap id="parameter_NamespaceUri" class="Namespace">
        <parameter property="uri" jdbcType="VARCHAR" javaType="java.lang.String"/>
    </parameterMap>
  
    <parameterMap id="parameter_QNameId" class="QName">
        <parameter property="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
    </parameterMap>
  
    <!--                -->
    <!-- SQL Snippets   -->
    <!--                -->
    
    <sql id="insert_Namespace_AutoIncrement">
        insert into alf_namespace (version, uri) 
        values (#version#, #uri#)
    </sql>
    
    <sql id="insert_Namespace_Sequence">
        insert into alf_namespace (id, version, uri) 
        values (#id#, #version#, #uri#)
    </sql>
    
    <sql id="insert_QName_AutoIncrement">
        insert into alf_qname (version, ns_id, local_name) 
        values (#version#, #namespaceId#, #localName#)
    </sql>
    
    <sql id="insert_QName_AutoIncrement_Sequence">
        insert into alf_qname (id, version, ns_id, local_name) 
        values (#id#, #version#, #namespaceId#, #localName#)
    </sql>
    
    <!--                -->
    <!-- Statements     -->
    <!--                -->
    
    <select id="select_NamespaceById" parameterMap="parameter_NamespaceId" resultMap="result_Namespace">
        select
            *
        from
            alf_namespace
        where
            id = ?
    </select>

    <select id="select_NamespaceByUri" parameterMap="parameter_NamespaceUri" resultMap="result_Namespace">
        select
            *
        from
            alf_namespace
        where
            uri = ?
    </select>
    
    <update id="update_Namespace" parameterClass="Namespace">
       update
           alf_namespace
       set
           uri = #uri#
       where
           id = #id#
    </update>

    <select id="select_QNameById" parameterMap="parameter_QNameId" resultMap="result_QName">
        select
            *
        from
            alf_qname
        where
            id = ?
    </select>

    <select id="select_QNameByNsAndLocalName" parameterClass="QName" resultMap="result_QName">
        select
            *
        from
            alf_qname
        where
            ns_id = #namespaceId# and
            local_name = #localName#
    </select>
    
    <update id="update_QName" parameterClass="QName">
       update
           alf_qname
       set
           ns_id = #namespaceId#,
           local_name = #localName#
       where
           id = #id#
    </update>

</sqlMap>