Class MultiSchemaMySqlMetadataHandler

java.lang.Object
org.dbunit.ext.mysql.MySqlMetadataHandler
org.dbunit.ext.mysql.MultiSchemaMySqlMetadataHandler
All Implemented Interfaces:
IMetadataHandler

public class MultiSchemaMySqlMetadataHandler extends MySqlMetadataHandler
A MySqlMetadataHandler for connections not restricted to a single schema (MySQL "catalog"), e.g. a connection made as MySQL's "root" specifically to work across several schemas at once with DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES enabled.

MySqlMetadataHandler's getTables()/getColumns()/getPrimaryKeys() pass a null schema straight through as the JDBC catalog argument. Per the JDBC specification catalog=null means "do not narrow the search by catalog", but MySQL Connector/J instead treats it as "the connection's current catalog only" by default (its nullCatalogMeansCurrent connection property), so tables in every other catalog are silently invisible and a lookup for one of them fails with NoSuchTableException.

This handler works around that driver behavior at the application level: whenever no single schema is given, it enumerates the catalogs visible to the connection (skipping MySQL's own information_schema/mysql/performance_schema/sys system catalogs) and unions the per-catalog results instead of ever passing a null catalog to the driver.

Configure it the same way as any other IMetadataHandler:

 config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);
 config.setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MultiSchemaMySqlMetadataHandler());
 
Since:
3.5.0