Building a view-entity

OFBiz view-entities are a convenient way of constructing SQL JOIN statements. They do not force the creation of database tables or map to database tables as do entity definitions, but rather they allow OFBiz to create runtime views of related tables so that users may easily access joined tables without creating complicated SQL JOIN statements.

Getting ready

View-entities are defined in entity definition files along with entity definitions. Make sure you have an entity definition file (to use for any view-entities) configured in an existing ofbiz-component.xml.

How to do it...

The process for creating one or more view-entities is similar to that of creating an entity definition, and can be done by following these steps:

  1. Open an existing entity definition file or create a new one.
  2. Add one or more view-entity elements as shown here. Please note: XML declarations shown below are for demonstration purposes only. Statements have been removed to make reading easier:
    <view-entity entity-name="EntityName"
    package-name="org.ofbiz.somePackageName"
    never-cache="true" title="My New View Entity">
    <!-- Entity definition XML declaration(s) go here.
    Removed for demonstration purposes -->
    </view-entity>
    
  3. Close the view-entity element with a closing tag (</view-entity>).
  4. Save and close the file.
  5. Restart OFBiz to make the view-entity definition effective.
  6. Use the WebTools Entity Reference - Interactive Version to see if the new view-entity was successfully created (https://localhost:8443/webtools/control/entityref).
  7. Programmatically, view-entities are accessed in the same manner as entities.

How it works...

OFBiz view-entities are a convenient way to create SQL JOIN statements (joining together table column data from two or more tables) using XML declarations instead of SQL statements. The Entity Engine automatically creates the SQL JOIN statement any time the view-entity is accessed.

View-entities may be created or removed from the OFBiz Entity Engine data model at any time using the mentioned recipe. View-entities are read-only, and attempts to store data using a view-entity will fail.

There's more...

An OFBiz view-entity has one or more participating "member" entities. As a convenient way to refer to a member entity, you must create an entity level alias for that member using the member-entity element as shown here:

member-entity element tag

Create a shortcut alias for each view-entity participating member.

  

Attribute name

Required?

Usage

entity-alias

Yes

Two-letter to four-letter alias or abbreviation used for the remainder of this definition to represent the full entity name as given in the entity-name attribute.

entity-name

Yes

The name of an existing entity.

Note: this attribute is case-sensitive. The value in this field must match an existing entity name.

Each member entity may have one or more field aliases defined for any existing entity field. All fields are referenced using field aliases within the context of the view-entity. To create field-level aliases, use the alias element tag as shown here:

alias element tag

For example, an alias element definition of:

<alias entity-alias="OH" name="orderId" >

Refers to the field orderId in the entity aliased within the member-entity as OH. If OH is aliased as OrderHeader, then this alias refers to the orderId field in the OrderHeader table.

  

Attribute name

Required?

Usage

entity-alias

Yes

Use the entity's alias as configured in the member-entity element instead of the real entity name.

name

Yes

The field from the aliased entity to use as part of this definition.

complex-alias element tag

Within the alias element, you may have one or more complex-alias elements defined. complex-alias elements are a mechanism for configuring filters on one or more return fields.

  

operator

Yes

Any supported mathematical operator for the field's data type.

One or more fields to be joined using the operator-supplied operator. Fields are defined using the complex-alias-field element tag.

  

If all fields for an entity should be returned when calling this view-entity, you may use the shortcut alias-all element as defined here:

alias-all element tag

Return all the fields for the specified entity alias.

 

Attribute name

Usage

entity-alias

Use the entity's alias as configured in the member-entity element instead of the real entity name.

To create a SQL OUTER JOIN (that is, a JOIN on two tables where records from the joined tables may not have matching pairs), use the view-link element to define the relationship between one entity and another target entity, and set the rel-optional value to true:

view-link element tag (Optional)

  

Attribute name

Required?

Usage

entity-alias

Yes

The alias for the entity participating in this relation.

rel-entity-alias

Yes

The alias of the related entity.

rel-optional

No

Valid values: true, false

Default: false

key-map element tag

The key-map entity defines the table relationship.

  

field-name

 

The name of the field as defined by the entity pointed to by the entity-alias attribute value.

See also

View-entities may be quite complex. For an in depth treatment of this subject, please see The Open For Business Project: Entity Engine Guide at:

http://ofbiz.apache.org/docs/entity.html

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.173.242