Seed data files are used to load the OFBiz database—sometimes referred to as "seeding" the database—with data whenever the ANT database data loading targets are called. You may create new seed data files as needed. Each Component may have one or more seed data files, and OFBiz supports an unlimited number of seed data files across the installation.
Navigate to the top-level directory for the component that will contain the new seed data file.
Follow this recipe to create new seed data files:
ofbiz-component.xml
file in an editor of your choice. entity-resource
XML declaration with the seed data file's location as shown here. The location
attribute contains the location of the file relative to the containing Component. The reader-name
attribute tells OFBiz when to load the file based on ANT targets.<entity-resource type="data" reader-name="seed" loader="main" location="data/mainSeedData.xml"/> <!-- For data to be loaded on the "demo" pass, use the reader-name of demo --> <entity-resource type="data" reader-name="demo" loader="main" location="data/mainDemoData.xml"/>
entity-engine-xml
declarations. For example, when opened in a plain text editor, your file should look something like the following:<?xml version="1.0" encoding="UTF-8"?> <entity-engine-xml> </entity-engine-xml>
<EntityName1 fieldName1 = "value"…fieldNameN="value" />
ant run-install
OFBiz provides a flexible database data loading environment by allowing the user to configure which data files should be loaded when the ANT tool is used. Within the ofbiz-component.xml
file, the presence of the entity-resource
element tells OFBiz that there is a data file to load, where that file is located, and under what circumstances to load data from that file into the database. This last piece of information is configured using the reader-name
attribute. The reader-name
attribute is set to a "reader" (for example, a reader-name
of seed)
based on which ANT target should be used to load the file. The following table translates reader-name values to ANT targets.
Note: some reader-name
values and equivalent ANT targets are cumulative in that they not only load files for the specified reader, but may also load other files. For example, the run-install
target loads all data files, including seed
and demo
.
If you want to load only specific types of data into the database using ANT commands, the following table maps the reader-name
(type of data to load) with the equivalent ANT command to use:
reader-name value |
ANT command (target) |
Usage |
---|---|---|
NA |
|
To clean all data from the database in preparation for clean build. |
|
|
Loads all types of data files. |
|
|
Load seed data. For example, geographic information. |
|
|
Loads seed-initial type only. |
|
|
Loads seed data types: seed, seed-initial, and ext. |
|
|
Loads seed data types: seed, seed-initial, ext, ext-test in that order. |
By choosing to run various ANT data loading scripts depending on your needs, you may selectively load data from files into the database while leaving other database entities untouched. This is a helpful facility should you need to repeatedly load seed or demo data while testing.
Within data files to be loaded using the ANT tool, all entity field values are represented as strings. OFBiz manages the translation of the string value to the target database data type. If you want a verbatim or literal value to be loaded in the database or value that contains characters XML parsers view as "special" or "trigger" values, then wrap your value with CDATA
sections as shown here:
<fieldName><![CDATA[verbatim string goes here!]]></fieldName>
3.137.178.9