One of the primary benefits of using the Entity Engine over direct SQL calls to access data is that OFBiz abstracts the details of how data is physically stored, away from the user. When making a request for data through the Entity Engine, the user does not need to know where the data is physically located or how it is formatted. The Entity Engine handles all the details of data mapping for the user in real time.
Since physical data storage formatting varies widely from database vendor to vendor, the Entity Engine must map these variations to consistent data type values for use within the OFBiz framework.
The following steps have to be performed before adding or modifying data type mapping:
entityengine.xml
file. Each field type file is defined with a field-type-name
element XML declaration. datasource
element with the appropriate name
attribute value. For example, if you wish to change the database field type definitions for the database called localderby
, find the name
attribute that has the value of localderby
. datasource
element is located, observe the field-type-name
attribute's value. For example, in the default out-of-the-box entityengine.xml
file, the field-type-name
value for localderby
is derby
as shown here:<datasource name="localderby" <!—Note: file contents removed for clarity --> field-type-name="derby"
field-type
element declaration given the field-type-name
value from step 3. For example, in the following field-type
element, we see that the field type definition file for the derby
data source is fieldtypederby.xml
(Note: the location of fieldtypederby.xml
defaults to ~framework/entity/fieldtype):
<field-type name="derby" loader="fieldfile" location="fieldtypederby.xml"/>
Adding or modifying a data type mapping may be performed by following these steps:
entityengine.xml
file. Use the process described earlier to find the appropriate file corresponding to the database data type needing modification. currency-amount
, edit the field-type-def
element as shown here:<field-type-def type="currency-amount" sql-type="NUMERIC(18,2)" java type="java.math.BigDecimal"> <validate method="isSignedDouble"/> </field-type-def>
field-type-def
to the document. Don't forget to close the element with a</field-type-def>
tag. ant clean-install
to remove any existing data. ant run-install
to reinstall any seed data.The Entity Engine automatically maps low-level database data types to data types that are consistent across all Entity Engine-managed databases using the mapping definitions found in field type definition files. In this way, OFBiz offloads the tedious and often error-prone task of converting physical database data storage formats for application use from the developer.
In the following example, an OFBiz data type is shown and then the equivalent storage data types per database are given. Using the Entity Engine as the layer between database access and application logic, the OFBiz developer need only reference the data as an OFBiz data type. There is no need to worry about the vagaries of the individual storage mediums in use. If the underlying database changes, applications will continue to work transparently as applications read and write OFBiz data type(s) to the Entity Engine and not the target database.
OFBiz data type: date-time | |||
---|---|---|---|
sql-type |
sql-type-alias |
java-type | |
Oracle |
|
|
|
PostgreSQL |
|
|
|
To define a new entity definition file, follow these few steps:
ofbiz-component.xml
file to make sure there is an entity-resource
element that locates an entity definition file. For example:<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
ofbiz-component.xml
file shown earlier. Make sure each file has the appropriate XML version and XSD declarations in the beginning of the file:<?xml version="1.0" encoding="UTF-8"?> <entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "http://ofbiz.apache.org/dtds/entitymodel.xsd">
</entitymodel>
). ofbiz-component.xml
file effective.18.191.14.93