`
zc-111
  • 浏览: 117586 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Ofbiz Entity Engine实体

阅读更多
转载:OFBIZ ENTITY ENGINE 菜谱,不晓得转的地方是不是原文发布地址,不贴出。感谢写菜谱的朋友。



* Keep your entity names less than 25 characters

  Oracle, for example, does not like tables with names longer than 30 characters, and OFBIZ

will add a "_" between words, so it's best to keep them short.

* 保证让你的entity names在25个字符以内

  因为有些数据库不允许表名超过30个字符,例如Oracle.而且ofbiz还要在单词之间加入"_",所以尽可能的让实体名称短。

* How relationships work

  如何建立关系

  They are defined in entitymodel.xml files for an <entity> like this:

  关系是在entitymodel.xml文件当中<entity>标签定义的,例如:

      <relation type="one" fk-name="PROD_CTGRY_PARENT" title="PrimaryParent" rel-entity-name="ProductCategory">

      <key-map field-name="primaryParentCategoryId" rel-field-name="productCategoryId"/>

      </relation>

      <relation type="many" title="PrimaryChild" rel-entity-name="ProductCategory">

        <key-map field-name="productCategoryId" rel-field-name="primaryParentCategoryId"/>

      </relation>



  type= defines the type of the relationship: "one" for one-to-one or "many" for

one-to-many from this entity

  type=定义了一个关系类型,从这个实体看来"one" 是one-to-one 或者"many"是one-to-many

  fk-name= is a foreign key name.  It is usually good practice to set your own foreign key name, although OFBIZ will auto-generate if it's not there.

  fk-name是一个外键名称,最佳实践策略是自己在这里定义外键名称,虽然如果这里不写OFBIZ会自动生成一个

  rel-entity-name= is the name of the related entity.

  rel-entity-name是被关联实体名称

  title= is used to distinguish different relationships when there are many relationships between the same two entities.

  title是用来在两个实体之间存在多种关系的时候用来区分不同关系的名称

  <key-map> defines the fields for the relationship. field-name= is for the field of this entity to use.  If the field on the related entity

  has a different field name, then rel-field-name= defines the field name in the related entity.  You can have many fields serve as part of a key-map.

  <key-map> 为关系定义了字段

  field-name是本实体用到的字段,如果在被关联实体当中使用不同的字段名,那么用rel-field-name定义被关联实体当中的字段名,一个key-map元素可以有多个字段名.



When you access a relationship, you would use .getRelated("") or .getRelatedOne("") with the title+entityName as parameter.  getRelated returns a List and is appropriate when it is a "many" relation.  .getRelatedOne returns a single GenericVaue and is appropriate for "one" relations.

当访问关系的时候可以用 .getRelated("") 或者 .getRelatedOne("") 用 title+entityName 作为参数。

当实体一个"many"关系的时候使用getRelated 返回一个列表,当实体一个"one"关系的时候使用getRelatedOne 返回一个GenericVaue .

* A few things about view-entities

关于view-entities的一些说明

View-entities are very powerful and allow you to create join-like queries, even when your database doesn't support joins.

view-entities是非常有用的并且允许你创建join-like查询,甚至你的数据库不支持joins都可以

The configuration of your database's join syntax is in entityengine.xml under the join-style attribute of <datasource ..>

在entityengine.xml中<datasource ..>元素当中的join-style属性当中设置你的数据库join语法

When you link two entities together using the <view-link ..> tag, remember

1.  The order of the entities you name is important.

2.  The default is an inner join (values must be present on both sides.)  To do an outer join, use rel-optional="true"

当你将两个实体连接在一起的时候使用 <view-link ..>标签,记住

1. 实体名称的顺序很重要

2. 缺省情况时内连接(值必须在两边都出现)如果要作一个外连接用rel-optional="true"

If several entities have the same field name, such as statusId, the one from the first entity will be used and the rest tossed out.  So if you need the field from one, put its <alias-all> before the others.  Alternatively, use <alias ..> tag

to give the same field from different entities names, such as:

如果几个实体拥有相同名称的字段,例如statusId,那么第一个实体的statusId被使用其它的都会抛弃掉,因此如果需要使用其它实体当中相同名字字段的时候,把它们放入<alias-all>,作为一个选择用 <alias ..> 标签



可以区分不同实体当中相同的名字字段,例如:



<alias entity="EntityOne" field="statusId"/>

<alias entity="EntityTwo" field="statusId"/>



Another alternative is to use <exclude field=""> inside an <alias-all> as follows:

另一个选择就是在 <alias-all>内使用<exclude field="">例如



<alias-all entity-alias="EN">

  <exclude field="fieldNameToExclude1"/>

  <exclude field="fieldNameToExclude2"/>

</alias-all>



This top-down approach is more compact, which comes in handy for large tables.

这种严密的写法更加紧凑,对于字段多的大表用的上。

Alternatively, you can specify one or more <exclude field="fieldName"> inside an  <alias-all>.

更加简洁的一种写法是在<alias-all>当中使用<exclude field="fieldName">

This top-down approach is more compact than specifying the alias for every field in a big

table.

这样比一个一个的指定字段的别名方法更加紧凑简洁。

If you need to do a query like this

如果你需要做一个如下查询

SELECT count(visitId) FROM ... GROUP BY trackingCodeId WHERE fromDate > ' 2005-01-01'



include field visitId with function="count", trackingCodeId with group-by="true", and



fromDate with group-by="false"

用function="count"包含字段visitId

,用group-by="true"给trackingCodeId,用fromDate给group-by="false"

Then **VERY IMPORTANT** when you do your query, such as delegator.findByCondition, you must specify the fields to select,and you must not specify the field fromDate, or you will get an error.  This is why these view-entities can't be viewed from webtools.

非常非常重要的是当你查询的时候,例如使用delegator.findByCondition,你必须指定选择的字段,在上例中



不指定fromDate,你会得到一个错误,这也是为什么view-entities为什么不能在webtools里面被看到的一个原因。



For an example, look at the view entities at the bottom of

更多的例子可以参考以下实体

applications/marketing/entitydef/entitymodel.xml and

the BSH scripts in applications/marketing/webapp/marketing/WEB-INF/actions/reports.



* How to build conditions for expiration dates

怎样建立一个根据有效日期的查询条件

There is a series of very helpful methods called EntityUtil.getFilterByDateExpr which return an EntityConditionList to filter out search results by date.

有一系列非常有用的方法叫 EntityUtil.getFilterByDateExpr 能够返回EntityConditionList用于通过日期实体条件。



* How to work with large sets of data

怎样使用大量的数据

If you need to select large sets of data, you should use the EntityListIterator instead of the List.  For example, if you did

如果你需要选择大量的数据集合,你可以用EntityListIterator替代List.例如如果你做了



List products = delegator.findAll("Product");



You may get yourself a "java.lang.OutOfMemoryError".  This is because findAll, findByAnd, findByCondition will try to retrieve all the records into memory as a List.  In that case, re-write your query to do return an EntityListIterator  then loop through it.  For example, this query can

be re-written as:

你可能得到一个"java.lang.OutOfMemoryError"异常。这是因为findAll, findByAnd, findByCondition尝试把所有的符合标准的纪录加载到内存当中,一个解决方案是重新写你的查询作为一个EntityListIterator并且遍历它,例如上面的查询可以写为





productsELI = delegator.findListIteratorByCondition("Product", new EntityExpr("productId",



EntityOperator.NOT_EQUAL, null), UtilMisc.toList("productId"), null);



Note that the only method for finding an EntityListIterator is a by condition, so you would have to re-write your conditions as EntityExpr (in this case, a dummy one which just says that productId is not null, which should apply to all Product entities,



since productId is a not-null primary key field) or EntityConditionList. This method also asks you to fill in the fields to select (in this case just productId) and order by (which I didn't specify with the last null.)



注意这是唯一的一个通过条件得到一个EntityListIterator的方法,你必须用EntityExpr(这个例子当中表示为 productId 不能为 null,其实是一句废话,就是说明所有纪录)或EntityConditionList者重写你的条件 。这个方法也要求指定所有要选择的字段(这个例子里面只有productId) 并且order by(在给出的例子当中没有指定,位置位于最有一个null参数)



You can pass a null EntityCondition to grab all records.  However, this does not work across all databases!  Beware the use of avanced functionality such as the EntityListIterator with maxdb and other odd databases.



你可以通过一个空的EntityCondition 抓取所有纪录,然而这种做法并不支持所有的数据库,对于大型数据库或者奇怪的数据库,谨慎的使用高级的函数例如EntityListIterator当中的函数。



* How to use an EntityListIterator

如何使用一个EntityListIterator



When iterating through the EntityListIterator, this is the preferred form:

当遍历EntityListIterator的时候如下的做法是首选的



while ((nextProduct = productsELI.next()) != null) {

....

    // operations on nextProduct

}



Using the .hasNext() method on EntityListIterator is considered wasteful.

在EntityListIterator 当中使用.hasNext()被认为是浪费资源的



When you are done, don't forget to close it:

当你使用EntityListIterator ,不要忘记关闭它
分享到:
评论

相关推荐

    原创 Ofbiz 入门教程

    都需要的部件,像用户认证、工作流、商务规则处理等,Ofbiz 的核心技术在于 Entity Engine,其他的组件基本都 是基于它的。简单来说 Entity Engine 的主要功能是将数据库表创建、对象与数据表的映射、对象的查询等做...

    ofbiz 入门+增删改查+实体

    ofbiz入门图文讲解,包括入门helloworld 和使用ofbiz 新建实体 操作数据库对实体增删改查

    OFbiz实体引擎指南

    OFBiz是一个非常著名的电子商务平台,是一个非常著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级、跨平台、跨数据库、跨...包括实体引擎, 服务引擎, 消息引擎, 工作流引擎, 规则引擎等。

    ofbiz综合文档

    OFBIZ的Web应用框架严格遵循MVC模式。 OFBizMVC中Model有它的封装业务逻辑的事件和服务承担. Control有controller承担, View...这个文件为不同的用途提供了一些例子,文件位于ofbiz/commonapp/etc/entityengine.xml。

    ofbiz入门教程-初学者开发指南

    Ofbiz(http://www.ofbiz.org) 是 Open Source 的商务软件系统,充分利用了各优秀的的Open ...都需要的部件,像用户认证、工作流、商务规则处理等,Ofbiz 的核心技术在于 Entity Engine,其他的组件基本都 是基于它的。

    OFBIZ快速入门OFBIZ快速入门

    OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门OFBIZ快速入门

    Ofbiz16.11.05运行及开发环境搭建等

    gradle ofbiz 16 开发环境搭建 2 Ofbiz中增加百度地图 8 使用entity-auto服务实现增加、修改、删除提示国际化 9 ...ofbiz实体引擎(九) 多租户 31 菜单权限配置 34 ofbiz权限判断语法整理 42 ofbiz 权限设计详解 43

    OFBIZ.txt(同表不同字段计算)

    OFBIZ的同一个表的不同字段之间的加减乘除等的计算公式

    ofbiz综合技术文档

    The Entity Engine API 40 JTA Support 42 Core Web Tools 43 1、介绍 44 二、编程指南 44 1、delegator对象的获取 44 2、 数据访问 44 三、编程参考 46 第四部分、工作流 46 一、工作流引擎指南 46 1、简介 46 2、...

    apache-ofbiz-16.11.06.zip

    OFBiz是一个十分有名的框架,这是他的16版本代码,OFBiz可用于开发ERP,支持网站,分为前端Widget,中间Service/ServiceEngine,后台Entity/EntityEngine.

    ofbiz资料大全

    里面是下载地址,如果逆向开发ofbiz,只要下载它就绝对没错了 Apache+OFBiz+开发初学者指南.rar OFBiz开发快速入门.rar OFBiz-技术文档.rar OFBiz API中文版.rar Apache OFBiz Cookbook Sep 2010.rar Opentaps ...

    ofbiz 教程_配置ofbiz

    ofbiz的获取与部署,主要用到了gradle 和 eclipse,注意:cmd部署时,需要一个较好的网络环境以下载gradle

    ofbiz学习笔记(自学整理)

    自学整理的ofbiz学习笔记,自学整理的ofbiz学习笔记,自学整理的ofbiz学习笔记,自学整理的ofbiz学习笔记,适合初学者,可以下个看看

    ofbiz_springservice.zip

    基于spring封装的ofbiz所有服务,使用spring security进行安全验证,可以方便的发布为微服务,同时实现了一套直接使用ofbiz实体引擎操作ofbiz所有数据库表的spring应用框架设计

    ofbiz jar file2

    ofbiz jar file, some jars for ofbiz

    ofbiz开发框架建表语句 ofbiz_sql

    ofbiz sql 表结构

    OFBIZ集成Activiti流程

    OFBiz集成Spring和Activiti,详细设计说明书。ofbiz版本12.04

    ofbiz数据结构设计

    ofbiz数据结构

    浅谈OFBIZ.doc

    浅谈OFBIZ.doc浅谈OFBIZ.doc浅谈OFBIZ.doc浅谈OFBIZ.doc浅谈OFBIZ.doc

Global site tag (gtag.js) - Google Analytics