问题
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
- 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.
- 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