Class MySqlMetadataHandler
- All Implemented Interfaces:
IMetadataHandler
- Direct Known Subclasses:
MultiSchemaMySqlMetadataHandler
Was introduced to fix "[ 2545095 ] Mysql FEATURE_QUALIFIED_TABLE_NAMES column SQLHelper.matches".
- Since:
- 2.4.4
- Version:
- $Revision$ $Date$
- Author:
- gommma (gommma AT users.sourceforge.net), Last changed by: $Author$
-
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.Returns the schema name to which the table of the current result set index belongs.getTables(DatabaseMetaData metaData, String schemaName, String[] tableType) 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 columnsResultSet, String catalog, String schema, String table, String column, boolean caseSensitive) Checks if the givenresultSetmatches the given schema and table name.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 asIMetadataHandler.matches(ResultSet, String, String, String, String, boolean)but operating on already-extracted values instead of a liveResultSetrow.booleanWhetherResultSetTableMetaData's per-table column-metadata cache may safely useIMetadataHandler.matchesColumn(String, String, String, String, String, String, String, String, boolean)in place of the row-by-rowIMetadataHandler.matches(ResultSet, String, String, String, String, boolean)scan for this handler.booleantableExists(DatabaseMetaData metaData, String schema, String tableName) Checks if the given table exists.
-
Constructor Details
-
MySqlMetadataHandler
public MySqlMetadataHandler()
-
-
Method Details
-
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- 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.
-
matches
public boolean matches(ResultSet resultSet, String schema, String table, boolean caseSensitive) throws SQLException Description copied from interface:IMetadataHandlerChecks if the givenresultSetmatches the given schema and table name. The comparison is case sensitive.- Specified by:
matchesin interfaceIMetadataHandler- 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.- See Also:
-
matches
public boolean matches(ResultSet columnsResultSet, String catalog, String schema, String table, String column, boolean caseSensitive) throws SQLException Description copied from interface:IMetadataHandlerChecks if the givenresultSetmatches the given schema and table name. The comparison is case sensitive.- Specified by:
matchesin interfaceIMetadataHandler- Parameters:
columnsResultSet- 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.
-
getSchema
Description copied from interface:IMetadataHandlerReturns the schema name to which the table of the current result set index belongs.- Specified by:
getSchemain interfaceIMetadataHandler- 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.
-
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- 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.
-
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- 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.
-
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- 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.
-
matchesColumn
public 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 asIMetadataHandler.matches(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 whoseIMetadataHandler.matches(ResultSet, String, String, String, String, boolean)override differs must override this method the same way, and overrideIMetadataHandler.supportsColumnCache()to returntrue. Mirrorsmatches(ResultSet, String, String, String, String, boolean)'s catalog/schema swap: MySQL'sgetColumnsrows report only a catalog, not a schema, so when the search side expects a schema but the row has none, the row's catalog is compared against the searched schema instead.- Specified by:
matchesColumnin interfaceIMetadataHandler- 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.
-
supportsColumnCache
public boolean supportsColumnCache()WhetherResultSetTableMetaData's per-table column-metadata cache may safely useIMetadataHandler.matchesColumn(String, String, String, String, String, String, String, String, boolean)in place of the row-by-rowIMetadataHandler.matches(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.- Specified by:
supportsColumnCachein interfaceIMetadataHandler- Returns:
true, sincematchesColumn(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)replicates this class'smatches(ResultSet, String, String, String, String, boolean)semantics.
-