OFBiz是一个非常好的企业级开发框架,实现了多层的松耦合结构,其中一部分松耦合就是通过配置文件实现的,这里就要提到一些配置文件和开发文件。

1、首先是entityengine.xml文件,这个文件是配置数据源的,也包括数据库连接池、事务实现类的配置和字段类型配置文件。企业级系统的开发一般都离不开数据库,那么在OFBiz中,数据库的配置就在这个配置文件里面,先配置一个group-map,然后配置其对应的数据源:

< delegator  name ="default"  entity-model-reader ="main"  entity-group-reader ="main"  entity-eca-reader ="main"
   distributed-cache-clear-enabled
="false" >
        
< group-map  group-name ="org.ofbiz"  datasource-name ="ofbiz" />
        
< group-map  group-name ="com.aicent"  datasource-name ="portal" />
    
</ delegator >

    
< datasource  name ="ofbiz"
            helper-class
="org.ofbiz.entity.datasource.GenericHelperDAO"
            field-type-name
="mysql"
            check-on-start
="false"
            add-missing-on-start
="false"
            check-pks-on-start
="false"
            use-foreign-keys
="true"
            join-style
="ansi-no-parenthesis"
            alias-view-columns
="false"
            drop-fk-use-foreign-key-keyword
="true"
            table-type
="InnoDB"  
            character-set
="latin1"
            collate
="latin1_swedish_ci" >
        
< read-data  reader-name ="seed" />
        
< read-data  reader-name ="seed-initial" />
        
< read-data  reader-name ="demo" />
        
< read-data  reader-name ="ext" />
        
< inline-jdbc
                
jdbc-driver ="com.mysql.jdbc.Driver"
        jdbc-uri
="jdbc:mysql://localhost/ofbiztrunk"
                jdbc-username
="root"
                jdbc-password
="123456"
                isolation-level
="ReadCommitted"
                pool-minsize
="2"
                pool-maxsize
="20" />
        
<!--  <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/>  -->
    
</ datasource >

datasource配置里面有一个 field-type-name ="mysql" ,到entitymodel.xml配置文件就知道是干吗用的了。

2.entitymodel.xml & entitygroup.xml
  OFBiz本质上来说还是面向数据库的设计,entitymodel.xml的配置entity的,entity实体对应数据库里面的table,实体的field对应数据库里面的字段,如下是一个entity配置:

< entity  entity-name ="Customerinfo"  package-name ="com.aicent.ccb"  no-auto-stamp ="true"
        title
="customerinfo" >
        
< field  name ="id"  type ="int10"   ></ field >
        
< field  name ="name"  type ="varchar128" ></ field >
        
< field  name ="customernameshort"  type ="varchar16" ></ field >
        
< field  name ="country"  type ="varchar64" ></ field >
        
< field  name ="businessaddr"  type ="text" ></ field >
        
< field  name ="mailaddr"  type ="text" ></ field >
        
< field  name ="billaddr"  type ="text" ></ field >
        
< field  name ="phone"  type ="varchar32" ></ field >
        
< field  name ="fax"  type ="varchar32" ></ field >
        
< field  name ="website"  type ="varchar128" ></ field >
        
< field  name ="note"  type ="text" ></ field >
</ entity >

里面有一个type,这个type对应数据库字段的类型(日期型,字符串型,整型等),这个对于关系在哪里呢?就在刚才说的 field-type-name 里面配置,如果配置为mysql,那么entitygengine.xml中mysql的
field-type指向的文件是:

< field-type  name ="mysql"  loader ="fieldfile"  location ="fieldtypemysql.xml" />

