Creating new seed data files

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.

Getting ready

Navigate to the top-level directory for the component that will contain the new seed data file.

How to do it...

Follow this recipe to create new seed data files:

  1. Open the ofbiz-component.xml file in an editor of your choice.
  2. Add an 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"/>
    
  3. Create a new seed data file by copying any existing seed data file and removing everything from the file except the initial version declaration and the start and end 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>
    
  4. Add one or more entries to this file representing the data to be loaded. The basic format for an entry is:
    <EntityName1 fieldName1 = "value"…fieldNameN="value" />
    
  5. Save the file.
  6. Navigate to the OFBiz Install directory.
  7. Run the ANT database load script.
    ant run-install
    
  8. Restart OFBiz.

How it works...

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.

Tip

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

ant clean-data

To clean all data from the database in preparation for clean build.

demo

ant run-install

Loads all types of data files.

seed

ant run-install-seed

Load seed data. For example, geographic information.

seed-initial

ant run-install-initial

Loads seed-initial type only.

ext

ant run-install-extseed

Loads seed data types: seed, seed-initial, and ext.

ext-test

ant run-install-exttest

Loads seed data types: seed, seed-initial, ext, ext-test in that order.

There's more…

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>
..................Content has been hidden....................

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