The SQL repository supports a simplified form of inheritance that uses an optional one-to-one relationship between the primary table and an auxiliary table. The same repository can define one item descriptor that inherits properties from another.

For example, a clothing store catalog might offer shirts and shorts. Because the two items are likely to have common properties, you might use inheritance as follows:

The data model for the clothing catalog can be represented as follows:

This approach has several advantages

The XML repository definition (with inheritance-related tags in bold face) looks like this:

<!-- The "clothing" item type, a base type -->
<item-descriptor name="clothing" sub-type-property="type">

  <!-- This is the primary table that holds clothing data -->
  <table name="clothing" type="primary" id-column-names="id">
    <property name="type" data-type="enumerated">
      <option value="shirt"/>
      <option value="shorts"/>
    </property>
    <property name="name"/>
    <property name="description"/>
    <property name="color"/>
    <property name="size"/>
    <property name="shippingWeight"/>
  </table>
</item-descriptor>

<!-- The "shirt" item type is a subclass of "clothing" -->
<item-descriptor name="shirt" super-type="clothing" sub-type-value="shirt">
  <table name="shirt" type="auxiliary" id-column-names="id">
    <property name="season"/>
  </table>
</item-descriptor>

<!-- The "shorts" item type, now a subclass of "clothing" -->
<item-descriptor name="shorts" super-type="clothing" sub-type-value="shorts">
  <table name="shorts" type="auxiliary" id-column-names="id">
    <property name="pleated" data-type="boolean"/>
  </table>
</item-descriptor>

These definitions utilize inheritance as follows:

Note: Instances of objects are associated with their superclasses by ID. So, in this example, a shirt ID always has a matching clothing ID.

A sub-type item descriptor must never set sub-type-value to NULL. Given the previous example: some clothing items might be neither shirts nor shorts. In this case, the clothing item descriptor should set its sub-type-value attribute to clothing and add clothing as an option to its sub-type-property:

<!-- The "clothing" item type, a base type -->
<item-descriptor name="clothing" sub-type-property="type"
                                 sub-type-value="clothing">
  <!-- This is the primary table that holds clothing data -->
  <table name="clothing" type="primary" id-column-names="id">
    <property name="type" data-type="enumerated">
      <option value="clothing"/>
      <option value="shirt"/>
      <option value="shorts"/>
    <property/>
   ...

From the Repository API point of view, each ItemDescriptor maps to a single RepositoryView. When an SQL repository uses item type inheritance, each parent item type results in a RepositoryViewContainer that contains its subtype views as children.


Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved.

Legal Notices