From 0fccf6b7bd3749d8b183e07d03fe3dc7564f3756 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 16 Feb 2016 09:35:12 -0600 Subject: [PATCH] HHH-10528 - use_nationalized_character_data global property is ignored --- .../boot/internal/MetadataBuilderImpl.java | 44 ++++++------ .../boot/spi/MetadataBuildingOptions.java | 2 +- .../UseNationalizedCharDataSettingTest.java | 67 +++++++++++++++++++ 3 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/nationalized/UseNationalizedCharDataSettingTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java index be8f7df543..4580dc57a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java @@ -583,44 +583,44 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont // jandexView = (IndexView) configService.getSettings().get( AvailableSettings.JANDEX_INDEX ); - scanOptions = new StandardScanOptions( + this.scanOptions = new StandardScanOptions( (String) configService.getSettings().get( AvailableSettings.SCANNER_DISCOVERY ), false ); // ScanEnvironment must be set explicitly - scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER ); - if ( scannerSetting == null ) { - scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER_DEPRECATED ); - if ( scannerSetting != null ) { + this.scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER ); + if ( this.scannerSetting == null ) { + this.scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER_DEPRECATED ); + if ( this.scannerSetting != null ) { DEPRECATION_LOGGER.logDeprecatedScannerSetting(); } } - archiveDescriptorFactory = strategySelector.resolveStrategy( + this.archiveDescriptorFactory = strategySelector.resolveStrategy( ArchiveDescriptorFactory.class, configService.getSettings().get( AvailableSettings.SCANNER_ARCHIVE_INTERPRETER ) ); - multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() ); + this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() ); - implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting( + this.implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting( AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS, StandardConverters.BOOLEAN, false ); - explicitDiscriminatorsForJoinedInheritanceSupported = !configService.getSetting( + this.explicitDiscriminatorsForJoinedInheritanceSupported = !configService.getSetting( AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS, StandardConverters.BOOLEAN, false ); - implicitlyForceDiscriminatorInSelect = configService.getSetting( + this.implicitlyForceDiscriminatorInSelect = configService.getSetting( AvailableSettings.FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT, StandardConverters.BOOLEAN, false ); - sharedCacheMode = configService.getSetting( + this.sharedCacheMode = configService.getSetting( "javax.persistence.sharedCache.mode", new ConfigurationService.Converter() { @Override @@ -639,7 +639,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont SharedCacheMode.UNSPECIFIED ); - defaultCacheAccessType = configService.getSetting( + this.defaultCacheAccessType = configService.getSetting( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, new ConfigurationService.Converter() { @Override @@ -665,13 +665,13 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont : serviceRegistry.getService( RegionFactory.class ).getDefaultAccessType() ); - specjProprietarySyntaxEnabled = configService.getSetting( + this.specjProprietarySyntaxEnabled = configService.getSetting( "hibernate.enable_specj_proprietary_syntax", StandardConverters.BOOLEAN, false ); - implicitNamingStrategy = strategySelector.resolveDefaultableStrategy( + this.implicitNamingStrategy = strategySelector.resolveDefaultableStrategy( ImplicitNamingStrategy.class, configService.getSettings().get( AvailableSettings.IMPLICIT_NAMING_STRATEGY ), new Callable() { @@ -686,13 +686,13 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } ); - physicalNamingStrategy = strategySelector.resolveDefaultableStrategy( + this.physicalNamingStrategy = strategySelector.resolveDefaultableStrategy( PhysicalNamingStrategy.class, configService.getSettings().get( AvailableSettings.PHYSICAL_NAMING_STRATEGY ), PhysicalNamingStrategyStandardImpl.INSTANCE ); - sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService ); + this.sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService ); final boolean useNewIdentifierGenerators = configService.getSetting( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, @@ -700,13 +700,19 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont true ); if ( useNewIdentifierGenerators ) { - idGenerationTypeInterpreter.disableLegacyFallback(); + this.idGenerationTypeInterpreter.disableLegacyFallback(); } else { - idGenerationTypeInterpreter.enableLegacyFallback(); + this.idGenerationTypeInterpreter.enableLegacyFallback(); } - reflectionManager = generateDefaultReflectionManager(); + this.useNationalizedCharacterData = configService.getSetting( + AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, + StandardConverters.BOOLEAN, + false + ); + + this.reflectionManager = generateDefaultReflectionManager(); } private ArrayList resolveInitialSourceProcessOrdering(ConfigurationService configService) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java index 351d5368e5..ab2ce2ebac 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/MetadataBuildingOptions.java @@ -192,7 +192,7 @@ public interface MetadataBuildingOptions { * * @return {@code true} if nationalized character data should be used by default; {@code false} otherwise. */ - public boolean useNationalizedCharacterData(); + boolean useNationalizedCharacterData(); boolean isSpecjProprietarySyntaxEnabled(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/nationalized/UseNationalizedCharDataSettingTest.java b/hibernate-core/src/test/java/org/hibernate/test/nationalized/UseNationalizedCharDataSettingTest.java new file mode 100644 index 0000000000..326a7b5e98 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/nationalized/UseNationalizedCharDataSettingTest.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.nationalized; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; +import org.hibernate.type.StringNVarcharType; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertSame; + +/** + * Test the use of {@link org.hibernate.cfg.AvailableSettings#USE_NATIONALIZED_CHARACTER_DATA} + * to indicate that nationalized character data should be used. + * + * @author Steve Ebersole + */ +public class UseNationalizedCharDataSettingTest extends BaseUnitTestCase { + @Test + @TestForIssue( jiraKey = "HHH-10528" ) + public void testSetting() { + final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() + .applySetting( AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, true ) + .build(); + + try { + final MetadataSources ms = new MetadataSources( ssr ); + ms.addAnnotatedClass( NationalizedBySettingEntity.class ); + + final Metadata metadata = ms.buildMetadata(); + final PersistentClass pc = metadata.getEntityBinding( NationalizedBySettingEntity.class.getName() ); + final Property nameAttribute = pc.getProperty( "name" ); + assertSame( StringNVarcharType.INSTANCE, nameAttribute.getType() ); + + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + + @Entity(name = "NationalizedBySettingEntity") + @Table(name = "nationalized_by_setting_entity") + public static class NationalizedBySettingEntity { + @Id + @GeneratedValue + private long id; + + String name; + } +}