simplify ObjectNameNormalizer

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-20 11:33:59 +02:00 committed by Steve Ebersole
parent 3946cfaf0b
commit 51acbd04dc
5 changed files with 21 additions and 52 deletions

View File

@ -36,12 +36,7 @@ public class MetadataBuildingContextRootImpl implements MetadataBuildingContext
this.options = options;
this.mappingDefaults = mappingDefaults;
this.metadataCollector = metadataCollector;
this.objectNameNormalizer = new ObjectNameNormalizer() {
@Override
protected MetadataBuildingContext getBuildingContext() {
return MetadataBuildingContextRootImpl.this;
}
};
this.objectNameNormalizer = new ObjectNameNormalizer(this);
this.typeDefinitionRegistry = new TypeDefinitionRegistryStandardImpl();
}

View File

@ -15,8 +15,12 @@ import org.hibernate.internal.util.StringHelper;
*
* @author Steve Ebersole
*/
public abstract class ObjectNameNormalizer {
private Database database;
public class ObjectNameNormalizer {
private final MetadataBuildingContext context;
public ObjectNameNormalizer(MetadataBuildingContext context) {
this.context = context;
}
/**
* Normalizes the quoting of identifiers.
@ -35,17 +39,11 @@ public abstract class ObjectNameNormalizer {
}
protected Database database() {
if ( database == null ) {
database = getBuildingContext().getMetadataCollector().getDatabase();
}
return database;
return getBuildingContext().getMetadataCollector().getDatabase();
}
public Identifier normalizeIdentifierQuoting(Identifier identifier) {
return getBuildingContext().getMetadataCollector()
.getDatabase()
.getJdbcEnvironment()
.getIdentifierHelper()
return database().getJdbcEnvironment().getIdentifierHelper()
.normalizeQuoting( identifier );
}
@ -74,20 +72,10 @@ public abstract class ObjectNameNormalizer {
* @return The logical name
*/
public Identifier determineLogicalName(String explicitName, NamingStrategyHelper namingStrategyHelper) {
Identifier logicalName;
if ( StringHelper.isEmpty( explicitName ) ) {
logicalName = namingStrategyHelper.determineImplicitName( getBuildingContext() );
}
else {
logicalName = namingStrategyHelper.handleExplicitName( explicitName, getBuildingContext() );
}
logicalName = getBuildingContext().getMetadataCollector()
.getDatabase()
.getJdbcEnvironment()
.getIdentifierHelper()
.normalizeQuoting( logicalName );
return logicalName;
final Identifier logicalName = StringHelper.isEmpty( explicitName )
? namingStrategyHelper.determineImplicitName( getBuildingContext() )
: namingStrategyHelper.handleExplicitName( explicitName, getBuildingContext() );
return database().getJdbcEnvironment().getIdentifierHelper().normalizeQuoting( logicalName );
}
/**
@ -116,5 +104,7 @@ public abstract class ObjectNameNormalizer {
*
* @return The current building context
*/
protected abstract MetadataBuildingContext getBuildingContext();
protected MetadataBuildingContext getBuildingContext() {
return context;
}
}

View File

@ -90,8 +90,7 @@ public class IncrementGenerator implements IdentifierGenerator, StandardGenerato
returnClass = type.getReturnedClass();
final JdbcEnvironment jdbcEnvironment = serviceRegistry.requireService( JdbcEnvironment.class );
final ObjectNameNormalizer normalizer =
(ObjectNameNormalizer) parameters.get( IDENTIFIER_NORMALIZER );
final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) parameters.get( IDENTIFIER_NORMALIZER );
column = parameters.getProperty( COLUMN );
if ( column == null ) {
@ -101,12 +100,8 @@ public class IncrementGenerator implements IdentifierGenerator, StandardGenerato
IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
final String schema = normalizer.toDatabaseIdentifierText(
parameters.getProperty( SCHEMA )
);
final String catalog = normalizer.toDatabaseIdentifierText(
parameters.getProperty( CATALOG )
);
final String schema = normalizer.toDatabaseIdentifierText( parameters.getProperty( SCHEMA ) );
final String catalog = normalizer.toDatabaseIdentifierText( parameters.getProperty( CATALOG ) );
String tableList = parameters.getProperty( TABLES );
if ( tableList == null ) {

View File

@ -48,12 +48,7 @@ public class EnversMetadataBuildingContextImpl implements EnversMetadataBuilding
this.auditEntityNameRegistry = new AuditEntityNameRegister();
this.auditEntityConfigurationRegistry = new AuditEntityConfigurationRegistry();
this.objectNameNormalizer = new ObjectNameNormalizer() {
@Override
protected MetadataBuildingContext getBuildingContext() {
return EnversMetadataBuildingContextImpl.this;
}
};
this.objectNameNormalizer = new ObjectNameNormalizer(this);
}
@Override

View File

@ -17,7 +17,6 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.EffectiveMappingDefaults;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
@ -41,12 +40,7 @@ public class MetadataBuildingContextTestingImpl implements MetadataBuildingConte
new PersistenceUnitMetadataImpl()
);
metadataCollector = new InFlightMetadataCollectorImpl( bootstrapContext, buildingOptions );
objectNameNormalizer = new ObjectNameNormalizer() {
@Override
protected MetadataBuildingContext getBuildingContext() {
return MetadataBuildingContextTestingImpl.this;
}
};
objectNameNormalizer = new ObjectNameNormalizer(this);
typeDefinitionRegistry = new TypeDefinitionRegistryStandardImpl();
bootstrapContext.getTypeConfiguration().scope( this );
}