Package org.dbunit.database
Interface IMetadataHandler
- All Known Implementing Classes:
Db2MetadataHandler,DefaultMetadataHandler,H2MetadataHandler,MultiSchemaMySqlMetadataHandler,MySqlMetadataHandler,NetezzaMetadataHandler
public interface IMetadataHandler
Handler to specify the behavior for a lookup of column metadata using database metadata.
- Since:
- 2.4.4
- Version:
- $Revision$ $Date$
- Author:
- gommma (gommma AT users.sourceforge.net), Last changed by: $Author$
-
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 databaseMetaData, String schemaName, String tableName) Returns the primary keys of the given table.Returns the schema name to which the table of the current result set index belongs.getTables(DatabaseMetaData databaseMetaData, String schemaName, String[] tableTypes) Returns the tables in the given schema that matches one of the given tableTypes.booleanChecks if the givenresultSetmatches the given schema and table name.booleanmatches(ResultSet resultSet, String catalog, String schema, String table, String column, boolean caseSensitive) Checks if the givenresultSetmatches the given schema and table name.default booleanmatchesColumn(String searchCatalog, String actualCatalog, String searchSchema, String actualSchema, String searchTable, String actualTable, String searchColumn, String actualColumn, boolean caseSensitive) Tests whether a candidate column's metadata values match the search criteria, using the same semantics asmatches(ResultSet, String, String, String, String, boolean)but operating on already-extracted values instead of a liveResultSetrow.default booleanWhetherResultSetTableMetaData's per-table column-metadata cache may safely usematchesColumn(String, String, String, String, String, String, String, String, boolean)in place of the row-by-rowmatches(ResultSet, String, String, String, String, boolean)scan for this handler.booleantableExists(DatabaseMetaData databaseMetaData, String schemaName, String tableName) Checks if the given table exists.
-
Method Details
-
getColumns
ResultSet getColumns(DatabaseMetaData databaseMetaData, String schemaName, String tableName) throws SQLException Returns the result set for an invocation ofDatabaseMetaData.getColumns(String, String, String, String).- 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.- Since:
- 2.4.4
-
matches
boolean matches(ResultSet resultSet, String schema, String table, boolean caseSensitive) throws SQLException Checks if the givenresultSetmatches the given schema and table name. The comparison is case sensitive.- Parameters:
resultSet- A result set produced viaDatabaseMetaData.getColumns(String, String, String, String)schema- the schema name to check.table- the table name to check.caseSensitive- Whether or not the comparison should be case sensitive- Returns:
trueif the column metadata of the givenresultSetmatches the given schema and table parameters.- Throws:
SQLException- if a database access error occurs.- Since:
- 2.4.4
- See Also:
-
matches
boolean matches(ResultSet resultSet, String catalog, String schema, String table, String column, boolean caseSensitive) throws SQLException Checks if the givenresultSetmatches the given schema and table name. The comparison is case sensitive.- Parameters:
resultSet- A result set produced viaDatabaseMetaData.getColumns(String, String, String, String)catalog- The name of the catalog to check. Ifnullit is ignored in the comparisonschema- The name of the schema to check. Ifnullit is ignored in the comparisontable- The name of the table to check. Ifnullit is ignored in the comparisoncolumn- The name of the column to check. Ifnullit is ignored in the comparisoncaseSensitive- Whether or not the comparison should be case sensitive- Returns:
trueif the column metadata of the givenresultSetmatches the given schema and table parameters.- Throws:
SQLException- if a database access error occurs.- Since:
- 2.4.4
-
getSchema
Returns the schema name to which the table of the current result set index belongs.- Parameters:
resultSet- The result set pointing to a valid record in the database that was returned byDatabaseMetaData.getTables(String, String, String, String[]).- Returns:
- The name of the schema from the given result set
- Throws:
SQLException- if a database access error occurs.- Since:
- 2.4.4
-
tableExists
boolean tableExists(DatabaseMetaData databaseMetaData, String schemaName, String tableName) throws SQLException Checks if the given table exists.- Parameters:
databaseMetaData- The database meta dataschemaName- 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.- Since:
- 2.4.5
-
getTables
ResultSet getTables(DatabaseMetaData databaseMetaData, String schemaName, String[] tableTypes) throws SQLException Returns the tables in the given schema that matches one of the given tableTypes.- Parameters:
databaseMetaData- The database meta dataschemaName- schema for which the tables should be retrieved;nullreturns all schemastableTypes- 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.- Since:
- 2.4.5
-
getPrimaryKeys
ResultSet getPrimaryKeys(DatabaseMetaData databaseMetaData, String schemaName, String tableName) throws SQLException Returns the primary keys of the given table.- Parameters:
databaseMetaData- 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.- Since:
- 2.4.5
-
matchesColumn
default boolean matchesColumn(String searchCatalog, String actualCatalog, String searchSchema, String actualSchema, String searchTable, String actualTable, String searchColumn, String actualColumn, boolean caseSensitive) Tests whether a candidate column's metadata values match the search criteria, using the same semantics asmatches(ResultSet, String, String, String, String, boolean)but operating on already-extracted values instead of a liveResultSetrow. This lets a caller that batch-fetches and cachesDatabaseMetaData#getColumnsrows (seeResultSetTableMetaData) replay this handler's matching rules against a cached row without re-querying or holding aResultSetopen.The default implementation mirrors
DefaultMetadataHandler's matching rules. A handler whosematches(ResultSet, String, String, String, String, boolean)override differs must override this method the same way, and overridesupportsColumnCache()to returntrue.- Parameters:
searchCatalog- The catalog to search for. Ifnullor empty it is ignored in the comparison.actualCatalog- The candidate row's catalog.searchSchema- The schema to search for. Ifnullor empty it is ignored in the comparison.actualSchema- The candidate row's schema.searchTable- The table to search for. Ifnullor empty it is ignored in the comparison.actualTable- The candidate row's table.searchColumn- The column to search for. Ifnullor empty it is ignored in the comparison.actualColumn- The candidate row's column.caseSensitive- Whether or not the comparison should be case sensitive.- Returns:
trueif the candidate's values match the search criteria.- Since:
- 3.2.1
-
supportsColumnCache
default boolean supportsColumnCache()WhetherResultSetTableMetaData's per-table column-metadata cache may safely usematchesColumn(String, String, String, String, String, String, String, String, boolean)in place of the row-by-rowmatches(ResultSet, String, String, String, String, boolean)scan for this handler.Returns
falseby default, so a customIMetadataHandlerwhosematches(...)override is not also replicated inmatchesColumn(...)keeps the legacy per-column behavior. Override to returntrueonly alongside amatchesColumn(...)override that fully replicates this handler's matching semantics.- Returns:
trueif this handler's cache fast path is safe to use.- Since:
- 3.2.1
-