Hybris data model
Hybris Data Models are defined in the <extension>-items.xml file of each
extension.
Data model items(entities) are defined with
itemtype elements.
Each item type is
consist of a Java class and database Table.
items.xml has six different tags and should be followed
by same order
automictypes
collections
enumtypes
maptypes
relations
itemtypes
Atomic types: The item
types which are primitive data types.
For example,
integer, float, double, boolean, Strings etc. They are defined in items.xml as
follows.
<atomictype class=“java.lang.String” extends=“java.lang.Object” autocreate=“true” generate=“false”/>
Collection
type: They are analogue of generic types in Java. A collection is a
group of similiar type item types. Like a group of language used for a
particular application could be stored as LanguageList.
<collectiontype
code=”LanguageSet” elementtype=”Language” autocreate=”true” generate=”true”
type=”set”/>
Enum
types: The group of fixed constants are defined as enums, like any
other language.
<enumtype code=“OrdStatus” autocreate=“true” generate=“true”>
<value code=“OPEN”/>
<value code=“IN-PROGRESS”/>
<value code=“CLOSE”/>
</enumtype>
Itemtypes: we need to define a new item type to specifies a specific
ComposedType.
<itemtype code="OFFLineProduct"
extends="Product"
autocreate="true"
generate="true"
jaloclass="org.hm.core.jalo.OFFLineProduct">
<description>OFF Line product extension that contains
additional attributes for off line.</description>
<deployment table="OFFLineProducts"
typecode="10100" propertytable="ProductProps"/>
<attributes>
<attribute qualifier="store"
type="java.lang.String">
<description> the products store name
</description>
<modifiers read="true"
write="true" search="true" optional="false"/>
<persistence type="property" />
</attribute>
<attribute
qualifier="intime" type="java.util.Date">
<description> the time stamp of the product
in </description>
<modifiers read="true"
write="true" search="true" optional="false"/>
<persistence type="property" />
</attribute>
<attribute qualifier="outtime"
type="java.util.Date">
<description> the time stamp of the product out
</description>
<modifiers read="true" write="true"
search="true" optional="false"/>
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
Here we defined a new item type extending parent item or Generic
item.
GenericItem extends
LocalizableItem extends ExtensibleItem extends Item
The jalo class, is
the module class which creates the item. This class is auto generated. when you
run ant build
Each of the characteristics of an item type is defined as
attribute of item type. The attribute itself could be of any type.
autocreate
- If 'true', the item will be created during initialization.
Default is 'true'.
generate - If true, it generates
constants for enum and source code for item, it has no effect
in automictypes,collections, maptype and relations.
attributes - Defines the list of
item attributes.
read –
If false, we cannot read this attribute, Defines if this attribute is
readable or not.
write –
If false, we cannot write this attribute, Defines if this
attribute is writable or not.
optional– if
false, it is mandatory to initialize this attribute. Since it is not optional.
unique– if
true, the attribute must hold a unique value. Similar to unique constraints in
DBMS.
search – if true, the attribute is searchable through queries
persistence -
Defines how the values of the attribute will be stored. Possible
values: 'property' (persistent), 'dynamic' (not persisted).
defaultvalue -Configures a default
value for this attribute used if no value is provided.
maptype: Like the java collection
framework, a type, which defines map objects.
<maptype code="localized:java.lang.String"
argumenttype="Language"
returntype="java.lang.String"
autocreate="true"
generate="false"/>
relationtype:
A RelationType defines a n-m or 1-n relation between types.
<relation code="OrderDiscountRelation"
autocreate="true" generate="false"
localized="false"
deployment="de.hybris.platform.persistence.link.OrderDiscountRelation">
<sourceElement
qualifier="orders" type="AbstractOrder"
cardinality="many" ordered="false">
<modifiers
read="true" write="true" search="true"
optional="true"/>
</sourceElement>
<targetElement
qualifier="discounts" type="Discount" cardinality="many"
ordered="true" collectiontype="list">
<modifiers
read="true" write="true" search="true"
optional="true"/>
</targetElement>
</relation>
No comments:
Post a Comment