ofbiz实现oracle平台小例子详解步骤及注意的问题

 一 , 在配置的过程中需要注意一下几点:(请先完成下面的小例子,再进行构建)
1,一般项目都是创建在hot-deploy目录下
2,数据源的配置在D:/ofbiz/framework/entity/configf下的entityengine.xml文件
    其中在配置oracle数据源时需要把schema-name="OFBIZ"属性删除,避免数据库实例不是ofbiz的情况,
    具体的文件内容会复制在文件最后
3 , D:/ofbiz/framework/entity/lib/jdbc需要在该目录下加入ojdbc.jar
4,在D:/ofbiz/framework/base/config目录下有ofbiz-containers.xml,里面定义了ofbiz项目启动时服务的端口,初始为8080
    建议在初期开发是不要更改该端口,如果出现oracle端口和8080冲突时,建议更改oracle的http服务的端口,因为在ofbiz
    提供的一些application中很多地方是把端口写死为8080,如果更改不方便访问一些应用程序
5 , 更改完数据源配置时需要重构ofbiz目录,具体做法如下
 在ofbiz根目录下,运行指令ant clean-all ,接着运行指令ant run-install
 执行完这两个ant的时候就已经完成了对数据库的映射
 注:如果是郭刚提供的ofbiz框架,在ant前,需要把D:/ofbiz/specialpurpose目录下的build.xml文件中的meetingroom/build.xml删除
6 , 框架重构完成以后,在用 java  -Xmx512m -jar ofbiz.jar进行启动时,可能会出现job_sandbox表出现异常,这时
 需要把该表中的RUN_BY_INSTANCE_ID字段全部手动填上值,并commit, 注:我全是负值为1

 

二 , 简单增删改查实例实现详细步骤:
 step1 :    首先在hot-deploy创建一个新的项目目录:hellosix
   在该目录下新建ofbiz-component.xml
   该xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="hellosix"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/ofbiz-component.xsd ">
    <!-- define resource loaders; most common is to use the component resource loader -->
    <resource-loader name="main" type="component"/>
    <!-- place the config directory on the classpath to access configuration files -->
    <classpath type="dir" location="config"/>
    <classpath type="dir" location="dtd"/>
    <classpath type="dir" location="script"/>
    <!-- load single or multiple external libraries -->
    <classpath type="jar" location="build/lib/*"/>
    <!-- entity resources: model(s), eca(s), group, and data definitions -->
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
    <entity-resource type="group" reader-name="main" loader="main" location="entitydef/entitygroup.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
    <!-- web applications; will be mounted when using the embedded Jetty container -->
    <webapp name="hellosix"
        title="UserExample"
        server="default-server"
        location="webapp/hellosix"
        base-permission="OFBTOOLS"
        mount-point="/hellosix"/>
</ofbiz-component>


 step2 :    在hellosix目录下创建一个entitydef目录
   在该目录下创建entitygroup.xml  , entitymodel.xml两个文件
   entitygroup.xml文件内容为:
   <?xml version="1.0" encoding="UTF-8"?>
   <entitygroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
    xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entitygroup.xsd ">
         <entity-group group="org.ofbiz" entity="UserExample"/>
          </entitygroup>

   entitymodel.xml文件内容为:
   <?xml version="1.0" encoding="UTF-8"?>
   <entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
       xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entitymodel.xsd ">
       <!-- ========================================================= -->
       <!-- ======================== Defaults ======================= -->
       <!-- ========================================================= -->
       <title>Entity of an Open For Business Project Component</title>
       <description>None</description>
       <copyright>Copyright 2001-2006 The Apache Software Foundation</copyright>
       <author>None</author>
       <version>1.0</version>
       <entity entity-name="UserExample" package-name="org.ofbiz.hellosix" title="UserExample Entity">
    <field name="userexampleId" type="id-ne"><!-- primary sequenced ID --></field>
    <field name="userexampleName" type="name"></field>
    <field name="description" type="description"></field>
    <field name="longDescription" type="very-long"></field>
    <field name="comments" type="comment"></field>
    <field name="userexampleSize" type="numeric"></field>
    <field name="userexampleDate" type="date-time"></field>
    <prim-key field="userexampleId"/>
       </entity>
   </entitymodel>

   到此为止我们就定义好了Schema,注意:在ofbiz-component.xml,里面有对entitymodel.xml和entitygroup.xml的引用


step3 : 启动ofbiz 访问url:http://localhost:8080/webtools/constrol/main ,点击右上方的"Login"
            用admin/ofibz 登陆,登陆进入后选择链接"Check/Update DataBase" ,这是会出现Check 的Form
     该表单验证Schema是否改变,默认的GroupName为org.ofbiz.
     点击"Check/Update DataBase"按钮,Ofbiz会检验变动情况,显示出一个详细列表,你可以检查一下
     我们刚才建的"UserExample",如果没有,那可能就是我们前面定义的xml文件有问题了,按照之前的不步骤
     重新再做一遍

     到现在为止,我们就成功的完成了,UserExample Schema的创建.

step 4 : 下面我们创建数据操作层
             在d:/ofbiz/hot-deploy/hellosix/ 下创建servicedef目录
      在该文件下创建services.xml文件
      该文件内容如下:

      <?xml version="1.0" encoding="UTF-8"?>
  <services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
   xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/services.xsd ">
      <description>UserExample Services</description>
      <vendor>OFBiz</vendor>
      <version>1.0</version>
      <!-- Example & Related Services -->
      <service name="createUserExample" default-entity-name="UserExample" engine="simple"
       location="org/ofbiz/hellosix/UserExampleServices.xml" invoke="createUserExample" auth="false">
   <description>Create a UserExample</description>
   <auto-attributes include="pk" mode="OUT" optional="false"/>
   <auto-attributes include="nonpk" mode="IN" optional="true"/>
   <override name="userexampleName" optional="false"/>
      </service>
      <service name="updateUserExample" default-entity-name="UserExample" engine="simple"
         location="org/ofbiz/hellosix/UserExampleServices.xml" invoke="updateUserExample" auth="false">
   <description>Update a UserExample</description>
   <auto-attributes include="pk" mode="IN" optional="false"/>
   <auto-attr

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值