HHH-17763 Rely on action-specific `SchemaFilter` instances

Deprecated `ExecutionOptions#getSchemaFilter` which was always returning the default implementation (not filtering anything)
This commit is contained in:
Marco Belladelli 2024-02-26 12:44:34 +01:00
parent 89dfa61b0c
commit c956208926
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
11 changed files with 82 additions and 75 deletions

View File

@ -244,7 +244,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
sqlGenerationContext, targets sqlGenerationContext, targets
); );
tablesInformation.put( namespace, nameSpaceTablesInformation ); tablesInformation.put( namespace, nameSpaceTablesInformation );
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
for ( Sequence sequence : namespace.getSequences() ) { for ( Sequence sequence : namespace.getSequences() ) {
if ( contributableInclusionFilter.matches( sequence ) ) { if ( contributableInclusionFilter.matches( sequence ) ) {
checkExportIdentifier( sequence, exportIdentifiers); checkExportIdentifier( sequence, exportIdentifiers);
@ -259,10 +259,10 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
//NOTE : Foreign keys must be created *after* all tables of all namespaces for cross namespace fks. see HHH-10420 //NOTE : Foreign keys must be created *after* all tables of all namespaces for cross namespace fks. see HHH-10420
for ( Namespace namespace : database.getNamespaces() ) { for ( Namespace namespace : database.getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
final NameSpaceTablesInformation nameSpaceTablesInformation = tablesInformation.get( namespace ); final NameSpaceTablesInformation nameSpaceTablesInformation = tablesInformation.get( namespace );
for ( Table table : namespace.getTables() ) { 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 ); final TableInformation tableInformation = nameSpaceTablesInformation.getTableInformation( table );
if ( tableInformation == null || tableInformation.isPhysicalTable() ) { if ( tableInformation == null || tableInformation.isPhysicalTable() ) {
applyForeignKeys( table, tableInformation, dialect, metadata, formatter, options, applyForeignKeys( table, tableInformation, dialect, metadata, formatter, options,

View File

@ -93,15 +93,15 @@ public abstract class AbstractSchemaValidator implements SchemaValidator {
ContributableMatcher contributableInclusionFilter, ContributableMatcher contributableInclusionFilter,
Dialect dialect) { Dialect dialect) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
validateTables( metadata, databaseInformation, options, contributableInclusionFilter, dialect, namespace ); validateTables( metadata, databaseInformation, options, contributableInclusionFilter, dialect, namespace );
} }
} }
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
for ( Sequence sequence : namespace.getSequences() ) { for ( Sequence sequence : namespace.getSequences() ) {
if ( ! options.getSchemaFilter().includeSequence( sequence ) ) { if ( !schemaFilter.includeSequence( sequence ) ) {
continue; continue;
} }

View File

@ -55,7 +55,7 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator {
final NameSpaceTablesInformation tablesInformation = final NameSpaceTablesInformation tablesInformation =
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() ); new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
createSchemaAndCatalog( createSchemaAndCatalog(
existingDatabase, existingDatabase,
options, options,
@ -71,7 +71,7 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator {
final NameSpaceTablesInformation tables = existingDatabase.getTablesInformation( namespace ); final NameSpaceTablesInformation tables = existingDatabase.getTablesInformation( namespace );
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable() && table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) { && contributableInclusionFilter.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers ); checkExportIdentifier( table, exportIdentifiers );
@ -88,7 +88,7 @@ public class GroupedSchemaMigratorImpl extends AbstractSchemaMigrator {
} }
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable() && table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) { && contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = tablesInformation.getTableInformation( table ); final TableInformation tableInformation = tablesInformation.getTableInformation( table );

View File

@ -40,7 +40,7 @@ public class GroupedSchemaValidatorImpl extends AbstractSchemaValidator {
final NameSpaceTablesInformation tables = databaseInformation.getTablesInformation( namespace ); final NameSpaceTablesInformation tables = databaseInformation.getTablesInformation( namespace );
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable() && table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) { && contributableInclusionFilter.matches( table ) ) {
validateTable( validateTable(

View File

@ -55,7 +55,7 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator {
final NameSpaceTablesInformation tablesInformation = final NameSpaceTablesInformation tablesInformation =
new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() ); new NameSpaceTablesInformation( metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper() );
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
createSchemaAndCatalog( createSchemaAndCatalog(
existingDatabase, existingDatabase,
options, options,
@ -69,7 +69,7 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator {
targets targets
); );
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable() && table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) { && contributableInclusionFilter.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers ); checkExportIdentifier( table, exportIdentifiers );
@ -86,7 +86,7 @@ public class IndividuallySchemaMigratorImpl extends AbstractSchemaMigrator {
} }
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable() && table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) { && contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = tablesInformation.getTableInformation( table ); final TableInformation tableInformation = tablesInformation.getTableInformation( table );

View File

@ -39,7 +39,7 @@ public class IndividuallySchemaValidatorImpl extends AbstractSchemaValidator {
Dialect dialect, Dialect dialect,
Namespace namespace) { Namespace namespace) {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& table.isPhysicalTable() && table.isPhysicalTable()
&& contributableInclusionFilter.matches( table ) ) { && contributableInclusionFilter.matches( table ) ) {
final TableInformation tableInformation = databaseInformation.getTableInformation( final TableInformation tableInformation = databaseInformation.getTableInformation(

View File

@ -230,15 +230,16 @@ public class SchemaCreatorImpl implements SchemaCreator {
final SqlStringGenerationContext context = createSqlStringGenerationContext(options, metadata); final SqlStringGenerationContext context = createSqlStringGenerationContext(options, metadata);
final Set<String> exportIdentifiers = setOfSize(50); 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 // next, create all "before table" auxiliary objects
createAuxiliaryObjectsBeforeTables(metadata, options, dialect, formatter, context, exportIdentifiers, targets); createAuxiliaryObjectsBeforeTables(metadata, options, dialect, formatter, context, exportIdentifiers, targets);
// next, create all UDTs // 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 // then, create all schema objects (tables, sequences, constraints, etc) in each schema
createSequencesTablesConstraints( createSequencesTablesConstraints(
metadata, metadata,
options, options,
schemaFilter,
contributableInclusionMatcher, contributableInclusionMatcher,
dialect, dialect,
formatter, formatter,
@ -247,7 +248,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
targets targets
); );
// foreign keys must be created after all tables of all namespaces for cross-namespace constraints (see HHH-10420) // 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 // next, create all "after table" auxiliary objects
createAuxiliaryObjectsAfterTables( metadata, options, dialect, formatter, context, exportIdentifiers, targets ); createAuxiliaryObjectsAfterTables( metadata, options, dialect, formatter, context, exportIdentifiers, targets );
// and finally add all init commands // and finally add all init commands
@ -287,6 +288,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createForeignKeys( private static void createForeignKeys(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher, ContributableMatcher contributableInclusionMatcher,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -294,9 +296,9 @@ public class SchemaCreatorImpl implements SchemaCreator {
GenerationTarget[] targets) { GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
// foreign keys must be created after unique keys for numerous DBs (see HHH-8390) // 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() ) { for ( Table table : namespace.getTables() ) {
if ( options.getSchemaFilter().includeTable( table ) if ( schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) { && contributableInclusionMatcher.matches( table ) ) {
// foreign keys // foreign keys
for ( ForeignKey foreignKey : table.getForeignKeys().values() ) { for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
@ -316,6 +318,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createSequencesTablesConstraints( private static void createSequencesTablesConstraints(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher, ContributableMatcher contributableInclusionMatcher,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -323,11 +326,12 @@ public class SchemaCreatorImpl implements SchemaCreator {
Set<String> exportIdentifiers, Set<String> exportIdentifiers,
GenerationTarget[] targets) { GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
// sequences // sequences
createSequences( createSequences(
metadata, metadata,
options, options,
schemaFilter,
contributableInclusionMatcher, contributableInclusionMatcher,
dialect, dialect,
formatter, formatter,
@ -340,6 +344,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
createTables( createTables(
metadata, metadata,
options, options,
schemaFilter,
contributableInclusionMatcher, contributableInclusionMatcher,
dialect, dialect,
formatter, formatter,
@ -351,6 +356,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
createTableConstraints( createTableConstraints(
metadata, metadata,
options, options,
schemaFilter,
contributableInclusionMatcher, contributableInclusionMatcher,
dialect, dialect,
formatter, formatter,
@ -366,6 +372,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createTableConstraints( private static void createTableConstraints(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher, ContributableMatcher contributableInclusionMatcher,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -375,7 +382,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
Namespace namespace) { Namespace namespace) {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable() if ( table.isPhysicalTable()
&& options.getSchemaFilter().includeTable( table ) && schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) { && contributableInclusionMatcher.matches( table ) ) {
// indexes // indexes
for ( Index index : table.getIndexes().values() ) { for ( Index index : table.getIndexes().values() ) {
@ -404,6 +411,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createTables( private static void createTables(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher, ContributableMatcher contributableInclusionMatcher,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -414,7 +422,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable() if ( table.isPhysicalTable()
&& !table.isView() && !table.isView()
&& options.getSchemaFilter().includeTable( table ) && schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) { && contributableInclusionMatcher.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers ); checkExportIdentifier( table, exportIdentifiers );
applySqlStrings( applySqlStrings(
@ -428,7 +436,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable() if ( table.isPhysicalTable()
&& table.isView() && table.isView()
&& options.getSchemaFilter().includeTable( table ) && schemaFilter.includeTable( table )
&& contributableInclusionMatcher.matches( table ) ) { && contributableInclusionMatcher.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers ); checkExportIdentifier( table, exportIdentifiers );
applySqlStrings( applySqlStrings(
@ -444,6 +452,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createSequences( private static void createSequences(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionMatcher, ContributableMatcher contributableInclusionMatcher,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -452,7 +461,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
GenerationTarget[] targets, GenerationTarget[] targets,
Namespace namespace) { Namespace namespace) {
for ( Sequence sequence : namespace.getSequences() ) { for ( Sequence sequence : namespace.getSequences() ) {
if ( options.getSchemaFilter().includeSequence( sequence ) if ( schemaFilter.includeSequence( sequence )
&& contributableInclusionMatcher.matches( sequence ) ) { && contributableInclusionMatcher.matches( sequence ) ) {
checkExportIdentifier( sequence, exportIdentifiers); checkExportIdentifier( sequence, exportIdentifiers);
applySqlStrings( applySqlStrings(
@ -491,12 +500,13 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createUserDefinedTypes( private static void createUserDefinedTypes(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
SqlStringGenerationContext context, SqlStringGenerationContext context,
GenerationTarget[] targets) { GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
for ( UserDefinedType userDefinedType : namespace.getDependencyOrderedUserDefinedTypes() ) { for ( UserDefinedType userDefinedType : namespace.getDependencyOrderedUserDefinedTypes() ) {
applySqlStrings( applySqlStrings(
dialect.getUserDefinedTypeExporter() dialect.getUserDefinedTypeExporter()
@ -513,6 +523,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
private static void createSchemasAndCatalogs( private static void createSchemasAndCatalogs(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
SqlStringGenerationContext context, SqlStringGenerationContext context,
@ -523,7 +534,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
if ( tryToCreateCatalogs || tryToCreateSchemas ) { if ( tryToCreateCatalogs || tryToCreateSchemas ) {
Set<Identifier> exportedCatalogs = new HashSet<>(); Set<Identifier> exportedCatalogs = new HashSet<>();
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
Namespace.Name logicalName = namespace.getName(); Namespace.Name logicalName = namespace.getName();
Namespace.Name physicalName = namespace.getPhysicalName(); Namespace.Name physicalName = namespace.getPhysicalName();
@ -738,11 +749,6 @@ public class SchemaCreatorImpl implements SchemaCreator {
public ExceptionHandler getExceptionHandler() { public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerHaltImpl.INSTANCE; return ExceptionHandlerHaltImpl.INSTANCE;
} }
@Override
public SchemaFilter getSchemaFilter() {
return schemaFilter;
}
}; };
createFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target ); createFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target );
@ -798,11 +804,6 @@ public class SchemaCreatorImpl implements SchemaCreator {
public ExceptionHandler getExceptionHandler() { public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE; return ExceptionHandlerLoggedImpl.INSTANCE;
} }
@Override
public SchemaFilter getSchemaFilter() {
return schemaFilter;
}
}, },
(contributed) -> true, (contributed) -> true,
new SourceDescriptor() { new SourceDescriptor() {

View File

@ -222,8 +222,8 @@ public class SchemaDropperImpl implements SchemaDropper {
targets targets
); );
dropAuxiliaryObjectsAfterTables( metadata, options, dialect, formatter, context, targets ); dropAuxiliaryObjectsAfterTables( metadata, options, dialect, formatter, context, targets );
dropUserDefinedTypes( metadata, options, dialect, formatter, context, targets ); dropUserDefinedTypes( metadata, options, schemaFilter, dialect, formatter, context, targets );
dropSchemasAndCatalogs( metadata, options, dialect, formatter, context, targets ); dropSchemasAndCatalogs( metadata, options, schemaFilter, dialect, formatter, context, targets );
} }
private void dropConstraintsTablesSequences( private void dropConstraintsTablesSequences(
@ -236,7 +236,7 @@ public class SchemaDropperImpl implements SchemaDropper {
GenerationTarget[] targets) { GenerationTarget[] targets) {
final Set<String> exportIdentifiers = setOfSize( 50 ); final Set<String> exportIdentifiers = setOfSize( 50 );
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
// we need to drop all constraints/indexes prior to dropping the tables // we need to drop all constraints/indexes prior to dropping the tables
applyConstraintDropping( applyConstraintDropping(
@ -253,6 +253,7 @@ public class SchemaDropperImpl implements SchemaDropper {
dropTables( dropTables(
metadata, metadata,
options, options,
schemaFilter,
inclusionFilter, inclusionFilter,
dialect, dialect,
formatter, formatter,
@ -265,6 +266,7 @@ public class SchemaDropperImpl implements SchemaDropper {
dropSequences( dropSequences(
metadata, metadata,
options, options,
schemaFilter,
inclusionFilter, inclusionFilter,
dialect, dialect,
formatter, formatter,
@ -323,6 +325,7 @@ public class SchemaDropperImpl implements SchemaDropper {
private static void dropSequences( private static void dropSequences(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher inclusionFilter, ContributableMatcher inclusionFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -331,7 +334,7 @@ public class SchemaDropperImpl implements SchemaDropper {
Namespace namespace, Namespace namespace,
GenerationTarget[] targets) { GenerationTarget[] targets) {
for ( Sequence sequence : namespace.getSequences() ) { for ( Sequence sequence : namespace.getSequences() ) {
if ( options.getSchemaFilter().includeSequence( sequence ) if ( schemaFilter.includeSequence( sequence )
&& inclusionFilter.matches( sequence ) ) { && inclusionFilter.matches( sequence ) ) {
checkExportIdentifier( sequence, exportIdentifiers); checkExportIdentifier( sequence, exportIdentifiers);
applySqlStrings( applySqlStrings(
@ -347,6 +350,7 @@ public class SchemaDropperImpl implements SchemaDropper {
private static void dropTables( private static void dropTables(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher inclusionFilter, ContributableMatcher inclusionFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -357,7 +361,7 @@ public class SchemaDropperImpl implements SchemaDropper {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable() if ( table.isPhysicalTable()
&& table.isView() && table.isView()
&& options.getSchemaFilter().includeTable( table ) && schemaFilter.includeTable( table )
&& inclusionFilter.matches( table ) ) { && inclusionFilter.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers); checkExportIdentifier( table, exportIdentifiers);
applySqlStrings( applySqlStrings(
@ -371,7 +375,7 @@ public class SchemaDropperImpl implements SchemaDropper {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable() if ( table.isPhysicalTable()
&& !table.isView() && !table.isView()
&& options.getSchemaFilter().includeTable( table ) && schemaFilter.includeTable( table )
&& inclusionFilter.matches( table ) ) { && inclusionFilter.matches( table ) ) {
checkExportIdentifier( table, exportIdentifiers); checkExportIdentifier( table, exportIdentifiers);
applySqlStrings( applySqlStrings(
@ -387,12 +391,13 @@ public class SchemaDropperImpl implements SchemaDropper {
private static void dropUserDefinedTypes( private static void dropUserDefinedTypes(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
SqlStringGenerationContext context, SqlStringGenerationContext context,
GenerationTarget[] targets) { GenerationTarget[] targets) {
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
final List<UserDefinedType> dependencyOrderedUserDefinedTypes = namespace.getDependencyOrderedUserDefinedTypes(); final List<UserDefinedType> dependencyOrderedUserDefinedTypes = namespace.getDependencyOrderedUserDefinedTypes();
Collections.reverse( dependencyOrderedUserDefinedTypes ); Collections.reverse( dependencyOrderedUserDefinedTypes );
for ( UserDefinedType userDefinedType : dependencyOrderedUserDefinedTypes ) { for ( UserDefinedType userDefinedType : dependencyOrderedUserDefinedTypes ) {
@ -411,6 +416,7 @@ public class SchemaDropperImpl implements SchemaDropper {
private static void dropSchemasAndCatalogs( private static void dropSchemasAndCatalogs(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
SqlStringGenerationContext context, SqlStringGenerationContext context,
@ -420,7 +426,7 @@ public class SchemaDropperImpl implements SchemaDropper {
if ( tryToDropCatalogs || tryToDropSchemas) { if ( tryToDropCatalogs || tryToDropSchemas) {
final Set<Identifier> exportedCatalogs = new HashSet<>(); final Set<Identifier> exportedCatalogs = new HashSet<>();
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) { for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
if ( options.getSchemaFilter().includeNamespace( namespace ) ) { if ( schemaFilter.includeNamespace( namespace ) ) {
Namespace.Name logicalName = namespace.getName(); Namespace.Name logicalName = namespace.getName();
Namespace.Name physicalName = namespace.getPhysicalName(); Namespace.Name physicalName = namespace.getPhysicalName();
@ -464,7 +470,7 @@ public class SchemaDropperImpl implements SchemaDropper {
if ( dialect.dropConstraints() ) { if ( dialect.dropConstraints() ) {
for ( Table table : namespace.getTables() ) { for ( Table table : namespace.getTables() ) {
if ( table.isPhysicalTable() if ( table.isPhysicalTable()
&& options.getSchemaFilter().includeTable( table ) && schemaFilter.includeTable( table )
&& inclusionFilter.matches( table ) ) { && inclusionFilter.matches( table ) ) {
for ( ForeignKey foreignKey : table.getForeignKeys().values() ) { for ( ForeignKey foreignKey : table.getForeignKeys().values() ) {
applySqlStrings( applySqlStrings(
@ -552,11 +558,6 @@ public class SchemaDropperImpl implements SchemaDropper {
public ExceptionHandler getExceptionHandler() { public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE; return ExceptionHandlerLoggedImpl.INSTANCE;
} }
@Override
public SchemaFilter getSchemaFilter() {
return schemaFilter;
}
}, },
(contributed) -> true, (contributed) -> true,
serviceRegistry.getService( JdbcEnvironment.class ).getDialect(), serviceRegistry.getService( JdbcEnvironment.class ).getDialect(),

View File

@ -58,9 +58,11 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
private static final Logger log = Logger.getLogger( SchemaTruncatorImpl.class ); private static final Logger log = Logger.getLogger( SchemaTruncatorImpl.class );
private final HibernateSchemaManagementTool tool; private final HibernateSchemaManagementTool tool;
private final SchemaFilter schemaFilter;
public SchemaTruncatorImpl(HibernateSchemaManagementTool tool, SchemaFilter truncatorFilter) { public SchemaTruncatorImpl(HibernateSchemaManagementTool tool, SchemaFilter truncatorFilter) {
this.tool = tool; this.tool = tool;
schemaFilter = truncatorFilter;
} }
@Override @Override
@ -111,12 +113,13 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
final boolean format = Helper.interpretFormattingEnabled( options.getConfigurationValues() ); final boolean format = Helper.interpretFormattingEnabled( options.getConfigurationValues() );
final Formatter formatter = format ? FormatStyle.DDL.getFormatter() : FormatStyle.NONE.getFormatter(); final Formatter formatter = format ? FormatStyle.DDL.getFormatter() : FormatStyle.NONE.getFormatter();
truncateFromMetadata( metadata, options, contributableInclusionFilter, dialect, formatter, targets ); truncateFromMetadata( metadata, options, schemaFilter, contributableInclusionFilter, dialect, formatter, targets );
} }
private void truncateFromMetadata( private void truncateFromMetadata(
Metadata metadata, Metadata metadata,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
ContributableMatcher contributableInclusionFilter, ContributableMatcher contributableInclusionFilter,
Dialect dialect, Dialect dialect,
Formatter formatter, Formatter formatter,
@ -128,11 +131,11 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
for ( Namespace namespace : database.getNamespaces() ) { for ( Namespace namespace : database.getNamespaces() ) {
if ( ! options.getSchemaFilter().includeNamespace( namespace ) ) { if ( ! schemaFilter.includeNamespace( namespace ) ) {
continue; continue;
} }
disableConstraints( namespace, metadata, formatter, options, context, disableConstraints( namespace, metadata, formatter, options, schemaFilter, context,
contributableInclusionFilter, targets ); contributableInclusionFilter, targets );
applySqlString( dialect.getTableCleaner().getSqlBeforeString(), formatter, options,targets ); applySqlString( dialect.getTableCleaner().getSqlBeforeString(), formatter, options,targets );
@ -142,7 +145,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
if ( ! table.isPhysicalTable() ) { if ( ! table.isPhysicalTable() ) {
continue; continue;
} }
if ( ! options.getSchemaFilter().includeTable( table ) ) { if ( ! schemaFilter.includeTable( table ) ) {
continue; continue;
} }
if ( ! contributableInclusionFilter.matches( table ) ) { if ( ! contributableInclusionFilter.matches( table ) ) {
@ -172,7 +175,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
// } // }
applySqlString( dialect.getTableCleaner().getSqlAfterString(), formatter, options,targets ); applySqlString( dialect.getTableCleaner().getSqlAfterString(), formatter, options,targets );
enableConstraints( namespace, metadata, formatter, options, context, enableConstraints( namespace, metadata, formatter, options, schemaFilter, context,
contributableInclusionFilter, targets ); contributableInclusionFilter, targets );
} }
@ -186,6 +189,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
Metadata metadata, Metadata metadata,
Formatter formatter, Formatter formatter,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
SqlStringGenerationContext context, SqlStringGenerationContext context,
ContributableMatcher contributableInclusionFilter, ContributableMatcher contributableInclusionFilter,
GenerationTarget... targets) { GenerationTarget... targets) {
@ -195,7 +199,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
if ( !table.isPhysicalTable() ) { if ( !table.isPhysicalTable() ) {
continue; continue;
} }
if ( ! options.getSchemaFilter().includeTable( table ) ) { if ( ! schemaFilter.includeTable( table ) ) {
continue; continue;
} }
if ( ! contributableInclusionFilter.matches( table ) ) { if ( ! contributableInclusionFilter.matches( table ) ) {
@ -232,6 +236,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
Metadata metadata, Metadata metadata,
Formatter formatter, Formatter formatter,
ExecutionOptions options, ExecutionOptions options,
SchemaFilter schemaFilter,
SqlStringGenerationContext context, SqlStringGenerationContext context,
ContributableMatcher contributableInclusionFilter, ContributableMatcher contributableInclusionFilter,
GenerationTarget... targets) { GenerationTarget... targets) {
@ -241,7 +246,7 @@ public class SchemaTruncatorImpl implements SchemaTruncator {
if ( !table.isPhysicalTable() ) { if ( !table.isPhysicalTable() ) {
continue; continue;
} }
if ( ! options.getSchemaFilter().includeTable( table ) ) { if ( ! schemaFilter.includeTable( table ) ) {
continue; continue;
} }
if ( ! contributableInclusionFilter.matches( table ) ) { if ( ! contributableInclusionFilter.matches( table ) ) {

View File

@ -24,5 +24,11 @@ public interface ExecutionOptions {
ExceptionHandler getExceptionHandler(); ExceptionHandler getExceptionHandler();
SchemaFilter getSchemaFilter(); /**
* @deprecated No longer used, see {@link org.hibernate.cfg.SchemaToolingSettings#HBM2DDL_FILTER_PROVIDER}
*/
@Deprecated( forRemoval = true )
default SchemaFilter getSchemaFilter() {
throw new UnsupportedOperationException();
}
} }

View File

@ -23,7 +23,6 @@ import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.Action; import org.hibernate.tool.schema.Action;
import org.hibernate.tool.schema.SourceType; import org.hibernate.tool.schema.SourceType;
import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.TargetType;
import org.hibernate.tool.schema.internal.DefaultSchemaFilter;
import org.hibernate.tool.schema.internal.ExceptionHandlerHaltImpl; import org.hibernate.tool.schema.internal.ExceptionHandlerHaltImpl;
import org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl; import org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl;
import org.hibernate.tool.schema.internal.Helper; import org.hibernate.tool.schema.internal.Helper;
@ -173,17 +172,6 @@ public class SchemaManagementToolCoordinator {
public static ExecutionOptions buildExecutionOptions( public static ExecutionOptions buildExecutionOptions(
final Map<String,Object> configurationValues, final Map<String,Object> configurationValues,
final ExceptionHandler exceptionHandler) { final ExceptionHandler exceptionHandler) {
return buildExecutionOptions(
configurationValues,
DefaultSchemaFilter.INSTANCE,
exceptionHandler
);
}
public static ExecutionOptions buildExecutionOptions(
final Map<String,Object> configurationValues,
final SchemaFilter schemaFilter,
final ExceptionHandler exceptionHandler) {
return new ExecutionOptions() { return new ExecutionOptions() {
@Override @Override
public boolean shouldManageNamespaces() { public boolean shouldManageNamespaces() {
@ -199,14 +187,20 @@ public class SchemaManagementToolCoordinator {
public ExceptionHandler getExceptionHandler() { public ExceptionHandler getExceptionHandler() {
return exceptionHandler; return exceptionHandler;
} }
@Override
public SchemaFilter getSchemaFilter() {
return schemaFilter;
}
}; };
} }
/**
* @deprecated Use {@link #buildExecutionOptions(Map, ExceptionHandler)} instead.
*/
@Deprecated(forRemoval = true)
public static ExecutionOptions buildExecutionOptions(
final Map<String,Object> configurationValues,
final SchemaFilter schemaFilter,
final ExceptionHandler exceptionHandler) {
return buildExecutionOptions( configurationValues, exceptionHandler );
}
private static void performDatabaseAction( private static void performDatabaseAction(
final Action action, final Action action,
Metadata metadata, Metadata metadata,