Configurable Features and Properties

DbUnit does not use System properties anymore since version 2.0. DbUnit use a configuration object, DatabaseConfig, to query and set feature flags and property values for a IDatabaseConnection. It is possible to change DbUnit behaviors, such as using batched statements or not, using the getFeature, setFeature, getProperty, and setProperty methods of DatabaseConfig.

While feature flags are always boolean, property values are arbitrary objects. Note that starting with dbunit 2.4.6 features can also be set using the setProperty method.

The following sample displays the batched statement feature status:

String id = DatabaseConfig.FEATURE_BATCHED_STATEMENTS;
DatabaseConfig config = connection.getConfig();
if (config.getFeature(id))
{
  System.out.println("Batched statements is enabled.");
}
else
{
  System.out.println("Batched statements is disabled.");
}

Constants

Each Feature Flag ID and Property ID has a corresponding constant on DatabaseConfig.

Feature Flags

Flag Feature ID Default Description
FEATURE_BATCHED_STATEMENTS http://www.dbunit.org/features/batchedStatements false Enable or disable usage of JDBC batched statement by DbUnit.
FEATURE_CASE_SENSITIVE_TABLE_NAMES http://www.dbunit.org/features/caseSensitiveTableNames false Enable or disable case sensitive table names. If enabled, Dbunit handles all table names in a case sensitive way.
FEATURE_QUALIFIED_TABLE_NAMES http://www.dbunit.org/features/qualifiedTableNames false Enable or disable multiple schemas support. If enabled, Dbunit access tables with names fully qualified by schema using this format: SCHEMA.TABLE.
Note: this feature was not compatible with the escape pattern property until the 2.2.1 release. Since then the two properties can be mixed without problem: each element will be properly escaped.
FEATURE_DATATYPE_WARNING http://www.dbunit.org/features/datatypeWarning true Enable or disable the warning message displayed when DbUnit encounter an unsupported data type.
FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES http://www.dbunit.org/features/skipOracleRecycleBinTables false Enable or disable the processing of oracle recycle bin tables (tables starting with BIN$). Oracle 10g recyle bin tables may break DbUnit’s assumption of tables name uniqueness within a schema since these table are case sensitive. Enable this feature for Oracle 10g databases until the bug in the oracle driver is fixed, which incorrectly reports this system tables to DbUnit.
FEATURE_ALLOW_EMPTY_FIELDS http://www.dbunit.org/features/allowEmptyFields false Allow to call INSERT/UPDATE with empty strings ('').
FEATURE_SORT_ALL_COLUMNS_WHEN_NO_PRIMARY_KEY http://www.dbunit.org/features/sortAllColumnsWhenNoPrimaryKey false When a table has no primary key, sort its SELECT by every non-LOB column instead of leaving row order database-defined (and thus nondeterministic). CLOB/BLOB columns are always excluded from the sort even when this feature is enabled, since some databases (notably Oracle) reject LOB columns in ORDER BY.
FEATURE_SKIP_CYCLE_CHECK http://www.dbunit.org/features/skipCycleCheck false Let DatabaseSequenceFilter skip its foreign-key dependency cycle check instead of throwing CyclicTablesDependencyException. Each cycle is instead treated as one unit for ordering purposes: tables outside it are still correctly sorted relative to it, but the relative order of the tables making up the cycle falls back to their original input order — only useful when the cycle is handled another way (e.g. nullable FK columns populated by a later operation, or database-side deferred constraint checking).

Properties

Property ID Default Description Note
http://www.dbunit.org/properties/escapePattern none Allows schema, table and column names escaping.
The property value is an escape pattern where the ? is replaced by the name.
For example, the pattern "[?]" is expanded as "[MY_TABLE]" for a table named "MY_TABLE".
The most common escape pattern is "\"?\"" which surrounds the table name with quotes (for the above example it would result in "\"MY_TABLE\"").
As a fallback if no questionmark is in the given String and its length is one it is used to surround the table name on the left and right side.
For example the escape pattern "\"" will have the same effect as the escape pattern "\"?\"".
This property was not compatible with the qualified table names feature until 2.2.1. Since then the two properties can be mixed resulting in each element properly escaped.
http://www.dbunit.org/properties/tableType String[]{"TABLE"} Used to configure the list of table types recognized by DbUnit, as a String[]. See java.sql.DatabaseMetaData.getTables() for possible values.
http://www.dbunit.org/properties/datatypeFactory org.dbunit.dataset.datatype.DefaultDataTypeFactory Used to configure the DataType factory. You can replace the default factory to add support for non-standard database vendor data types. The Object must implement org.dbunit.dataset.datatype.IDataTypeFactory. The following factories are currently available:
org.dbunit.ext.db2.Db2DataTypeFactory
org.dbunit.ext.h2.H2DataTypeFactory
org.dbunit.ext.hsqldb.HsqldbDataTypeFactory
org.dbunit.ext.mckoi.MckoiDataTypeFactory
org.dbunit.ext.mssql.MsSqlDataTypeFactory
org.dbunit.ext.mysql.MySqlDataTypeFactory
org.dbunit.ext.oracle.OracleDataTypeFactory
org.dbunit.ext.oracle.Oracle10DataTypeFactory
org.dbunit.ext.postgresql.PostgresqlDataTypeFactory
org.dbunit.ext.netezza.NetezzaDataTypeFactory
To create your own data type factory, see the generic base implementation at org.dbunit.dataset.datatype.DefaultDataTypeFactory.
http://www.dbunit.org/properties/statementFactory org.dbunit.database.statement.PreparedStatementFactory Used to configure the statement factory. The Object must implement org.dbunit.database.statement.IStatementFactory.
http://www.dbunit.org/properties/resultSetTableFactory org.dbunit.database.CachedResultSetTableFactory Used to configure the ResultSet table factory. The Object must implement org.dbunit.database.IResultSetTableFactory.
http://www.dbunit.org/properties/primaryKeyFilter none Use to override primary keys detection. The Object must implement org.dbunit.dataset.filter.IColumnFilter.
http://www.dbunit.org/properties/mssql/identityColumnFilter none Use to override IDENTITY column detection. The Object must implement org.dbunit.dataset.filter.IColumnFilter.
http://www.dbunit.org/properties/batchSize 100 Integer object giving the size of batch updates.
http://www.dbunit.org/properties/fetchSize 100 Integer object giving the statement fetch size for loading data into a result set table.
http://www.dbunit.org/properties/metadataHandler org.dbunit.database.DefaultMetadataHandler Used to configure the handler used to control database metadata related methods. The Object must implement org.dbunit.database.IMetadataHandler. The following RDBMS specific handlers are currently available:
org.dbunit.ext.db2.Db2MetadataHandler
org.dbunit.ext.h2.H2MetadataHandler
org.dbunit.ext.mysql.MySqlMetadataHandler
org.dbunit.ext.mysql.MultiSchemaMySqlMetadataHandler
org.dbunit.ext.netezza.NetezzaMetadataHandler
For all others the default handler should do the job: org.dbunit.database.DefaultMetadataHandler. See IMetadataHandler for the full reference.
http://www.dbunit.org/properties/allowVerifytabledefinitionExpectedtableCountMismatch false By default, DefaultPrepAndExpectedTestCase fails the test when the expected dataset has more tables than the supplied VerifyTableDefinitions (see VerifyTableDefinition for the class reference) — a safety net for an expected table that was defined but never wired to a VerifyTableDefinition, which would otherwise be silently skipped during verification. Set this property to true to relax that check and allow the counts to disagree.