ofbiz连接mysql并创建独立数据库
Ofbiz:数据库移植mysql并创建自己的mysql
Ofbiz原生数据库是derby,而作为开发使用,其就不能满足我们需求,ofbiz支持多种数据库,我们就可以将数据移植到mysql.
第一步:找到frameworkentityconfigentityengine.xml这个文件,找到之后进行下面相关操作.
1、添加或者修改datasource,因为该文件本身存在这些资料,只是被注释掉了.
<datasourcename="localmysql"
helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
field-type-name="mysql"
check-on-start="true"
add-missing-on-start="true"
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="utf8"
collate="utf8_general_ci">
<read-data reader-name="tenant"/>
<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:3306/ofbiz?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="root"
jdbc-password=""
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/>
</datasource>
<datasource name="localmysqlolap"
helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
field-type-name="mysql"
check-on-start="true"
add-missing-on-start="true"
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="utf8"
collate="utf8_general_ci ">
<read-data reader-name="tenant"/>
<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:3306/ofbizolap?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="root"
jdbc-password=""
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/>
</datasource>
<datasource name="localmysqltenant"
helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
field-type-name="mysql"
check-on-start="true"
add-missing-on-start="true"
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="utf8"
collate="utf8_general_ci">
<read-data reader-name="tenant"/>
<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:3306/ofbiztenant?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="root"
jdbc-password=""
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/>
</datasource>
2.还是在该文件添加一些内容,注意上面的datasource name=""与下面的datasource-name是对应的.
<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="localmysql"/>
<group-map group-name="org.ofbiz.olap"datasource-name="localmysqlolap"/>
<group-map group-name="org.ofbiz.tenant" datasource-name="localmysqltenant"/>
</delegator>
<delegator name="default-no-eca"entity-model-reader="main" entity-group-reader="main"entity-eca-reader="main" entity-eca-enabled="false"distributed-cache-clear-enabled="false">
<group-mapgroup-name="org.ofbiz" datasource-name="localmysql"/>
<group-map group-name="org.ofbiz.olap"datasource-name="localmysqlolap"/>
<group-map group-name="org.ofbiz.tenant"datasource-name="localmysqltenant"/>
</delegator>
<!-- be sure that your default delegator (or the one you use) usesthe same datasource for test. You must run "ant load-demo" beforerunning "ant run-tests" -->
<delegator name="test" entity-model-reader="main"entity-group-reader="main" entity-eca-reader="main">
<group-mapgroup-name="org.ofbiz" datasource-name="localmysql"/>
<group-map group-name="org.ofbiz.olap"datasource-name="localmysqlolap"/>
<group-map group-name="org.ofbiz.tenant" datasource-name="localmysqltenant"/>
</delegator>
datasource-name:就是配置1中对应的数据库名
group-name: :是用来进行分组辨识的,即可以将数据资料移植到不同的数据库
问题:可以一直为什么要创建三个数据库,一个不行?带着这个问题我们进行下面操作.
第二步:找到frameworkentityentitydefentitygroup.xml文件,内容如下
<span style="font-size:14px;"><?xml version="1.0"encoding="UTF-8"?>
<entitygroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/entitygroup.xsd">
<!-- ========================================================= -->
<!-- org.ofbiz.entity.tenant -->
<!-- ========================================================= -->
<entity-group group="org.ofbiz.tenant"entity="Tenant"/>
<entity-group group="org.ofbiz.tenant"entity="TenantDataSource"/>
<entity-group group="org.ofbiz.tenant"entity="Component"/>
<entity-group group="org.ofbiz.tenant"entity="TenantComponent"/>
<entity-group group="org.ofbiz.tenant"entity="TenantDomainName"/>
</entitygroup></span>
就是这个配置将Tenant等一些实体(数据库中的表,至于创建方式我就不在这里讲述了)分到org.ofbiz.tenant这个组名的数据库中即上面中第三个数据库,数据库名叫localmysqltenant.当然若没有这种配置,那么数据资料就会到默认数据库中,但是这里是项目自带,所以我们就需要这样一个数据库,同样的道理还有到另一个数据库中的资料,加上默认的,所以我们需要三个数据库.
至于这些文件的加载在当前目下ofbiz-component.xml文件下,如下:
<entity-resource type="model"reader-name="main" loader="main"location="entitydef/entitymodel.xml"/>
<entity-resourcetype="group" reader-name="main" loader="main"location="entitydef/entitygroup.xml"/>
注意:framework/base/lib下需要导入mysql的包
上面就配置完成,然后我们在数据库创建对应的三个数据库名会跟上文中一一对应(注意编码一致),在启动的时候带参数load-data(如何代参运行,不知道的话,详情百度,嘻嘻)
下面我们独立创建一个数据库,来放我们自己的资料.
相应文件的位置:
第一步:在上文配置文件frameworkentityconfigentityengine.xml下加入相应的配置,我的资料如下:
<datasourcename="wuliys"
<pre name="code" class="html">
helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
field-type-name="mysql"
check-on-start="true"
add-missing-on-start="true"
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="utf8"
collate="utf8_general_ci">
<read-data reader-name="tenant"/>
<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:3306/wuliys?autoReconnect=true&characterEncoding=UTF-8"
jdbc-username="root"
jdbc-password=""
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"
time-between-eviction-runs-millis="600000"/>
</datasource>
<pre name="code" class="html"><span style="font-size:18px;"><group-mapgroup-name="org.ofbiz.wuliys" datasource-name="wuliys"/></span>
至于这些资料所放位置与上文一一对应
第二步:创建对应的数据库wuliys,并设置其编码为utf-8,字符集utf8_general_ci
第三步:创建一个实体,文件路径mypartyentitydefentitymodel.xml,注意其可以是hot-deploy下的一个模块,也可以是你分离出来的一个模块.内容如下:
<pre name="code" class="html"><span style="font-size:18px;"><entitymodelxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/entitymodel.xsd">
<title>Entity of anApache OFBiz Component</title>
<description>None</description>
<version>1.0</version>
<entityentity-name="Test" package-name="wuliys">
<field name="myId" type="id-ne"></field>
<field name="myName"type="id-ne"></field>
<prim-key field="myId"/>
</entity>
</entitymodel></span>
第四步:将创建的实体引入到自己所想到的分组,文件路径: mypartyentitydefentitygroup.xml,内容如下:
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<entitygroupxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/entitygroup.xsd">
<entity-group entity="Test"group="org.ofbiz.wuliys"/>
</entitygroup></span><span style="font-size:18px;">
</span>
第五步:在该实体下创建一条数据,文件路径mypartydatatestdata.xml,内容如下:
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<entity-engine-xml>
<Test myName="jack"></Test>
<Test myName="zheng"></Test>
</entity-engine-xml>
</span>
第六步:将这写配置文件在该模块的ofbiz-component.xml下加载,内容如下
<span style="font-size:18px;"><?xmlversion="1.0" encoding="UTF-8"?>
<ofbiz-componentname="myparty"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
<resource-loader name="main"type="component"/>
<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"/>
<entity-resourcetype="data" reader-name="seed" loader="main"location="data/testdata.xml"/>
<webappname="myparty"
server="default-server"
location="webapp/myparty"
mount-point="/myparty"></webapp>
</ofbiz-component></span><span style="font-size:18px;">
</span>
而后带参load-data启动一下,就在数据库相应位置创建好了自己的数据资料.
备注:新手写blog,查阅网上的相关资料,加上自己的一些想法
- 米市的热潮来袭?三枚域名超六位数美金交易
- 微信新出了逆天功能,或许你用得上
- 网站系统架构梳理-解决高负载高并发
- silverlight 相册雏型
- Mysql优化系列(1)--Innodb引擎下mysql自身配置优化
- 一台服务器多实例mysql做主从复制
- spring AOP日志管理
- vue-route+webpack部署单页路由项目,访问刷新出现404问题
- UNIX 高手的 10 个习惯
- linux下截取给定路径中的目录部分
- 一年坎坷也曾怀疑自己,如今五冠在手的柯洁将再战AI
- 从MapX到MapXtreme2004[3]-搜索图元Feature
- git push上传代码到gitlab上,报错401/403(或需要输入用户名和密码)
- mysql下mysqladmin日常管理命令总结
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- 搭建一个高可用负载均衡的集群架构(第一部分)
- Java Stream函数式编程第三篇:管道流结果处理
- MySQL慢查询日志
- Pandas处理时间序列数据的20个关键知识点
- CentOS7下的LNMP环境搭建Dedecms网站
- 持久层框架JPA与Mybatis该如何选型
- 技术分享 | Online DDL 工具 pt-osc
- 基于hexo框架搭建个人博客【技术创作训练营】
- 对比讲解lambda表达式与传统接口函数实现方式
- 如何使用Java8 Stream API对Map按键或值进行排序
- TencentOS tiny RTOS快速入门
- Nginx用户认证与域名重定向
- LNMP架构介绍与搭建
- Mac 最新版Python3.7.4安装配置,设置默认python版本
- 15个应该掌握的Jupyter Notebook 使用技巧