上班之余抽點(diǎn)時(shí)間出來(lái)寫(xiě)寫(xiě)博文,希望對(duì)新接觸的朋友有幫助。今天在這里和大家一起學(xué)習(xí)一下單元測(cè)試日期
??
? 我們目項(xiàng)在公司的大戰(zhàn)略下要需從oracle遷徙到mysql,我們的目項(xiàng)應(yīng)用的是ibatis,在ibatis層上要需的一些修改點(diǎn)如下:?jiǎn)卧獪y(cè)試框架我們用的是jtester。
??
1. 插入主鍵生成 Oracle insert時(shí)主鍵id是應(yīng)用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. 分頁(yè) Oracle用采三層嵌套的分頁(yè)式方,用的是偏移量的最小值和最大值取獲分頁(yè)容內(nèi): <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分頁(yè)用采limit,offset法語(yǔ),應(yīng)用偏移量和每頁(yè)條數(shù) <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. 日期數(shù)函 Oracle與mysql的日期API還是有很大差異的,對(duì)于日期的操縱要需全體查檢一遍。我們只用到上面三個(gè)日期的法方: Oracle Mysql 功能 to_char(last_offer_paytime,'yyyy/MM/dd') date_format(last_offer_paytime,'%Y/%m/%d') 日期轉(zhuǎn)為字符串 to_date(#searchDate#, 'yyyy/MM/dd') str_to_date(#searchDate#, '%Y/%m/%d') 字符串轉(zhuǎn)為日期 to_date(#searchDate#, 'yyyy/MM/dd') + 1 date_add(str_to_date(#searchDate#, '%Y/%m/%d'),interval 1 day) 日期相加 4. 品質(zhì)證保 可能大部分sql都會(huì)做或多或少的修改,如何證保品質(zhì),我們這邊對(duì)每一個(gè)sql都做了單元測(cè)試,之前可能一些沒(méi)做的也全體補(bǔ)起來(lái)了,苦辛袁飛,程達(dá)做了很充分的單元測(cè)試,極大的證保了遷徙品質(zhì),甚至發(fā)現(xiàn)了本來(lái)隱藏的一些問(wèn)題。對(duì)于遷徙說(shuō)來(lái),單元測(cè)試是最好的品質(zhì)證保法方。 應(yīng)用jtester裝封的DbFit來(lái)做DAO的單元測(cè)試 @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); } 單元測(cè)試的工作量占了去O工作量的2/3,均平每一個(gè)表要需0.8人日,當(dāng)然這個(gè)還要看sql的數(shù)量和復(fù)雜度。議建還是要需做單元測(cè)試來(lái)證保品質(zhì)。 5. 數(shù)據(jù)類型的差異,建表通過(guò)idb就能夠成完。不過(guò)brand有一個(gè)配置字段用到了Oracle的CLOB類型,mysql則要需應(yīng)用text類型。
?
文章結(jié)束給大家分享下程序員的一些笑話語(yǔ)錄: 一個(gè)合格的程序員是不會(huì)寫(xiě)出 諸如 “摧毀地球” 這樣的程序的,他們會(huì)寫(xiě)一個(gè)函數(shù)叫 “摧毀行星”而把地球當(dāng)一個(gè)參數(shù)傳進(jìn)去。
單元測(cè)試日期使用ibatis將數(shù)據(jù)庫(kù)從oracle遷移到mysql的幾個(gè)修改點(diǎn)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
