<?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
    default-lazy="false"
    auto-import="true"
    default-access="property"
    default-cascade="all"
    package="gov.va.med.esr.common.model.ee">

  <class name="MECPeriod"
         table="MEC_PERIOD">

    <id name="identifier"
        type="big_decimal"
        column="MEC_PERIOD_ID">
      <generator class="gov.va.med.fw.persistent.hibernate.BigSequenceGenerator">
        <param name="sequence">mec_period_s</param>
      </generator>
    </id>

    <version name="version" type="integer" column="RECORD_MODIFIED_COUNT"/>

    <property name="personId" type="java.math.BigDecimal" column="PERSON_ID" not-null="true"/>
    <property name="mecStartDate" type="java.util.Date" column="MEC_START_DATE" not-null="false"/>
    <property name="mecEndDate" type="java.util.Date" column="MEC_END_DATE" not-null="false"/>

    <property name="createdOn" column="RECORD_CREATED_DATE" type="timestamp" not-null="true"
              update="false"/>
    <property name="modifiedOn" column="RECORD_MODIFIED_DATE" type="timestamp" not-null="true"/>
    <property name="createdBy" column="RECORD_CREATED_BY" update="false"
              type="gov.va.med.fw.persistent.hibernate.AuditUserType"/>
    <property name="modifiedBy" column="RECORD_MODIFIED_BY"
              type="gov.va.med.fw.persistent.hibernate.AuditUserType"/>

  </class>


 	<query name="MECPeriod_GetByPersonId">
        FROM  MECPeriod mecPeriod
        WHERE  mecPeriod.personId = :personId
    </query>

    <query name="MECPeriod_GetPeriodByDate">
           FROM  MECPeriod mecPeriod
           WHERE  mecPeriod.personId = :personId
           AND mecPeriod.mecStartDate &lt; to_date(:statusDate, 'yyyy-mm-dd')
           AND (mecPeriod.mecEndDate is null OR mecPeriod.mecEndDate &gt; to_date(:statusDate, 'yyyy-mm-dd'))
     </query>

    <sql-query name="MECPeriod_GetListToProcess">
        <![CDATA[
           SELECT person_id
           FROM person p
           where p.record_modified_date > to_date(:calendarYear, 'yyyy')
           and ROWNUM <= :batchSize
           order by p.record_modified_date desc
		]]>
    </sql-query>

    <!-- <query name="MECPeriod_GetListToProcess">
        FROM  MECPeriod mecPeriod
        WHERE  mecPeriod.startDate = :calendarYear
        AND rownum < :batchSize
    </query>-->

</hibernate-mapping>
