<?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.security.permissions.impl.hibernate.NodePermissionEntryImpl"
        proxy="org.alfresco.repo.security.permissions.impl.hibernate.NodePermissionEntry"
        table="node_permission"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false" 
        lazy="true"
        optimistic-lock="version" >

        <composite-id name="nodeKey" class="org.alfresco.repo.domain.NodeKey">
           <key-property name="protocol" length="50" />
           <key-property name="identifier" length="100" />
           <key-property name="guid" length="36"/>
        </composite-id>
        
        <property name="inherits" column="inherits" type="boolean" not-null="true" />
        
        <set
            name="permissionEntries"
            lazy="true"
            sort="unsorted"
            inverse="true" 
            fetch="select" 
            optimistic-lock="true"
            cascade="delete" >
            <key>
               <column name="protocol" length="50" />
               <column name="identifier" length="100" />
               <column name="guid" length="36" />
            </key>
            <one-to-many class="org.alfresco.repo.security.permissions.impl.hibernate.PermissionEntryImpl" />
        </set>
      
    </class>
    
    <class 
        name="org.alfresco.repo.security.permissions.impl.hibernate.PermissionEntryImpl"
        proxy="org.alfresco.repo.security.permissions.impl.hibernate.PermissionEntry"
        table="node_perm_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="increment" />
        </id>
        
        <many-to-one 
            name="nodePermissionEntry" 
            class="org.alfresco.repo.security.permissions.impl.hibernate.NodePermissionEntryImpl" 
            lazy="no-proxy" fetch="select" optimistic-lock="true" not-null="true"  > 
              <column name="protocol" length="50" />
              <column name="identifier" length="100" />
              <column name="guid" length="36"/>
        </many-to-one>
        
        <many-to-one 
            name="permissionReference" 
            class="org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl" 
            lazy="no-proxy" fetch="select" optimistic-lock="true" not-null="false">
            <column name="typeUri" length="100" />
            <column name="typeName" length="100" />
            <column name="name" length="100" />
        </many-to-one>
        
        <many-to-one 
            name="recipient" 
            class="org.alfresco.repo.security.permissions.impl.hibernate.RecipientImpl" 
            lazy="no-proxy" fetch="select" optimistic-lock="true" not-null="false">
        </many-to-one>
        
        <property name="allowed" column="allowed" type="boolean" not-null="true" />
        
    </class>
    
    <class
        name="org.alfresco.repo.security.permissions.impl.hibernate.PermissionReferenceImpl"
        proxy="org.alfresco.repo.security.permissions.impl.hibernate.PermissionReference"
        table="permission_ref"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false"
        lazy="true"
        optimistic-lock="version" >
        
        <composite-id>
            <key-property name="typeUri" type="string" length="100" column="type_uri"/>
            <key-property name="typeName" type="string" length="100" column="type_name"/>
            <key-property name="name" type="string" length="100" column="name"  />
        </composite-id>
    </class>
    
    <class
        name="org.alfresco.repo.security.permissions.impl.hibernate.RecipientImpl"
        proxy="org.alfresco.repo.security.permissions.impl.hibernate.Recipient"
        table="recipient"
        dynamic-insert="false"
        dynamic-update="false"
        select-before-update="false"
        lazy="true"
        optimistic-lock="version" >
        
        <composite-id>
            <key-property name="recipient"
            column="recipient" 
            type="string" length="100"  />
        </composite-id>
        
        <set name="externalKeys" 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.GetPermissionsForRecipient">
      select
         permissionEntry
      from
         org.alfresco.repo.security.permissions.impl.hibernate.PermissionEntryImpl as permissionEntry
         join permissionEntry.recipient as recipient
      where
         recipient = :recipientKey 
   </query>
    
</hibernate-mapping>