org.unitils.dbunit.util
Class MultiSchemaXmlDataSetReader

java.lang.Object
  extended by org.unitils.dbunit.util.MultiSchemaXmlDataSetReader

public class MultiSchemaXmlDataSetReader
extends Object

A reader for DbUnit xml datasets that creates a new ITable instance for each element (row).

Following format is expected:

 <dataset>
      <first_table  myColumn1="value1" myColumn2="value2" />
      <second_table myColumnA="A" />
      <first_table  myColumn2="other value2" />
      <empty_table />
 </dataset>
 

Elements for a table may occur more than once and anywhere in the data set. If multiple elements exist, they may specify different attributes (columns). Missing attributes (columns) will be treated as null values.

Namespaces can be used to specify tables from different database schemas. The namespace URI should contain the name of the database schema:

 <dataset xmlns="SCHEMA_A" xmlns:b="SCHEMA_B">
      <first_table  myColumn1="value1" myColumn2="value2" />
      <b:second_table myColumnA="A" />
      <first_table  myColumn2="other value2" />
      <empty_table />
 </dataset>
 

This example defines 2 schemas: SCHEMA_A and SCHEMA_B. The first schema is set as default schema (=default namespace). The 'first_table' table has no namespce and is therefore linked to SCHEMA_A. The 'second_table' table is prefixed with namespace b which is linked to SCHEMA_B. If no default namespace is defined, the schema that is passed as constructor argument is taken as default schema.

Author:
Tim Ducheyne, Filip Neven

Nested Class Summary
protected static class MultiSchemaXmlDataSetReader.DataSetContentHandler
          The xml content handler that is going to create the data sets.
 
Constructor Summary
MultiSchemaXmlDataSetReader(String defaultSchemaName)
          Creates a data set reader.
 
Method Summary
protected  XMLReader createXMLReader()
          Factory method for creating the SAX xml reader.
protected  void disableValidation(SAXParserFactory saxParserFactory)
          Disables validation on the given sax parser factory.
 MultiSchemaDataSet readDataSetXml(File... dataSetFiles)
          Parses the datasets from the given files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiSchemaXmlDataSetReader

public MultiSchemaXmlDataSetReader(String defaultSchemaName)
Creates a data set reader.

Parameters:
defaultSchemaName - The schema name to use when none is specified, not null
Method Detail

readDataSetXml

public MultiSchemaDataSet readDataSetXml(File... dataSetFiles)
Parses the datasets from the given files. Each schema is given its own dataset and each row is given its own table.

Parameters:
dataSetFiles - The dataset files, not null
Returns:
The read data set, not null

createXMLReader

protected XMLReader createXMLReader()
Factory method for creating the SAX xml reader.

Returns:
the XML reader, not null

disableValidation

protected void disableValidation(SAXParserFactory saxParserFactory)
Disables validation on the given sax parser factory.

Parameters:
saxParserFactory - The factory, not null


Copyright © 2011. All Rights Reserved.