HHH-14019 Allow customizing the Database target in the Schema Management tool

Add an API allowing Hibernate Reactive to plug in to schema export:
we've decided that HR should not use JDBC for schema export
This commit is contained in:
gavinking 2020-05-13 20:57:28 +02:00 committed by Sanne Grinovero
parent cb4909a5e1
commit 137c524a14
3 changed files with 28 additions and 7 deletions

View File

@ -56,6 +56,7 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
private static final Logger log = Logger.getLogger( HibernateSchemaManagementTool.class );
private ServiceRegistry serviceRegistry;
private GenerationTarget customTarget;
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
@ -107,6 +108,15 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
return JdbcMetadaAccessStrategy.interpretSetting( options );
}
@Override
public void setCustomDatabaseGenerationTarget(GenerationTarget generationTarget) {
this.customTarget = generationTarget;
}
GenerationTarget getCustomDatabaseGenerationTarget() {
return customTarget;
}
GenerationTarget[] buildGenerationTargets(
TargetDescriptor targetDescriptor,
JdbcContext jdbcContext,
@ -132,7 +142,10 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
}
if ( targetDescriptor.getTargetTypes().contains( TargetType.DATABASE ) ) {
targets[index] = new GenerationTargetToDatabase( getDdlTransactionIsolator( jdbcContext ), true );
targets[index] = customTarget == null
? new GenerationTargetToDatabase( getDdlTransactionIsolator( jdbcContext ), true )
: customTarget;
index++;
}
return targets;

View File

@ -423,7 +423,7 @@ public class SchemaDropperImpl implements SchemaDropper {
SourceDescriptor sourceDescriptor) {
final JournalingGenerationTarget target = new JournalingGenerationTarget();
doDrop( metadata, options, tool.getServiceRegistry().getService( JdbcEnvironment.class ).getDialect(), sourceDescriptor, target );
return new DelayedDropActionImpl( target.commands );
return new DelayedDropActionImpl( target.commands, tool.getCustomDatabaseGenerationTarget() );
}
/**
@ -514,9 +514,11 @@ public class SchemaDropperImpl implements SchemaDropper {
private static final CoreMessageLogger log = CoreLogging.messageLogger( DelayedDropActionImpl.class );
private final ArrayList<String> commands;
private GenerationTarget target;
public DelayedDropActionImpl(ArrayList<String> commands) {
public DelayedDropActionImpl(ArrayList<String> commands, GenerationTarget target) {
this.commands = commands;
this.target = target;
}
@Override
@ -524,10 +526,14 @@ public class SchemaDropperImpl implements SchemaDropper {
log.startingDelayedSchemaDrop();
final JdbcContext jdbcContext = new JdbcContextDelayedDropImpl( serviceRegistry );
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(
serviceRegistry.getService( TransactionCoordinatorBuilder.class ).buildDdlTransactionIsolator( jdbcContext ),
true
);
if ( target == null ) {
target = new GenerationTargetToDatabase(
serviceRegistry.getService( TransactionCoordinatorBuilder.class )
.buildDdlTransactionIsolator( jdbcContext ),
true
);
}
target.prepare();
try {

View File

@ -10,6 +10,7 @@ import java.util.Map;
import org.hibernate.Incubating;
import org.hibernate.service.Service;
import org.hibernate.tool.schema.internal.exec.GenerationTarget;
/**
* Contract for schema management tool integration.
@ -22,4 +23,5 @@ public interface SchemaManagementTool extends Service {
SchemaDropper getSchemaDropper(Map options);
SchemaMigrator getSchemaMigrator(Map options);
SchemaValidator getSchemaValidator(Map options);
void setCustomDatabaseGenerationTarget(GenerationTarget generationTarget);
}