Populating the Data Model(往Data Model中插入值)

本章目标

在前面我们已经学习了怎么新建数据模型,现在我们要往我们新建的数据模型中插入一些数据来测试

有2中方式往数据模型中插入数据,一种是在hmc中插入数据,还有一种是用hybris的Import-Export Data Framework 一般叫做ImpEx。

Enter data via the hMC

先手工的通过hmc插入一些数据

  1. 启动hybris,到http://localhost:9001/hmc/hybris地址
  2. 浏览Stadium,点击NEW然后输入下面图中的数据,点击cliclk 保存一个新的Stadium
  3. 增加第二个Stadium, name:Allianz   Capacity:66000

添加一些匹配上面创建的体育场

  1. 先确定已经初始化了Cuppy, CuppyTrail 和 CuppyTrailhmc
  2. 给新建的stadium分配一些matches 

在这里我们给stadium增加一些matchs的例子阐述了hMC是怎么处理items.xml中定义的这些relationships类型的

ImpEx by Convention

一般给数据模型导入数据,我大部分都会选择ImpEx 方法- "ImpEx By Convention" 定义跟导入批量的stadium数据都要比在hMC中手工插入数据方便的多。

  • 一般文件命名为 essentialdata*.impex 和 projectdata*.impex ,文件保存在 <extension>resources/impex 文件夹下
  • 如果使用ImpEx by Configuration方法,必须提前在config/local.properties中提供 ImpEx的文件名路径。详情可参考ImpEx Import for Essential and Project Data.

Create an ImpEx File

新建文件cuppytrail/resources/impex/projectdataStadium.impex:

INSERT_UPDATE Stadium;code[unique=true];capacity
;Emirates;60361
;VillaPark;42788
 
UPDATE Match;id[unique=true];group(competition(code),code)[unique=true];stadium(code)
;1;wc2010:A;Emirates
;2;wc2010:A;Emirates
;3;wc2010:B;Emirates
;4;wc2010:B;VillaPark
 
$START_USERRIGHTS
Type;UID;MemberOfGroups;Password;Target;read;change;create;remove;change_perm
UserGroup;cuppyadmins;;;;;;;;
;;;;Stadium;+;+;+;+;-
$END_USERRIGHTS
  1. This ImpEx contains a header row with a SQL Table Command and columns, stating that we want to update the table Stadium, in particular the columns code (whose values must be unique), capacity and matches whose ids will be specified below. This is followed by several rows containing the data to import.
  2. We are specifying two stadiums and several matches to import
  3. The code attribute needs to be unique: unique=true. 
  4. The USERRIGHTS section sets access rights for cuppyadmins-usergroup on Stadium type.
  5. You can view the import file in Excel, but be aware that you should not save the file in Excel as any special characters may be corrupted

Invoke the ImpEx from within hybris

  1. 打开Platform/Update位置
  2. 只选择cuppytrail项目
  3. 这时候浏览器会显示Creating project data for cuppytrail ...通知你ImpEx已经执行
  4. 如果你之前已经完成Trail ~ Integration in the hMC 这部分学习
    1. 打开hmc查看刚才导入的是否成功
  5. 补充点
    1. 在hmc中选择System - Types,搜索 "Stadium"
    2. 在搜索的结果里,双击Stadium
    3. 点击编辑按钮,执行通用搜索,在结果列表中双击第一个
    4. 新弹出一个浏览器窗口,看到新建了一个stadium

        

或者你还可以在hmc中导入ImpEx 

  1. 登陆hmc
  2. 打开节点 System -> Tools -> Import
  3. 选择要导入的文件位置
  4. 点击开始按钮执行导入
原文地址:https://www.cnblogs.com/pingjie/p/4344798.html