HHH-14744 : Refactor contextual information for SchemaManagementTool to be more easily extended by Hibernate Reactive
Move new methods out of SchemaManagementTool and into ExtractionTool
This commit is contained in:
parent
800436ee88
commit
8aae155c50
|
@ -34,7 +34,7 @@ public class DatabaseInformationImpl
|
|||
private final ExtractionContext extractionContext;
|
||||
private final InformationExtractor extractor;
|
||||
|
||||
private final Map<QualifiedSequenceName, SequenceInformation> sequenceInformationMap = new HashMap<QualifiedSequenceName, SequenceInformation>();
|
||||
private final Map<QualifiedSequenceName, SequenceInformation> 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();
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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);
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue