A derived property definition can specify one of several different derivation methods to determine the appropriate property value. The SQL repository traverses in order each of the expressions in the <derivation> tag, applying the specified derivation method. There are six derivation methods included in the Oracle ATG Web Commerce platform:

firstNonNull

By default, the SQL repository derives a property by traversing the expressions in order, starting with the property itself. The first non-null value found is used as the property value. This is the firstNonNull derivation method.

The firstNonNull method is the default derivation method, and so it is not necessary to specify it in the XML. However, the derivation method can be specified in the method attribute of a <derivation> tag in the SQL repository definition file, as in this example:

<item-descriptor name="employee">
   <property name="department" item-type="department"/>
   <property name="empSpendingLimit" data-type="int"/>
   <property name="spendingLimit" writable="false">
     <derivation method="firstNonNull">
       <expression>empSpendingLimit</expression>
       <expression>department.spendingLimit</expression>
     </derivation>
   </property>
 </item-descriptor>
firstWithAttribute

The firstWithAttribute method requires you to specify an attribute named derivationAttribute. The code iterates through the expressions in order, and uses the first property with an attribute that matches the value of the derivationAttribute. If the value with the real key is null, the value of the defaultKey is used.

For example:

<item-desciptor name="myItem">
  <property name="name">
    <derivation method="firstWithAttribute">
       <expression>englishName</expression>
       <expression>icelandicName</expression>
      <expression>shonaName</expression>
    </derivation>
    <attribute name="derivationAttribute" value="language"/>
    <attribute name="defaultKey" value="en"/>
  </property>

  <property name="englishName">
    <attribute name="language" value="en"/>
  </property>
  <property name="icelandicName">
    <attribute name="language" value="is"/>
  </property>
  <property name="shonaName">
    <attribute name="language" value="sn"/>
  </property>
</item-descriptor>

If getKey returns sn (the user is in Zimbabwe, for example) myItem.name returns the same value as myItem.shonaName.

firstWithLocale

The firstWithLocale method is a subclass of firstWithAttribute. It performs the following actions:

The locale is searched in a locale-specific way. For example, if locale=fr_FR_EURO, it first looks for a property where the locale attribute is fr_FR_EURO, then looks for fr_FR, and finally looks for fr.

There is also a defaultKey, which the keyService uses if the value with the real key is null. In other words, if the real key is de_DE and you are looking for displayName, but displayName_de is null, displayName_en is returned instead (assuming its locale is en and the defaultKey is en or en_US).

Using a defaultKey can slow performance. If no default key is defined, it is not used. If the default key is the same as the current key, there are no performance implications. In all other cases, there is an extra clause on all search terms, which can result in a slower search.

The following example of a derived property definition uses the firstWithLocale derivation method:

<property name="displayName data-type="string">
  <derivation method="firstWithLocale">
    <expression>displayName_en</expression>
    <expression>displayName_de</expression>
  </derivation>
    <attribute name="derivationAttribute" value="locale"/>
    <attribute name="keyService" value="/atg/userprofiling/LocaleService"/>
    <attribute name="defaultKey" value="en"/>
</property>
alias

The Alias derivation method lets you define an alternate name for a repository item property and use either name to access the property. This can be useful in a situation where different application modules use the same property, but want to use different names for the property. A single alternate name can be defined in an <expression> element within a <derivation> element.

For example, suppose an item descriptor defines a property named firstName. You want some application code to refer to this property as name1. You can use the Alias derivation method to define name1 to be the equivalent of firstName, as follows:

<item-descriptor name="user" ...>
  <table name="USER" ...>
    <property name="firstName" ...>
    ....
  </table>
    <property name="name1">
    <derivation method="alias">
        <expression>firstName</expression>
    </derivation>
  </property>

In this example, when the name1 property is accessed, the firstName property of the item is returned.

union

The Union derivation method enables the combination of several properties of a repository item into a single property. The class takes two or more set or list type properties, and combines the values of those properties in the current repository item to create the new derived property. The members of the set or list can be of any data type supported by the Repository API. For example, suppose you have set type properties named brothers and sisters. You can use the Union derivation method to create a derived property named siblings that combines the values of the brothers and sisters properties into a single property.

<property name="siblings">
   <derivation method="union">
      <expression>brothers</expression>
      <expression>sisters</expression>
   </derivation>
</property>

The siblings property represents a union of values in the sets brothers and sisters. The data type of the values in the collections defined in all the expressions of the derived property must be the same.

If two or more of the properties to be combined in the Union derived property include the same element, the Union derived property has duplicate elements if the property is of type list, but has unique elements if the property is of type set.

collectiveUnion

The CollectiveUnion derivation method enables a property to be derived from a union of subproperties. The expression element is a property in the item descriptor that represents a collection of values. The derived property returns a union of the properties indicated by the value of the collectionProperty attribute.

For example, suppose you have an item descriptor named sku. Each sku type item has a parentProducts property, which is a collection of product type repository items. The following defines a catalogs property that is derived from a union of the catalogs properties of the items that make up the parentProducts property.

<item-descriptor name="sku" ...>
  <property name="catalogs">
    <derivation method="collectiveUnion">
       <expression>parentProducts</expression>
    </derivation>
    <attribute name="collectionProperty" value="catalogs"/>
  </property>
  <table name="sku_prod" ... >
    <property name="parentProducts"
              data-type="set" component-item-type="product">
    ...
  </table>
</item-descriptor>
<item-descriptor name="product" ...>
  <table name="prod_com" ... >
    <property name="catalogs" ... />
    ...
  </table>
</item-descriptor>

In this example, the union of product.catalogs is returned for each product in the parentProducts property of the sku item. The derived property is accessible through the sku item’s catalogs property.


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