Class JDBCMetaDataBasedModelElementFinder
java.lang.Object
net.sf.jailer.modelbuilder.JDBCMetaDataBasedModelElementFinder
- All Implemented Interfaces:
ModelElementFinder
Finds associations and tables by analyzing the JDBC meta data.
- Author:
- Ralf Wisser
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceProvides a session with elevated privileges for reading restricted schema metadata. -
Field Summary
FieldsModifier and TypeFieldDescriptionSet of sql types (uppercase) not listed inTypeswhich needs a length argument. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intfilterLength(int length, int precision, String typeName, int type, DBMS dbms, int origLength) Filters the length attribute of a column in a DBMS specific way.static intfilterPrecision(int length, int precision, String typeName, int type, DBMS dbms, int origLength) Filters the precision attribute of a column in a DBMS specific way.static StringfilterType(String sqlType, int length, String typeName, int type, DBMS dbms, int origLength) Filters the type attribute of a column in a DBMS specific way.findAssociations(DataModel dataModel, Map<Association, String[]> namingSuggestion, Session session, ExecutionContext executionContext) Finds associations by reading the databases meta-data.findColumns(Table table, Session session, ExecutionContext executionContext) findPartitions(Session session, String introspectionSchema) Finds all table names that are partitions in the given schema.findTables(Session session, ExecutionContext executionContext) Finds all tables in the DB schema.getCatalogsWithSchemas(Session session) Finds all catalogs with all schemas in DB.static ResultSetgetColumns(Session session, String schemaPattern, String tableNamePattern, String columnNamePattern, boolean withCaching, boolean onlyIfCached, String tableType) Finds comments for all model elements.static StringgetDefaultSchema(Session session, String userName) Gets default schema of DB.static StringgetDefaultSchema(Session session, String userName, List<String> schemaNames) Gets default schema of DB.static ResultSetgetExportedKeys(Session session, String schema, String table) Gets the exported keys (referenced by foreign keys in other tables) for a table.static ResultSetgetImportedKeys(Session session, String schema, String table, boolean withCaching) Gets the imported keys (foreign keys) for a table, optionally using a cache.static ResultSetgetIndexes(Session session, String schemaPattern, String tableNamePattern) static ResultSetgetPrimaryKeys(Session session, String schema, String table, boolean withCaching) Retrieves primary key information for a given table.static ResultSetgetProcedures(Session session, String schemaPattern, String functionPattern) getSchemas(Session session, String userName) Finds all schemas in DB.static ResultSetstatic voidresetCaches(Session session) Resets all cached metadata for the given session.static ColumntoColumn(ResultSetMetaData metaData, int i, Session session) Converts a column fromResultSetMetaDatainto aColumnmodel object.toString()Gets description.
-
Field Details
-
TYPES_WITH_LENGTH
-
privilegedSessionProvider
public static JDBCMetaDataBasedModelElementFinder.PrivilegedSessionProvider privilegedSessionProvider
-
-
Constructor Details
-
JDBCMetaDataBasedModelElementFinder
public JDBCMetaDataBasedModelElementFinder()
-
-
Method Details
-
findAssociations
public Collection<Association> findAssociations(DataModel dataModel, Map<Association, String[]> namingSuggestion, Session session, ExecutionContext executionContext) throws ExceptionFinds associations by reading the databases meta-data.- Specified by:
findAssociationsin interfaceModelElementFinder- Parameters:
dataModel- model containing already known elementsnamingSuggestion- to put naming suggestions for associations intosession- the statement executor for executing SQL-statementsexecutionContext- the execution context- Returns:
- found associations
- Throws:
Exception- on each error
-
getImportedKeys
public static ResultSet getImportedKeys(Session session, String schema, String table, boolean withCaching) throws SQLException Gets the imported keys (foreign keys) for a table, optionally using a cache.- Parameters:
session- the database sessionschema- the schema nametable- the table namewithCaching- iftrue, use a cached result set if available- Returns:
- a result set describing the imported keys
- Throws:
SQLException
-
getExportedKeys
public static ResultSet getExportedKeys(Session session, String schema, String table) throws SQLException Gets the exported keys (referenced by foreign keys in other tables) for a table.- Parameters:
session- the database sessionschema- the schema nametable- the table name- Returns:
- a result set describing the exported keys
- Throws:
SQLException
-
findTables
Finds all tables in the DB schema.- Specified by:
findTablesin interfaceModelElementFinder- Parameters:
session- the statement executor for executing SQL-statementsexecutionContext- the execution context- Returns:
- the set of tables found in the schema
- Throws:
Exception- on each error
-
findPartitions
-
getPrimaryKeys
public static ResultSet getPrimaryKeys(Session session, String schema, String table, boolean withCaching) throws SQLException Retrieves primary key information for a given table.- Parameters:
session- the database sessionschema- the schema nametable- the table namewithCaching- iftrue, use a cached result set if available- Returns:
- a result set describing the primary keys
- Throws:
SQLException
-
getTables
public static ResultSet getTables(Session session, String schemaPattern, String tableNamePattern, String[] types) throws SQLException CallsDatabaseMetaData.getTables(String, String, String, String[]). Uses schemaPattern as catalogPattern on MySQL.- Parameters:
session- the database sessionschemaPattern- the schema name patterntableNamePattern- the table name patterntypes- the list of table types to include- Returns:
- a result set describing the matching tables
- Throws:
SQLException
-
getComments
Finds comments for all model elements.- Specified by:
getCommentsin interfaceModelElementFinder- Returns:
- map from element (table, column) to the comment
-
getIndexes
public static ResultSet getIndexes(Session session, String schemaPattern, String tableNamePattern) throws SQLException CallsDatabaseMetaData.getIndexInfo(String, String, String, boolean, boolean). Uses schemaPattern as catalogPattern on MySQL.- Parameters:
session- the database sessionschemaPattern- the schema name patterntableNamePattern- the table name pattern- Returns:
- a result set describing the indexes of matching tables
- Throws:
SQLException
-
getColumns
public static ResultSet getColumns(Session session, String schemaPattern, String tableNamePattern, String columnNamePattern, boolean withCaching, boolean onlyIfCached, String tableType) throws SQLException CallsDatabaseMetaData.getColumns(String, String, String, String). Uses schemaPattern as catalogPattern on MySQL.- Parameters:
session- the database sessionschemaPattern- the schema name patterntableNamePattern- the table name patterncolumnNamePattern- the column name patternwithCaching- iftrue, use a cached result set if availableonlyIfCached- iftrue, return only from cache; skip if cache is not populatedtableType- the table type (e.g. "TABLE", "SYNONYM")- Returns:
- a result set describing the matching columns
- Throws:
SQLException
-
getProcedures
public static ResultSet getProcedures(Session session, String schemaPattern, String functionPattern) throws SQLException CallsDatabaseMetaData.getProcedures(String, String, String). Uses schemaPattern as catalogPattern on MySQL.- Parameters:
session- the database sessionschemaPattern- the schema name patternfunctionPattern- the procedure/function name pattern- Returns:
- a result set describing matching procedures and functions
- Throws:
SQLException
-
getSchemas
-
getCatalogsWithSchemas
-
getDefaultSchema
-
getDefaultSchema
Gets default schema of DB.- Parameters:
session- the statement executor for executing SQL-statementsuserName- schema with this name may be emptyschemaNames- optional list of known schema names to use for resolution- Returns:
- the default schema name
-
findColumns
public List<Column> findColumns(Table table, Session session, ExecutionContext executionContext) throws SQLException - Specified by:
findColumnsin interfaceModelElementFinder- Parameters:
table- the tablesession- the statement executor for executing SQL-statementsexecutionContext- the execution context- Returns:
- the list of columns found for the given table
- Throws:
Exception- on each errorSQLException
-
filterLength
public static int filterLength(int length, int precision, String typeName, int type, DBMS dbms, int origLength) Filters the length attribute of a column in a DBMS specific way.- Parameters:
length- the length as given from driverprecision- the precision as given from drivertypeName- the SQL type nametype- the sql typedbms- the DBMSorigLength- the original unfiltered length- Returns:
- filtered length
-
filterPrecision
public static int filterPrecision(int length, int precision, String typeName, int type, DBMS dbms, int origLength) Filters the precision attribute of a column in a DBMS specific way.- Parameters:
length- the length as given from driverprecision- the precision as given from drivertypeName- the SQL type nametype- the sql typedbms- the DBMSorigLength- the original unfiltered length- Returns:
- filtered precision
-
filterType
public static String filterType(String sqlType, int length, String typeName, int type, DBMS dbms, int origLength) Filters the type attribute of a column in a DBMS specific way.- Parameters:
sqlType- the SQL type name as given from driverlength- the length as given from drivertypeName- the native type name as given from drivertype- the sql type codedbms- the DBMSorigLength- the original unfiltered length- Returns:
- filtered type name
-
toColumn
public static Column toColumn(ResultSetMetaData metaData, int i, Session session) throws SQLException Converts a column fromResultSetMetaDatainto aColumnmodel object.- Parameters:
metaData- the result set meta datai- the 1-based column indexsession- the database session- Returns:
- the corresponding
Column - Throws:
SQLException
-
resetCaches
Resets all cached metadata for the given session.- Parameters:
session- the session whose caches should be cleared
-
toString
-