The Open For Business Project SourceForge Logo

The Open For Business Project: Entity Engine Configuration Guide

Written By: David E. Jones, [email protected]
Minor corrections by: Pawel H. Debski
Last Updated: January 28, 2003

Table of Contents


Related Documents:



Introduction


This document describes the configuration of the Entity Engine. It starts with an introduction to general ideas and then goes through each part of the entityengine.xml file and explains the available elements and their usage. The entityengine.xml file used for the OFBiz applications has examples of a number of different options and is located in ofbiz/commonapp/etc/entityengine.xml.

The configuration of the Entity Engine is done through a simple XML file called entityengine.xml that must exist somewhere on the classpath. This file is used to define parameters for persistence servers such as EJB server parameters or JDBC server parameters. It is also used to specify which XML entity model, entity group, and field type model files will be used for that server. The default file for the OFBiz distribution can be found in ofbiz/commonapp/etc/entityengine.xml.

Each application that uses the Entity Engine does so through a GenericDelegator instance. The delegator name must be passed to the static factory method that is then passed to the constructor if a new instance is needed. This delegator name is used to look up settings for that delegator in the entityengine.xml file. Each delegator uses an entity model reader and an entity group reader that specifies a group name for each named entity in the entity model file. The entityengine.xml file contains the settings that map each group name to a GenericHelper for that group. GenericHelper is an interface that must be implemented for each type of data source (i.e.: JDBC, EJB, SOAP, HTTP, et cetera). 

The settings for each named GenericHelper are specified datsource elements in the entityengine.xml file. For a JDBC helper these would include database connection parameters such as either the JNDI data source parameters or the JDBC parameters including the driver name, the JDBC URI, and the username and password for the database. An EJB helper would contain JNDI parameters such as the context provider URL, the initial context factory, and the URL package prefixes.

The GenericDelegator is the primary access method for Entity Engine services. Each service request is dispatched to the helper that corresponds to the entity that the service is requested for according to the group name of the entity specified in the entity group XML file and the helper for that group specified in the entityengine.xml file. The default entity group XML file for the OFBiz entity model can be found in ofbiz/commonapp/entitydef/entitygroup.xml.


Resource Loaders


The resource-loader tag is used to configure a named resource loader that can be used elsewhere to load XML and other resources. It has the following attributes.

Attribute Name Required? Description
nameY The name of the resource loader. Used in other tags in the 'loader' attribute.
classY The class to use that extends the abstract class org.ofbiz.core.entity.config.ResourceLoader. Available classes include FileLoader, UrlLoader, and ClasspathLoader, all in the same package as the ResourceLoader class.
prepend-envN The name of a Java environment property to put at the very beginning of the full location, before the prefix. This is optional.
prefixN A string to put before the location when making the full location. This is optional. If used will go after the prepended environment property and before the location specified for each resource.


JTA Elements


For JTA support the Entity Engine needs access to the javax.transaction.UserTransaction and optionally the javax.transaction.TransactionManager interface implementations for the TX Manager being used. These are retrieved through the org.ofbiz.core.entity.TransactionFactory class. This class uses the class specified with the class attribute of the transaction-factory. This class may be changed depending on which application server or transaction manager you are running OFBiz on.

The default TX Manager is Tyrex from Exolab (www.exolab.org) and the factory class for Tyrex is org.ofbiz.core.entity.transaction.TyrexFactory. There is also a special class for Weblogic: org.ofbiz.core.entity.transaction.WeblogicFactory, which must be changed to include the Weblogic specific stuff and then compiled with weblogic.jar on the classpath.

The most widely useful transaction factory class is the org.ofbiz.core.entity.transaction.JNDIFactory class. This class uses some additional elements from the entityengine.xml file to locate the UserTransaction and TransactionManager objects in JNDI.

The user-transaction-jndi and transaction-manager-jndi tags are used to specify the object names in JNDI and the name of the JNDI Server to use, as configured above. Both tags have two required attributes: jndi-server-name and jndi-name. An example jndi-name for the UserTransaction object is java:comp/UserTransaction and for the TransactionManager object is java:comp/TransactionManager.


Delegator Elements


The GenericDelagator is created through a factory method that takes a String argument containing the delegator name. This delegator name is used to look up a delegator tag in the entityengine.xml file.

Attribute Name Required? Description
nameY The name of the Delegator. Used to look up this tag by delegator name.
entity-model-readerY The name of the entity-model-reader to use for this delegator.
entity-group-readerY The name of the entity-group-reader to use for this delegator.

The delegator tag must contain one or more group-map tags specifying a datasource to use for each group of entities that the delegator will know about from the entity-group-reader. The delegator uses this file to assign a group to each entity. When an operation on an entity is performed it looks up the group and the datasource helper that corresponds to the group and uses that Helper to perform lower level Data Source operations. With this technique when the application is written it does not have to know which Helper is responsible for a given entity, and can therefore handle an entity or groups of entities assigned to different Data Sources with a simple configuration.


Entity Model XML Files


The entity-model-reader tag is used to configure each named entity model reader. The tag has a name attribute used to specify the entity model reader's name. Each reader may load from multiple resources that are each specified with a resource tag inside the main tag.

Each resource tag has two required attributes: loader which specifies which resource-loader to use and location which specifies the location that the resource-loader will use inside itself to load the resource.


Entity Group XML File


