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:
parent
cb4909a5e1
commit
137c524a14
|
@ -56,6 +56,7 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
|
||||||
private static final Logger log = Logger.getLogger( HibernateSchemaManagementTool.class );
|
private static final Logger log = Logger.getLogger( HibernateSchemaManagementTool.class );
|
||||||
|
|
||||||
private ServiceRegistry serviceRegistry;
|
private ServiceRegistry serviceRegistry;
|
||||||
|
private GenerationTarget customTarget;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
|
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
|
||||||
|
@ -107,6 +108,15 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
|
||||||
return JdbcMetadaAccessStrategy.interpretSetting( options );
|
return JdbcMetadaAccessStrategy.interpretSetting( options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCustomDatabaseGenerationTarget(GenerationTarget generationTarget) {
|
||||||
|
this.customTarget = generationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerationTarget getCustomDatabaseGenerationTarget() {
|
||||||
|
return customTarget;
|
||||||
|
}
|
||||||
|
|
||||||
GenerationTarget[] buildGenerationTargets(
|
GenerationTarget[] buildGenerationTargets(
|
||||||
TargetDescriptor targetDescriptor,
|
TargetDescriptor targetDescriptor,
|
||||||
JdbcContext jdbcContext,
|
JdbcContext jdbcContext,
|
||||||
|
@ -132,7 +142,10 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( targetDescriptor.getTargetTypes().contains( TargetType.DATABASE ) ) {
|
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;
|
return targets;
|
||||||
|
|
|
@ -423,7 +423,7 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
SourceDescriptor sourceDescriptor) {
|
SourceDescriptor sourceDescriptor) {
|
||||||
final JournalingGenerationTarget target = new JournalingGenerationTarget();
|
final JournalingGenerationTarget target = new JournalingGenerationTarget();
|
||||||
doDrop( metadata, options, tool.getServiceRegistry().getService( JdbcEnvironment.class ).getDialect(), sourceDescriptor, target );
|
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 static final CoreMessageLogger log = CoreLogging.messageLogger( DelayedDropActionImpl.class );
|
||||||
|
|
||||||
private final ArrayList<String> commands;
|
private final ArrayList<String> commands;
|
||||||
|
private GenerationTarget target;
|
||||||
|
|
||||||
public DelayedDropActionImpl(ArrayList<String> commands) {
|
public DelayedDropActionImpl(ArrayList<String> commands, GenerationTarget target) {
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -524,10 +526,14 @@ public class SchemaDropperImpl implements SchemaDropper {
|
||||||
log.startingDelayedSchemaDrop();
|
log.startingDelayedSchemaDrop();
|
||||||
|
|
||||||
final JdbcContext jdbcContext = new JdbcContextDelayedDropImpl( serviceRegistry );
|
final JdbcContext jdbcContext = new JdbcContextDelayedDropImpl( serviceRegistry );
|
||||||
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(
|
|
||||||
serviceRegistry.getService( TransactionCoordinatorBuilder.class ).buildDdlTransactionIsolator( jdbcContext ),
|
if ( target == null ) {
|
||||||
true
|
target = new GenerationTargetToDatabase(
|
||||||
);
|
serviceRegistry.getService( TransactionCoordinatorBuilder.class )
|
||||||
|
.buildDdlTransactionIsolator( jdbcContext ),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
target.prepare();
|
target.prepare();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.Incubating;
|
import org.hibernate.Incubating;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
|
import org.hibernate.tool.schema.internal.exec.GenerationTarget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract for schema management tool integration.
|
* Contract for schema management tool integration.
|
||||||
|
@ -22,4 +23,5 @@ public interface SchemaManagementTool extends Service {
|
||||||
SchemaDropper getSchemaDropper(Map options);
|
SchemaDropper getSchemaDropper(Map options);
|
||||||
SchemaMigrator getSchemaMigrator(Map options);
|
SchemaMigrator getSchemaMigrator(Map options);
|
||||||
SchemaValidator getSchemaValidator(Map options);
|
SchemaValidator getSchemaValidator(Map options);
|
||||||
|
void setCustomDatabaseGenerationTarget(GenerationTarget generationTarget);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue