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

<!DOCTYPE hibernate-mapping PUBLIC
    '-//Hibernate/Hibernate Mapping DTD 3.0//EN' 
    'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>

<hibernate-mapping>
    <class 
        name="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"
        proxy="org.alfresco.repo.domain.DbAccessControlList"
        table="access_control_list"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false" 
        lazy="true"
        optimistic-lock="version" >

        <id name="id" column="id" type="long" >
           <generator class="native" />
        </id>

        <set name="entries"
               inverse="true"
               lazy="false" 
               cascade="delete"
               optimistic-lock="true"
               fetch="join" >
            <key column="acl_id" />
            <one-to-many class="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl"  />
        </set>

        <property name="inherits" column="inherits" type="boolean" not-null="true" />
        
    </class>
    
    <class 
        name="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl"
        proxy="org.alfresco.repo.domain.DbAccessControlEntry"
        table="access_control_entry"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false"
        lazy="true"
        optimistic-lock="version" >
        
        <id name="id" column="id" type="long" >
            <generator class="native" />
        </id>

        <natural-id mutable="true" >
           <many-to-one 
                   name="accessControlList" 
                   class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"
                   column="acl_id"
                   lazy="no-proxy"
                   fetch="select"
                   optimistic-lock="true"
                   not-null="true" /> 
           <many-to-one 
                   name="permission" 
                   class="org.alfresco.repo.domain.hibernate.DbPermissionImpl"
                   column="permission_id"
                   lazy="no-proxy"
                   fetch="select"
                   optimistic-lock="true"
                   not-null="true" /> 
           <many-to-one 
                   name="authority" 
                   class="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
                   column="authority_id"
                   lazy="no-proxy"
                   fetch="select"
                   optimistic-lock="true"
                   not-null="true" /> 
        </natural-id>
        
        <property name="allowed" column="allowed" type="boolean" not-null="true" />

    </class>
    
    <class
        name="org.alfresco.repo.domain.hibernate.DbPermissionImpl"
        proxy="org.alfresco.repo.domain.DbPermission"
        table="permission"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false"
        lazy="false"
        optimistic-lock="version" >
        
        <id name="id" column="id" type="long" >
            <generator class="native" />
        </id>

        <natural-id mutable="true">
           <property name="typeQname" column="type_qname" type="QName" length="200" />
           <property name="name" type="string" length="100" column="name" />
        </natural-id>

    </class>
    
    <class
        name="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
        proxy="org.alfresco.repo.domain.DbAuthority"
        table="authority"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false"
        lazy="false"
        optimistic-lock="version" >
        
        <id name="recipient" column="recipient" type="string" length="100" />

        <set
            name="externalKeys"
            table="auth_ext_keys"
            lazy="true"
            sort="unsorted"
            fetch="select"
            optimistic-lock="true" >
            <key >
               <column name="id" />
            </key>
            <element column="externalKey" length="100" not-null="true" type="string" />
        </set>
    </class>

   <query name="permission.GetPermission" cacheable="true">
      select distinct
         permission
      from
         org.alfresco.repo.domain.hibernate.DbPermissionImpl as permission
      where
         permission.typeQname = :permissionTypeQName and
         permission.name = :permissionName
   </query>
   
   <query name="permission.GetAccessControlEntriesForAuthority">
      select
         ace
      from
         org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl as ace
      where
         ace.authority.recipient = :authorityRecipient
   </query>
   
</hibernate-mapping>