<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.lightstreamer.mpndb.beans">

   <class name="Subscription" table="SUBSCRIPTIONS">

      <meta attribute="class-description">
         This class defines a subscription of a Mobile Push Notification module instance.
      </meta>

      <id name="subscriptionId" column="SUBSCRIPTION_ID" type="string" length="36">
         <generator class="org.hibernate.id.UUIDGenerator" />
      </id>

      <property name="status" column="SUB_STATUS" index="INDEX_SUBSCRIPTION_STATUS">
        <type name="com.lightstreamer.mpndb.types.GenericEnumUserType">
          <param name="enumClass">com.lightstreamer.mpndb.enums.SubscriptionStatus</param>
          <param name="identifierMethod">getId</param>
          <param name="valueOfMethod">fromId</param>
        </type>
      </property>

      <property name="statusChangeDate" column="SUB_STATUS_CHANGE_DATE" type="timestamp" />

      <many-to-one name="device" class="Device">
      	<column name="DEVICE_ID" not-null="true" index="INDEX_SUBSCRIPTION_STATUS" />
      </many-to-one>

      <property name="adapterSetName" column="ADAPTER_SET_NAME" type="string" length="32" index="INDEX_SUBSCRIPTION_KEY" />
      <property name="dataAdapterName" column="DATA_ADAPTER_NAME" type="string" length="32" index="INDEX_SUBSCRIPTION_KEY" />
        <!--
            Warning: The column lenghts should be consistent with the Adapter Set
            and Data Adapter names configured.
        -->

      <property name="groupId" column="GROUP_ID" type="string" length="255" index="INDEX_SUBSCRIPTION_KEY" />
      <property name="schemaName" column="SCHEMA_NAME" type="string" length="255" index="INDEX_SUBSCRIPTION_KEY" />
        <!--
            Warning: The column lenghts should be enough to store all the possible group ids
            and schema names allowed by the Metadata Adapter for MPN subscriptions.
        -->

      <list name="items" table="SUBSCRIPTION_ITEMS" inverse="true" lazy="true" cascade="all">
      	<key column="SUBSCRIPTION_ID" />
      	<list-index column="ITEM_IDX" />
      	<one-to-many class="SubscriptionItem" />
      </list>

      <list name="fields" table="SUBSCRIPTION_FIELDS" lazy="true" cascade="all">
      	<key column="SUBSCRIPTION_ID" />
      	<list-index column="FIELD_IDX" />
      	<element column="FIELD" type="string" length="32" />
          <!--
              Warning: The column lenght should be enough to store all the possible
              field names available for MPN subscriptions.
          -->
      </list>

      <property name="mode" column="SUB_MODE" type="string" length="16" />

      <property name="notificationFormat" column="NOTIFICATION_FORMAT" type="string" length="8192" />
        <!--
            Warning: The column lenght should be enough to store all the possible values
            of notification format allowed by the Metadata Adapter for MPN subscriptions.
        -->

      <property name="triggerExpression" column="TRIGGER_EXP" type="string" length="255" index="INDEX_SUBSCRIPTION_KEY" />
        <!--
            Warning: The column lenght should be enough to store all the possible values
            of trigger expression allowed by the Metadata Adapter for MPN subscriptions.
        -->
      <property name="triggeredDate" column="TRIGGERED_DATE" type="timestamp" />

   </class>

</hibernate-mapping>
