我们项目在公司的大战略下需要从oracle迁移到mysql,我们的项目使用的是ibatis,在ibatis层上需要的一些修改点如下:单元测试框架我们用的是jtester。
1. 插入主键生成 Oracle insert时主键id是使用sequence方式: <insert id="MS-BRANDMEMBER-INSERT" parameterClass="TA-brandMember"> <selectKey resultClass="long" keyProperty="id"> SELECT seq_industry_brand_member.nextval FROM DUAL </selectKey> insert into industry_brand_member (id, gmt_create, gmt_modified, member_id, bu, active, brand_id, cat_ids, auth_date_from, auth_date_to, auth_level, area, status, operator, original) values (#id#, sysdate, sysdate, #memberId#, #mallId#, #active#, #brandId#, #catIds#, #authDateFrom#, #authDateTo#, #authLevel#, #area#, #status#, #operator#, #original#) </insert> mysql需要修改为: <insert id="MS-BRANDMEMBER-INSERT" parameterClass="TA-brandMember"> insert into industry_brand_member (gmt_create, gmt_modified, member_id, mall_id, active, brand_id, cat_ids, auth_date_from, auth_date_to, auth_level, area, status, operator, original) values (now(), now(), #memberId#, #mallId#, #active#, #brandId#, #catIds#, #authDateFrom#, #authDateTo#, #authLevel#, #area#, #status#, #operator#, #original#) <selectKey resultClass="java.lang.Long" keyProperty="id"> SELECT LAST_INSERT_ID() AS ID </selectKey> </insert> 2. 分页 Oracle采用三层嵌套的分页方式,用的是偏移量的最小值和最大值获取分页内容: <select id="SELECT-BRANDIDLIST-BY-MALLID" resultClass="long" parameterClass="java.util.Map"> select brandId from(select brandId,rownum as no from(select distinct(brand_id) as brandId from industry_brand_member where <isNotNull property="mallId"> bu = #mallId:VARCHAR# AND </isNotNull> <isNotNull property="status"> status=#status:VARCHAR# AND </isNotNull> brand_id is not null order by brand_id asc)) <![CDATA[ where no>=#start# and no<#end# ]]> </select> Mysql分页采用limit,offset语法,使用偏移量和每页条数 <select id="SELECT-BRANDIDLIST-BY-MALLID" resultClass="long" parameterClass="java.util.Map"> select distinct(brand_id) as brandId from industry_brand_member where <isNotNull property="mallId"> mall_id = #mallId:VARCHAR# AND </isNotNull> <isNotNull property="status"> status=#status:VARCHAR# AND </isNotNull> brand_id is not null order by brand_id asc limit #start#,#pageSize# </select> 3. 日期函数 Oracle与mysql的日期API还是有很大差异的,对于日期的操作需要全部检查一遍。我们只用到下面三个日期的方法: Oracle Mysql 功能 to_char(last_offer_paytime,'yyyy/MM/dd') date_format(last_offer_paytime,'%Y/%m/%d') 日期转为字符串 to_date(#searchDate#, 'yyyy/MM/dd') str_to_date(#searchDate#, '%Y/%m/%d') 字符串转为日期 to_date(#searchDate#, 'yyyy/MM/dd') + 1 date_add(str_to_date(#searchDate#, '%Y/%m/%d'),interval 1 day) 日期相加 4. 质量保证 可能大部分sql都会做或多或少的修改,如何保证质量,我们这边对每个sql都做了单元测试,之前可能一些没做的也全部补起来了,辛苦袁飞,程达做了很充分的单元测试,极大的保证了迁移质量,甚至发现了原来隐藏的一些问题。对于迁移来说,单元测试是最好的质量保证方法。 使用jtester封装的DbFit来做DAO的单元测试 @Test @DbFit(when="wiki/sampleshow/BuyerDAO.insert.when.wiki", then="wiki/sampleshow/BuyerDAO.insert.then.wiki") public void TestInsertSampleShowBuyer() { SampleShowBuyer SampleShowBuyer = new SampleShowBuyer(); SampleShowBuyer.setMemberId("yanhandle"); SampleShowBuyer.setPhoneNumber("13512345678"); Long id = sampleShowBuyerDAO.insertSampleShowBuyer(SampleShowBuyer); want.object(id).notNull(); want.number(id).greaterThan(0l); } 单元测试的工作量占了去O工作量的2/3,平均每个表需要0.8人日,当然这个还要看sql的数量和复杂度。建议还是需要做单元测试来保证质量。 5. 数据类型的差异,建表通过idb就可以完成。不过brand有一个配置字段用到了Oracle的CLOB类型,mysql则需要使用text类型。
相关推荐
Ibatis连接ORACLE数据库的小例子
该示例演示使用iBATIS操纵Oracle、MySQL和MS SERVER三种数据库(实现查询与新增动作),只需要修改配置档与SQL影射档即可,而Java部分的代码不用修改。本人觉得,该框架一个非常简单、使用方便的持久层框架。其中:...
1.每个实体类需要配置各自的“SqlMap.config”在“config/SysConfig.xml”中,SqlMap,db1.Db1SqlMap就是“ibatis/db1/Db1SqlMap.config”,不同的db将分配不同的mapper类。 2.数据库链接统一放在“config/ibatis/...
本工程用于研究Ibatis和MySQL结合使用的方法 本工程编码方式:UTF-8 须执行的SQL语句: CREATE DATABASE `test`; USE `test`; DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `id` char(36) NOT NULL...
C#中iBatis连接mySQL使用的DLL
一个Ibatis。net 的应用事例 数据库为oracle 用vs2008 导入即可使用。
Ibatis连接MySQL数据库实例 有代码 项目下下来直接跑就行了,不过要修改数据库配置信息哦 跑不起来我吃翔三斤
操作数据库 iBATIS查询,java 和spring的配置方法
在用iBatis.net与数据库打交道的过程中,发现iBatis.net拼接字符串不能直接拷贝然后在dbms里执行
使用ibatis操作大对象,使用mySQl数据库对图片进行操作
描述与iBatis相关技术与数据库进行增删改查操作
使用Struts1.2+IBatis对数据库表进行增、删、改、查操作; 有清晰的案例使用说明,完整的案例, 直接可以附加看效果。 案例作者:宋海康
IBATIS连接多数据库参考文档,只供参考,学习。
ibatis+oracle简单实例,其中包括ibatis jar包以及oracle驱动包
运用IBATIS在三层架构的基础上建立的数据库连接,主要是一个框架,突出重点,一看就明白。最适合初学者快速学习使用,里面的条路清晰。
Ibatis 2.3.4 数据库无关分页 有示例,可以运行 网上找的很不错
ibatis学习总结,oracle 学习总结,大数据量处理
平常积累的spring,Structs2,ibatis框架jar包,oracle,mysql,sql等数据库jar包,全部是自己开发的时候用的,现在贡献出来,分数虽然高了点,但是确实不要你费心去找,有时会有的不可以用。
我做的是 spring + quartz+ mysql and oracle 持久层 ibatis and hibernate 项目用eclipse 导入 不同的数据库 请在数据库运行不同的SQL 脚本 用hibernate 时注意 是什么数据库 hibernate.properties 文件第一二行...
本工程以“银行账号转账”为例子演示了 如何处理Ibatis结合MySQL数据库使用时的事务操作 本工程编码方式:UTF-8 须执行的SQL语句: CREATE DATABASE `test`; USE `test`; CREATE TABLE `lm_bank_card` ( `id` ...