|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.ddlutils.platform.JdbcModelReader
public class JdbcModelReader
An utility class to create a Database model from a live database.
Constructor Summary | |
---|---|
JdbcModelReader(Platform platform)
Creates a new model reader instance. |
Method Summary | |
---|---|
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. |
java.lang.String |
determineSchemaOf(java.sql.Connection connection,
java.lang.String schemaPattern,
Table table)
Deprecated. Will be removed once full schema support is in place |
protected java.util.List |
getColumnsForColumn()
Returns the descriptors for the columns to be read from the column meta data result set. |
protected java.util.List |
getColumnsForFK()
Returns the descriptors for the columns to be read from the foreign key meta data result set. |
protected java.util.List |
getColumnsForIndex()
Returns the descriptors for the columns to be read from the index meta data result set. |
protected java.util.List |
getColumnsForPK()
Returns the descriptors for the columns to be read from the primary key meta data result set. |
protected java.util.List |
getColumnsForTable()
Returns the descriptors for the columns to be read from the table meta data result set. |
protected java.sql.Connection |
getConnection()
Returns the active connection. |
Database |
getDatabase(java.sql.Connection connection,
java.lang.String name)
Reads the database model from the given connection. |
Database |
getDatabase(java.sql.Connection connection,
java.lang.String name,
java.lang.String catalog,
java.lang.String schema,
java.lang.String[] tableTypes)
Reads the database model from the given connection. |
java.lang.String |
getDefaultCatalogPattern()
Returns the catalog(s) in the database to read per default. |
java.lang.String |
getDefaultColumnPattern()
Returns the default pattern to read the relevant columns from the database. |
java.lang.String |
getDefaultSchemaPattern()
Returns the schema(s) in the database to read per default. |
java.lang.String |
getDefaultTablePattern()
Returns the default pattern to read the relevant tables from the database. |
java.lang.String[] |
getDefaultTableTypes()
Returns the table types to recognize per default. |
Platform |
getPlatform()
Returns the platform that this model reader belongs to. |
PlatformInfo |
getPlatformInfo()
Returns the platform specific settings. |
protected java.util.List |
initColumnsForColumn()
Returns descriptors for the columns that shall be read from the result set when reading the meta data for table columns. |
protected java.util.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 java.util.List |
initColumnsForIndex()
Returns descriptors for the columns that shall be read from the result set when reading the meta data for indices. |
protected java.util.List |
initColumnsForPK()
Returns descriptors for the columns that shall be read from the result set when reading the meta data for primary keys. |
protected java.util.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,
java.util.List columnsToSearchFor)
Checks whether the given index matches the column list. |
protected Column |
readColumn(DatabaseMetaDataWrapper metaData,
java.util.Map values)
Extracts a column definition from the result set. |
protected java.util.Collection |
readColumns(DatabaseMetaDataWrapper metaData,
java.lang.String tableName)
Reads the column definitions for the indicated table. |
protected java.util.Map |
readColumns(java.sql.ResultSet resultSet,
java.util.List columnDescriptors)
Reads the indicated columns from the result set. |
protected void |
readForeignKey(DatabaseMetaDataWrapper metaData,
java.util.Map values,
java.util.Map knownFks)
Reads the next foreign key spec from the result set. |
protected java.util.Collection |
readForeignKeys(DatabaseMetaDataWrapper metaData,
java.lang.String tableName)
Retrieves the foreign keys of the indicated table. |
protected void |
readIndex(DatabaseMetaDataWrapper metaData,
java.util.Map values,
java.util.Map knownIndices)
Reads the next index spec from the result set. |
protected java.util.Collection |
readIndices(DatabaseMetaDataWrapper metaData,
java.lang.String tableName)
Determines the indices for the indicated table. |
protected java.lang.String |
readPrimaryKeyName(DatabaseMetaDataWrapper metaData,
java.util.Map values)
Extracts a primary key name from the result set. |
protected java.util.Collection |
readPrimaryKeyNames(DatabaseMetaDataWrapper metaData,
java.lang.String tableName)
Retrieves the names of the columns that make up the primary key for a given table. |
protected Table |
readTable(DatabaseMetaDataWrapper metaData,
java.util.Map values)
Reads the next table from the meta data. |
protected java.util.Collection |
readTables(java.lang.String catalog,
java.lang.String schemaPattern,
java.lang.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(java.lang.String catalogPattern)
Sets the catalog(s) in the database to read per default. |
void |
setDefaultColumnPattern(java.lang.String columnPattern)
Sets the default pattern to read the relevant columns from the database. |
void |
setDefaultSchemaPattern(java.lang.String schemaPattern)
Sets the schema(s) in the database to read per default. |
void |
setDefaultTablePattern(java.lang.String tablePattern)
Sets the default pattern to read the relevant tables from the database. |
void |
setDefaultTableTypes(java.lang.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 java.lang.String |
unescape(java.lang.String text,
java.lang.String unescaped,
java.lang.String escaped)
Replaces a specific character sequence in the given text with the character sequence whose escaped version it is. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JdbcModelReader(Platform platform)
platform
- The plaftform this builder belongs toMethod Detail |
---|
public Platform getPlatform()
public PlatformInfo getPlatformInfo()
protected java.util.List initColumnsForTable()
protected java.util.List initColumnsForColumn()
protected java.util.List initColumnsForPK()
protected java.util.List initColumnsForFK()
protected java.util.List initColumnsForIndex()
public java.lang.String getDefaultCatalogPattern()
public void setDefaultCatalogPattern(java.lang.String catalogPattern)
catalogPattern
- The catalog(s)public java.lang.String getDefaultSchemaPattern()
public void setDefaultSchemaPattern(java.lang.String schemaPattern)
schemaPattern
- The schema(s)public java.lang.String getDefaultTablePattern()
public void setDefaultTablePattern(java.lang.String tablePattern)
tablePattern
- The table patternpublic java.lang.String getDefaultColumnPattern()
public void setDefaultColumnPattern(java.lang.String columnPattern)
columnPattern
- The column patternpublic java.lang.String[] getDefaultTableTypes()
public void setDefaultTableTypes(java.lang.String[] types)
types
- The table typesprotected java.util.List getColumnsForTable()
protected java.util.List getColumnsForColumn()
protected java.util.List getColumnsForPK()
protected java.util.List getColumnsForFK()
protected java.util.List getColumnsForIndex()
protected java.sql.Connection getConnection()
readTables(String, String, String[])
.
null
if there is no active connectionpublic Database getDatabase(java.sql.Connection connection, java.lang.String name) throws java.sql.SQLException
connection
- The connectionname
- The name of the resulting database; null
when the default name (the catalog)
is desired which might be null
itself though
java.sql.SQLException
public Database getDatabase(java.sql.Connection connection, java.lang.String name, java.lang.String catalog, java.lang.String schema, java.lang.String[] tableTypes) throws java.sql.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 ones
java.sql.SQLException
protected java.util.Collection readTables(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String[] tableTypes) throws java.sql.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 ones
java.sql.SQLException
protected Table readTable(DatabaseMetaDataWrapper metaData, java.util.Map values) throws java.sql.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 table
java.sql.SQLException
protected void removeSystemIndices(DatabaseMetaDataWrapper metaData, Table table) throws java.sql.SQLException
metaData
- The database meta datatable
- The table
java.sql.SQLException
protected void removeInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table) throws java.sql.SQLException
metaData
- The database meta datatable
- The table
java.sql.SQLException
protected void removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk) throws java.sql.SQLException
metaData
- The database meta datatable
- The table where the table is definedfk
- The foreign key
java.sql.SQLException
protected boolean matches(Index index, java.util.List columnsToSearchFor)
index
- The indexcolumnsToSearchFor
- The names of the columns that the index should be for
true
if the index matches the columnsprotected boolean isInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table, Index index) throws java.sql.SQLException
metaData
- The database meta datatable
- The table owning the indexindex
- The index to check
true
if the index seems to be an internal primary key one
java.sql.SQLException
protected boolean isInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk, Index index) throws java.sql.SQLException
metaData
- The database meta datatable
- The table owning the index and foreign keyfk
- The foreign keyindex
- The index to check
true
if the index seems to be an internal primary key one
java.sql.SQLException
protected java.util.Collection readColumns(DatabaseMetaDataWrapper metaData, java.lang.String tableName) throws java.sql.SQLException
metaData
- The database meta datatableName
- The name of the table
java.sql.SQLException
protected Column readColumn(DatabaseMetaDataWrapper metaData, java.util.Map values) throws java.sql.SQLException
metaData
- The database meta datavalues
- The column meta data values as defined by getColumnsForColumn()
java.sql.SQLException
protected java.util.Collection readPrimaryKeyNames(DatabaseMetaDataWrapper metaData, java.lang.String tableName) throws java.sql.SQLException
metaData
- The database meta datatableName
- The name of the table from which to retrieve PK information
java.sql.SQLException
protected java.lang.String readPrimaryKeyName(DatabaseMetaDataWrapper metaData, java.util.Map values) throws java.sql.SQLException
metaData
- The database meta datavalues
- The primary key meta data values as defined by getColumnsForPK()
java.sql.SQLException
protected java.util.Collection readForeignKeys(DatabaseMetaDataWrapper metaData, java.lang.String tableName) throws java.sql.SQLException
metaData
- The database meta datatableName
- The name of the table from which to retrieve FK information
java.sql.SQLException
protected void readForeignKey(DatabaseMetaDataWrapper metaData, java.util.Map values, java.util.Map knownFks) throws java.sql.SQLException
metaData
- The database meta datavalues
- The foreign key meta data as defined by getColumnsForFK()
knownFks
- The already read foreign keys for the current table
java.sql.SQLException
protected java.util.Collection readIndices(DatabaseMetaDataWrapper metaData, java.lang.String tableName) throws java.sql.SQLException
metaData
- The database meta datatableName
- The name of the table
java.sql.SQLException
protected void readIndex(DatabaseMetaDataWrapper metaData, java.util.Map values, java.util.Map knownIndices) throws java.sql.SQLException
metaData
- The database meta datavalues
- The index meta data as defined by getColumnsForIndex()
knownIndices
- The already read indices for the current table
java.sql.SQLException
protected java.util.Map readColumns(java.sql.ResultSet resultSet, java.util.List columnDescriptors) throws java.sql.SQLException
resultSet
- The result setcolumnDescriptors
- The dscriptors of the columns to read
java.sql.SQLException
protected void determineAutoIncrementFromResultSetMetaData(Table table, Column[] columnsToCheck) throws java.sql.SQLException
ResultSetMetaData.isAutoIncrement(int)
method.
table
- The tablecolumnsToCheck
- The columns to check (e.g. the primary key columns)
java.sql.SQLException
protected void sortForeignKeys(Database model)
model
- The modelprotected java.lang.String unescape(java.lang.String text, java.lang.String unescaped, java.lang.String escaped)
text
- The textunescaped
- The unescaped string, e.g. "'"escaped
- The escaped version, e.g. "''"
public java.lang.String determineSchemaOf(java.sql.Connection connection, java.lang.String schemaPattern, Table table) throws java.sql.SQLException
connection
- The database connectionschemaPattern
- The schema pattern to limit the schemas to search intable
- The table to search for
null
if the schema of the table
could not be found
java.sql.SQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |