org.kuali.common.impex.util
Class ExtractionUtils

java.lang.Object
  extended by org.kuali.common.impex.util.ExtractionUtils

public class ExtractionUtils
extends Object

The following class contains methods used for schema extraction with java.sql.DatabaseMetaData


Field Summary
protected static int COLUMN_DEFAULT_INDEX
           
protected static int COLUMN_NAME_INDEX
           
protected static int COLUMN_NULLABLE_INDEX
           
protected static int COLUMN_REMARKS_INDEX
           
protected static String COLUMN_RESULT_SET_NULLABLE_VALUE
           
protected static int COLUMN_TYPE_INDEX
           
protected static int COLUMN_TYPE_SCALE_INDEX
           
protected static int COLUMN_TYPE_SIZE_INDEX
           
protected static ForeignKeyConstraintType DEFAULT_CONSTRAINT_RULE
           
protected static boolean DEFAULT_NULLABLE
           
protected static int FOREIGN_KEY_IMPORTED_COLUMN_NAME_INDEX
           
protected static int FOREIGN_KEY_IMPORTED_TABLE_NAME_INDEX
           
protected static int FOREIGN_KEY_LOCAL_COLUMN_NAME_INDEX
           
protected static int FOREIGN_KEY_NAME_INDEX
           
protected static int FOREIGN_KEY_ON_DELETE_INDEX
           
protected static int FOREIGN_KEY_ON_UPDATE_INDEX
           
protected static List<String> IGNORED_TABLE_NAME_PREFIXES
           
protected static int INDEX_COLUMN_NAME_INDEX
           
protected static int INDEX_NAME_INDEX
           
protected static int INDEX_NON_UNIQUE_INDEX
           
protected static String ORACLE_RECYCLE_BIN_TABLE_NAME_PREFIX
          Oracle creates tables with a prefix of "BIN$" to represent a recently deleted table (a 'recycle bin' of sorts), introduced in Oracle 10

See this article for details: http://docs.oracle.com/cd/B19306_01/server.102/b14231/tables.htm#ADMIN01511

protected static int PRIMARY_KEY_COLUMN_NAME_INDEX
           
protected static int PRIMARY_KEY_NAME_INDEX
           
protected static String PRIMARY_KEY_UNNAMED_KEY
           
protected static String SINGLE_QUOTE
           
protected static Map<Integer,DataType> SQL_TYPE_TO_DATA_TYPE
           
protected static int TABLE_COMMENT_INDEX
           
protected static String TABLE_META_DATA_TYPE
           
protected static int TABLE_NAME_INDEX
           
 
Constructor Summary
ExtractionUtils()
           
 
Method Summary
static void addOrUpdateForeignKeys(ResultSet rs, Map<String,ForeignKey> foreignKeys, String tableName)
           
static List<ForeignKey> extractForeignKeys(DatabaseMetaData meta, String schema, List<String> tables, org.kuali.common.util.PercentCompleteInformer informer)
           
static List<Column> extractTableColumns(String tableName, String schemaName, DatabaseMetaData databaseMetaData)
           
static String extractTableComment(String tableName, String schemaName, DatabaseMetaData databaseMetaData)
           
static List<Index> extractTableIndices(String tableName, String schemaName, DatabaseMetaData databaseMetaData)
          This method extracts raw index information for a table.
static Map<String,List<String>> extractTablePrimaryKeyColumns(String tableName, String schemaName, DatabaseMetaData databaseMetaData)
           
protected static Map<Integer,DataType> getDataTypeMapping()
           
static List<String> getNamedPrimaryKeyColumns(Map<String,List<String>> primaryKeyData)
          Returns the first list of primary key columns found in the primary key data that does not have an "unnamed" primary key name.
static String getPrimaryKeyName(Map<String,List<String>> primaryKeyData)
          Returns the first primary key name found in the primary key data that does not have an "unnamed" primary key name.
static List<String> getTableNames(DataSource dataSource, String schema)
           
static List<String> getTableNamesFromMetaData(String schema, DatabaseMetaData meta)
           
static List<String> getTableNamesFromMetaDataUsingIgnorePrefixes(String schemaName, DatabaseMetaData databaseMetaData)
           
static DataTypeSize translateExtractedTypeSize(Integer typeSize, Integer typeSizeScale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_META_DATA_TYPE

protected static final String TABLE_META_DATA_TYPE
See Also:
Constant Field Values

TABLE_NAME_INDEX

protected static final int TABLE_NAME_INDEX
See Also:
Constant Field Values

TABLE_COMMENT_INDEX

protected static final int TABLE_COMMENT_INDEX
See Also:
Constant Field Values

COLUMN_NAME_INDEX

protected static final int COLUMN_NAME_INDEX
See Also:
Constant Field Values

COLUMN_TYPE_INDEX

protected static final int COLUMN_TYPE_INDEX
See Also:
Constant Field Values

COLUMN_TYPE_SIZE_INDEX

protected static final int COLUMN_TYPE_SIZE_INDEX
See Also:
Constant Field Values

COLUMN_TYPE_SCALE_INDEX

protected static final int COLUMN_TYPE_SCALE_INDEX
See Also:
Constant Field Values

COLUMN_REMARKS_INDEX

protected static final int COLUMN_REMARKS_INDEX
See Also:
Constant Field Values

COLUMN_DEFAULT_INDEX

protected static final int COLUMN_DEFAULT_INDEX
See Also:
Constant Field Values

COLUMN_NULLABLE_INDEX

protected static final int COLUMN_NULLABLE_INDEX
See Also:
Constant Field Values

COLUMN_RESULT_SET_NULLABLE_VALUE

protected static final String COLUMN_RESULT_SET_NULLABLE_VALUE
See Also:
Constant Field Values

PRIMARY_KEY_COLUMN_NAME_INDEX

protected static final int PRIMARY_KEY_COLUMN_NAME_INDEX
See Also:
Constant Field Values

PRIMARY_KEY_NAME_INDEX

protected static final int PRIMARY_KEY_NAME_INDEX
See Also:
Constant Field Values

PRIMARY_KEY_UNNAMED_KEY

protected static final String PRIMARY_KEY_UNNAMED_KEY
See Also:
Constant Field Values

INDEX_NON_UNIQUE_INDEX

protected static final int INDEX_NON_UNIQUE_INDEX
See Also:
Constant Field Values

INDEX_NAME_INDEX

protected static final int INDEX_NAME_INDEX
See Also:
Constant Field Values

INDEX_COLUMN_NAME_INDEX

protected static final int INDEX_COLUMN_NAME_INDEX
See Also:
Constant Field Values

FOREIGN_KEY_IMPORTED_TABLE_NAME_INDEX

protected static final int FOREIGN_KEY_IMPORTED_TABLE_NAME_INDEX
See Also:
Constant Field Values

FOREIGN_KEY_IMPORTED_COLUMN_NAME_INDEX

protected static final int FOREIGN_KEY_IMPORTED_COLUMN_NAME_INDEX
See Also:
Constant Field Values

FOREIGN_KEY_LOCAL_COLUMN_NAME_INDEX

protected static final int FOREIGN_KEY_LOCAL_COLUMN_NAME_INDEX
See Also:
Constant Field Values

FOREIGN_KEY_ON_UPDATE_INDEX

protected static final int FOREIGN_KEY_ON_UPDATE_INDEX
See Also:
Constant Field Values

FOREIGN_KEY_ON_DELETE_INDEX

protected static final int FOREIGN_KEY_ON_DELETE_INDEX
See Also:
Constant Field Values

FOREIGN_KEY_NAME_INDEX

protected static final int FOREIGN_KEY_NAME_INDEX
See Also:
Constant Field Values

SQL_TYPE_TO_DATA_TYPE

protected static final Map<Integer,DataType> SQL_TYPE_TO_DATA_TYPE

ORACLE_RECYCLE_BIN_TABLE_NAME_PREFIX

protected static final String ORACLE_RECYCLE_BIN_TABLE_NAME_PREFIX
Oracle creates tables with a prefix of "BIN$" to represent a recently deleted table (a 'recycle bin' of sorts), introduced in Oracle 10

See this article for details: http://docs.oracle.com/cd/B19306_01/server.102/b14231/tables.htm#ADMIN01511

See Also:
Constant Field Values

IGNORED_TABLE_NAME_PREFIXES

protected static final List<String> IGNORED_TABLE_NAME_PREFIXES

SINGLE_QUOTE

protected static final String SINGLE_QUOTE
See Also:
Constant Field Values

DEFAULT_NULLABLE

protected static final boolean DEFAULT_NULLABLE
See Also:
Constant Field Values

DEFAULT_CONSTRAINT_RULE

protected static final ForeignKeyConstraintType DEFAULT_CONSTRAINT_RULE
Constructor Detail

ExtractionUtils

public ExtractionUtils()
Method Detail

getDataTypeMapping

protected static Map<Integer,DataType> getDataTypeMapping()

getTableNames

public static List<String> getTableNames(DataSource dataSource,
                                         String schema)
                                  throws SQLException
Throws:
SQLException

getTableNamesFromMetaDataUsingIgnorePrefixes

public static List<String> getTableNamesFromMetaDataUsingIgnorePrefixes(String schemaName,
                                                                        DatabaseMetaData databaseMetaData)
                                                                 throws SQLException
Throws:
SQLException

getTableNamesFromMetaData

public static List<String> getTableNamesFromMetaData(String schema,
                                                     DatabaseMetaData meta)
                                              throws SQLException
Throws:
SQLException

extractTableComment

public static String extractTableComment(String tableName,
                                         String schemaName,
                                         DatabaseMetaData databaseMetaData)
                                  throws SQLException
Throws:
SQLException

extractTableColumns

public static List<Column> extractTableColumns(String tableName,
                                               String schemaName,
                                               DatabaseMetaData databaseMetaData)
                                        throws SQLException
Throws:
SQLException

translateExtractedTypeSize

public static DataTypeSize translateExtractedTypeSize(Integer typeSize,
                                                      Integer typeSizeScale)

extractTablePrimaryKeyColumns

public static Map<String,List<String>> extractTablePrimaryKeyColumns(String tableName,
                                                                     String schemaName,
                                                                     DatabaseMetaData databaseMetaData)
                                                              throws SQLException
Throws:
SQLException

getNamedPrimaryKeyColumns

public static List<String> getNamedPrimaryKeyColumns(Map<String,List<String>> primaryKeyData)
Returns the first list of primary key columns found in the primary key data that does not have an "unnamed" primary key name. Used as a convenience method to get the most relevant primary key information from the full data extracted for primary keys of a table

Parameters:
primaryKeyData - a Map assumed to be the result of calling extractPrimaryKeyColumns
Returns:
a list of strings, or an empty list if no list is found within the parameter data

getPrimaryKeyName

public static String getPrimaryKeyName(Map<String,List<String>> primaryKeyData)
Returns the first primary key name found in the primary key data that does not have an "unnamed" primary key name. Used as a convenience method to get the most relevant primary key information from the full data extracted for primary keys of a table

Parameters:
primaryKeyData - a Map assumed to be the result of calling extractPrimaryKeyColumns
Returns:
the name of the primary key, or null if the table has no primary key

extractTableIndices

public static List<Index> extractTableIndices(String tableName,
                                              String schemaName,
                                              DatabaseMetaData databaseMetaData)
                                       throws SQLException
This method extracts raw index information for a table. ** NOTE ** Unique constraints will be included in these indices, but not the primary key index for the table (if it has one) ** NOTE **

Parameters:
tableName - Name of the table
schemaName - Name of the schema
databaseMetaData - Connection to the database metadata
Returns:
All indices for the given parameters
Throws:
SQLException

extractForeignKeys

public static List<ForeignKey> extractForeignKeys(DatabaseMetaData meta,
                                                  String schema,
                                                  List<String> tables,
                                                  org.kuali.common.util.PercentCompleteInformer informer)
                                           throws SQLException
Throws:
SQLException

addOrUpdateForeignKeys

public static void addOrUpdateForeignKeys(ResultSet rs,
                                          Map<String,ForeignKey> foreignKeys,
                                          String tableName)
                                   throws SQLException
Throws:
SQLException


Copyright © 2004-2013 The Kuali Foundation. All Rights Reserved.