How to extract a subset of a database into a dbunit file using a sql query?

放肆的年华 提交于 2020-01-03 18:37:59

问题


Why ?

I have got a big Oracle table. I would like to test some DAO methods. To do so, I use dbunit.

Problem

I would like to extract a subset of an existing database as a dbunit flat xml file using a sql query. Example of query :

Select 
      t1.field1 as field1, t1.field2 as field2, t2.field3 as field3
From 
       table1 t1
       Join table2 t2 on t1.fieldX=t2.fieldX
Where 
       t1.field6='value' and t2.field8='value2'

in this case it will extract all records of table1 and table2 which are results of the query and then it also extract all dependencies of these records.

What I've tried

  1. Jailer

I've tested Jailer which is a good tool. The problem is that I can only do a query on one table and extract it keeping relations. My sql query have several joins and where conditions that cannot be resolve using this software.

  1. DBUnit generation

I've also tried to use DBUnit directly to generate the dataset but it need a lot of work because we cannot generate a subset from a sql query directly but only by specifiyng a succession of little queries on each table. I've got lot of joins and where conditions so it's not an acceptable solutions.

Question

How to generate a subset of a database (and export it in a dbunit flat xml file) using a sql query as a base for the export ?


回答1:


I think what you want might be outside of the purview of DBUnit.

What I think the best way to do this is to set-up a series of views which handle the joins and pull your data out through that. Once you have your views you can use SQL queries to pull the data out.



来源:https://stackoverflow.com/questions/14256757/how-to-extract-a-subset-of-a-database-into-a-dbunit-file-using-a-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!