📄 components.html
字号:
<tr class="a"> <th> Class </th> <th> Description </th> </tr> <tr class="b"> <td> <a href="apidocs/org/dbunit/database/DatabaseConnection.html"> DatabaseConnection </a> </td> <td> Wraps a JDBC connection. </td> </tr> <tr class="a"> <td> <a href="apidocs/org/dbunit/database/DatabaseDataSourceConnection.html"> DatabaseDataSourceConnection </a> </td> <td> Wraps a JDBC DataSource. </td> </tr> </table> </p> <h3> <a name="dataset"> IDataSet </a> </h3> <p> The <a href="apidocs/org/dbunit/dataset/IDataSet.html"> IDataSet </a> interface represents is a collection of tables. This is the primary abstraction used by DbUnit to manipulate tabular data. </p> <p> Most commonly u sed implemetations: <table border="1" width="100%" cellspacing="2" cellpadding="3"> <tr class="b"> <th> Implementation </th> <th> Description </th> </tr> <tr class="a"> <td> <a name="flatxmldataset" href="apidocs/org/dbunit/dataset/xml/FlatXmlDataSet.html"> FlatXmlDataSet </a> </td> <td> Reads and writes flat XML dataset document. Each XML element corresponds to a table row. Each XML element name corresponds to a table name. The XML attributes correspond to table columns. <br> </br> Flat XML dataset document sample: <div id="source"> <pre><!DOCTYPE dataset SYSTEM "my-dataset.dtd"><dataset> <TEST_TABLE COL0="row 0 col 0" COL1="row 0 col 1" COL2="row 0 col 2"/> <TEST_TABLE COL1="row 1 col 1"/> <SECOND_TABLE COL0="row 0 col 0" COL1="row 0 col 1" /> <EMPTY_TABLE/></dataset></pre> </div> <br> </br> To specify null values, omit corresponding attribute. In the above example, missing COL0 and COL2 attributes of TEST_TABLE second row represents null values. <br> </br> Table metadata is deduced from the first row of each table. <b> Beware you may get a NoSuchColumnException if the first row of a table has one or more null values. </b> Because of that, this is highly recommended to use DTD. DbUnit will use the columns declared in the DTD as table metadata. DbUnit only support external system URI. The URI can be absolute or relative. <br> </br> Another way to cope with this problem is to use the <a href="#replacementdataset"> ReplacementDataSet </a> . </td> </tr> <tr class="b"> <td> <a name="xmldataset" href="apidocs/org/dbunit/dataset/xml/XmlDataSet.html"> XmlDataSet </a> </td> <td> Reads and writes original XML dataset document. This format is very verbiose and must conform to the following DTD: <div id="source"> <pre><?xml version="1.0" encoding="UTF-8"?><!ELEMENT dataset (table+)><!ELEMENT table (column*, row*)><!ATTLIST table name CDATA #REQUIRED><!ELEMENT column (#PCDATA)><!ELEMENT row (value | null | none)*><!ELEMENT value (#PCDATA)><!ELEMENT null EMPTY></pre> </div> <br> </br> <a name="originalxmlsample"> XML dataset document sample: </a> <div id="source"> <pre><!DOCTYPE dataset SYSTEM "dataset.dtd"><dataset> <table name="TEST_TABLE"> <column>COL0</column> <column>COL1</column> <column>COL2</column> <row> <value>row 0 col 0</value> <value>row 0 col 1</value> <value>row 0 col 2</value> </row> <row> <null/> <value>row 1 col 1</value> <null/> </row> </table> <table name="SECOND_TABLE"> <column>COLUMN0</column> <column>COLUMN1</column> <row> <value>row 0 col 0</value> <value>row 0 col 1</value> </row> </table> <table name='EMPTY_TABLE'> <column>COLUMN0</column> <column>COLUMN1</column> </table></dataset></pre> </div> <br> </br> </td> </tr> <tr class="a"> <td> <a name="streamingdataset" href="apidocs/org/dbunit/database/StreamingDataSet.html"> StreamingDataSet </a> </td> <td> Consumes a producer and expose its content as a dataset. Provides cursor like forward only access to it and only keeps the active row in memory. Can be used with FlatXmlProducer and XmlProvider. <br> </br> This is a very efficient way to load XML dataset document when working with forward only database operations (UPDATE, INSERT, REFRESH). <br> </br> Following sample shows how to load a flat XML dataset with the StreamingDataSet: <div id="source"> <pre> IDataSetProducer producer = new FlatXmlProducer( new InputSource("dataset.xml")); IDataSet dataSet = new StreamingDataSet(producer);</pre> </div> </td> </tr> <tr class="b"> <td> <a name="databasedataset" href="apidocs/org/dbunit/database/DatabaseDataSet.html"> DatabaseDataSet </a> </td> <td> Adapter that provides access to a database instance as a dataset. This class is not usually instantiated directly but from the factory method <code> IDatabaseConnection.createDataSet() </code> . </td> </tr> <tr class="a"> <td> <a name="querydataset" href="apidocs/org/dbunit/database/QueryDataSet.html"> QueryDataSet </a> </td> <td> Holds collection of tables resulting from database queries. <br> </br> Following sample snippet creates a dataset containing two tables: FOO, resulting from specified query and BAR, resulting from generated query "SELECT * FROM BAR". <div id="source"> <pre> QueryDataSet dataSet = new QueryDataSet(connection); dataSet.addTable("FOO", "SELECT * FROM TABLE WHERE COL='VALUE'"); dataSet.addTable("BAR");</pre> </div> </td> </tr> <tr class="b"> <td> <a name="defaultdataset" href="apidocs/org/dbunit/dataset/DefaultDataSet.html"> DefaultDataSet </a> </td> <td> Uses to create datasets programmatically. </td> </tr> <tr class="a"> <td> <a name="compositedataset" href="apidocs/org/dbunit/dataset/CompositeDataSet.html"> CompositeDataSet </a> </td> <td> Combines multiple datasets into a single logical dataset. </td> </tr> <tr class="b"> <td> <a name="filtereddataset" href="apidocs/org/dbunit/dataset/FilteredDataSet.html"> FilteredDataSet </a> </td> <td> Decorator that exposes only some tables from decorated dataset. Can be used with different filtering strategies. Some strategies can include/exclude tables without altering their order while others expose tables with a different order. <table border="1" width="100%" cellspacing="2" cellpadding="3"> <tr class="a"> <th> Strategy </th> <th> Description </th> </tr> <tr class="b"> <td> IncludeTableFilter </td> <td> Exposes only matching tables pattern without modifying the original table order. Support wildcards . </td> </tr> <tr class="a"> <td> ExcludeTableFilter </td> <td> Hides matching tables pattern without modifying the original table order. Support wildcards. </td> </tr> <tr class="b"> <td> SequenceTableFilter </td> <td> Exposes a configured table sequence and can be used to reorder dataset table. This is the original filtering strategy from DbUnit 1.x. </td> </tr> <tr class="a"> <td> DatabaseSequenceFilter </td> <td> Automatically determine the tables order using foreign/exported keys information. This strategy is vendor independent and should work with any JDBC driver that implement the <code> DatabaseMetaData.getExportedKeys() </code> method. <br> </br> Support simple multilevel dependency like this: <div id="source"> <pre> A / \ B C / \ D E</pre> </div> </td> </tr> </table> </td> </tr> <tr class="b"> <td> <a name="xlsdataset" href="apidocs/org/dbunit/dataset/excel/XlsDataSet.html"> XlsDataSet </a> </td> <td> Read and writes MS Excel dataset documents. Each sheet represents a table. The first row of a sheet defines the columns names and remaining rows contains the data. </td> </tr> <tr class="a"> <td> <a name="replacementdataset" href="apidocs/org/dbunit/dataset/ReplacementDataSet.html"> ReplacementDataSet </a> </td> <td> Decorator that replaces placeholder objects from the decorated dataset with replacement objects. Substring substitution is also possible. <br> </br> Interestingly this provides a new way to specify null values in flat XML datasets. For example you can use a placeholder value, like "[NULL ] " in your flat XML dataset and replace it with <code> null </code> at runtime. <div id="source"> <pre><?xml version="1.0"?><dataset> <TEST_TABLE COL0="row 0 col 0" COL1="[null]"/> <TEST_TABLE COL1="row 1 col 0" COL2="row 1 col 1"/> </dataset></pre> </div> <br> </br> Loading the flat XML dataset: <div id="source"> <pre>ReplacementDataSet dataSet = new ReplacementDataSet( new FlatXmlDataSet(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -