<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
  version="2.0">
  
  <named-query name="getAllTasksEvents">
    <query>select t from TaskEventImpl t where t.taskId = :taskId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="getAllTasksEventsByProcessInstanceId">
    <query>select t from TaskEventImpl t where t.processInstanceId = :processInstanceId</query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="deleteAllTaskEvents">
    <query>delete from TaskEventImpl t
    </query>
  </named-query>
  <named-query name="deleteTaskEventsForTask">
    <query>delete from TaskEventImpl t where t.taskId = :taskId
    </query>
  </named-query>

  <named-query name="DeleteTaskVariableForTask">
    <query>delete TaskVariableImpl where type = :type and taskId = :taskId
    </query>
  </named-query>    

  <named-query name="getAllBAMTaskSummaries">
    <query>select b from BAMTaskSummaryImpl b where b.taskId = :taskId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="deleteBAMTaskSummariesForTask">
    <query>delete from BAMTaskSummaryImpl b where b.taskId = :taskId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="deleteAllBAMTaskSummaries">
    <query>delete from BAMTaskSummaryImpl b</query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getAllAuditTasks">
    <query>
      select t from AuditTaskImpl t order by t.taskId DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="getAllAuditTasksByStatus">
    <query>
      select t from AuditTaskImpl t where t.actualOwner = :owner and t.status in :statuses order by t.taskId DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

  <named-query name="getAllAuditTasksByUser">
    <query>
      select t from AuditTaskImpl t where t.actualOwner = :owner order by t.taskId DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="getAllGroupAuditTasksByUser">
    <query>
      select distinct t from AuditTaskImpl t, TaskImpl ti join ti.peopleAssignments.potentialOwners pos
      where (t.actualOwner = null or t.actualOwner = '') and t.status = 'Ready' and ti.id = t.taskId and pos.id in :potentialOwners 
      order by t.taskId DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="getAllAdminAuditTasksByUser">
    <query>
      select distinct t from AuditTaskImpl t, TaskImpl ti join ti.peopleAssignments.businessAdministrators bas
      where ti.id = t.taskId and bas.id in :businessAdmins order by t.taskId DESC
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>
  <named-query name="getAuditTaskById">
    <query>
      select t from AuditTaskImpl t where t.taskId = :taskId
    </query>
    <!-- hint name="org.hibernate.timeout" value="200"/ -->
  </named-query>

</entity-mappings>
