From 8aae155c50fa3e26daa59be41ab2c8a05fb57d72 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 29 Jul 2021 14:08:30 -0700 Subject: [PATCH] HHH-14744 : Refactor contextual information for SchemaManagementTool to be more easily extended by Hibernate Reactive Move new methods out of SchemaManagementTool and into ExtractionTool --- .../internal/DatabaseInformationImpl.java | 7 ++-- .../HibernateSchemaManagementTool.java | 42 +++++++++++++++++++ .../tool/schema/spi/ExtractionTool.java | 30 +++++++++++++ .../tool/schema/spi/SchemaManagementTool.java | 32 +------------- 4 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ExtractionTool.java diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java index 7d968b92dc..9af4d368df 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java @@ -34,7 +34,7 @@ public class DatabaseInformationImpl private final ExtractionContext extractionContext; private final InformationExtractor extractor; - private final Map sequenceInformationMap = new HashMap(); + private final Map sequenceInformationMap = new HashMap<>(); public DatabaseInformationImpl( ServiceRegistry serviceRegistry, @@ -43,7 +43,7 @@ public class DatabaseInformationImpl Namespace.Name defaultNamespace, SchemaManagementTool tool) throws SQLException { this.jdbcEnvironment = jdbcEnvironment; - this.extractionContext = tool.createExtractionContext( + this.extractionContext = tool.getExtractionTool().createExtractionContext( serviceRegistry, jdbcEnvironment, ddlTransactionIsolator, @@ -52,8 +52,7 @@ public class DatabaseInformationImpl this ); - // todo : make this pluggable - this.extractor = tool.createInformationExtractor( extractionContext ); + this.extractor = tool.getExtractionTool().createInformationExtractor( extractionContext ); // because we do not have defined a way to locate sequence info by name initializeSequences(); diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java index 2fea2a4d71..7741de5d8f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java @@ -9,12 +9,14 @@ package org.hibernate.tool.schema.internal; import java.sql.Connection; import java.util.Map; +import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; import org.hibernate.engine.jdbc.spi.SqlStatementLogger; @@ -27,12 +29,17 @@ import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.tool.schema.JdbcMetadaAccessStrategy; import org.hibernate.tool.schema.TargetType; +import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl; +import org.hibernate.tool.schema.extract.spi.ExtractionContext; +import org.hibernate.tool.schema.extract.spi.InformationExtractor; import org.hibernate.tool.schema.internal.exec.GenerationTarget; import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase; import org.hibernate.tool.schema.internal.exec.GenerationTargetToScript; import org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout; +import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl; import org.hibernate.tool.schema.internal.exec.JdbcConnectionAccessProvidedConnectionImpl; import org.hibernate.tool.schema.internal.exec.JdbcContext; +import org.hibernate.tool.schema.spi.ExtractionTool; import org.hibernate.tool.schema.spi.SchemaCreator; import org.hibernate.tool.schema.spi.SchemaDropper; import org.hibernate.tool.schema.spi.SchemaFilterProvider; @@ -114,6 +121,11 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv this.customTarget = generationTarget; } + @Override + public ExtractionTool getExtractionTool() { + return HibernateExtractionTool.INSTANCE; + } + GenerationTarget getCustomDatabaseGenerationTarget() { return customTarget; } @@ -352,4 +364,34 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv } } + private static class HibernateExtractionTool implements ExtractionTool { + + private static final HibernateExtractionTool INSTANCE = new HibernateExtractionTool(); + + private HibernateExtractionTool() { + } + + @Override + public ExtractionContext createExtractionContext( + ServiceRegistry serviceRegistry, + JdbcEnvironment jdbcEnvironment, + DdlTransactionIsolator ddlTransactionIsolator, + Identifier defaultCatalog, + Identifier defaultSchema, + ExtractionContext.DatabaseObjectAccess databaseObjectAccess) { + return new ImprovedExtractionContextImpl( + serviceRegistry, + jdbcEnvironment, + ddlTransactionIsolator, + defaultCatalog, + defaultSchema, + databaseObjectAccess + ); + } + + @Override + public InformationExtractor createInformationExtractor(ExtractionContext extractionContext) { + return new InformationExtractorJdbcDatabaseMetaDataImpl( extractionContext ); + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ExtractionTool.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ExtractionTool.java new file mode 100644 index 0000000000..2b7da672ac --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ExtractionTool.java @@ -0,0 +1,30 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.tool.schema.spi; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.hibernate.resource.transaction.spi.DdlTransactionIsolator; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.tool.schema.extract.spi.ExtractionContext; +import org.hibernate.tool.schema.extract.spi.InformationExtractor; + +/** + * @author Gail Badner + */ +public interface ExtractionTool { + + ExtractionContext createExtractionContext( + ServiceRegistry serviceRegistry, + JdbcEnvironment jdbcEnvironment, + DdlTransactionIsolator ddlTransactionIsolator, + Identifier defaultCatalog, + Identifier defaultSchema, + ExtractionContext.DatabaseObjectAccess databaseObjectAccess); + + InformationExtractor createInformationExtractor(ExtractionContext extractionContext); +} diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementTool.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementTool.java index 8d046383fe..9fc88b8e56 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementTool.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementTool.java @@ -7,21 +7,10 @@ package org.hibernate.tool.schema.spi; import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Function; import org.hibernate.Incubating; -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.model.relational.Namespace; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.resource.transaction.spi.DdlTransactionIsolator; import org.hibernate.service.Service; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl; -import org.hibernate.tool.schema.extract.spi.ExtractionContext; -import org.hibernate.tool.schema.extract.spi.InformationExtractor; import org.hibernate.tool.schema.internal.exec.GenerationTarget; -import org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl; /** * Contract for schema management tool integration. @@ -44,24 +33,5 @@ public interface SchemaManagementTool extends Service { */ void setCustomDatabaseGenerationTarget(GenerationTarget generationTarget); - default ExtractionContext createExtractionContext( - ServiceRegistry serviceRegistry, - JdbcEnvironment jdbcEnvironment, - DdlTransactionIsolator ddlTransactionIsolator, - Identifier defaultCatalog, - Identifier defaultSchema, - ExtractionContext.DatabaseObjectAccess databaseObjectAccess) { - return new ImprovedExtractionContextImpl( - serviceRegistry, - jdbcEnvironment, - ddlTransactionIsolator, - defaultCatalog, - defaultSchema, - databaseObjectAccess - ); - } - - default InformationExtractor createInformationExtractor(ExtractionContext extractionContext) { - return new InformationExtractorJdbcDatabaseMetaDataImpl( extractionContext ); - } + ExtractionTool getExtractionTool(); }