简体   繁体   English

如何使用SQL查询将数据库的子集提取到dbunit文件中?

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

Why ? 为什么呢

I have got a big Oracle table. 我有一张大桌子。 I would like to test some DAO methods. 我想测试一些DAO方法。 To do so, I use dbunit. 为此,我使用dbunit。

Problem 问题

I would like to extract a subset of an existing database as a dbunit flat xml file using a sql query. 我想使用sql查询将现有数据库的子集提取为dbunit flat xml文件。 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. 在这种情况下,它将提取作为查询结果的table1和table2的所有记录,然后还提取这些记录的所有依赖关系。

What I've tried 我尝试过的

  1. Jailer 狱卒

I've tested Jailer which is a good tool. 我已经测试过Jailer,这是一个很好的工具。 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. 我的sql查询具有多个联接,并且其中的条件无法使用此软件解决。

  1. DBUnit generation DBUnit生成

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. 我也尝试过直接使用DBUnit来生成数据集,但是它需要大量工作,因为我们不能直接从sql查询中生成子集,而只能通过在每个表上指定一系列小查询来生成。 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 ? 如何使用sql查询作为导出的基础来生成数据库的子集(并将其导出到dbunit flat xml文件中)?

I think what you want might be outside of the purview of DBUnit. 我认为您想要的可能超出了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 . 一旦有了视图,就可以使用SQL查询提取数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM