Skip to content

Commit

Permalink
modernize some typecasts in Initiators
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Dec 13, 2024
1 parent dec2716 commit d26e613
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public BatchBuilder initiateService(Map<String, Object> configurationValues, Ser
);
}

if ( builder instanceof BatchBuilder ) {
return (BatchBuilder) builder;
if ( builder instanceof BatchBuilder batchBuilder ) {
return batchBuilder;
}

final String builderClassName = builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public MultiTenantConnectionProvider<?> initiateService(Map<String, Object> conf
return null;
}

if ( configValue instanceof MultiTenantConnectionProvider<?> ) {
return (MultiTenantConnectionProvider<?>) configValue;
if ( configValue instanceof MultiTenantConnectionProvider<?> multiTenantConnectionProvider ) {
return multiTenantConnectionProvider;
}
else {
final Class<MultiTenantConnectionProvider<?>> implClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public MutationExecutorService initiateService(Map<String, Object> configuration
return createStandardService( configurationValues, registry );
}

if ( custom instanceof MutationExecutorService ) {
return (MutationExecutorService) custom;
if ( custom instanceof MutationExecutorService mutationExecutorService ) {
return mutationExecutorService;
}

final Class<? extends MutationExecutorService> customImplClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ else if ( value.equals( EntityCopyAllowedLoggedObserver.SHORT_NAME )
//We load an "example instance" just to get its Class;
//this might look excessive, but it also happens to test eagerly (at boot) that we can actually construct these
//and that they are indeed of the right type.
EntityCopyObserver exampleInstance =
final EntityCopyObserver exampleInstance =
registry.requireService( StrategySelector.class )
.resolveStrategy( EntityCopyObserver.class, value );
Class<?> observerType = exampleInstance.getClass();
final Class<?> observerType = exampleInstance.getClass();
LOG.debugf( "Configured EntityCopyObserver is a custom implementation of type %s", observerType.getName() );
return new EntityObserversFactoryFromClass( observerType );
}
Expand All @@ -65,8 +65,8 @@ private Object getConfigurationValue(final Map<?,?> configurationValues) {
if ( value == null ) {
return EntityCopyNotAllowedObserver.SHORT_NAME; //default
}
else if ( value instanceof String ) {
return value.toString().trim();
else if ( value instanceof String string ) {
return string.trim();
}
else {
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public PersisterClassResolver initiateService(Map<String, Object> configurationV
return (PersisterClassResolver) customImpl;
}

@SuppressWarnings("unchecked")
final Class<? extends PersisterClassResolver> customImplClass = customImpl instanceof Class
? (Class<? extends PersisterClassResolver>) customImpl
: locate( registry, customImpl.toString() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public PersisterFactory initiateService(Map<String, Object> configurationValues,
return new PersisterFactoryImpl();
}

if ( customImpl instanceof PersisterFactory ) {
return (PersisterFactory) customImpl;
if ( customImpl instanceof PersisterFactory persisterFactory ) {
return persisterFactory;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.schema.spi.SqlScriptCommandExtractor;

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

/**
* @author Steve Ebersole
*/
Expand All @@ -26,14 +27,14 @@ public Class<SqlScriptCommandExtractor> getServiceInitiated() {

@Override
public SqlScriptCommandExtractor initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final Object explicitSettingValue = configurationValues.get( Environment.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR );
final Object explicitSettingValue = configurationValues.get( HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR );

if ( explicitSettingValue == null ) {
return SingleLineSqlScriptExtractor.INSTANCE;
}

if ( explicitSettingValue instanceof SqlScriptCommandExtractor ) {
return (SqlScriptCommandExtractor) explicitSettingValue;
if ( explicitSettingValue instanceof SqlScriptCommandExtractor commandExtractor ) {
return commandExtractor;
}

final String explicitSettingName = explicitSettingValue.toString().trim();
Expand Down

0 comments on commit d26e613

Please sign in to comment.