Available Types
There are a few available types and they serve specific purposes. For example, a MapType is a typed collection of key/value pairs that you can use for localized values.
AtomicTypes
AtomicTypes are the most basic types available in SAP Commerce. They are the representation of Java Number and String object types, such as java.lang.Integer or java.lang.String. SAP Commerce has mappings for the common Java number and String object types. As the factory default AtomicTypes represent the most common Java number and String types, most probably you might not have to define AtomicTypes anyway. When you define an AtomicType yourself, you need to assign a Java class object to it.
Unlike the other types, an AtomicType definition does not have a code attribute to set the unique identifier. Instead, the AtomicType class attribute is used as its reference.
If you need to localize this referrer into various languages, you may do so in the type localization files ( locales_xx.properties, located in an extension resources/localization directory) - the following code snippet assigns a localization to the java.util.Date AtomicType:
### Localization for type localized:java.util.Date type.localized:java.util.date.name=Date type.localized:java.util.date.description=This is a localized info text on a Date
SAP Commerce stores AtomicType instances in the database as strings (VARCHAR) or numbers (NUMBER), if possible. If you define AtomicTypes yourself, you need to make sure that those types are serializable (that is, you need to find a storage format for them that your database system can manage).
CollectionTypes
As you need to define the type of items that are stored in a CollectionType from the very start, it is impossible to store any other type of items in the same CollectionType. For example, the StringCollection type is restricted to String type items only, so SAP Commerce blocks any attempt of storing other values, such as Integer values, into a StringCollection instance. A comparable concept is the idea of Java 5 Generic Types
.
A CollectionType contains a typed number of instances of types (a dozen Strings, for example). A CollectionType has a unique identifier (referred to as code) and a definition of the type of elements it contains (elementtype). This type definition may include any type of item within SAP Commerce, even other CollectionTypes.
CollectionTypes are based on the Java Collection class. Via the type attribute in a CollectionType definition, you can make use of the Collection class and some of its subclasses (List, Set, and SortedSet). A Collection
is a list of elements. A List
is a number of ordered items. Although there may be equal items in a List, the items order is relevant. Items in a List may be accessed by an index counter. A Set
is an unordered number of items that must all be unique, no two items may be equal. A SortedSet
is the combination to a List and a Set. It contains a number of ordered items that must all be unique.
There are two types of relations that you can build with CollectionTypes: one to many relations and many to one relations. Both kinds of relation are unidirectional by design.
|
One-to-many relations (1:n) |
Many-to-one relations (n:1) |
|---|---|
|
Keep links to the respective values via an attribute on the source item, for example, a list of Primary Keys.
If the CollectionType contains AtomicTypes, the values are stored as binary fields in the database. If it stores a collection of items, then those items' Primary Keys (PKs) are stored in the database in string form - a list of PKs, basically. As all the values of one CollectionType instance are stored as one single field, reading in and writing the values is quite fast as it is done in a single database access (especially with caching). Processing them, however, is more delicate for three reasons:
|
Store the attribute values at the respective target items and have a getter method at the source type to retrieve the values.
Unlike the one-to-many kind of relation represented by a CollectionType, this kind of relation:
|
As CollectionTypes have technical limitations that make modeling n:m relations delicate, SAP recommends using RelationTypes to model complex correlations.
EnumerationTypes
Very much like the Enum concept in Java or C, EnumerationTypes (EnumTypes for short) map a predefined verbatim value to another, internal kind of value. EnumTypes are ComposedTypes and handle values in a special way: the values are also their instances. Therefore, an EnumType called color with the values red, green, and blue has three instances: red, green, and blue. This kind of type is useful for attributes whose values only have a limited number of choices (yes or no, for example).
If you define EnumTypes yourself with default Platform items as values, those values are always instances of this new EnumType. As a result, all the values for self-defined EnumTypes are stored in the same database table as the EnumType itself. Since all EnumTypes end up in one single database table, however, this table might become quite large when you define a lot of EnumTypes. If you know that an EnumType might have a large number of values, SAP recommends using a different database table to deploy this EnumType.
MapType
A MapType is a typed collection of key/value pairs. For each key (referred to as argument), there is a corresponding value (referred to as return type). The direction of mapping is always argument - return value.
A very common use of MapTypes is localized values - values that may differ in every language available in the system, like product descriptions in German and English, for example.
RelationTypes
RelationTypes model dependencies between numbers of items on both dependency sides. They represent n:m relations in SAP Commerce. RelationTypes allow you to reflect instances with many products belonging to several categories. The following diagram illustrates these relationships:
Internally, the elements on both sides of the relation are linked together via instances of a helper type called LinkItem. LinkItems hold two attributes, SourceItem and TargetItem, that hold references to the respective item (as in the graphic).
For each entry within a relation (in other words, for each link from one item to another), there is a LinkItem instance that stores the PKs of the related items. LinkItem instances are handled transparently and automatically by the Platform: On the API level, you only need to use the respective getter and setter methods.
If you delete an item from a relation, neither the item you seem to delete nor its related item is deleted, only the LinkItem is removed. In other words, both the source item and the target item remain, only the link between them is removed.
When the Platform runs a search for either side of a RelationType, it runs through all the relation's LinkItem instances and returns a Java Collection that contains the values. SAP Commerce sorts RelationType instances in source-to-target direction by the order the individual relation entries were created. The target-to-source direction is not sorted by the Platform, therefore the order of its results may vary depending on the database you use (that is, without any sorting by your web application or the SQL statements).
ItemTypes
ItemTypes (more commonly referred to as ComposedTypes) are the foundation of the SAP Commerce type system. All types (and therefore items) are ultimately derived of a ComposedType. ComposedTypes hold meta information on types and the types' attributes and relations, including the item type's code (in other words: unique identifier), its JNDI deployment location, the database table the item is stored in and the type's Java class.
Every type (and therefore item) may have any number of attributes. These attributes may either be defined by the type's AttributeDescriptors or inherited from its supertypes. Every attribute that is inherited downwards has its settings stored separately for each children type. That way, it is possible to override attribute access rights inherited from the supertype for a child type, so that you may set an attribute to be writable for your self-defined types that wasn't set writable on the type the attribute was originally defined with.
In the graphic, the Country type has an attribute regions that stores a list of the PKs of the regions.
In the graphic, Country has a getter method called getAllRegions() that runs a FlexibleSearch statement on the database to find all instances of Region.