?? faq.fml
字號:
<?xml version="1.0" encoding="UTF-8"?>
<faqs title="Frequently Asked Questions">
<part id="general">
<title>General</title>
<faq id="supportedvendors">
<question>
Which relational database systems are supported?
</question>
<answer>
<p>See the publicly maintained <a href="http://www.dbunit.org/cgi-bin/wiki.pl?SupportedRDBMS">list of compatible RDBMS</a> at the <a href="http://www.dbunit.org/wiki/">DbUnit Wiki.</a> Don't hesitate to contribute to this list, particularly for database not listed yet.</p>
</answer>
</faq>
<faq id="build">
<question>
How to build DbUnit?
</question>
<answer>
<p><a href=" http://www.dbunit.org/cgi-bin/wiki.pl?BuildingDbUnit">BuildingDbUnit</a> detailed instruction.</p>
</answer>
</faq>
<faq id="p6spy">
<question>
How to see SQL statements issued by DbUnit using P6Spy?
</question>
<answer>
<p><a href="http://www.p6spy.com">P6Spy</a> is a transparent JDBC proxy-driver
specialized to log the statements performed against the actual driver you normally would use.
Using p6spy would allow to log the SQL statements issued by DbUnit.
</p>
<p>To install P6Spy, complete the following steps:
<ol>
<li>Put the p6spy.jar file in your classpath.
</li><li>Move spy.properties into a directory listed in your classpath. Unlike
JAR files, you do not directly reference your property file in the
classpath (e.g.: if you have the file c:\r\proj\confspy.properties make sure you
put c:\r\proj\conf in the classpath).
</li><li>Modify your application to use the P6Spy database driver i.e.
com.p6spy.engine.spy.P6SpyDriver.
</li><li>Modify the realdriver line in the spy.properties file to reflect the
wrapped database driver. An example of a modified realdriver line follows:
realdriver = oracle.jdbc.driver.OracleDriver
</li></ol>
Installation is complete. When you run your application, a spy.log file is
generated in the same directory from where you run the application.
The log file contains a list of all of the database statements
executed. You can change both the destination of spy.log and what it logs by
editing the spy.properties file.</p>
</answer>
</faq>
<faq id="knownfixedissues">
<question>
How to learn more about known and fixed issues?
</question>
<answer>
<p>Look at <a href="http://www.dbunit.org/cgi-bin/wiki.pl?ChangesSinceLastRelease">ChangesSinceLastRelease</a> and at <a href="http://www.dbunit.org/issue-tracking.html">Issue Tracking</a>.</p>
</answer>
</faq>
</part>
<part id="use">
<title>Using DbUnit</title>
<faq id="extract">
<question>
How to extract a flat XML dataset from my database?
</question>
<answer>
<p>
The following sample demonstrates how you can export one or many tables
from a database to an flat XML dataset file.
<source>
public class DatabaseExportSample
{
public static void main(String[] args) throws Exception
{
// database connection
Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:hsqldb:sample", "sa", "");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
// partial database export
QueryDataSet partialDataSet = new QueryDataSet(connection);
partialDataSet.addTable("FOO", "SELECT * FROM TABLE WHERE COL='VALUE'");
partialDataSet.addTable("BAR");
FlatXmlDataSet.write(partialDataSet, new FileOutputStream("partial.xml"));
// full database export
IDataSet fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
}
}</source></p> </answer>
</faq>
<faq id="generatedtd">
<question>
How to generate a DTD representing my database schema?
</question>
<answer>
<p>The following sample demonstrates how you can generate a flat xml dataset
DTD from a database.</p>
<source>
public class DatabaseExportSample
{
public static void main(String[] args) throws Exception
{
// database connection
Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:hsqldb:sample", "sa", "");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
// write DTD file
FlatDtdDataSet.write(connection.createDataSet(),
new FileOutputStream("test.dtd"));
}
}</source>
</answer>
</faq>
<faq id="multipleschema">
<question>
Can I work with multiple database schemas having tables with identical name?
</question>
<answer>
Yes, see <a href="#AmbiguousTableNameException">Why I get a "AmbiguousTableNameException"?</a>.
</answer>
</faq>
<faq id="identity">
<question>
Can I use DbUnit with IDENTITY or auto-increment
columns?
</question>
<answer>
<p>
Many RDBMS allow IDENTITY and auto-increment columns to be overwritten with client values implicitly. DbUnit can be used with these RDBMS natively.
Some databases, like MS SQL Server and Sybase, need to explicitly activate client values writing. The way to activate this feature is vendor specific.
<br/>
DbUnit provides this functionality for MS SQL Server with the <a href="components.html#IdentityInsertOperation">IdentityInsertOperation</a> class.
</p>
</answer>
</faq>
<faq id="flatxmlnull">
<question>
How to specify NULL values with flat XML dataset?
</question>
<answer>
<p>See <a href="components.html#FlatXmlDataSet">FlatXmlDataSet documentation</a></p>
</answer>
</faq>
<faq id="views">
<question>
Can I use DbUnit with database views?
</question>
<answer>
<p>
Yes. By default DbUnit is configured to only recognize normal tables. Modify the
<a href="properties.html#tabletype">table type property</a> to work with other table types.
For example, use <code>{"TABLE", "VIEW"}</code> for views.
</p>
<p>
Be aware that REFRESH, DELETE and UPDATE operations are not compatible with tables without
primary keys. They are not usable with views without <a href="#customprimarykeys">overriding primary keys detection</a>. CLEAN_INSERT, INSERT and DELETE_ALL
operations are compatible with views.
</p>
</answer>
</faq>
<faq id="batchstatement">
<question>
How to enable batched statement?
</question>
<answer>
See <a href="properties.html#batchstatement">batched statement</a> feature.
</answer>
</faq>
<faq id="dateformat">
<question>
What are the dates formats supported by DbUnit?
</question>
<answer>
<p>DbUnit use the JDBC escape formats for string representation.
<table border="1">
<tr>
<th>Type</th>
<th>Format</th>
</tr>
<tr>
<td>DATE</td>
<td>yyyy-mm-dd</td>
</tr>
<tr>
<td>TIME</td>
<td>hh:mm:ss</td>
</tr>
<tr>
<td>TIMESTAMP</td>
<td>yyyy-mm-dd hh:mm:ss.fffffffff</td>
</tr>
</table>
</p>
</answer>
</faq>
<faq id="typefactory">
<question>
How to replace the default data type factory?
</question>
<answer>
<p>
You can replace the default DbUnit <a href="properties.html#typefactory">data type factory</a> to get support for custom data type.
DbUnit provides extended factories for some vendors, which are located in <code>org.dbunit.ext</code> subpackages.
</p>
<p>
Here is how to setup the Oracle factory:
<source>
IDatabaseConnection connection = new DatabaseConnection(
jdbcConnection, schema);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new OracleDataTypeFactory());
</source>
</p>
<p>
Don't hesitate to submit your own implementation if you encounter types not currently supported by DbUnit.
</p>
</answer>
</faq>
<faq id="streaming">
<question>
How to perform streamed import and export?
</question>
<answer>
<p>
Historically, DbUnit has memory consumption issues when working with very large dataset files. DbUnit 2.0 includes many improvements, like using SAX2 instead of the Electric XML parser and and streamed XML dataset writing, to overcome the memory consumption problems.
</p>
<p>
For compatibility reason, streamed export and import are not enabled by default. When working with large dataset, using this feature can make a huge difference.
</p>
<h5>
Database Export:
</h5>
<p>
Configure your DbUnit connection to use ForwardOnlyResultSetTable when exporting very
large dataset. ForwardOnlyResultSetTable is a very efficient database table implemtation useful
when random data access is not required. By default, DbUnit uses CachedResultSetTable which consume
more memory but provides random data access.
</p>
<p>
Following sample shows how to configure your DbUnit connection to use
ForwardOnlyResultSetTable:
<source>
IDatabaseConnection connection = new DatabaseConnection(
jdbcConnection, schema);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY,
new ForwardOnlyResultSetTableFactory());
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -