10004---Trail ~ New Data Model

--Background on hybris Data Models

Data Models are defined in the <extension>-items.xmlfile of each extension.;;;Essentially data entities (called "items" in hybris) are defined withitemtype elements, whereas relations between items are defined with relation elements.

The red classes in the diagram below show the files created for the Player itemtype incuppy-items.xml.

The classes from which they are derived are shown in yellow.

The key point to bear in mind here is that many classes are generated from itemtypes and fall into three categories:

  • Model classes created for use in the ServiceLayer where partners are encouraged to develop their business logic. Below, we will specify a new Itemtype Stadium, and hybris will generate several files including aStadiumModelJava class that we can use.
  • Webservice-related classes which are created to support CRUD logic via RESTful URIs.These classes are only generated when the optional extension platformwebservices is included in your configuration.We will see how the Java classes StadiumDTO(s) and StadiumResoure(s) are used   in the webservice trail step.
  • Low-level Jalo classes. We will not address these classes as their use is discouraged.

     --Add a dependency between CuppyTrail and Cuppy

    1. Tell Eclipse that the Cuppytrail extension depends on the Cuppy extension: right click on cuppytrail - build path - configure build path

    2. Tell the hybris build framework that the Cuppytrail extension depends on theCuppy extension. Opencuppytrail/extensioninfo.xml and add

      <requires-extension name="cuppy"/>

    --Add Stadium to cuppytrail-items.xml

             <itemtype code="Stadium" generate="true" autocreate="true">
                <deployment table="CuppyTrailStadium" typecode="10123" />
                <attributes>
                    <attribute qualifier="code" type="java.lang.String" >
                        <persistence type="property"/>
                        <modifiers optional="false" unique="true"/>
                    </attribute>
                    <attribute qualifier="capacity" type="java.lang.Integer">
                        <description>Capacity</description>
                        <persistence type="property" />
                    </attribute>
                </attributes>
            </itemtype>

    You can check the used deployment typecodes in the hac  http://localhost:9001/maintain/deployments

    Key points to note are that the code

    itemtype code=Stadium generate=true autocreate=true

    • defines a new type Stadium which implicitly extends from GenericItem
    • autocreate=true indicates that Stadium is a new type
    • generate=true creates required sourcecode (not the model class) for the type
    deployment table=CuppyTrailStadium typecode=10123 
    • specifies how the new type is mapped to the database
    • table defines the database table
    • typecode is used internally e.g. to create item pks. Typecodes between 0 and 10000 are reserved by hybris. Nevertheless there are some exceptions 
     attribute qualifier=code type=java.lang.String
    • creates a new attribute code by using the atomic type java.lang.String
    persistence type=property 
    • Defines how item are stored. property reflects the normal persistent behaviour
    modifiers ... /
    • advanced settings like read and write access
  • --Relations

    <relations>
        <relationcode="StadiumMatchRelation"localized="false"generate="true"autocreate="true">
           <sourceElementtype="Stadium"qualifier="stadium"cardinality="one"/>
           <targetElementtype="Match"qualifier="matches"cardinality="many"/>
        </relation>
    </relations> 

     the relation is a one-to-many relation. which means that the mapping will be done by an additional column on the many side, i.e. the tableMatch

    --Enumtypes

    <enumtypes>
            <enumtype code="StadiumType" autocreate="true" generate="true" dynamic="false">
                <value code="openair"/>
                <value code="enclosed"/>
            </enumtype>
            <enumtype code="StadiumAccess" autocreate="true" generate="true" dynamic="true">
                <value code="road"/>
                <value code="rail"/>
                <value code="plane"/>
            </enumtype>
    </enumtypes>

    --Default values

    <attribute type="StadiumType" qualifier="StadiumType">
        <persistence type="property"/>
        <defaultvalue>em().getEnumerationValue("StadiumType","openair")</defaultvalue>
    </attribute>

    --Updating the hybris System

    Since we modified the hybris Data Model (by modifying an items.xml file), we must update the system, i.e. push the changes through to the database.

    Select only the first checkbox: Update running system,

     

    --Type system localization

  • Run all & updating systme[Update the system by selecting only Localize types]

    type.stadiummatchrelationmatchescoll.name=StadiumMatchRelationMatchesColl
    type.stadiummatchrelationmatchescoll.description=
      
    ### Localization for type StadiumAccess
    type.stadiumaccess.name=StadiumAccess
    type.stadiumaccess.description=
    ### Localization for type StadiumType
    type.stadiumtype.name=StadiumType
    type.stadiumtype.description=
    ### Localization for type StadiumMatchRelation
    type.stadiummatchrelation.name=StadiumMatchRelation
    type.stadiummatchrelation.description=
      
    ### Localizationfor type Match
    type.match.stadium.name=Stadium
    type.match.stadium.description=
    ### Localizationfor type Stadium
    type.stadium.name=Stadium
    type.stadium.description=
    type.stadium.stadiumtype.name=Stadium type
    type.stadium.stadiumtype.description=
    type.stadium.capacity.name=Capacity
    type.stadium.capacity.description=
    type.stadium.code.name=Name
    type.stadium.code.description=
    type.stadium.matches.name=Matches
    type.stadium.matches.description=
    ### localizationfor enumvalues
    type.stadiumtype.openair.name=openair
    type.stadiumtype.enclosed.name=enclosed
    type.stadiumaccess.road.name=road
    type.stadiumaccess.rail.name=rail
    type.stadiumaccess.plane.name=plane

    The easiest way is to do an export from hmc (Export Type Localizations)


    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值