Skip to content

Commit

Permalink
TEIID-5174 filtering SYS and always getting columns per table
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jan 23, 2018
1 parent 510d9a9 commit 2ff8000
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Expand Up @@ -104,8 +104,6 @@ public TableInfo(String catalog, String schema, String name, Table table) {
private Pattern excludeProcedures;
private Pattern excludeSequences;

private int excludedTables;

private boolean useAnyIndexCardinality;
private boolean importStatistics;

Expand Down Expand Up @@ -240,7 +238,7 @@ private void getProcedures(MetadataFactory metadataFactory,
}
}
String fullProcedureName = getFullyQualifiedName(procedureCatalog, procedureSchema, procedureName);
if (excludeProcedures != null && excludeProcedures.matcher(fullProcedureName).matches()) {
if ((excludeProcedures != null && excludeProcedures.matcher(fullProcedureName).matches()) || isHiddenSchema(procedureCatalog, procedureSchema)) {
continue;
}
Procedure procedure = metadataFactory.addProcedure(useFullSchemaName?fullProcedureName:procedureName);
Expand Down Expand Up @@ -329,8 +327,7 @@ private Map<String, TableInfo> getTables(MetadataFactory metadataFactory,
String tableName = tables.getString(3);
String remarks = tables.getString(5);
String fullName = getFullyQualifiedName(tableCatalog, tableSchema, tableName);
if (shouldExclude(fullName)) {
excludedTables++;
if (shouldExclude(fullName) || isHiddenSchema(tableCatalog, tableSchema)) {
continue;
}
Table table = addTable(metadataFactory, tableCatalog, tableSchema,
Expand Down Expand Up @@ -388,22 +385,13 @@ private void getColumns(MetadataFactory metadataFactory,
DatabaseMetaData metadata, Map<String, TableInfo> tableMap, Connection conn)
throws SQLException {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "JDBCMetadataProcessor - Importing columns"); //$NON-NLS-1$
boolean singleSchema = schemaPattern != null && !schemaPattern.contains("_") && !schemaPattern.contains("%"); //$NON-NLS-1$ //$NON-NLS-2$
if ((excludeTables == null && schemaPattern == null && tableNamePattern == null) //getting everything
|| (singleSchema && tableNamePattern == null &&
(excludeTables == null //getting all from a single schema
|| tableMap.size()/2 > Math.sqrt(tableMap.size()/2 + excludedTables)))) { //not excluding enough from a single schema
ResultSet columns = metadata.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern);
for (TableInfo ti : new LinkedHashSet<TableInfo>(tableMap.values())) {
ResultSet columns = metadata.getColumns(ti.catalog, ti.schema, ti.name, columnNamePattern);
processColumns(metadataFactory, tableMap, columns, conn);
} else {
for (TableInfo ti : new LinkedHashSet<TableInfo>(tableMap.values())) {
ResultSet columns = metadata.getColumns(ti.catalog, ti.schema, ti.name, columnNamePattern);
processColumns(metadataFactory, tableMap, columns, conn);
}
}
}

private void processColumns(MetadataFactory metadataFactory,
private void processColumns(MetadataFactory metadataFactory,
Map<String, TableInfo> tableMap, ResultSet columns, Connection conn)
throws SQLException {
int rsColumns = columns.getMetaData().getColumnCount();
Expand Down Expand Up @@ -799,6 +787,9 @@ public void getSequences(MetadataFactory metadataFactory, Connection conn) throw
String sequenceCatalog = sequences.getString(1);
String sequenceSchema = sequences.getString(2);
String sequenceName = sequences.getString(3);
if (isHiddenSchema(sequenceCatalog, sequenceSchema)) {
continue;
}
//TODO: type
String sequenceTeiidName = getFullyQualifiedName(sequenceCatalog, sequenceSchema, sequenceName);
if (excludeSequences != null && excludeSequences.matcher(sequenceTeiidName).matches()) {
Expand Down Expand Up @@ -1151,5 +1142,15 @@ public boolean isUseIntegralTypes() {
public void setUseIntegralTypes(boolean useIntegralTypes) {
this.useIntegralTypes = useIntegralTypes;
}

/**
* If the schema is hidden regardless of the specified schema pattern
* @param catalog
* @param schema
* @return true if no objects should be imported from the given schema
*/
protected boolean isHiddenSchema(String catalog, String schema) {
return false;
}

}
Expand Up @@ -166,5 +166,10 @@ protected ResultSet executeSequenceQuery(Connection conn)
protected String getSequenceNextSQL(String fullyQualifiedName) {
return fullyQualifiedName + ".nextval"; //$NON-NLS-1$
}

@Override
public boolean isHiddenSchema(String catalog, String schema) {
return "SYS".equalsIgnoreCase(schema); //$NON-NLS-1$
}

}

0 comments on commit 2ff8000

Please sign in to comment.