Skip to content

Commit

Permalink
HHH-17763 Rely on action-specific SchemaFilter instances
Browse files Browse the repository at this point in the history
Deprecated `ExecutionOptions#getSchemaFilter` which was always returning the default implementation (not filtering anything)
  • Loading branch information
mbladel committed Mar 4, 2024
1 parent 89dfa61 commit c956208
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void performMigration(
sqlGenerationContext, targets
);
tablesInformation.put( namespace, nameSpaceTablesInformation );
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
for ( Sequence sequence : namespace.getSequences() ) {
if ( contributableInclusionFilter.matches( sequence ) ) {
checkExportIdentifier( sequence, exportIdentifiers);
Expand All @@ -259,10 +259,10 @@ private void performMigration(

//NOTE : Foreign keys must be created *after* all tables of all namespaces for cross namespace fks. see HHH-10420
for ( Namespace namespace : database.getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
final NameSpaceTablesInformation nameSpaceTablesInformation = tablesInformation.get( namespace );
for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) && contributableInclusionFilter.matches( table ) ) {
if ( schemaFilter.includeTable( table ) && contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = nameSpaceTablesInformation.getTableInformation( table );
if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
applyForeignKeys( table, tableInformation, dialect, metadata, formatter, options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public void performValidation(
ContributableMatcher contributableInclusionFilter,
Dialect dialect) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
validateTables( metadata, databaseInformation, options, contributableInclusionFilter, dialect, namespace );
}
}

for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
for ( Sequence sequence : namespace.getSequences() ) {
if ( ! options.getSchemaFilter().includeSequence( sequence ) ) {
if ( !schemaFilter.includeSequence( sequence ) ) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected NameSpaceTablesInformation performTablesMigration(
final NameSpaceTablesInformation tablesInformation =
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );

if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
createSchemaAndCatalog(
existingDatabase,
options,
Expand All @@ -71,7 +71,7 @@ protected NameSpaceTablesInformation performTablesMigration(

final NameSpaceTablesInformation tables = existingDatabase.getTablesInformation( namespace );
for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers );
Expand All @@ -88,7 +88,7 @@ else if ( tableInformation.isPhysicalTable() ) {
}

for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = tablesInformation.getTableInformation( table );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void validateTables(

final NameSpaceTablesInformation tables = databaseInformation.getTablesInformation( namespace );
for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) {
validateTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected NameSpaceTablesInformation performTablesMigration(
final NameSpaceTablesInformation tablesInformation =
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );

if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
createSchemaAndCatalog(
existingDatabase,
options,
Expand All @@ -69,7 +69,7 @@ protected NameSpaceTablesInformation performTablesMigration(
targets
);
for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers );
Expand All @@ -86,7 +86,7 @@ else if ( tableInformation.isPhysicalTable() ) {
}

for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = tablesInformation.getTableInformation( table );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void validateTables(
Dialect dialect,
Namespace namespace) {
for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = databaseInformation.getTableInformation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,16 @@ public void createFromMetadata(
final SqlStringGenerationContext context = createSqlStringGenerationContext(options, metadata);
final Set<String> exportIdentifiers = setOfSize(50);

createSchemasAndCatalogs(metadata, options, dialect, formatter, context, targets);
createSchemasAndCatalogs(metadata, options, schemaFilter, dialect, formatter, context, targets);
// next, create all "before table" auxiliary objects
createAuxiliaryObjectsBeforeTables(metadata, options, dialect, formatter, context, exportIdentifiers, targets);
// next, create all UDTs
createUserDefinedTypes(metadata, options, dialect, formatter, context, targets);
createUserDefinedTypes(metadata, options, schemaFilter, dialect, formatter, context, targets);
// then, create all schema objects (tables, sequences, constraints, etc) in each schema
createSequencesTablesConstraints(
metadata,
options,
schemaFilter,
contributableInclusionMatcher,
dialect,
formatter,
Expand All @@ -247,7 +248,7 @@ public void createFromMetadata(
targets
);
// foreign keys must be created after all tables of all namespaces for cross-namespace constraints (see HHH-10420)
createForeignKeys( metadata, options, contributableInclusionMatcher, dialect, formatter, context, targets );
createForeignKeys( metadata, options, schemaFilter, contributableInclusionMatcher, dialect, formatter, context, targets );
// next, create all "after table" auxiliary objects
createAuxiliaryObjectsAfterTables( metadata, options, dialect, formatter, context, exportIdentifiers, targets );
// and finally add all init commands
Expand Down Expand Up @@ -287,16 +288,17 @@ private static void createAuxiliaryObjectsAfterTables(
private static void createForeignKeys(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher,
Dialect dialect,
Formatter formatter,
SqlStringGenerationContext context,
GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
// foreign keys must be created after unique keys for numerous DBs (see HHH-8390)
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table )
if ( schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) {
// foreign keys
for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
Expand All @@ -316,18 +318,20 @@ private static void createForeignKeys(
private static void createSequencesTablesConstraints(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher,
Dialect dialect,
Formatter formatter,
SqlStringGenerationContext context,
Set<String> exportIdentifiers,
GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
// sequences
createSequences(
metadata,
options,
schemaFilter,
contributableInclusionMatcher,
dialect,
formatter,
Expand All @@ -340,6 +344,7 @@ private static void createSequencesTablesConstraints(
createTables(
metadata,
options,
schemaFilter,
contributableInclusionMatcher,
dialect,
formatter,
Expand All @@ -351,6 +356,7 @@ private static void createSequencesTablesConstraints(
createTableConstraints(
metadata,
options,
schemaFilter,
contributableInclusionMatcher,
dialect,
formatter,
Expand All @@ -366,6 +372,7 @@ private static void createSequencesTablesConstraints(
private static void createTableConstraints(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher,
Dialect dialect,
Formatter formatter,
Expand All @@ -375,7 +382,7 @@ private static void createTableConstraints(
Namespace namespace) {
for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable()
&& options.getSchemaFilter().includeTable( table )
&& schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) {
// indexes
for ( Index index : table.getIndexes().values() ) {
Expand Down Expand Up @@ -404,6 +411,7 @@ private static void createTableConstraints(
private static void createTables(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher,
Dialect dialect,
Formatter formatter,
Expand All @@ -414,7 +422,7 @@ private static void createTables(
for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable()
&& !table.isView()
&& options.getSchemaFilter().includeTable( table )
&& schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers );
applySqlStrings(
Expand All @@ -428,7 +436,7 @@ private static void createTables(
for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable()
&& table.isView()
&& options.getSchemaFilter().includeTable( table )
&& schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers );
applySqlStrings(
Expand All @@ -444,6 +452,7 @@ private static void createTables(
private static void createSequences(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher,
Dialect dialect,
Formatter formatter,
Expand All @@ -452,7 +461,7 @@ private static void createSequences(
GenerationTarget[] targets,
Namespace namespace) {
for ( Sequence sequence : namespace.getSequences() ) {
if ( options.getSchemaFilter().includeSequence( sequence )
if ( schemaFilter.includeSequence( sequence )
&& contributableInclusionMatcher.matches( sequence ) ) {
checkExportIdentifier( sequence, exportIdentifiers);
applySqlStrings(
Expand Down Expand Up @@ -491,12 +500,13 @@ private static void createAuxiliaryObjectsBeforeTables(
private static void createUserDefinedTypes(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
Dialect dialect,
Formatter formatter,
SqlStringGenerationContext context,
GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
for ( UserDefinedType userDefinedType : namespace.getDependencyOrderedUserDefinedTypes() ) {
applySqlStrings(
dialect.getUserDefinedTypeExporter()
Expand All @@ -513,6 +523,7 @@ private static void createUserDefinedTypes(
private static void createSchemasAndCatalogs(
Metadata metadata,
ExecutionOptions options,
SchemaFilter schemaFilter,
Dialect dialect,
Formatter formatter,
SqlStringGenerationContext context,
Expand All @@ -523,7 +534,7 @@ private static void createSchemasAndCatalogs(
if ( tryToCreateCatalogs || tryToCreateSchemas ) {
Set<Identifier> exportedCatalogs = new HashSet<>();
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) {
if ( schemaFilter.includeNamespace( namespace ) ) {
Namespace.Name logicalName = namespace.getName();
Namespace.Name physicalName = namespace.getPhysicalName();

Expand Down Expand Up @@ -738,11 +749,6 @@ public Map<String,Object> getConfigurationValues() {
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerHaltImpl.INSTANCE;
}

@Override
public SchemaFilter getSchemaFilter() {
return schemaFilter;
}
};

createFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target );
Expand Down Expand Up @@ -798,11 +804,6 @@ public Map<String,Object> getConfigurationValues() {
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}

@Override
public SchemaFilter getSchemaFilter() {
return schemaFilter;
}
},
(contributed) -> true,
new SourceDescriptor() {
Expand Down

0 comments on commit c956208

Please sign in to comment.