<?xml version="1.0" ?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                           "http://castor.org/mapping.dtd">
<mapping>

  <!--  Mapping for ProductGroup  -->
  <class name="myapp.ProductGroup"
         identity="id">
    <description>Product group</description>
    <map-to table="prod_group" xml="group" />
    <field name="id" type="integer" >
      <sql name="id" type="integer"/>
      <bind-xml node="attribute"/>
    </field>
    <field name="name" type="string">
      <sql name="name" type="char" dirty="check" />
      <bind-xml node="text" />
    </field>
  </class>


  <!--  Mapping for Product  -->
  <class name="myapp.Product" identity="id">
    <description>Product definition</description>
    <map-to table="prod" xml="product" />
    <field name="id" type="integer">
      <sql name="id" type="integer" />
      <bind-xml name="id" node="attribute"/>
    </field>
    <field name="name" type="string">
      <sql name="name" type="char" />
      <bind-xml name="name" node="element" />
    </field>
    <field name="price" type="float">
      <sql name="price" type="numeric" />
      <bind-xml name="price" node="element" />
    </field>

    <!--  Product has reference to ProductGroup,
          many products may reference same group  -->
    <field name="group" type="myapp.ProductGroup">
      <sql name="group_id" />
      <bind-xml name="group" node="element" />
    </field>

    <!-- Product has reference to ProductDetail
         many details per product  -->
    <field name="details" type="myapp.ProductDetail" required="true"
           collection="vector">
      <sql many-key="prod_id"/>
      <bind-xml name="detail" node="element" />
    </field>

    <!-- Product has reference to Category with
         many-many relationship -->
    <field name="categories" type="myapp.Category" required="true"
           collection="vector">
      <sql name="category_id"
           many-table="category_prod" many-key="prod_id" />
      <bind-xml name="category" node="element" />
    </field>

  </class>


  <!--  Mapping for Product Detail -->
  <class name="myapp.ProductDetail" identity="id" depends="myapp.Product" >
    <description>Product detail</description>
    <map-to table="prod_detail" xml="detail" />
    <field name="id" type="integer">
      <sql name="id" type="integer"/>
      <bind-xml node="attribute"/>
    </field>
    <field name="product" type="myapp.Product">
      <sql name="prod_id" />
      <bind-xml name="product" node="element" reference="true"/>
    </field>
    <field name="name" type="string">
      <sql name="name" type="char"/>
      <bind-xml node="text" />
    </field>
  </class>


  <!--  Mapping for Computer, extending Product  -->
  <class name="myapp.Computer" extends="myapp.Product" identity="id">
    <description>Computer definition, extends generic product</description>
    <map-to table="computer" xml="computer" />
    <field name="id" type="integer">
      <sql name="id" type="integer" />
      <bind-xml name="id" node="attribute"/>
    </field>
    <field name="cpu" type="string">
      <sql name="cpu" type="char"/>
      <bind-xml node="element" />
    </field>
  </class>


  <!--  Mapping for Category  -->
  <class name="myapp.Category" identity="id">
    <description>
        A product category, any number of products can belong to
        the same category, a product can belong to any number of
        categories
    </description>
    <map-to table="category" xml="category" />
    <field name="id" type="integer">
      <sql name="id" type="integer"/>
      <bind-xml/>
    </field>
    <field name="name" type="string">
      <sql name="name" type="char"/>
      <bind-xml node="element" />
    </field>
    <field name="products" type="myapp.Product" required="true"
           collection="vector">
      <sql name="prod_id"
           many-table="category_prod" many-key="category_id" />
      <bind-xml name="product" node="element" />
    </field>
  </class>


</mapping>

