The data model is base of application. Data model is define the structure of your application. Business logic is always based on top of the data model and helps an organize and maintain their database. In Hybris, each extension has <extension-name>-items.xml file. Data Models are define in same file.
Type system is used for design data modeling or organize data in Hybris. Types define an objects for manage and store data with Java implementation . For instance, Java have class and object . Class is blueprint of Object and Object is instance of Class. Same concept is follow in Hybris. Hybris is define Type and Item. Type is blueprint of Item and Item is instance of type.
JAVA: Class is blueprint of Object <-> Object is instance of Class.
HYBRIS: Type is blueprint of Item <-> Item is instance of Type.
Type = items.xml + Java implementation
There are two kind of Types
Data entities are defined with item type elements, whereas relations between items are defined with relation elements. Item.xml file is locate resource/<extension-name>-items.xml file in each extension. which is used for create data model of business . you can define new types ,override and extend existing types.
For example:
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="items.xsd">
<atomictypes>
...
</atomictypes>
<collectiontypes>
...
</collectiontypes>
<enumtypes>
...
</enumtypes>
<maptypes>
...
</maptypes>
<relations>
...
</relations>
<itemtypes>
...
</itemtypes>
</items>
items.xml file has maintain the above order of elements. because It is always validated against items.xsd. xsd file has defined the order in which the elements have to be follow same order in items.xml . if you will not follow same order. build will fail.
items.xml file is parsed and evaluated in running order in one single pass. The Hybris does not allow multi-pass processing of the items.xml file . This means that you need to define types in order of inheritance. More abstract types need to be defined more to the beginning of the items.xml file and more concrete types need to be defined more to the end. During a hybris build, the build process validate that every extension's /resources directory contains a copy of a items.xsd file . This main file allows the hybris to validate the extension's items.xml against the items.xsd file.
AtomicTypes are the basic types in the Hybris Commerce Suite. It is the representation like Java number and String object types, such as java.lang.Integer or java.lang.String. When you define an AtomicType yourself, you need to assign a Java class object to it and it is generate upon platform initialization
<atomictypes>
<atomictype class="java.lang.Object" autocreate="true" generate="false"/>
<atomictype class="java.lang.Number" extends="java.lang.Object" autocreate="true" generate="false"/>
<atomictype class="java.lang.Integer" extends="java.lang.Number" autocreate="true" generate="false"/>
</atomictypes>
A CollectionType contains number of instances of types . It is based on the Java Collection class. you can use of the Collection class and some of its sub-classes (List, Set, and SortedSet) . 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.
<collectiontypes>
<collectiontype code = "ProductCollection" elementtype = "Product" autocreate = "true" generate = "true"/>
<collectiontype code = "LanguageList" elementtype = "Langauage" autocreate = "true" generate = "true"/>
<collectiontype code="AbstractOrderEntryList" elementtype="AbstractOrderEntry" autocreate="true" generate="false" type="list"/>
</collectiontypes>
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. As all the values of one CollectionType instance are stored as one single column in database so reading and writing the values is quite fast .
Collection Types have technical limitations
EnumerationTypes is very much similar as Enum concept in Java. EnumTypes are ComposedTypes and handle values only have a limited number of choices like Gender Male , Female etc. All EnumTypes values , which are define in application , are store one single database table. This table might become quite large when a lot of EnumTypes define.
<enumtype code="Gender" autocreate="true" generate="true" >
<value code="MALE"/>
<value code="FEMALE"/>
</enumtype>
<enumtype code="Gender" autocreate="true" generate="true" dynamic="true">
<value code="MALE"/>
<value code="FEMALE"/>
</enumtype>
Hybris provide to create dynamic type Enum by using dynamic="true".
A MapType is a typed collection of key/value pairs.it is used to store key values pairs in Hybris data modeling. A very common use of MapTypes is localized values - values that may differ in every language available in the system, like product name in Spanish and English.
<maptypes>
<maptype code="localized:java.lang.String" argumenttype="Language" returntype="java.lang.String" autocreate="true" generate="false"/>
</maptypes>
Localized values are stored in a separate database table, whose name is composed of the name of the table the type is stored in, plus the suffix lp (short for localized property).
Example : sampletype table and localized table will be sampletypelp
RelationTypes represent n:m relations in the hybris . You can link a one item to other item. LinkItems hold two attributes, SourceItem and TargetItem, that hold references to the respective item . LinkItem is helper type item which is linked together of source and target item.
<relation code="Country2RegionRelation" generate="true" localized="false" autocreate="true">
<sourceElement type="Country" qualifier="country" cardinality="one">
<modifiers read="true" write="true" search="true" optional="false" unique="true"/>
</sourceElement>
<targetElement type="Region" qualifier="regions" cardinality="many">
<modifiers read="true" write="true" search="true" partof="true"/>
</targetElement>
</relation>
Kind of relation
ItemTypes are the base of the hybris. Item types are used to create new tables or to update existing tables.
<itemtype code="OrderEntry"
extends="AbstractOrderEntry"
jaloclass="de.hybris.platform.jalo.order.OrderEntry"
autocreate="true"
generate="true">
<deployment table="OrderEntries" typecode="46"/>
<attributes>
<attribute autocreate="true" redeclare="true" qualifier="order" type="Order">
<modifiers read="true" write="false" search="true" removable="true" optional="false" initial="true" unique="true"/>
</attribute>
</attributes>
</itemtype>
Hybris provide two ways for set the database column type :
By specifying the database column type in the item.xml file, such as:
<persistence type="property">
<columntype>
<value>VARCHAR</value>
</columntype>
</persistence>
You can also define this in more detail by specifying database systems such as:
<persistence type="property">
<columntype database="oracle">
<value>CLOB</value>
</columntype>
<columntype database="mysql">
<value>text</value>
</columntype>
<columntype>
<value>varchar(4000)</value>
</columntype>
</persistence>
<deployment table="table_name" typecode="46"/>
ServiceLayer: Generates *Model.java source files (model classes) for all item types of configured extensions to the bootstrap/gensrc directory
Jalo Layer: Generates Generated*.java source files (item classes) for all item types of your extension to the gensrc directory of your extension. The Jalo layer in hybris is deprecated now.
Since we modified the Hybris Data Model or modifying an items.xml file. After Run "ant all" and start Hybris server. we must update the system, i.e. push the changes through to the database.
Verify that the new type Item