4

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 ?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jerome Cance
  • 8,103
  • 12
  • 53
  • 106
  • Do you want a subset of the whole database, a single table or the result of a SELECT statement? Because you are mixing these terms I'm a bit confused - also because of the "*several joins and where conditions*" comment which indicates you want to export the result of a SELECT statement rather than the "database" or a table. –  Jan 10 '13 at 11:24
  • I've edited my post to reflect that. My query is a select. – Jerome Cance Jan 10 '13 at 11:29

1 Answers1

2

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.

Mark Robinson
  • 3,135
  • 1
  • 22
  • 37