在fieldtypemysql.xml中,就可以找到如int10,varchar128表示的实际mysql字段类型了:

 1  < fieldtypemodel  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  
 2          xsi:noNamespaceSchemaLocation ="http://ofbiz.apache.org/dtds/fieldtypemodel.xsd" >
 3     <!--  ===================== field-type-def ====================  -->
 4       <!--  General Types  -->  
 5       < field-type-def  type ="blob"  sql-type ="BLOB"  java-type ="java.sql.Blob" ></ field-type-def >
 6      
 7       < field-type-def  type ="date-time"  sql-type ="DATETIME"  java-type ="java.sql.Timestamp" ></ field-type-def >
 8       < field-type-def  type ="date"  sql-type ="DATE"  java-type ="java.sql.Date" ></ field-type-def >
 9       < field-type-def  type ="time"  sql-type ="TIME"  java-type ="java.sql.Time" ></ field-type-def >
10      
11       < field-type-def  type ="currency-amount"  sql-type ="DECIMAL(18,2)"  java-type ="java.math.BigDecimal" >< validate  method ="isSignedDouble"   /></ field-type-def >
12       < field-type-def  type ="currency-precise"  sql-type ="DECIMAL(18,3)"  java-type ="java.math.BigDecimal" >< validate  method ="isSignedDouble"   /></ field-type-def >
13       < field-type-def  type ="fixed-point"  sql-type ="DECIMAL(18,6)"  java-type ="java.math.BigDecimal" >< validate  method ="isSignedDouble"   /></ field-type-def >
14       < field-type-def  type ="floating-point"  sql-type ="DECIMAL(18,6)"  java-type ="Double" >< validate  method ="isSignedDouble"   /></ field-type-def >
15       < field-type-def  type ="numeric"  sql-type ="DECIMAL(20,0)"  java-type ="Long" >< validate  method ="isSignedLong"   /></ field-type-def >
16       < field-type-def  type ="integer"  sql-type ="INTEGER"  java-type ="Integer" ></ field-type-def >
17      
18       < field-type-def  type ="id"  sql-type ="VARCHAR(20)"  java-type ="String" ></ field-type-def >
19       < field-type-def  type ="id-long"  sql-type ="VARCHAR(60)"  java-type ="String" ></ field-type-def >
20       < field-type-def  type ="id-vlong"  sql-type ="VARCHAR(250)"  java-type ="String" ></ field-type-def >
21      
22       < field-type-def  type ="indicator"  sql-type ="CHAR(1)"  java-type ="String" ></ field-type-def >
23       < field-type-def  type ="very-short"  sql-type ="VARCHAR(10)"  java-type ="String" ></ field-type-def >
24       < field-type-def  type ="short-varchar"  sql-type ="VARCHAR(60)"  java-type ="String" ></ field-type-def >
25       < field-type-def  type ="long-varchar"  sql-type ="VARCHAR(255)"  java-type ="String" ></ field-type-def >
26       < field-type-def  type ="very-long"  sql-type ="LONGTEXT"  java-type ="String" ></ field-type-def >
27     
28       < field-type-def  type ="comment"  sql-type ="VARCHAR(255)"  java-type ="String" ></ field-type-def >
29       < field-type-def  type ="description"  sql-type ="VARCHAR(255)"  java-type ="String" ></ field-type-def >
30       < field-type-def  type ="name"  sql-type ="VARCHAR(100)"  java-type ="String" ></ field-type-def >
31       < field-type-def  type ="value"  sql-type ="VARCHAR(255)"  java-type ="String" ></ field-type-def >
32      
33       <!--  customize field type definitions for ccb  -->
34       < field-type-def  type ="text"  sql-type ="TEXT"  java-type ="String" ></ field-type-def >
35      
36       < field-type-def  type ="char"  sql-type ="CHAR(1)"  java-type ="String" ></ field-type-def >
37       < field-type-def  type ="char125"  sql-type ="CHAR(125)"  java-type ="String" ></ field-type-def >
38       < field-type-def  type ="varchar16"  sql-type ="VARCHAR(16)"  java-type ="String" ></ field-type-def >
39       < field-type-def  type ="varchar20"  sql-type ="VARCHAR(20)"  java-type ="String" ></ field-type-def >
40       < field-type-def  type ="varchar24"  sql-type ="VARCHAR(24)"  java-type ="String" ></ field-type-def >
41       < field-type-def  type ="varchar50"  sql-type ="VARCHAR(50)"  java-type ="String" ></ field-type-def >
42       < field-type-def  type ="varchar64"  sql-type ="VARCHAR(64)"  java-type ="String" ></ field-type-def >
43       < field-type-def  type ="varchar128"  sql-type ="VARCHAR(128)"  java-type ="String" ></ field-type-def >
44 </ fieldtypemodel >

