单元测试日期使用ibatis将数据库从oracle迁移到mysql的几个修改点

上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助。今天在这里和大家一起学习一下单元测试日期

  

  我们目项在公司的大战略下要需从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类型。

文章结束给大家分享下程序员的一些笑话语录: 一个合格的程序员是不会写出 诸如 “摧毁地球” 这样的程序的,他们会写一个函数叫 “摧毁行星”而把地球当一个参数传进去。

原文地址:https://www.cnblogs.com/xinyuyuanm/p/3050659.html