上班之余抽點時間出來寫寫博文,希望對新接觸的朋友有幫助。今天在這里和大家一起學習一下單元測試日期
??
? 我們目項在公司的大戰略下要需從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類型。
?
文章結束給大家分享下程序員的一些笑話語錄: 一個合格的程序員是不會寫出 諸如 “摧毀地球” 這樣的程序的,他們會寫一個函數叫 “摧毀行星”而把地球當一個參數傳進去。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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