OFBiz这里为什么不在entitymodel里面直接使用字段在数据库中的类型,而这么绕呢?我想至少有两个目的:首先是公司企业开发时可以针对使用的字段类型有一个规范,所有的字段都采用这个配置文件中的字段类型,而不是开发人员自己随意定义数据库字段的类型;第二是为了使用不同Vendor的数据库,如果想从mysql换成oracle,只需要定义另一份fieldtypeoracle.xml,field-type-def中sql-type不变,而sql-tye换成oracle的类型即可。

entitygroup.xml配置文件时用于配置entitymodel.xml中配置的entity是属于哪个group的,这个group对应entityengine.xml中的group-name,如果忘记在entitygroup.xml中配置,那么在OFBiz 9之前,这个entity就无法使用,不会创建相应的table,OFBiz 9以后,默认的group name是org.ofbiz。

< entitygroup  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation
="http://www.ofbiz.org/dtds/entitygroup.xsd" >


    
< entity-group  group ="com.aicent"  entity ="Customerextra"   />
    
< entity-group  group ="com.aicent"  entity ="Customerinfo"   />

</ entitygroup >

3.ofbiz-containers.xml 里面配置了各种容器类,经常修改的容器就是name为catalina-container的容器,使用的是embeded tomcat,里面可以修改各种tomcat的配置项,就像我们修改tomcat的配置文件server.xml一样,在里面修改端口等信息。

4.log4j.xml 日志配置文件

5.component-load.xml 这个文件在几个文件夹中都存在,如framework,applications,specialpurpose中。OFBiz将一个个应用实现为component,这些componnet是就好像tomcat中webapps中的一个个web应用。每次是否加载这个component可以在component-load.xml配置,如果不想加载,注释掉就可以。

< component-loader  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  
        xsi:noNamespaceSchemaLocation
="http://ofbiz.apache.org/dtds/component-loader.xsd" >
    
< load-component  component-location ="commonext" /> <!--  common component used by most other components  -->      
    
< load-component  component-location ="securityext" />
    
<!--
    <load-component component-location="party"/>
    <load-component component-location="content"/>
    <load-component component-location="workeffort"/>
    <load-component component-location="product"/>
    <load-component component-location="manufacturing"/>
    <load-component component-location="accounting"/>
    <load-component component-location="humanres"/>
    <load-component component-location="order"/>
    <load-component component-location="marketing"/>
    
-->
</ component-loader >

到底哪些目录下的component-load.xml有效呢,这个目录在framework/base/config/component-load.xml进进行配置:

< component-loader  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  
        xsi:noNamespaceSchemaLocation
="http://ofbiz.apache.org/dtds/component-loader.xsd" >
    
< load-components  parent-directory ="framework" />  
    
< load-components  parent-directory ="themes" />  
    
< load-components  parent-directory ="applications" />
    
< load-components  parent-directory ="specialpurpose" />
    
< load-components  parent-directory ="hot-deploy" />
</ component-loader >

6.general.properties 这里面配置的东西很多,大家自己去看吧。

7.cache.properties 配置OFBiz中的缓存,配置这个文件需要对OFBiz中的缓存有所了解,这个在后续文章中进行分析。

其他还有一些比较配置的文件,就不一一说明了。