Package org.teiid.translator.jdbc
Class JDBCMetadataProcessor
- java.lang.Object
-
- org.teiid.translator.jdbc.JDBCMetadataProcessor
-
- All Implemented Interfaces:
MetadataProcessor<Connection>
- Direct Known Subclasses:
HanaMetadataProcessor
,HiveMetadataProcessor
,JDBCMetdataProcessor
,ModeShapeJDBCMetdataProcessor
,OracleMetadataProcessor
,PIMetadataProcessor
,PostgreSQLMetadataProcessor
,PrestoDBMetadataProcessor
public class JDBCMetadataProcessor extends Object implements MetadataProcessor<Connection>
Reads fromDatabaseMetaData
and creates metadata through theMetadataFactory
.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
useFullSchemaName
-
Fields inherited from interface org.teiid.translator.MetadataProcessor
FQN, SOURCE_PREFIX
-
-
Constructor Summary
Constructors Constructor Description JDBCMetadataProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Column
addColumn(ResultSet columns, Table table, MetadataFactory metadataFactory, int rsColumns)
Add a column to the given table based upon the current row of the columns resultsetprotected Table
addTable(MetadataFactory metadataFactory, String tableCatalog, String tableSchema, String tableName, String remarks, String fullName)
protected Table
addTable(MetadataFactory metadataFactory, String tableCatalog, String tableSchema, String tableName, String remarks, String fullName, ResultSet tables)
protected ResultSet
executeSequenceQuery(Connection conn)
Return a result set with three columns - sequence_catalog, sequence_schema, and sequence_name or null if sequences are not supportedString
getCatalog()
protected String
getCatalogTerm()
String
getColumnNamePattern()
void
getConnectorMetadata(Connection conn, MetadataFactory metadataFactory)
String
getExcludeProcedures()
String
getExcludeSequences()
String
getExcludeTables()
protected String
getFullyQualifiedName(String catalogName, String schemaName, String objectName, boolean quoted)
protected void
getGeographyMetadata(Column c, Connection conn, String tableCatalog, String tableSchema, String tableName, String columnName)
Get the geospatial metadata for the column, including srid, type, and dimensionalityprotected String
getGeographyMetadataTableName()
Return the name of the metadata table or view for geography metadata that conforms to the simple features specification or null if none existsprotected void
getGeometryMetadata(Column c, Connection conn, String tableCatalog, String tableSchema, String tableName, String columnName)
Get the geospatial metadata for the column, including srid, type, and dimensionalityprotected String
getGeometryMetadataTableName()
Return the name of the metadata table or view for geometry metadata that conforms to the simple features specification or null if none existsprotected void
getGeospatialMetadata(Column c, Connection conn, String tableCatalog, String tableSchema, String tableName, String columnName, Class<? extends AbstractGeospatialType> clazz)
protected boolean
getIndexInfoForTable(String catalogName, String schemaName, String tableName, boolean uniqueOnly, boolean approximateIndexes, String tableType)
Override to control or disable the default index logicprotected String
getNativeComponentType(String typeName)
Extract the native component type from the typeName, or return null if that is not possible.String
getProcedureNamePattern()
protected String
getRuntimeType(int type, String typeName, int precision)
protected String
getRuntimeType(int type, String typeName, int precision, int scale)
String
getSchemaName()
String
getSchemaPattern()
protected String
getSchemaTerm()
String
getSequenceNamePattern()
protected String
getSequenceNextSQL(String fullyQualifiedName)
Return the native sql for getting the next value or null if not supportedvoid
getSequences(MetadataFactory metadataFactory, Connection conn)
String
getTableNamePattern()
protected void
getTableStatistics(Connection conn, String catalog, String schema, String name, Table table)
protected String
getTableTerm()
String[]
getTableTypes()
boolean
isAutoCreateUniqueConstraints()
protected boolean
isHiddenSchema(String catalog, String schema)
If the schema is hidden regardless of the specified schema patternboolean
isImportApproximateIndexes()
boolean
isImportForeignKeys()
boolean
isImportIndexes()
boolean
isImportKeys()
boolean
isImportLargeAsLob()
boolean
isImportProcedures()
boolean
isImportRowIdAsBinary()
boolean
isImportSequences()
boolean
isImportStatistics()
boolean
isQuoteNameInSource()
protected boolean
isUnsignedTypeName(String name)
Determine if the type name represents an unsigned typeboolean
isUseAnyIndexCardinality()
boolean
isUseCatalogName()
boolean
isUseFullSchemaName()
boolean
isUseIntegralTypes()
boolean
isUseProcedureSpecificName()
boolean
isUseQualifiedName()
boolean
isUseTypeInfo()
boolean
isWidenUnsingedTypes()
protected String
modifyProcedureNameInSource(String nameInSource)
Override to modify the nameInSource for a procedurevoid
process(MetadataFactory metadataFactory, Connection conn)
protected String
quoteName(String name)
void
setAutoCreateUniqueConstraints(boolean autoCreateUniqueConstraints)
void
setCatalog(String catalog)
void
setColumnNamePattern(String columnNamePattern)
void
setEndQuoteString(String quoteString)
void
setExcludeProcedures(String excludeProcedures)
void
setExcludeSequences(String excludeSequences)
void
setExcludeTables(String excludeTables)
void
setImportApproximateIndexes(boolean importApproximateIndexes)
void
setImportForeignKeys(boolean importForeignKeys)
void
setImportIndexes(boolean importIndexes)
void
setImportKeys(boolean importKeys)
void
setImportLargeAsLob(boolean importLargeAsLob)
void
setImportProcedures(boolean importProcedures)
void
setImportRowIdAsBinary(boolean importRowIdAsBinary)
void
setImportSequences(boolean importSequences)
void
setImportStatistics(boolean importStatistics)
void
setProcedureNamePattern(String procedureNamePattern)
void
setQuoteNameInSource(boolean quoteIdentifiers)
void
setQuoteString(String quoteString)
void
setSchemaName(String schema)
void
setSchemaPattern(String schema)
void
setSequenceNamePattern(String sequenceNamePattern)
void
setStartQuoteString(String quoteString)
void
setTableNamePattern(String tableNamePattern)
void
setTableTypes(String[] tableTypes)
void
setUseAnyIndexCardinality(boolean useAnyIndexCardinality)
void
setUseCatalogName(boolean useCatalog)
void
setUseFullSchemaName(boolean useFullSchemaName)
void
setUseIntegralTypes(boolean useIntegralTypes)
void
setUseProcedureSpecificName(boolean useProcedureSpecificName)
void
setUseQualifiedName(boolean useQualifiedName)
void
setUseTypeInfo(boolean useTypeInfo)
void
setWidenUnsignedTypes(boolean widenUnsignedTypes)
void
setWidenUnsingedTypes(boolean widenUnsingedTypes)
Deprecated.protected boolean
shouldExclude(String fullName)
-
-
-
Method Detail
-
process
public void process(MetadataFactory metadataFactory, Connection conn) throws TranslatorException
- Specified by:
process
in interfaceMetadataProcessor<Connection>
- Throws:
TranslatorException
-
getConnectorMetadata
public void getConnectorMetadata(Connection conn, MetadataFactory metadataFactory) throws SQLException, TranslatorException
- Throws:
SQLException
TranslatorException
-
isUnsignedTypeName
protected boolean isUnsignedTypeName(String name)
Determine if the type name represents an unsigned type- Parameters:
name
-- Returns:
-
getTableStatistics
protected void getTableStatistics(Connection conn, String catalog, String schema, String name, Table table) throws SQLException
- Parameters:
conn
-catalog
-schema
-name
-table
-- Throws:
SQLException
-
modifyProcedureNameInSource
protected String modifyProcedureNameInSource(String nameInSource)
Override to modify the nameInSource for a procedure- Parameters:
nameInSource
-- Returns:
-
shouldExclude
protected boolean shouldExclude(String fullName)
-
addTable
protected Table addTable(MetadataFactory metadataFactory, String tableCatalog, String tableSchema, String tableName, String remarks, String fullName, ResultSet tables) throws SQLException
- Throws:
SQLException
-
getCatalogTerm
protected String getCatalogTerm()
-
getSchemaTerm
protected String getSchemaTerm()
-
getTableTerm
protected String getTableTerm()
-
addTable
protected Table addTable(MetadataFactory metadataFactory, String tableCatalog, String tableSchema, String tableName, String remarks, String fullName)
- Parameters:
metadataFactory
-tableCatalog
-tableSchema
-tableName
-remarks
-fullName
-- Returns:
-
addColumn
protected Column addColumn(ResultSet columns, Table table, MetadataFactory metadataFactory, int rsColumns) throws SQLException
Add a column to the given table based upon the current row of the columns resultset- Parameters:
columns
-table
-metadataFactory
-rsColumns
-- Returns:
- the column added
- Throws:
SQLException
-
getRuntimeType
protected String getRuntimeType(int type, String typeName, int precision, int scale)
-
getNativeComponentType
protected String getNativeComponentType(String typeName)
Extract the native component type from the typeName, or return null if that is not possible.- Parameters:
typeName
-- Returns:
-
getSequences
public void getSequences(MetadataFactory metadataFactory, Connection conn) throws SQLException
- Throws:
SQLException
-
executeSequenceQuery
protected ResultSet executeSequenceQuery(Connection conn) throws SQLException
Return a result set with three columns - sequence_catalog, sequence_schema, and sequence_name or null if sequences are not supported- Parameters:
conn
-- Returns:
- Throws:
SQLException
-
getSequenceNextSQL
protected String getSequenceNextSQL(String fullyQualifiedName)
Return the native sql for getting the next value or null if not supported- Parameters:
fullyQualifiedName
-- Returns:
-
getIndexInfoForTable
protected boolean getIndexInfoForTable(String catalogName, String schemaName, String tableName, boolean uniqueOnly, boolean approximateIndexes, String tableType)
Override to control or disable the default index logic- Parameters:
catalogName
-schemaName
-tableName
-uniqueOnly
-approximateIndexes
-tableType
-- Returns:
- true if the default logic should still be used, or false if the default index logic should not run
-
getFullyQualifiedName
protected String getFullyQualifiedName(String catalogName, String schemaName, String objectName, boolean quoted)
-
setTableNamePattern
public void setTableNamePattern(String tableNamePattern)
-
setTableTypes
public void setTableTypes(String[] tableTypes)
-
getTableTypes
@TranslatorProperty(display="Table Types", category=IMPORT, description="Comma separated list - without spaces - of imported table types. null returns all types") public String[] getTableTypes()
-
setUseFullSchemaName
public void setUseFullSchemaName(boolean useFullSchemaName)
-
setProcedureNamePattern
public void setProcedureNamePattern(String procedureNamePattern)
-
setImportIndexes
public void setImportIndexes(boolean importIndexes)
-
setImportKeys
public void setImportKeys(boolean importKeys)
-
setImportProcedures
public void setImportProcedures(boolean importProcedures)
-
setImportApproximateIndexes
public void setImportApproximateIndexes(boolean importApproximateIndexes)
-
setWidenUnsingedTypes
@Deprecated public void setWidenUnsingedTypes(boolean widenUnsingedTypes)
Deprecated.- See Also:
setWidenUnsignedTypes(boolean)
-
setWidenUnsignedTypes
public void setWidenUnsignedTypes(boolean widenUnsignedTypes)
-
setQuoteNameInSource
public void setQuoteNameInSource(boolean quoteIdentifiers)
-
setCatalog
public void setCatalog(String catalog)
-
setSchemaPattern
public void setSchemaPattern(String schema)
-
setSchemaName
public void setSchemaName(String schema)
-
setUseProcedureSpecificName
public void setUseProcedureSpecificName(boolean useProcedureSpecificName)
-
setUseCatalogName
public void setUseCatalogName(boolean useCatalog)
-
setAutoCreateUniqueConstraints
public void setAutoCreateUniqueConstraints(boolean autoCreateUniqueConstraints)
-
setExcludeProcedures
public void setExcludeProcedures(String excludeProcedures)
-
setExcludeTables
public void setExcludeTables(String excludeTables)
-
setUseQualifiedName
public void setUseQualifiedName(boolean useQualifiedName)
-
setUseAnyIndexCardinality
public void setUseAnyIndexCardinality(boolean useAnyIndexCardinality)
-
setImportStatistics
public void setImportStatistics(boolean importStatistics)
-
setImportForeignKeys
public void setImportForeignKeys(boolean importForeignKeys)
-
setColumnNamePattern
public void setColumnNamePattern(String columnNamePattern)
-
isImportProcedures
@TranslatorProperty(display="Import Procedures", category=IMPORT, description="true to import procedures and procedure columns - Note that it is not always possible to import procedure result set columns due to database limitations. It is also not currently possible to import overloaded procedures.") public boolean isImportProcedures()
-
isImportKeys
@TranslatorProperty(display="Import Keys", category=IMPORT, description="true to import primary and foreign keys - NOTE foreign keys to tables that are not imported will be ignored") public boolean isImportKeys()
-
isImportForeignKeys
@TranslatorProperty(display="Import Foreign Key", category=IMPORT, description="true to import foreign keys") public boolean isImportForeignKeys()
-
isImportIndexes
@TranslatorProperty(display="Import Indexes", category=IMPORT, description="true to import index/unique key/cardinality information") public boolean isImportIndexes()
-
getProcedureNamePattern
@TranslatorProperty(display="Procedure Name Pattern", category=IMPORT, description=" a procedure name pattern; must match the procedure name as it is stored in the database") public String getProcedureNamePattern()
-
isUseFullSchemaName
@TranslatorProperty(display="Use Full Schema Name", category=IMPORT, description="When false, directs the importer to drop the source catalog/schema from the Teiid object name, so that the Teiid fully qualified name will be in the form of <model name>.<table name> - Note: when false this may lead to objects with duplicate names when importing from multiple schemas, which results in an exception. This option does not affect the name in source property.") public boolean isUseFullSchemaName()
-
getTableNamePattern
@TranslatorProperty(display="Table Name Pattern", category=IMPORT, description=" a table name pattern; must match the table name as it is stored in the database") public String getTableNamePattern()
-
getCatalog
@TranslatorProperty(display="catalog", category=IMPORT, description="a catalog name; must match the catalog name as it is stored in the database; \"\" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search") public String getCatalog()
-
getSchemaPattern
@TranslatorProperty(display="Schema Pattern", category=IMPORT, description="a schema name pattern; must match the schema name as it is stored in the database; \"\" retrieves those without a schema; null means that the schema name should not be used to narrow the search") public String getSchemaPattern()
-
getSchemaName
@TranslatorProperty(display="Schema Name", category=IMPORT, description="an exact schema name; must match the schema name as it is stored in the database; Takes precedence over schemaPatten if supplied.") public String getSchemaName()
-
isImportApproximateIndexes
@TranslatorProperty(display="Import Approximate Indexes", category=IMPORT, description="true to import approximate index information. when true, result is allowed to reflect approximate or out of data values; when false, results are requested to be accurate") public boolean isImportApproximateIndexes()
-
isWidenUnsingedTypes
@TranslatorProperty(display="Widen unSigned Types", category=IMPORT, description="true to convert unsigned types to the next widest type. For example SQL Server reports tinyint as an unsigned type. With this option enabled, tinyint would be imported as a short instead of a byte.") public boolean isWidenUnsingedTypes()
-
isQuoteNameInSource
@TranslatorProperty(display="Quote NameInSource", category=IMPORT, description="false will override the default and direct Teiid to create source queries using unquoted identifiers.") public boolean isQuoteNameInSource()
-
isUseProcedureSpecificName
@TranslatorProperty(display="Use Procedure Specific Name", category=IMPORT, description="true will allow the import of overloaded procedures (which will normally result in a duplicate procedure error) by using the unique procedure specific name as the Teiid name. This option will only work with JDBC 4.0 compatible drivers that report specific names.") public boolean isUseProcedureSpecificName()
-
isUseCatalogName
@TranslatorProperty(display="Use Catalog Name", category=IMPORT, description="true will use any non-null/non-empty catalog name as part of the name in source, e.g. \"catalog\".\"schema\".\"table\".\"column\", and in the Teiid runtime name if useFullSchemaName is also true. false will not use the catalog name in either the name in source or the Teiid runtime name. Should be set to false for sources that do not fully support a catalog concept, but return a non-null catalog name in their metadata - such as HSQL.") public boolean isUseCatalogName()
-
isAutoCreateUniqueConstraints
@TranslatorProperty(display="Auto Create Unique Constraints", category=IMPORT, description="true to create a unique constraint if one is not found for a foreign keys") public boolean isAutoCreateUniqueConstraints()
-
isUseQualifiedName
@TranslatorProperty(display="use Qualified Name", category=IMPORT, description="true will use name qualification for both the Teiid name and name in source as dictated by the useCatalogName and useFullSchemaName properties. Set to false to disable all qualification for both the Teiid name and the name in source, which effectively ignores the useCatalogName and useFullSchemaName properties. Note: when false this may lead to objects with duplicate names when importing from multiple schemas, which results in an exception.") public boolean isUseQualifiedName()
-
isUseAnyIndexCardinality
@TranslatorProperty(display="Use Any Index Cardinality", category=IMPORT, description="true will use the maximum cardinality returned from DatabaseMetaData.getIndexInfo. importKeys or importIndexes needs to be enabled for this setting to have an effect. This allows for better stats gathering from sources that don\'t support returning a statistical index.") public boolean isUseAnyIndexCardinality()
-
isImportStatistics
@TranslatorProperty(display="Import Statistics", category=IMPORT, description="true will use database dependent logic to determine the cardinality if none is determined. Not yet supported by all database types - currently only supported by Oracle and MySQL.") public boolean isImportStatistics()
-
getColumnNamePattern
@TranslatorProperty(display="Column Name Pattern", category=IMPORT, description="a column name pattern; must match the column name as it is stored in the database. Used to import columns of tables. Leave unset to import all columns.", advanced=true) public String getColumnNamePattern()
-
getExcludeTables
@TranslatorProperty(display="Exclude Tables", category=IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid table name will exclude it from import. Applied after table names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an inclusion filter") public String getExcludeTables()
-
getExcludeProcedures
@TranslatorProperty(display="Exclude Procedures", category=IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid procedure name will exclude it from import. Applied after procedure names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an inclusion filter") public String getExcludeProcedures()
-
setQuoteString
public void setQuoteString(String quoteString)
-
setStartQuoteString
public void setStartQuoteString(String quoteString)
-
setEndQuoteString
public void setEndQuoteString(String quoteString)
-
isImportRowIdAsBinary
@TranslatorProperty(display="Import RowId as binary", category=IMPORT, description="Import RowId values as varbinary rather than object.") public boolean isImportRowIdAsBinary()
-
setImportRowIdAsBinary
public void setImportRowIdAsBinary(boolean importRowIdAsBinary)
-
isImportLargeAsLob
@TranslatorProperty(display="Import Large as LOB", category=IMPORT, description="Import character and binary types larger than the Teiid max as clob or blob respectively.") public boolean isImportLargeAsLob()
-
setImportLargeAsLob
public void setImportLargeAsLob(boolean importLargeAsLob)
-
isImportSequences
@TranslatorProperty(display="Import Sequences", category=IMPORT, description="true to import sequences") public boolean isImportSequences()
-
setImportSequences
public void setImportSequences(boolean importSequences)
-
getExcludeSequences
@TranslatorProperty(display="Exclude Tables", category=IMPORT, description="A case-insensitive regular expression that when matched against a fully qualified Teiid sequence name will exclude it from import. Applied after table names are retrieved. Use a negative look-ahead (?!<inclusion pattern>).* to act as an inclusion filter") public String getExcludeSequences()
-
setExcludeSequences
public void setExcludeSequences(String excludeSequences)
-
getSequenceNamePattern
@TranslatorProperty(display="Sequence Name Pattern", category=IMPORT, description="a sequence name pattern; must match the sequence name as it is stored in the database") public String getSequenceNamePattern()
-
setSequenceNamePattern
public void setSequenceNamePattern(String sequenceNamePattern)
-
isUseIntegralTypes
@TranslatorProperty(display="Use Integral Types", category=IMPORT, description="Use integral types rather than decimal when the scale is 0.") public boolean isUseIntegralTypes()
-
setUseIntegralTypes
public void setUseIntegralTypes(boolean useIntegralTypes)
-
isHiddenSchema
protected boolean isHiddenSchema(String catalog, String schema)
If the schema is hidden regardless of the specified schema pattern- Parameters:
catalog
-schema
-- Returns:
- true if no objects should be imported from the given schema
-
getGeometryMetadata
protected void getGeometryMetadata(Column c, Connection conn, String tableCatalog, String tableSchema, String tableName, String columnName)
Get the geospatial metadata for the column, including srid, type, and dimensionality- Parameters:
c
-conn
-tableCatalog
-tableSchema
-tableName
-columnName
-
-
getGeographyMetadata
protected void getGeographyMetadata(Column c, Connection conn, String tableCatalog, String tableSchema, String tableName, String columnName)
Get the geospatial metadata for the column, including srid, type, and dimensionality- Parameters:
c
-conn
-tableCatalog
-tableSchema
-tableName
-columnName
-
-
getGeospatialMetadata
protected void getGeospatialMetadata(Column c, Connection conn, String tableCatalog, String tableSchema, String tableName, String columnName, Class<? extends AbstractGeospatialType> clazz)
-
getGeographyMetadataTableName
protected String getGeographyMetadataTableName()
Return the name of the metadata table or view for geography metadata that conforms to the simple features specification or null if none exists- Returns:
-
getGeometryMetadataTableName
protected String getGeometryMetadataTableName()
Return the name of the metadata table or view for geometry metadata that conforms to the simple features specification or null if none exists- Returns:
-
isUseTypeInfo
@TranslatorProperty(display="Use Type Info", category=IMPORT, description="If JDBC DatabaseMetaData getTypeInfo should be used. If false, array component types and unsigned types may not be able to be determined.") public boolean isUseTypeInfo()
-
setUseTypeInfo
public void setUseTypeInfo(boolean useTypeInfo)
-
-