Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some cleanups and javadoc around SchemaManager #9141

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
*
* @see org.hibernate.SessionFactory#getSchemaManager()
*
* @apiNote This interface was added to JPA 3.2 as
* {@link jakarta.persistence.SchemaManager}, which it now inherits,
* with a minor change to the naming of its operations. It is retained
* for backward compatibility and as a place to define additional
* functionality in the future.
*
* @since 6.2
* @author Gavin King
*/
Expand All @@ -27,6 +33,8 @@ public interface SchemaManager extends jakarta.persistence.SchemaManager {
*
* @param createSchemas if {@code true}, attempt to create schemas,
* otherwise, assume the schemas already exist
*
* @apiNote This operation is a synonym for {@link #create}.
*/
void exportMappedObjects(boolean createSchemas);

Expand All @@ -38,6 +46,8 @@ public interface SchemaManager extends jakarta.persistence.SchemaManager {
*
* @param dropSchemas if {@code true}, drop schemas,
* otherwise, leave them be
*
* @apiNote This operation is a synonym for {@link #drop}.
*/
void dropMappedObjects(boolean dropSchemas);

Expand All @@ -46,6 +56,8 @@ public interface SchemaManager extends jakarta.persistence.SchemaManager {
* have the expected definitions.
* <p>
* Programmatic way to run {@link org.hibernate.tool.schema.spi.SchemaValidator}.
*
* @apiNote This operation is a synonym for {@link #validate}.
*/
void validateMappedObjects();

Expand All @@ -56,16 +68,8 @@ public interface SchemaManager extends jakarta.persistence.SchemaManager {
* load script}.
* <p>
* Programmatic way to run {@link org.hibernate.tool.schema.spi.SchemaTruncator}.
*
* @apiNote This operation is a synonym for {@link #truncate}.
*/
void truncateMappedObjects();

@Override
default void create(boolean createSchemas) {
exportMappedObjects( createSchemas );
}

@Override
default void drop(boolean dropSchemas) {
dropMappedObjects( dropSchemas );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void truncateMappedObjects() {
);
}

@Override
public void create(boolean createSchemas) {
exportMappedObjects( createSchemas );
}

@Override
public void drop(boolean dropSchemas) {
dropMappedObjects( dropSchemas );
}

@Override
public void validate() throws SchemaValidationException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.config.ConfigurationHelper;

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

/**
* Determines how JDBC metadata is read by the schema management tooling.
*
Expand Down Expand Up @@ -39,7 +41,7 @@ public String toString() {
return super.toString().toLowerCase(Locale.ROOT);
}

public static JdbcMetadaAccessStrategy interpretSetting(Map options) {
public static JdbcMetadaAccessStrategy interpretSetting(Map<String,Object> options) {
if ( options == null ) {
return interpretHbm2ddlSetting( null );
}
Expand All @@ -48,7 +50,7 @@ else if ( ConfigurationHelper.getBoolean( AvailableSettings.ENABLE_SYNONYMS, opt
return INDIVIDUALLY;
}
else {
return interpretHbm2ddlSetting( options.get( AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY ) );
return interpretHbm2ddlSetting( options.get( HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY ) );
}
}

Expand All @@ -66,7 +68,7 @@ public static JdbcMetadaAccessStrategy interpretHbm2ddlSetting(Object value) {
return strategy;
}
}
throw new IllegalArgumentException( "Unrecognized '" + AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY + "' value: '" + value + "'");
throw new IllegalArgumentException( "Unrecognized '" + HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY + "' value: '" + value + "'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.hibernate.boot.model.relational.SqlStringGenerationContext;
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;
Expand All @@ -18,7 +17,6 @@
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
Expand All @@ -40,6 +38,7 @@
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.SchemaFilter;
import org.hibernate.tool.schema.spi.SchemaFilterProvider;
import org.hibernate.tool.schema.spi.SchemaManagementException;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
Expand All @@ -61,8 +60,11 @@
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DB_MINOR_VERSION;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DB_NAME;
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION;
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_FILTER_PROVIDER;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
import static org.hibernate.internal.util.StringHelper.isEmpty;
import static org.hibernate.internal.util.StringHelper.isNotEmpty;

/**
* The standard Hibernate implementation of {@link SchemaManagementTool}
Expand Down Expand Up @@ -101,33 +103,25 @@ public SchemaTruncator getSchemaTruncator(Map<String,Object> options) {

@Override
public SchemaMigrator getSchemaMigrator(Map<String,Object> options) {
if ( determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED ) {
return new GroupedSchemaMigratorImpl( this, getSchemaFilterProvider( options ).getMigrateFilter() );
}
else {
return new IndividuallySchemaMigratorImpl( this, getSchemaFilterProvider( options ).getMigrateFilter() );
}
final SchemaFilter migrateFilter = getSchemaFilterProvider( options ).getMigrateFilter();
return determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED
? new GroupedSchemaMigratorImpl( this, migrateFilter )
: new IndividuallySchemaMigratorImpl( this, migrateFilter );
}

@Override
public SchemaValidator getSchemaValidator(Map<String,Object> options) {
if ( determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED ) {
return new GroupedSchemaValidatorImpl( this, getSchemaFilterProvider( options ).getValidateFilter() );
}
else {
return new IndividuallySchemaValidatorImpl( this, getSchemaFilterProvider( options ).getValidateFilter() );
}
final SchemaFilter validateFilter = getSchemaFilterProvider( options ).getValidateFilter();
return determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED
? new GroupedSchemaValidatorImpl( this, validateFilter )
: new IndividuallySchemaValidatorImpl( this, validateFilter );
}

private SchemaFilterProvider getSchemaFilterProvider(Map<String,Object> options) {
final Object configuredOption = (options == null)
? null
: options.get( AvailableSettings.HBM2DDL_FILTER_PROVIDER );
return serviceRegistry.requireService( StrategySelector.class ).resolveDefaultableStrategy(
SchemaFilterProvider.class,
configuredOption,
DefaultSchemaFilterProvider.INSTANCE
);
return serviceRegistry.requireService( StrategySelector.class )
.resolveDefaultableStrategy( SchemaFilterProvider.class,
options == null ? null : options.get( HBM2DDL_FILTER_PROVIDER ),
DefaultSchemaFilterProvider.INSTANCE );
}

private JdbcMetadaAccessStrategy determineJdbcMetadaAccessStrategy(Map<String,Object> options) {
Expand Down Expand Up @@ -259,7 +253,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_NAME ),
() -> {
final String name = (String) configurationValues.get( DIALECT_DB_NAME );
if ( StringHelper.isNotEmpty( name ) ) {
if ( isNotEmpty( name ) ) {
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_NAME, JAKARTA_HBM2DDL_DB_NAME );
}
return name;
Expand All @@ -270,7 +264,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_VERSION ),
() -> {
final String name = (String) configurationValues.get( DIALECT_DB_VERSION );
if ( StringHelper.isNotEmpty( name ) ) {
if ( isNotEmpty( name ) ) {
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_VERSION, JAKARTA_HBM2DDL_DB_VERSION );
}
return name;
Expand All @@ -281,7 +275,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_MAJOR_VERSION ),
() -> {
final String name = (String) configurationValues.get( DIALECT_DB_MAJOR_VERSION );
if ( StringHelper.isNotEmpty( name ) ) {
if ( isNotEmpty( name ) ) {
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_MAJOR_VERSION, JAKARTA_HBM2DDL_DB_MAJOR_VERSION );
}
return name;
Expand All @@ -292,7 +286,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_MINOR_VERSION ),
() -> {
final String name = (String) configurationValues.get( DIALECT_DB_MINOR_VERSION );
if ( StringHelper.isNotEmpty( name ) ) {
if ( isNotEmpty( name ) ) {
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_MINOR_VERSION, JAKARTA_HBM2DDL_DB_MINOR_VERSION );
}
return name;
Expand All @@ -315,14 +309,14 @@ public String getDatabaseVersion() {

@Override
public int getDatabaseMajorVersion() {
return StringHelper.isEmpty( dbMajor )
return isEmpty( dbMajor )
? NO_VERSION
: Integer.parseInt( dbMajor );
}

@Override
public int getDatabaseMinorVersion() {
return StringHelper.isEmpty( dbMinor )
return isEmpty( dbMinor )
? NO_VERSION
: Integer.parseInt( dbMinor );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,4 @@ public interface ExecutionOptions {
boolean shouldManageNamespaces();

ExceptionHandler getExceptionHandler();

/**
* @deprecated No longer used, see {@link org.hibernate.cfg.SchemaToolingSettings#HBM2DDL_FILTER_PROVIDER}
*/
@Deprecated( forRemoval = true )
default SchemaFilter getSchemaFilter() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
import org.hibernate.tool.schema.spi.ExceptionHandler;
import org.hibernate.tool.schema.spi.ExecutionOptions;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.hibernate.tool.schema.spi.ScriptSourceInput;
import org.hibernate.tool.schema.spi.SourceDescriptor;
Expand Down Expand Up @@ -71,11 +70,6 @@ public boolean shouldManageNamespaces() {
public ExceptionHandler getExceptionHandler() {
return Throwable::printStackTrace;
}

@Override
public SchemaFilter getSchemaFilter() {
return SchemaFilter.ALL;
}
};

final SchemaManagementTool schemaManagementTool = serviceRegistry.getService( SchemaManagementTool.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.hibernate.tool.schema.spi.ExceptionHandler;
import org.hibernate.tool.schema.spi.ExecutionOptions;
import org.hibernate.tool.schema.spi.SchemaDropper;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.hibernate.tool.schema.spi.ScriptSourceInput;
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
Expand Down Expand Up @@ -101,7 +100,7 @@ public ScriptSourceInput getScriptSourceInput() {
}

@Override
public Map getConfigurationValues() {
public Map<String,Object> getConfigurationValues() {
return serviceRegistry.getService( ConfigurationService.class ).getSettings();
}

Expand All @@ -115,11 +114,6 @@ public ExceptionHandler getExceptionHandler() {
return this;
}

@Override
public SchemaFilter getSchemaFilter() {
return SchemaFilter.ALL;
}

@Override
public void handleException(CommandAcceptanceException exception) {
throw exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.hibernate.tool.schema.spi.ContributableMatcher;
import org.hibernate.tool.schema.spi.ExceptionHandler;
import org.hibernate.tool.schema.spi.ExecutionOptions;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.tool.schema.spi.SchemaManagementTool;
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
import org.hibernate.tool.schema.spi.TargetDescriptor;
Expand Down Expand Up @@ -92,19 +91,14 @@ public boolean shouldManageNamespaces() {
}

@Override
public Map getConfigurationValues() {
return ssr.getService( ConfigurationService.class ).getSettings();
public Map<String,Object> getConfigurationValues() {
return ssr.requireService( ConfigurationService.class ).getSettings();
}

@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}

@Override
public SchemaFilter getSchemaFilter() {
return SchemaFilter.ALL;
}
},
ContributableMatcher.ALL,
new TargetDescriptor() {
Expand Down
Loading
Loading