The entity-group-reader tag is used to configure each named entity group reader. The tag has a name attribute used to specify the entity group reader's name. The group reader uses a single XML file to get the entity-group mappings.

The tag has two required attributes: loader which specifies which resource-loader to use and location which specifies the location that the resource-loader will use inside itself to load the resource.


Field Type XML File


The field-type tag is used to configure each named field type. The tag has a name attribute used to specify the field type's name. The group reader uses a single XML file to get the field type information.

The tag has two required attributes: loader which specifies which resource-loader to use and location which specifies the location that the resource-loader will use inside itself to load the resource.


Data Source Elements


Many datasources can be configured using one datasource tag for each datasource. This tag has the following attributes, and may contain the following sub-elements:

Attribute Name Required? Description
nameY That name of the datasource.
helper-classY There can be many types of datasource helpers the main one used is the JDBC/DAO helper. You can code you own helpers and use them by implementing the org.ofbiz.core.entity.GenericHelper interface. For JDBC/DAO helpers the class will be org.ofbiz.core.entity.GenericHelperDAO.
field-type-nameY The name of the field-type to use. Must match the name of an existing field-type tag as defined above.
check-on-startN Check the datasource on startup? Must be true or false, defaults to true.
add-missing-on-startN Add missing entities and fields to the datasource on startup when checking is done? Must be true or false, defaults to false.
use-foreign-keysN Use/Create foreign keys for "one" relationships? Must be true or false, defaults to true.
use-foreign-key-indicesN Use/Create indices for foreign keys (i.e. an index on the foreign key columns)? Note that creating foreign keys is not required for this to work and that indices are created for type "one" relationship definitions. Must be true or false, defaults to true.
check-fks-on-startN Check foreign keys at startup and add missing as needed? Must be true or false, defaults to false. Some databases have a hard time with this and do not return a full list of foreign keys resulting in duplicate foreign keys being added to the database.
check-fk-indices-on-startN Check foreign key indices at startup and add missing as needed? Must be true or false, defaults to false.
use-pk-constraint-namesN Use constraint names for Primary Keys? Some databases have a problem with this, but work fine if they assign their own names. Must be true or false, defaults to true.
constraint-name-clip-lengthN Specifies max length of a constraint name. Constraint names are clipped to this length. When playing with this watch for duplicate constraint names. Must be an integer, defaults to 30.
fk-styleN Specifies the foreign key syntax style, either naming the foreign key constraint, or naming the foreign key itself. Most databases use the name_constraint syntax, but SAP DB is an exception to that and there may be others. Must be either "name_constraint" or "name_fk". Defaults to name_constraint.
use-fk-initially-deferredN Specifies whether or not to use the INITIALLY DEFERRED option available in many databases when creating foreign keys. Not all databases support this option. When enabled and supported the foreign keys will not be checked until a transaction is committed, as opposed to checking foreign keys as operations are done inside a transaction. Must be set to "true" or "false". Defaults to true.
join-styleN Specifies the syntax to use when doing table joins in view-entity operations. Many databases are adopting the ANSI JOIN standard, but before that was introduced theta joins were much more common. Two theta join styles are supported: Oracle and MS SQL. Must be "ansi", "theta-oracle" or "theta-mssql". Defaults to "ansi".

Sub-Element Name How Many Description
sql-load-path0 to many Used to specify a list of full paths to directories that will be searched for XML and SQL files to import into the data source by the install page in the WebTools webapp. Each tag has two attributes: path for the path location, and prepend-env to optionally specify a Java environment property to prepend to the specified path.
inline-jdbc0 or 1 Used to specify the JDBC parameters to be used either by Tyrex or if Tyrex is not available then by directly loading the driver (very slow). You must specify either inline-jdbc or jndi-jdbc, but not both, for the DAOHelper.
jndi-jdbc0 or 1 Used to specify the jndi-server and jndi-name to get a Connection or XAConnection from JNDI. You must specify either inline-jdbc or jndi-jdbc, but not both, for the DAOHelper.
ANY0 or 1 Any tag may go inside the datasource tag to specify parameters for other GenericHelper implementations. These will not be checked at load time unless the DTD is modified to describe them.

The inline-jdbc tag has the following attributes:

Attribute Name Required? Description
jdbc-driverY The JDBC driver class for the database.
jdbc-uriY The URI used to specify the type and location of the database.
jdbc-usernameY The username to connect to the database as.
jdbc-passwordY The username's password.
isolation-levelN This is used by Tyrex to specify the transaction isolation level. The standard JDBC transaction isolation levels are available:
  • 'ReadCommitted'
  • 'ReadUncommitted'
  • 'RepeatableRead'
  • 'Serializable' (default)

The jndi-jdbc tag has the following attributes:

Attribute Name Required? Description
jndi-server-nameY The name of the JNDI Server to use as configured in this file with the jndi-server tag, described above.
jndi-nameY The name of the Connection or XAConnection object in JNDI.

The data source retrieved from JNDI should be pooled and transactional, with connections already enlisted if a JTA transaction has been started. It can be either a DataSource or an XADataSource object.

If the JNDI elements are not specified the ConnectionFactory will get the JDBC parameters from entityengine.xml file and try to use Tyrex for the transaction manager and connection pool. If Tyrex is not available the Entity Engine will hobble along creating a JDBC connection manually each time one is requested. A warning will be printed when this happens.