public class JdbcModelReader extends Object
| Constructor and Description |
|---|
JdbcModelReader(Platform platform)
Creates a new model reader instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
closeResultSet(ResultSet resultSet)
Closes the given result set.
|
protected void |
closeStatement(Statement stmt)
Closes the given statement.
|
protected CascadeActionEnum |
convertAction(Short jdbcActionValue)
Converts the JDBC action value (one of the
importKey constants in the
DatabaseMetaData class) to a CascadeActionEnum. |
protected void |
determineAutoIncrementFromResultSetMetaData(Table table,
Column[] columnsToCheck)
Helper method that determines the auto increment status for the given columns via the
ResultSetMetaData.isAutoIncrement(int) method. |
String |
determineSchemaOf(Connection connection,
String schemaPattern,
Table table)
Deprecated.
Will be removed once full schema support is in place
|
protected List |
getColumnsForColumn()
Returns the descriptors for the columns to be read from the column meta data result set.
|
protected List |
getColumnsForFK()
Returns the descriptors for the columns to be read from the foreign key meta data result set.
|
protected List |
getColumnsForIndex()
Returns the descriptors for the columns to be read from the index meta data result set.
|
protected List |
getColumnsForPK()
Returns the descriptors for the columns to be read from the primary key meta data result set.
|
protected List |
getColumnsForTable()
Returns the descriptors for the columns to be read from the table meta data result set.
|
protected Connection |
getConnection()
Returns the active connection.
|
Database |
getDatabase(Connection connection,
String name)
Reads the database model from the given connection.
|
Database |
getDatabase(Connection connection,
String name,
String catalog,
String schema,
String[] tableTypes)
Reads the database model from the given connection.
|
String |
getDefaultCatalogPattern()
Returns the catalog(s) in the database to read per default.
|
String |
getDefaultColumnPattern()
Returns the default pattern to read the relevant columns from the database.
|
String |
getDefaultSchemaPattern()
Returns the schema(s) in the database to read per default.
|
String |
getDefaultTablePattern()
Returns the default pattern to read the relevant tables from the database.
|
String[] |
getDefaultTableTypes()
Returns the table types to recognize per default.
|
protected org.apache.commons.logging.Log |
getLog()
Returns the log used by the model reader.
|
Platform |
getPlatform()
Returns the platform that this model reader belongs to.
|
PlatformInfo |
getPlatformInfo()
Returns the platform specific settings.
|
protected List |
initColumnsForColumn()
Returns descriptors for the columns that shall be read from the result set when
reading the meta data for table columns.
|
protected List |
initColumnsForFK()
Returns descriptors for the columns that shall be read from the result set when
reading the meta data for foreign keys originating from a table.
|
protected List |
initColumnsForIndex()
Returns descriptors for the columns that shall be read from the result set when
reading the meta data for indices.
|
protected List |
initColumnsForPK()
Returns descriptors for the columns that shall be read from the result set when
reading the meta data for primary keys.
|
protected List |
initColumnsForTable()
Returns descriptors for the columns that shall be read from the result set when
reading the meta data for a table.
|
protected boolean |
isInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData,
Table table,
ForeignKey fk,
Index index)
Tries to determine whether the index is the internal database-generated index
for the given foreign key.
|
protected boolean |
isInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData,
Table table,
Index index)
Tries to determine whether the index is the internal database-generated index
for the given table's primary key.
|
protected boolean |
matches(Index index,
List columnsToSearchFor)
Checks whether the given index matches the column list.
|
protected Column |
readColumn(DatabaseMetaDataWrapper metaData,
Map values)
Extracts a column definition from the result set.
|
protected Collection |
readColumns(DatabaseMetaDataWrapper metaData,
String tableName)
Reads the column definitions for the indicated table.
|
protected Map |
readColumns(ResultSet resultSet,
List columnDescriptors)
Reads the indicated columns from the result set.
|
protected void |
readForeignKey(DatabaseMetaDataWrapper metaData,
Map values,
Map knownFks)
Reads the next foreign key spec from the result set.
|
protected Collection |
readForeignKeys(DatabaseMetaDataWrapper metaData,
String tableName)
Retrieves the foreign keys of the indicated table.
|
protected void |
readIndex(DatabaseMetaDataWrapper metaData,
Map values,
Map knownIndices)
Reads the next index spec from the result set.
|
protected Collection |
readIndices(DatabaseMetaDataWrapper metaData,
String tableName)
Determines the indices for the indicated table.
|
protected String |
readPrimaryKeyName(DatabaseMetaDataWrapper metaData,
Map values)
Extracts a primary key name from the result set.
|
protected Collection |
readPrimaryKeyNames(DatabaseMetaDataWrapper metaData,
String tableName)
Retrieves the names of the columns that make up the primary key for a given table.
|
protected Table |
readTable(DatabaseMetaDataWrapper metaData,
Map values)
Reads the next table from the meta data.
|
protected Collection |
readTables(String catalog,
String schemaPattern,
String[] tableTypes)
Reads the tables from the database metadata.
|
protected void |
removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData,
Table table,
ForeignKey fk)
Tries to remove the internal index for the given foreign key.
|
protected void |
removeInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData,
Table table)
Tries to remove the internal index for the table's primary key.
|
protected void |
removeSystemIndices(DatabaseMetaDataWrapper metaData,
Table table)
Removes system indices (generated by the database for primary and foreign keys)
from the table.
|
void |
setDefaultCatalogPattern(String catalogPattern)
Sets the catalog(s) in the database to read per default.
|
void |
setDefaultColumnPattern(String columnPattern)
Sets the default pattern to read the relevant columns from the database.
|
void |
setDefaultSchemaPattern(String schemaPattern)
Sets the schema(s) in the database to read per default.
|
void |
setDefaultTablePattern(String tablePattern)
Sets the default pattern to read the relevant tables from the database.
|
void |
setDefaultTableTypes(String[] types)
Sets the table types to recognize per default.
|
protected void |
sortForeignKeys(Database model)
Sorts the foreign keys in the tables of the model.
|
protected String |
unescape(String text,
String unescaped,
String escaped)
Replaces a specific character sequence in the given text with the character sequence
whose escaped version it is.
|
public JdbcModelReader(Platform platform)
platform - The plaftform this builder belongs toprotected org.apache.commons.logging.Log getLog()
public Platform getPlatform()
public PlatformInfo getPlatformInfo()
protected List initColumnsForTable()
protected List initColumnsForColumn()
protected List initColumnsForPK()
protected List initColumnsForFK()
protected List initColumnsForIndex()
public String getDefaultCatalogPattern()
public void setDefaultCatalogPattern(String catalogPattern)
catalogPattern - The catalog(s)public String getDefaultSchemaPattern()
public void setDefaultSchemaPattern(String schemaPattern)
schemaPattern - The schema(s)public String getDefaultTablePattern()
public void setDefaultTablePattern(String tablePattern)
tablePattern - The table patternpublic String getDefaultColumnPattern()
public void setDefaultColumnPattern(String columnPattern)
columnPattern - The column patternpublic String[] getDefaultTableTypes()
public void setDefaultTableTypes(String[] types)
types - The table typesprotected List getColumnsForTable()
protected List getColumnsForColumn()
protected List getColumnsForPK()
protected List getColumnsForFK()
protected List getColumnsForIndex()
protected Connection getConnection()
readTables(String, String, String[]).null if there is no active connectionpublic Database getDatabase(Connection connection, String name) throws SQLException
connection - The connectionname - The name of the resulting database; null when the default name (the catalog)
is desired which might be null itself thoughSQLExceptionpublic Database getDatabase(Connection connection, String name, String catalog, String schema, String[] tableTypes) throws SQLException
connection - The connectionname - The name of the resulting database; null when the default name (the catalog)
is desired which might be null itself thoughcatalog - The catalog to acess in the database; use null for the default valueschema - The schema to acess in the database; use null for the default valuetableTypes - The table types to process; use null or an empty list for the default onesSQLExceptionprotected Collection readTables(String catalog, String schemaPattern, String[] tableTypes) throws SQLException
catalog - The catalog to acess in the database; use null for the default valueschemaPattern - The schema(s) to acess in the database; use null for the default valuetableTypes - The table types to process; use null or an empty list for the default onesSQLExceptionprotected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
metaData - The database meta datavalues - The table metadata values as defined by getColumnsForTable()null if the result set row did not contain a valid tableSQLExceptionprotected void removeSystemIndices(DatabaseMetaDataWrapper metaData, Table table) throws SQLException
metaData - The database meta datatable - The tableSQLExceptionprotected void removeInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table) throws SQLException
metaData - The database meta datatable - The tableSQLExceptionprotected void removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk) throws SQLException
metaData - The database meta datatable - The table where the table is definedfk - The foreign keySQLExceptionprotected boolean matches(Index index, List columnsToSearchFor)
index - The indexcolumnsToSearchFor - The names of the columns that the index should be fortrue if the index matches the columnsprotected boolean isInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table, Index index) throws SQLException
metaData - The database meta datatable - The table owning the indexindex - The index to checktrue if the index seems to be an internal primary key oneSQLExceptionprotected boolean isInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk, Index index) throws SQLException
metaData - The database meta datatable - The table owning the index and foreign keyfk - The foreign keyindex - The index to checktrue if the index seems to be an internal primary key oneSQLExceptionprotected Collection readColumns(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
metaData - The database meta datatableName - The name of the tableSQLExceptionprotected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
metaData - The database meta datavalues - The column meta data values as defined by getColumnsForColumn()SQLExceptionprotected Collection readPrimaryKeyNames(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
metaData - The database meta datatableName - The name of the table from which to retrieve PK informationSQLExceptionprotected String readPrimaryKeyName(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
metaData - The database meta datavalues - The primary key meta data values as defined by getColumnsForPK()SQLExceptionprotected Collection readForeignKeys(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
metaData - The database meta datatableName - The name of the table from which to retrieve FK informationSQLExceptionprotected void readForeignKey(DatabaseMetaDataWrapper metaData, Map values, Map knownFks) throws SQLException
metaData - The database meta datavalues - The foreign key meta data as defined by getColumnsForFK()knownFks - The already read foreign keys for the current tableSQLExceptionprotected CascadeActionEnum convertAction(Short jdbcActionValue)
importKey constants in the
DatabaseMetaData class) to a CascadeActionEnum.jdbcActionValue - The jdbc action valueprotected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
metaData - The database meta datatableName - The name of the tableSQLExceptionprotected void readIndex(DatabaseMetaDataWrapper metaData, Map values, Map knownIndices) throws SQLException
metaData - The database meta datavalues - The index meta data as defined by getColumnsForIndex()knownIndices - The already read indices for the current tableSQLExceptionprotected Map readColumns(ResultSet resultSet, List columnDescriptors) throws SQLException
resultSet - The result setcolumnDescriptors - The dscriptors of the columns to readSQLExceptionprotected void determineAutoIncrementFromResultSetMetaData(Table table, Column[] columnsToCheck) throws SQLException
ResultSetMetaData.isAutoIncrement(int) method.table - The tablecolumnsToCheck - The columns to check (e.g. the primary key columns)SQLExceptionprotected void sortForeignKeys(Database model)
model - The modelprotected String unescape(String text, String unescaped, String escaped)
text - The textunescaped - The unescaped string, e.g. "'"escaped - The escaped version, e.g. "''"public String determineSchemaOf(Connection connection, String schemaPattern, Table table) throws SQLException
connection - The database connectionschemaPattern - The schema pattern to limit the schemas to search intable - The table to search fornull if the schema of the table
could not be foundSQLExceptionprotected void closeResultSet(ResultSet resultSet)
resultSet - The result setprotected void closeStatement(Statement stmt)
stmt - The statementCopyright © 2010-2015 Pivotal Software, Inc. All rights reserved.