您的位置:首页 > 其它

关于dbunit的导出数据排序问题

2011-05-08 18:47 579 查看
【问题描述】近日项目中用到 DBunit导出数据到一个XML文件里面,然后提交到版本控制器上面,这是为了实现工作在不同模块的同事之间实现单元测试数据共享,每次有同事更新数据文件之后,当比较和 前面版本有什么不同的时候,总是遇到由于导出数据没有被排序造成一些困扰,我们用的ant target是

<target name="export.testdata" description="exports test data from schema">
<property name="jdbc.url" value="jdbc:oracle:thin:@${common.db.host}:${common.db.port}:${common.db.sid}"/>
<property name="out.file" location="../test/data/cust.xml"/>
<echo message="exporting data from ${jdbc.url} (${common.db.user}) to ${out.file}"/>
<dbunit driver="oracle.jdbc.driver.OracleDriver" url="${jdbc.url}"
userid="${common.db.user}" password="${common.db.pwd}">
<dbconfig>
<property name="datatypeFactory" value="org.dbunit.ext.oracle.OracleDataTypeFactory" />
<feature name="batchedStatements" value="true" />
</dbconfig>
<export dest="${out.file}" format="flat">
<query name="IMPL" sql="select * from IMPL ORDER BY 1"/>
<table name="USERS"/>
</export>
</dbunit>
</target>


【解决办法】导出的时候 在 export里面 用 query代替 table

<target name="export.testdata" description="exports test data from schema">
<property name="jdbc.url" value="jdbc:oracle:thin:@${common.db.host}:${common.db.port}:${common.db.sid}"/>
<property name="out.file" location="../test/data/cust.xml"/>
<echo message="exporting data from ${jdbc.url} (${common.db.user}) to ${out.file}"/>
<dbunit driver="oracle.jdbc.driver.OracleDriver" url="${jdbc.url}"
userid="${common.db.user}" password="${common.db.pwd}">
<dbconfig>
<property name="datatypeFactory" value="org.dbunit.ext.oracle.OracleDataTypeFactory" />
<feature name="batchedStatements" value="true" />
</dbconfig>
<export dest="${out.file}" format="flat">
<query name="USERS" sql="select * from USERS ORDER BY 1"/>
</export>
</dbunit>
</target>


注:参看 http://www.dbunit.org/anttask.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