Skip to content

Commit

Permalink
very tiny refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Dec 13, 2024
1 parent d26e613 commit 7fa22d3
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@

import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.schema.spi.SchemaManagementTool;

import static org.hibernate.cfg.SchemaToolingSettings.SCHEMA_MANAGEMENT_TOOL;

/**
* @author Steve Ebersole
*/
public class SchemaManagementToolInitiator implements StandardServiceInitiator<SchemaManagementTool> {
public static final SchemaManagementToolInitiator INSTANCE = new SchemaManagementToolInitiator();

public SchemaManagementTool initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final Object setting = configurationValues.get( AvailableSettings.SCHEMA_MANAGEMENT_TOOL );
SchemaManagementTool tool =
registry.requireService( StrategySelector.class )
.resolveStrategy( SchemaManagementTool.class, setting );
if ( tool == null ) {
tool = registry.requireService( JdbcServices.class ).getDialect()
.getFallbackSchemaManagementTool( configurationValues, registry );
}

return tool;
public SchemaManagementTool initiateService(
Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final SchemaManagementTool tool = configuredTool( configurationValues, registry );
return tool == null
? getDialect( registry ).getFallbackSchemaManagementTool( configurationValues, registry )
: tool;
}

private static SchemaManagementTool configuredTool(
Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
return registry.requireService( StrategySelector.class )
.resolveStrategy( SchemaManagementTool.class, configurationValues.get( SCHEMA_MANAGEMENT_TOOL ) );
}

private static Dialect getDialect(ServiceRegistryImplementor registry) {
return registry.requireService( JdbcServices.class ).getDialect();
}

@Override
Expand Down

0 comments on commit 7fa22d3

Please sign in to comment.