Class MultiSchemaMySqlMetadataHandler
- All Implemented Interfaces:
IMetadataHandler
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetColumns(DatabaseMetaData databaseMetaData, String schemaName, String tableName) Returns the result set for an invocation ofDatabaseMetaData.getColumns(String, String, String, String).getPrimaryKeys(DatabaseMetaData metaData, String schemaName, String tableName) Returns the primary keys of the given table.getTables(DatabaseMetaData metaData, String schemaName, String[] tableType) Returns the tables in the given schema that matches one of the given tableTypes.booleantableExists(DatabaseMetaData metaData, String schema, String tableName) Checks if the given table exists.Methods inherited from class org.dbunit.ext.mysql.MySqlMetadataHandler
getSchema, matches, matches, matchesColumn, supportsColumnCache
-
Constructor Details
-
MultiSchemaMySqlMetadataHandler
public MultiSchemaMySqlMetadataHandler()
-
-
Method Details
-
getTables
public ResultSet getTables(DatabaseMetaData metaData, String schemaName, String[] tableType) throws SQLException Description copied from interface:IMetadataHandlerReturns the tables in the given schema that matches one of the given tableTypes.- Specified by:
getTablesin interfaceIMetadataHandler- Overrides:
getTablesin classMySqlMetadataHandler- Parameters:
metaData- The database meta dataschemaName- schema for which the tables should be retrieved;nullreturns all schemastableType- a list of table types to include;nullreturns all types- Returns:
- The ResultSet which is retrieved using
DatabaseMetaData.getTables(String, String, String, String[]) - Throws:
SQLException- if a database access error occurs.
-
getColumns
public ResultSet getColumns(DatabaseMetaData databaseMetaData, String schemaName, String tableName) throws SQLException Description copied from interface:IMetadataHandlerReturns the result set for an invocation ofDatabaseMetaData.getColumns(String, String, String, String).- Specified by:
getColumnsin interfaceIMetadataHandler- Overrides:
getColumnsin classMySqlMetadataHandler- Parameters:
databaseMetaData- The database metadata to be used for retrieving the columnsschemaName- The schema nametableName- The table name- Returns:
- The result set containing all columns
- Throws:
SQLException- if a database access error occurs.
-
getPrimaryKeys
public ResultSet getPrimaryKeys(DatabaseMetaData metaData, String schemaName, String tableName) throws SQLException Description copied from interface:IMetadataHandlerReturns the primary keys of the given table.- Specified by:
getPrimaryKeysin interfaceIMetadataHandler- Overrides:
getPrimaryKeysin classMySqlMetadataHandler- Parameters:
metaData- The database meta dataschemaName- schema for which the tables should be retrieved;nullreturns all schemastableName- table for which the primary keys are retrieved- Returns:
- The ResultSet which is retrieved using
DatabaseMetaData.getPrimaryKeys(String, String, String) - Throws:
SQLException- if a database access error occurs.
-
tableExists
public boolean tableExists(DatabaseMetaData metaData, String schema, String tableName) throws SQLException Description copied from interface:IMetadataHandlerChecks if the given table exists.- Specified by:
tableExistsin interfaceIMetadataHandler- Overrides:
tableExistsin classMySqlMetadataHandler- Parameters:
metaData- The database meta dataschema- The schema in which the table should be searched. Ifnullthe schema is not used to narrow the table name.tableName- The table name to be searched- Returns:
- Returns
trueif the given table exists in the given schema. Else returnsfalse. - Throws:
SQLException- if a database access error occurs.
-