Skip to content

Commit 76ab5d7

Browse files
committed
some cleanups and javadoc around SchemaManager
Signed-off-by: Gavin King <[email protected]>
1 parent 37ce9bb commit 76ab5d7

21 files changed

+83
-179
lines changed

hibernate-core/src/main/java/org/hibernate/relational/SchemaManager.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*
1616
* @see org.hibernate.SessionFactory#getSchemaManager()
1717
*
18+
* @apiNote This interface was added to JPA 3.2 as
19+
* {@link jakarta.persistence.SchemaManager}, which it now inherits,
20+
* with a minor change to the naming of its operations. It is retained
21+
* for backward compatibility and as a place to define additional
22+
* functionality in the future.
23+
*
1824
* @since 6.2
1925
* @author Gavin King
2026
*/
@@ -27,6 +33,8 @@ public interface SchemaManager extends jakarta.persistence.SchemaManager {
2733
*
2834
* @param createSchemas if {@code true}, attempt to create schemas,
2935
* otherwise, assume the schemas already exist
36+
*
37+
* @apiNote This operation is a synonym for {@link #create}.
3038
*/
3139
void exportMappedObjects(boolean createSchemas);
3240

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

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

@@ -56,16 +68,8 @@ public interface SchemaManager extends jakarta.persistence.SchemaManager {
5668
* load script}.
5769
* <p>
5870
* Programmatic way to run {@link org.hibernate.tool.schema.spi.SchemaTruncator}.
71+
*
72+
* @apiNote This operation is a synonym for {@link #truncate}.
5973
*/
6074
void truncateMappedObjects();
61-
62-
@Override
63-
default void create(boolean createSchemas) {
64-
exportMappedObjects( createSchemas );
65-
}
66-
67-
@Override
68-
default void drop(boolean dropSchemas) {
69-
dropMappedObjects( dropSchemas );
70-
}
7175
}

hibernate-core/src/main/java/org/hibernate/relational/internal/SchemaManagerImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public void truncateMappedObjects() {
8989
);
9090
}
9191

92+
@Override
93+
public void create(boolean createSchemas) {
94+
exportMappedObjects( createSchemas );
95+
}
96+
97+
@Override
98+
public void drop(boolean dropSchemas) {
99+
dropMappedObjects( dropSchemas );
100+
}
101+
92102
@Override
93103
public void validate() throws SchemaValidationException {
94104
try {

hibernate-core/src/main/java/org/hibernate/tool/schema/JdbcMetadaAccessStrategy.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hibernate.cfg.AvailableSettings;
1111
import org.hibernate.internal.util.config.ConfigurationHelper;
1212

13+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY;
14+
1315
/**
1416
* Determines how JDBC metadata is read by the schema management tooling.
1517
*
@@ -39,7 +41,7 @@ public String toString() {
3941
return super.toString().toLowerCase(Locale.ROOT);
4042
}
4143

42-
public static JdbcMetadaAccessStrategy interpretSetting(Map options) {
44+
public static JdbcMetadaAccessStrategy interpretSetting(Map<String,Object> options) {
4345
if ( options == null ) {
4446
return interpretHbm2ddlSetting( null );
4547
}
@@ -48,7 +50,7 @@ else if ( ConfigurationHelper.getBoolean( AvailableSettings.ENABLE_SYNONYMS, opt
4850
return INDIVIDUALLY;
4951
}
5052
else {
51-
return interpretHbm2ddlSetting( options.get( AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY ) );
53+
return interpretHbm2ddlSetting( options.get( HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY ) );
5254
}
5355
}
5456

@@ -66,7 +68,7 @@ public static JdbcMetadaAccessStrategy interpretHbm2ddlSetting(Object value) {
6668
return strategy;
6769
}
6870
}
69-
throw new IllegalArgumentException( "Unrecognized '" + AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY + "' value: '" + value + "'");
71+
throw new IllegalArgumentException( "Unrecognized '" + HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY + "' value: '" + value + "'");
7072
}
7173
}
7274
}

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/HibernateSchemaManagementTool.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
1111
import org.hibernate.boot.registry.selector.spi.StrategySelector;
12-
import org.hibernate.cfg.AvailableSettings;
1312
import org.hibernate.dialect.Dialect;
1413
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
1514
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@@ -18,7 +17,6 @@
1817
import org.hibernate.engine.jdbc.spi.JdbcServices;
1918
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
2019
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
21-
import org.hibernate.internal.util.StringHelper;
2220
import org.hibernate.internal.util.config.ConfigurationHelper;
2321
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
2422
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
@@ -40,6 +38,7 @@
4038
import org.hibernate.tool.schema.spi.ExtractionTool;
4139
import org.hibernate.tool.schema.spi.SchemaCreator;
4240
import org.hibernate.tool.schema.spi.SchemaDropper;
41+
import org.hibernate.tool.schema.spi.SchemaFilter;
4342
import org.hibernate.tool.schema.spi.SchemaFilterProvider;
4443
import org.hibernate.tool.schema.spi.SchemaManagementException;
4544
import org.hibernate.tool.schema.spi.SchemaManagementTool;
@@ -61,8 +60,11 @@
6160
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DB_MINOR_VERSION;
6261
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DB_NAME;
6362
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION;
63+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_FILTER_PROVIDER;
6464
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
6565
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
66+
import static org.hibernate.internal.util.StringHelper.isEmpty;
67+
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
6668

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

102104
@Override
103105
public SchemaMigrator getSchemaMigrator(Map<String,Object> options) {
104-
if ( determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED ) {
105-
return new GroupedSchemaMigratorImpl( this, getSchemaFilterProvider( options ).getMigrateFilter() );
106-
}
107-
else {
108-
return new IndividuallySchemaMigratorImpl( this, getSchemaFilterProvider( options ).getMigrateFilter() );
109-
}
106+
final SchemaFilter migrateFilter = getSchemaFilterProvider( options ).getMigrateFilter();
107+
return determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED
108+
? new GroupedSchemaMigratorImpl( this, migrateFilter )
109+
: new IndividuallySchemaMigratorImpl( this, migrateFilter );
110110
}
111111

112112
@Override
113113
public SchemaValidator getSchemaValidator(Map<String,Object> options) {
114-
if ( determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED ) {
115-
return new GroupedSchemaValidatorImpl( this, getSchemaFilterProvider( options ).getValidateFilter() );
116-
}
117-
else {
118-
return new IndividuallySchemaValidatorImpl( this, getSchemaFilterProvider( options ).getValidateFilter() );
119-
}
114+
final SchemaFilter validateFilter = getSchemaFilterProvider( options ).getValidateFilter();
115+
return determineJdbcMetadaAccessStrategy( options ) == JdbcMetadaAccessStrategy.GROUPED
116+
? new GroupedSchemaValidatorImpl( this, validateFilter )
117+
: new IndividuallySchemaValidatorImpl( this, validateFilter );
120118
}
121119

122120
private SchemaFilterProvider getSchemaFilterProvider(Map<String,Object> options) {
123-
final Object configuredOption = (options == null)
124-
? null
125-
: options.get( AvailableSettings.HBM2DDL_FILTER_PROVIDER );
126-
return serviceRegistry.requireService( StrategySelector.class ).resolveDefaultableStrategy(
127-
SchemaFilterProvider.class,
128-
configuredOption,
129-
DefaultSchemaFilterProvider.INSTANCE
130-
);
121+
return serviceRegistry.requireService( StrategySelector.class )
122+
.resolveDefaultableStrategy( SchemaFilterProvider.class,
123+
options == null ? null : options.get( HBM2DDL_FILTER_PROVIDER ),
124+
DefaultSchemaFilterProvider.INSTANCE );
131125
}
132126

133127
private JdbcMetadaAccessStrategy determineJdbcMetadaAccessStrategy(Map<String,Object> options) {
@@ -259,7 +253,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
259253
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_NAME ),
260254
() -> {
261255
final String name = (String) configurationValues.get( DIALECT_DB_NAME );
262-
if ( StringHelper.isNotEmpty( name ) ) {
256+
if ( isNotEmpty( name ) ) {
263257
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_NAME, JAKARTA_HBM2DDL_DB_NAME );
264258
}
265259
return name;
@@ -270,7 +264,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
270264
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_VERSION ),
271265
() -> {
272266
final String name = (String) configurationValues.get( DIALECT_DB_VERSION );
273-
if ( StringHelper.isNotEmpty( name ) ) {
267+
if ( isNotEmpty( name ) ) {
274268
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_VERSION, JAKARTA_HBM2DDL_DB_VERSION );
275269
}
276270
return name;
@@ -281,7 +275,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
281275
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_MAJOR_VERSION ),
282276
() -> {
283277
final String name = (String) configurationValues.get( DIALECT_DB_MAJOR_VERSION );
284-
if ( StringHelper.isNotEmpty( name ) ) {
278+
if ( isNotEmpty( name ) ) {
285279
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_MAJOR_VERSION, JAKARTA_HBM2DDL_DB_MAJOR_VERSION );
286280
}
287281
return name;
@@ -292,7 +286,7 @@ public JdbcContext resolveJdbcContext(Map<String,Object> configurationValues) {
292286
() -> configurationValues.get( JAKARTA_HBM2DDL_DB_MINOR_VERSION ),
293287
() -> {
294288
final String name = (String) configurationValues.get( DIALECT_DB_MINOR_VERSION );
295-
if ( StringHelper.isNotEmpty( name ) ) {
289+
if ( isNotEmpty( name ) ) {
296290
DEPRECATION_LOGGER.deprecatedSetting( DIALECT_DB_MINOR_VERSION, JAKARTA_HBM2DDL_DB_MINOR_VERSION );
297291
}
298292
return name;
@@ -315,14 +309,14 @@ public String getDatabaseVersion() {
315309

316310
@Override
317311
public int getDatabaseMajorVersion() {
318-
return StringHelper.isEmpty( dbMajor )
312+
return isEmpty( dbMajor )
319313
? NO_VERSION
320314
: Integer.parseInt( dbMajor );
321315
}
322316

323317
@Override
324318
public int getDatabaseMinorVersion() {
325-
return StringHelper.isEmpty( dbMinor )
319+
return isEmpty( dbMinor )
326320
? NO_VERSION
327321
: Integer.parseInt( dbMinor );
328322
}

hibernate-core/src/main/java/org/hibernate/tool/schema/spi/ExecutionOptions.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,4 @@ public interface ExecutionOptions {
2020
boolean shouldManageNamespaces();
2121

2222
ExceptionHandler getExceptionHandler();
23-
24-
/**
25-
* @deprecated No longer used, see {@link org.hibernate.cfg.SchemaToolingSettings#HBM2DDL_FILTER_PROVIDER}
26-
*/
27-
@Deprecated( forRemoval = true )
28-
default SchemaFilter getSchemaFilter() {
29-
throw new UnsupportedOperationException();
30-
}
3123
}

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/contributed/BasicContributorTests.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
1717
import org.hibernate.tool.schema.spi.ExceptionHandler;
1818
import org.hibernate.tool.schema.spi.ExecutionOptions;
19-
import org.hibernate.tool.schema.spi.SchemaFilter;
2019
import org.hibernate.tool.schema.spi.SchemaManagementTool;
2120
import org.hibernate.tool.schema.spi.ScriptSourceInput;
2221
import org.hibernate.tool.schema.spi.SourceDescriptor;
@@ -71,11 +70,6 @@ public boolean shouldManageNamespaces() {
7170
public ExceptionHandler getExceptionHandler() {
7271
return Throwable::printStackTrace;
7372
}
74-
75-
@Override
76-
public SchemaFilter getSchemaFilter() {
77-
return SchemaFilter.ALL;
78-
}
7973
};
8074

8175
final SchemaManagementTool schemaManagementTool = serviceRegistry.getService( SchemaManagementTool.class );

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaDropTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.hibernate.tool.schema.spi.ExceptionHandler;
2525
import org.hibernate.tool.schema.spi.ExecutionOptions;
2626
import org.hibernate.tool.schema.spi.SchemaDropper;
27-
import org.hibernate.tool.schema.spi.SchemaFilter;
2827
import org.hibernate.tool.schema.spi.SchemaManagementTool;
2928
import org.hibernate.tool.schema.spi.ScriptSourceInput;
3029
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
@@ -101,7 +100,7 @@ public ScriptSourceInput getScriptSourceInput() {
101100
}
102101

103102
@Override
104-
public Map getConfigurationValues() {
103+
public Map<String,Object> getConfigurationValues() {
105104
return serviceRegistry.getService( ConfigurationService.class ).getSettings();
106105
}
107106

@@ -115,11 +114,6 @@ public ExceptionHandler getExceptionHandler() {
115114
return this;
116115
}
117116

118-
@Override
119-
public SchemaFilter getSchemaFilter() {
120-
return SchemaFilter.ALL;
121-
}
122-
123117
@Override
124118
public void handleException(CommandAcceptanceException exception) {
125119
throw exception;

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/SchemaUpdateTableBackedSequenceTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.hibernate.tool.schema.spi.ContributableMatcher;
2828
import org.hibernate.tool.schema.spi.ExceptionHandler;
2929
import org.hibernate.tool.schema.spi.ExecutionOptions;
30-
import org.hibernate.tool.schema.spi.SchemaFilter;
3130
import org.hibernate.tool.schema.spi.SchemaManagementTool;
3231
import org.hibernate.tool.schema.spi.ScriptTargetOutput;
3332
import org.hibernate.tool.schema.spi.TargetDescriptor;
@@ -92,19 +91,14 @@ public boolean shouldManageNamespaces() {
9291
}
9392

9493
@Override
95-
public Map getConfigurationValues() {
96-
return ssr.getService( ConfigurationService.class ).getSettings();
94+
public Map<String,Object> getConfigurationValues() {
95+
return ssr.requireService( ConfigurationService.class ).getSettings();
9796
}
9897

9998
@Override
10099
public ExceptionHandler getExceptionHandler() {
101100
return ExceptionHandlerLoggedImpl.INSTANCE;
102101
}
103-
104-
@Override
105-
public SchemaFilter getSchemaFilter() {
106-
return SchemaFilter.ALL;
107-
}
108102
},
109103
ContributableMatcher.ALL,
110104
new TargetDescriptor() {

0 commit comments

Comments
 (0)