org.dbunit.ant
Class QuerySet

java.lang.Object
  extended by org.dbunit.ant.QuerySet

public class QuerySet
extends java.lang.Object

This element is a container for Queries. It facilitates reuse through references. Using Ant 1.6 and greater, references can be defined in a single build file and imported into many others. An example of where this is useful follows:

In our database we have INDIVIDUALS which must have an associated NAME_INFO and at least one IND_ADDRESS. The developer creating a dataset for his/her tests probably won't know all the details of what relationships are expected, and if he did, its an error prone and repetitive task to create the correct SQL for entities in each dataset. Missing a related table, not only creates invalid data for your tests, but also is likely to cause DBUnit setUp() failures due to foreign key constraint errors. (ex. If a previous test had inserted INDIVIDUALS and NAME_INFO and my test tries to delete only the INDIVIDUALS, the NAME_INFO.IND_ID constraint would prevent it)

Usage:

 <!-- ======== Define the reusable reference ========== -->

 <queryset id="individuals">
    <query name="INDIVIDUALS" sql="
      SELECT * FROM APS_DATA.INDIVIDUALS WHERE IND_ID IN (@subQuery@)"/>

    <query name="NAME_INFO" sql="
      SELECT B.* FROM APS_DATA.INDIVIDUALS A, APS_DATA.NAME_INFO B
      WHERE A.IND_ID IN (@subQuery@)
      AND B.IND_ID = A.IND_ID"/>

    <query name="IND_ADDRESSES" sql="
      SELECT B.* FROM APS_DATA.INDIVIDUALS A, APS_DATA.IND_ADDRESSES B
      WHERE A.IND_ID IN (@subQuery@)
      AND B.IND_ID = A.IND_ID"/>
 </queryset>

 <!-- ========= Use the reference ====================== -->

 <dbunit dest="@{destDir}" driver="${jdbcDriver}"
     url="${jdbcURL}" userid="${jdbcUser}" password="${jdbcPassword}">
   <export dest="someDir">
   <queryset refid="individuals">
      <filterset>
        <filter token="subQuery" value="
          SELECT IND_ID FROM APS_DATA.INDIVIDUALS WHERE USER_NAME = 'UNKNOWN'"/>
      </filterset>
   </queryset>

   <queryset>
      <query name="MAN_EVENT_TYPE"
        sql="SELECT * FROM MANUSCRIPTS.MAN_EVENT_TYPE"/>
      <query name="JOURNAL" sql="SELECT * FROM MANUSCRIPTS.JOURNAL"/>
   </queryset>
   </export>
 </dbunit>

 

Since:
Sep. 13 2004
Version:
$Revision: 741 $
Author:
Lenny Marks lenny@aps.org

Constructor Summary
QuerySet()
           
 
Method Summary
 void addFilterSet(org.apache.tools.ant.types.FilterSet filterSet)
           
 void addQuery(Query query)
           
 void copyQueriesFrom(QuerySet referenced)
           
 java.lang.String getId()
           
protected  java.util.List getQueries()
           
 java.lang.String getRefid()
           
 void setId(java.lang.String string)
           
 void setRefid(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuerySet

public QuerySet()
Method Detail

addQuery

public void addQuery(Query query)

addFilterSet

public void addFilterSet(org.apache.tools.ant.types.FilterSet filterSet)

getId

public java.lang.String getId()

getRefid

public java.lang.String getRefid()

setId

public void setId(java.lang.String string)

setRefid

public void setRefid(java.lang.String string)

getQueries

protected java.util.List getQueries()

copyQueriesFrom

public void copyQueriesFrom(QuerySet referenced)


Copyright © 2002-2008. All Rights Reserved.