OfBiz Entity Engine 学习

1. entitymodle.xml中的字段类型参见 opentaps-1.0\framework\entity\fieldtype
     比较常见的字段类型定义如下:
         <field-type-def type="id-ne" sql-type="VARCHAR(20)" java-type="String">
                    <validate method="isNotEmpty" />
        </field-type-def>
         <field-type-def type="id" sql-type="VARCHAR(20)" java-type="String"></field-type-def>
         <field-type-def type="comment" sql-type="VARCHAR(255)" java-type="String"></field-type-def>
        <field-type-def type="description" sql-type="VARCHAR(255)" java-type="String"></field-type-def>
        <field-type-def type="name" sql-type="VARCHAR(100)" java-type="String"></field-type-def>
        <field-type-def type="value" sql-type="VARCHAR(255)" java-type="String"></field-type-def>

entity

Attribute Name Required? Description
entity-name Y The name of the entity as it is referred to when using the Entity Engine Java API and various other places in the Entity Engine.
table-name N The name of the database table that corresponds to this entity. This attribute is optional and if not specified the table name will be derived from the entity name.
package-name Y The name of the package that this entity is contained in. With hundreds of entities in a large data model this is used to organize and structure the entities definitions.
dependent-on N This can be used to specify a parent entity or an entity that this entity is dependent on. This is currently not used for anything automated in the Entity Engine, but can be used to specify an heirarchical entity structure.
enable-lock N Specifies whether or not optimistic locking should be used for this entity. The lastUpdatedStamp field must exist on the entity and will be used to keep track of the last time the entity instance was updated. If the current instance to be updated does not have a matching lastUpdatedStamp an EntityLockedException will be thrown. Must be true or false. Defaults to false.
never-cache N If this is set to true caching of this entity will not be allowed. Automatic cache clearing will not be done to improve efficiency and any attempt to use the cache methods on the entity will result in an exception so that it is easier to find and eliminate where this is being done. Must be true or false. Defaults to false.
title N A title for the entity. If not specified defaults to the global setting for the file the entity is in.
copyright N The copyright of the entity. If not specified defaults to the global setting for the file the entity is in.
author N The author of the entity. If not specified defaults to the global setting for the file the entity is in.
version N The version of the entity. If not specified defaults to the global setting for the file the entity is in.
Sub-Element Name How Many Description
description 0 or 1 A description of the entity. If not specified defaults to the global setting for the file the entity is in. This element has no attributes and should contain only a simple string of characters.
field 1 to many Used to declare fields that are part of the entity.
prim-key 0 to many Used to declare which fields are primary keys
relation 0 to many Used to declare relationships between entities.

field

Attribute Name Required? Description
name Y The name of the field that is used to refer to it in Java code and other places.
col-name N The name of the corresponding database column. This is not required and if not specified this will be derived from the field name.
type Y The type of the field. This is looked up in the field types file for the current datasource at run-time to determine the Java and SQL types for the field and database column.

Sub-Element Name How Many Description
validate 0 to many Each validate element has a single attribute called name which specifies the name of the validation method to call. These methods are not called in all Entity Engine operations and are only used for generic user interfaces like the Entity Data Maintenance pages in WebTools.

prim-key

Attribute Name Required? Description
field Y The name of the field that will be part of the primary key.

relation

Attribute Name Required? Description
type Y Specifies the type of the relationship including the cardinality of the relationship (in one direction) and if a foreign key should be created for cardinality one relationships. Must be "one", "one-nofk", or "many".
title N Because you may want to have more than one relationship to a single entity this attribute allows you to specify a title that will be prepended to the rel-entity-name to make up the name of the relationship. If not specified the rel-entity-name alone will be used as the relationship name.
rel-entity-name Y The name of the related entity. The relationship goes from this entity to the related entity.
fk-name N The foreign key name can be created automatically from the relationship name, but this is not recommended for two reasons: many databases have a very small maximum size (like 18 characters) for foreign key and index names, and many databases require that the FK name be unique for the entire database and not just for the table the FK is coming from.

Sub-Element Name How Many Description
key-map 1 to many The key-map is used to specify a field in this entity that corresponds to a field in the related entity. This element has two attributes: field-name and rel-field-name. These are used to specify the name of the field on this entity and the corresponding name of the field on the related entity.

更加详细的内容参照: http://ofbiz.apache.org/docs/entity.html

你可能感兴趣的:(OfBiz Entity Engine 学习)