(1.4) Trail ~ New Data Model

来源:互联网 发布:java为什么垃圾 编辑:程序博客网 时间:2024/05/19 04:06

数据模型

数据模型是定义在 《extension》 -items.xml 中的
基本数据实体(在hybirs中称为 items)
《extension》 -items.xml 主要表现出了各种对应关系

可以通过Webservice-related来创建支持crud和可以通过restful urls ,但是只能是platformwebservices 这个项目在你的配置中的时候

我们需要表现出 实体- stadiums - 每个stadiums的所有比赛
因为matches在cuppy 扩展中已经定义了,所以我们只需要做以下操作:

  • 添加一个新的item 在cuppytrail-items.xml ,定义新的数据实体 stadium
  • 添加一个新的关联在 cuppytrail-items.xml 创建stadium 和match的一对多关联
  • 添加一个枚举类型在cuppytrail-items.xml 创建stadium的类型和入口,将创建两个新的枚举类型
  • 添加一个默认值在 cuppytrail-items.xml
  • 添加默认值到类型创建

添加从属关系在cuppytrail和cuppy之间

cuppytrail依赖cuppy的数据模型,在cuppytrail的extensioninfo.xml中设置从属,在开始元素下设置

<requires-extension name="cuppy"/>

告诉eclipse cuppytrail和cuppy之间的从属关系
这里写图片描述


添加stadium 到 cuppytrail-items.xml ,把以下的代码替换cuppytrail/resources/cuppytrail-items.xml

<?xml version="1.0" encoding="ISO-8859-1"?><!-- [y] hybris Platform Copyright (c) 2000-2013 hybris AG All rights reserved. This software is the confidential and proprietary information of hybris ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with hybris.--><items   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:noNamespaceSchemaLocation="items.xsd">    <itemtypes>        <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>    </itemtypes></items>

保存 执行 ant all

itemtype code=Stadium generate=true autocreate=true

规定一个新的类型 Stadium 隐式的从GenericItem 来继承
autocreate=true 表明Stadium 是一个新的类型
generate=true 为这个新类型stadium创建必须的源代码 (不是模型类)


deployment table=CuppyTrailStadium typecode=10123 

指定了新类型是如何映射到数据库的

table 指定了数据库表
typecode is used internally e.g. to create item pks. Typecodes between 0 and 10000 are reserved by hybris.
占时没理解 ,通过下面的链接了解一下https://wiki.hybris.com/display/release5/Specifying+a+Deployment+for+hybris+Platform+Types

检查部署typecodes 通过
http://localhost:9001/maintain/deployments

 attribute qualifier=code type=java.lang.String

创建一个新的属性代码通过 java.lang.String

persistence type=property 

定义项目是如何存储的。属性反映了正常持续的行为

 modifiers ... /

高级设置比如读和写访问


关系

定义一个新的关系StadiumMatchRelation 在Stadium 和Match 之间,使用关系标签

在 cuppytrail/resources/cuppytrail-items.xml里面,立即添加以下元素在itemstype 元素之前

<relations>    <relation code="StadiumMatchRelation" localized="false" generate="true" autocreate="true">       <sourceElement type="Stadium" qualifier="stadium" cardinality="one" />       <targetElement type="Match" qualifier="matches" cardinality="many"/>    </relation></relations> 

这个关系是 一对多的关系


Enumtypes
添加以下元素在关系元素之前:cuppytrail/resources/cuppytrail-items.xml

<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

添加属性 StadiumType给两个现有的list Stadium attributes and define the default value to be openair :

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

Rebuild the Project

run ant all.

完整的 cuppytrail-items.xml 应该和这个一样

<?xml version="1.0" encoding="ISO-8859-1"?><!-- [y] hybris Platform Copyright (c) 2000-2013 hybris AG All rights reserved. This software is the confidential and proprietary information of hybris ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with hybris.--><!--    ATTENTION: This is just an example file. You have to edit it according to your needs.--><items   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:noNamespaceSchemaLocation="items.xsd">    <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>    <relations>        <relation code="StadiumMatchRelation"                localized="false" generate="true" autocreate="true">            <sourceElement type="Stadium" qualifier="stadium" cardinality="one"/>            <targetElement type="Match" qualifier="matches" cardinality="many"/>        </relation>    </relations>    <itemtypes>        <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>                <attribute type="StadiumType" qualifier="StadiumType">                    <persistence type="property"/>                    <defaultvalue>em().getEnumerationValue("StadiumType","openair")</defaultvalue>                </attribute>            </attributes>        </itemtype>    </itemtypes></items>

Check the model
platform/bootstrap/gensrc/de/hybris/platform/cuppytrail/model/StadiumModel.java

outline视图StadiumModel表明,它提供了访问代码,容量和StadiumType cuppytrail-items中指定的属性。xml,并集合中指定的匹配关系。
这里写图片描述

因为我们修改了配置文件,所以我们必须更新系统,把改变更新到数据库

首先执行
ant initialize and ant updatesystem

启动hybris

进入 (http://localhost:9001/platform/update) 只选择Update running system 并点击update

验证hybris更新完成后

进入 http://localhost:9001/hmc/hybris 登陆
选择System–>Types如下图搜索Stadium,会看到5个结果
这里写图片描述


类型系统本地化Type system localization

定义新的类型types,你也需要提供他们的本地化which are used e.g. by cockpits
为此我们需要添加 key=localized 这个字段在 cuppytrail/resources/localization/cuppytrail-locales_en.properties

可以直接在hmc 页面上添加
这里写图片描述

复制并粘贴到文件的文本 cuppytrail/resources/localization/cuppytrail-locales_en.properties and cuppytrail/resources/localization/cuppytrail-locales_de.properties

type.stadiummatchrelationmatchescoll.name=StadiumMatchRelationMatchesColltype.stadiummatchrelationmatchescoll.description=### Localization for type StadiumAccesstype.stadiumaccess.name=StadiumAccesstype.stadiumaccess.description=### Localization for type StadiumTypetype.stadiumtype.name=StadiumTypetype.stadiumtype.description=### Localization for type StadiumMatchRelationtype.stadiummatchrelation.name=StadiumMatchRelationtype.stadiummatchrelation.description=### Localization for type Matchtype.match.stadium.name=Stadiumtype.match.stadium.description=### Localization for type Stadiumtype.stadium.name=Stadiumtype.stadium.description=type.stadium.stadiumtype.name=Stadium typetype.stadium.stadiumtype.description=type.stadium.capacity.name=Capacitytype.stadium.capacity.description=type.stadium.code.name=Nametype.stadium.code.description=type.stadium.matches.name=Matchestype.stadium.matches.description=### localization for enum valuestype.stadiumtype.openair.name=openairtype.stadiumtype.enclosed.name=enclosedtype.stadiumaccess.road.name=roadtype.stadiumaccess.rail.name=railtype.stadiumaccess.plane.name=plane

ant all

然后在update页面只勾选 Localize types 更新

0 0
原创粉丝点击