One of the main features in Hybris is the flexibility to add new objects to the global Hybris Commerce Data model. Hybris data modeling helps an organization in maintaining their database and help to manage database connections and queries. Hybris Type system is used to design data modeling in Hybris.
A Hybris type system has the following types supported for data modeling −
Items.xml − This file is used for data modeling in a Hybris Commerce data model.
Item types − This is used to create tables.
Relation types − This is used to create relation between tables.
Atomic types − Used to create various Atomic types.
Collection types − Used to create Collections.
Map Types − To define maps.
Enum types − To define Enums.
Let us now discuss all of these in detail.
These are defined as basic types in Hybris, which include Java number and string objects – java.lang.integer, java.lang.boolean or java.lang.string.
<atomictypes> <atomictype class = "java.lang.Object" autocreate = "true" generate = "false" /> <atomictype class = "java.lang.Boolean" extends = "java.lang.Object" autocreate = "true" generate = "false" /> <atomictype class = "java.lang.Double" extends = "java.lang.Number" autocreate = "true" generate = "false" /> <atomictype class = "java.lang.String" extends = "java.lang.Object" autocreate = "true" generate = "false" /> </atomictypes>
Item types are used to create new tables or to update existing tables. This is considered as a base for a Hybris type system. All new table structures are configured over this type using different attributes as shown below −
<itemtype code = "Customer" extends = "User" jaloclass = "de.hybris/platform.jalo.user.Customer" autocreate = "true" generate = "true"> <attributes> <attribute autocreate = "true" qualifier = "customerID" type = "java.lang.String"> <modifiers read = "true" write = "true" search = "true" optional = "true"/> <persistence type = "property"/> </attribute> </attributes> </itemtype>
This type is used to create a link between tables. For example – You can link a country and region.
<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>
These are used to build enumeration in Java for preparing a particular set of values. For example – Months in a year.
<enumtype code = "CreditCardType" autocreate = "true" generate = "true"> <value code = "amex"/> <value code = "visa"/> <value code = "master"/> <value code = "diners"/> </enumtype>
These are used to build collection/group of element types – group of products, etc.
<collectiontype code = "ProductCollection" elementtype = "Product" autocreate = "true" generate = "true"/> <collectiontype code = "LanguageList" elementtype = "Langauage" autocreate = "true" generate = "true"/> <collectiontype code = "LanguageSet" elementtype = "Langauage" autocreate = "true" generate = "true"/>
Map types are used to store key values pairs in Hybris data modeling. Each key represents its own code.
<maptype code = "localized:java.lang.String" argumenttype = "Language" returntype = "java.lang.String" autocreate = "true" generate = "false"/>