From c05d4b46b7e3f8ae772ac473930137f654a88871 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 6 Sep 2025 08:40:42 +0200 Subject: [PATCH] lots of use of 'var' --- .../boot/cfgxml/spi/LoadedConfig.java | 97 ++- .../jaxb/hbm/transform/HbmXmlTransformer.java | 635 ++++++++---------- .../process/spi/MetadataBuildingProcess.java | 149 ++-- .../interceptor/LazyAttributesMetadata.java | 9 +- .../java/org/hibernate/cfg/Configuration.java | 6 +- .../collection/spi/PersistentBag.java | 23 +- .../collection/spi/PersistentList.java | 11 +- .../collection/spi/PersistentMap.java | 19 +- .../collection/spi/PersistentSet.java | 19 +- .../PreparedStatementGroupStandard.java | 5 +- .../engine/jndi/internal/JndiServiceImpl.java | 21 +- .../AbstractFlushingEventListener.java | 10 +- .../internal/FilterConfiguration.java | 32 +- .../org/hibernate/internal/FilterHelper.java | 12 +- .../internal/util/EntityPrinter.java | 11 +- .../util/collections/MapBackedClassValue.java | 10 +- .../EntityManagerFactoryBuilderImpl.java | 6 +- .../jpa/spi/NativeQueryTupleTransformer.java | 5 +- .../sqm/function/SqmFunctionRegistry.java | 16 +- .../java/spi/CollectionJavaType.java | 7 +- 20 files changed, 488 insertions(+), 615 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/spi/LoadedConfig.java b/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/spi/LoadedConfig.java index c64c88a032aa..f95379127d4a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/spi/LoadedConfig.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/spi/LoadedConfig.java @@ -15,12 +15,8 @@ import org.hibernate.boot.CacheRegionDefinition; import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgCollectionCacheType; -import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgConfigPropertyType; import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEntityCacheType; -import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerGroupType; -import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType; import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgHibernateConfiguration; -import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgMappingReferenceType; import org.hibernate.event.spi.EventType; import org.jboss.logging.Logger; @@ -75,13 +71,13 @@ public Map, Set> getEventListenerMap() { * @return The parsed representation */ public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) { - final LoadedConfig cfg = new LoadedConfig( jaxbCfg.getSessionFactory().getName() ); + final var cfg = new LoadedConfig( jaxbCfg.getSessionFactory().getName() ); - for ( JaxbCfgConfigPropertyType jaxbProperty : jaxbCfg.getSessionFactory().getProperty() ) { + for ( var jaxbProperty : jaxbCfg.getSessionFactory().getProperty() ) { cfg.addConfigurationValue( jaxbProperty.getName(), jaxbProperty.getValue() ); } - for ( JaxbCfgMappingReferenceType jaxbMapping : jaxbCfg.getSessionFactory().getMapping() ) { + for ( var jaxbMapping : jaxbCfg.getSessionFactory().getMapping() ) { cfg.addMappingReference( MappingReference.consume( jaxbMapping ) ); } @@ -89,27 +85,27 @@ public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) { cfg.addCacheRegionDefinition( parseCacheRegionDefinition( cacheDeclaration ) ); } - if ( !jaxbCfg.getSessionFactory().getListener().isEmpty() ) { - for ( JaxbCfgEventListenerType listener : jaxbCfg.getSessionFactory().getListener() ) { - final EventType eventType = EventType.resolveEventTypeByName( listener.getType().value() ); + final var eventListeners = jaxbCfg.getSessionFactory().getListener(); + if ( !eventListeners.isEmpty() ) { + for ( var listener : eventListeners ) { + final var eventType = EventType.resolveEventTypeByName( listener.getType().value() ); cfg.addEventListener( eventType, listener.getClazz() ); } } - if ( !jaxbCfg.getSessionFactory().getEvent().isEmpty() ) { - for ( JaxbCfgEventListenerGroupType listenerGroup : jaxbCfg.getSessionFactory().getEvent() ) { - if ( listenerGroup.getListener().isEmpty() ) { - continue; - } - - final String eventTypeName = listenerGroup.getType().value(); - final EventType eventType = EventType.resolveEventTypeByName( eventTypeName ); - - for ( JaxbCfgEventListenerType listener : listenerGroup.getListener() ) { - if ( listener.getType() != null ) { - LOG.debugf( "Listener [%s] defined as part of a group also defined event type", listener.getClazz() ); + final var listenerGroups = jaxbCfg.getSessionFactory().getEvent(); + if ( !listenerGroups.isEmpty() ) { + for ( var listenerGroup : listenerGroups ) { + if ( !listenerGroup.getListener().isEmpty() ) { + final String eventTypeName = listenerGroup.getType().value(); + final var eventType = EventType.resolveEventTypeByName( eventTypeName ); + for ( var listener : listenerGroup.getListener() ) { + if ( listener.getType() != null ) { + LOG.debugf( "Listener [%s] defined as part of a group also defined event type", + listener.getClazz() ); + } + cfg.addEventListener( eventType, listener.getClazz() ); } - cfg.addEventListener( eventType, listener.getClazz() ); } } } @@ -118,17 +114,13 @@ public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) { } private static String trim(String value) { - if ( value == null ) { - return null; - } + return value == null ? null : value.trim(); - return value.trim(); } private void addConfigurationValue(String propertyName, String value) { value = trim( value ); configurationValues.put( propertyName, value ); - if ( !propertyName.startsWith( "hibernate." ) ) { configurationValues.put( "hibernate." + propertyName, value ); } @@ -138,7 +130,6 @@ private void addMappingReference(MappingReference mappingReference) { if ( mappingReferences == null ) { mappingReferences = new ArrayList<>(); } - mappingReferences.add( mappingReference ); } @@ -152,8 +143,7 @@ private static CacheRegionDefinition parseCacheRegionDefinition(Object cacheDecl "all".equals( jaxbClassCache.getInclude() ) ); } - else { - final JaxbCfgCollectionCacheType jaxbCollectionCache = (JaxbCfgCollectionCacheType) cacheDeclaration; + else if ( cacheDeclaration instanceof JaxbCfgCollectionCacheType jaxbCollectionCache ) { return new CacheRegionDefinition( CacheRegionDefinition.CacheRegionType.COLLECTION, jaxbCollectionCache.getCollection(), @@ -162,6 +152,9 @@ private static CacheRegionDefinition parseCacheRegionDefinition(Object cacheDecl false ); } + else { + throw new IllegalArgumentException( "Unrecognized cache declaration" ); + } } public void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) { @@ -213,22 +206,18 @@ public void merge(LoadedConfig incoming) { } protected void addConfigurationValues(Map configurationValues) { - if ( configurationValues == null ) { - return; + if ( configurationValues != null ) { + this.configurationValues.putAll( configurationValues ); } - - this.configurationValues.putAll( configurationValues ); } private void addMappingReferences(List mappingReferences) { - if ( mappingReferences == null ) { - return; - } - - if ( this.mappingReferences == null ) { - this.mappingReferences = new ArrayList<>(); + if ( mappingReferences != null ) { + if ( this.mappingReferences == null ) { + this.mappingReferences = new ArrayList<>(); + } + this.mappingReferences.addAll( mappingReferences ); } - this.mappingReferences.addAll( mappingReferences ); } private void addCacheRegionDefinitions(List cacheRegionDefinitions) { @@ -243,21 +232,19 @@ private void addCacheRegionDefinitions(List cacheRegionDe } private void addEventListeners(Map, Set> eventListenerMap) { - if ( eventListenerMap == null ) { - return; - } - - if ( this.eventListenerMap == null ) { - this.eventListenerMap = new HashMap<>(); - } + if ( eventListenerMap != null ) { + if ( this.eventListenerMap == null ) { + this.eventListenerMap = new HashMap<>(); + } - for ( Map.Entry, Set> incomingEntry : eventListenerMap.entrySet() ) { - Set listenerClasses = this.eventListenerMap.get( incomingEntry.getKey() ); - if ( listenerClasses == null ) { - listenerClasses = new HashSet<>(); - this.eventListenerMap.put( incomingEntry.getKey(), listenerClasses ); + for ( var incomingEntry : eventListenerMap.entrySet() ) { + var listenerClasses = this.eventListenerMap.get( incomingEntry.getKey() ); + if ( listenerClasses == null ) { + listenerClasses = new HashSet<>(); + this.eventListenerMap.put( incomingEntry.getKey(), listenerClasses ); + } + listenerClasses.addAll( incomingEntry.getValue() ); } - listenerClasses.addAll( incomingEntry.getValue() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java index 4ea0e7becce4..559b94e6a50e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java @@ -16,7 +16,6 @@ import org.hibernate.AssertionFailure; import org.hibernate.annotations.NotFoundAction; -import org.hibernate.annotations.OnDeleteAction; import org.hibernate.boot.MappingException; import org.hibernate.boot.internal.LimitedCollectionClassification; import org.hibernate.boot.jaxb.Origin; @@ -24,12 +23,10 @@ import org.hibernate.boot.jaxb.hbm.spi.EntityInfo; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmAnyAssociationType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmArrayType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmAuxiliaryDatabaseObjectType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmBagCollectionType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmBasicAttributeType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmBasicCollectionElementType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCacheInclusionEnum; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmClassRenameType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmColumnType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCompositeAttributeType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCompositeCollectionElementType; @@ -37,7 +34,6 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCompositeKeyBasicAttributeType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCompositeKeyManyToOneType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmConfigParameterContainer; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmConfigParameterType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCustomSqlDmlType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDiscriminatorSubclassEntityType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDynamicComponentType; @@ -46,16 +42,13 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFetchStyleEnum; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFetchStyleWithSubselectEnum; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterAliasMappingType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterDefinitionType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterParameterType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmGeneratorSpecificationType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmIdBagCollectionType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmIndexType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmJoinedSubclassEntityType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmKeyType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmLazyEnum; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmLazyWithExtraEnum; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmLazyWithNoProxyEnum; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmListIndexType; @@ -69,11 +62,9 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedQueryType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryCollectionLoadReturnType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryJoinReturnType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryPropertyReturnType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryReturnType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryScalarReturnType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNotFoundEnum; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmOnDeleteEnum; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmOneToManyCollectionElementType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmOneToOneType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmOuterJoinEnum; @@ -86,11 +77,9 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSetType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSimpleIdType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTimestampAttributeType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTypeDefinitionType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTypeSpecificationType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmUnionSubclassEntityType; -import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmVersionAttributeType; import org.hibernate.boot.jaxb.hbm.spi.PluralAttributeInfo; import org.hibernate.boot.jaxb.hbm.spi.ResultSetMappingContainer; import org.hibernate.boot.jaxb.hbm.spi.ToolingHintContainer; @@ -163,8 +152,6 @@ import org.hibernate.boot.jaxb.mapping.spi.db.JaxbTableMapping; import org.hibernate.boot.jaxb.spi.Binding; import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; @@ -204,6 +191,9 @@ import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; +import static org.hibernate.internal.util.StringHelper.qualify; +import static org.hibernate.internal.util.StringHelper.split; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; /** * Transforms {@code hbm.xml} {@linkplain JaxbHbmHibernateMapping JAXB} bindings into @@ -375,9 +365,9 @@ private void transferRootEntity( applyTable( entityInfo.getPersistentClass(), mappingEntity ); for ( var hbmSync : hbmClass.getSynchronize() ) { - final var sync = new JaxbSynchronizedTableImpl(); - sync.setTable( hbmSync.getTable() ); - mappingEntity.getSynchronizeTables().add( sync ); + final var synchronizedTable = new JaxbSynchronizedTableImpl(); + synchronizedTable.setTable( hbmSync.getTable() ); + mappingEntity.getSynchronizeTables().add( synchronizedTable ); } if ( hbmClass.getLoader() != null ) { @@ -389,22 +379,25 @@ private void transferRootEntity( } if ( hbmClass.getSqlInsert() != null ) { - mappingEntity.setSqlInsert( new JaxbCustomSqlImpl() ); - mappingEntity.getSqlInsert().setValue( hbmClass.getSqlInsert().getValue() ); - mappingEntity.getSqlInsert().setResultCheck( hbmClass.getSqlInsert().getCheck() ); - mappingEntity.getSqlInsert().setValue( hbmClass.getSqlInsert().getValue() ); + final var sqlInsert = new JaxbCustomSqlImpl(); + sqlInsert.setValue( hbmClass.getSqlInsert().getValue() ); + sqlInsert.setResultCheck( hbmClass.getSqlInsert().getCheck() ); + sqlInsert.setValue( hbmClass.getSqlInsert().getValue() ); + mappingEntity.setSqlInsert( sqlInsert ); } if ( hbmClass.getSqlUpdate() != null ) { - mappingEntity.setSqlUpdate( new JaxbCustomSqlImpl() ); - mappingEntity.getSqlUpdate().setValue( hbmClass.getSqlUpdate().getValue() ); - mappingEntity.getSqlUpdate().setResultCheck( hbmClass.getSqlUpdate().getCheck() ); - mappingEntity.getSqlUpdate().setValue( hbmClass.getSqlUpdate().getValue() ); + final var sqlUpdate = new JaxbCustomSqlImpl(); + sqlUpdate.setValue( hbmClass.getSqlUpdate().getValue() ); + sqlUpdate.setResultCheck( hbmClass.getSqlUpdate().getCheck() ); + sqlUpdate.setValue( hbmClass.getSqlUpdate().getValue() ); + mappingEntity.setSqlUpdate( sqlUpdate ); } if ( hbmClass.getSqlDelete() != null ) { - mappingEntity.setSqlDelete( new JaxbCustomSqlImpl() ); - mappingEntity.getSqlDelete().setValue( hbmClass.getSqlDelete().getValue() ); - mappingEntity.getSqlDelete().setResultCheck( hbmClass.getSqlDelete().getCheck() ); - mappingEntity.getSqlDelete().setValue( hbmClass.getSqlDelete().getValue() ); + final var sqlDelete = new JaxbCustomSqlImpl(); + sqlDelete.setValue( hbmClass.getSqlDelete().getValue() ); + sqlDelete.setResultCheck( hbmClass.getSqlDelete().getCheck() ); + sqlDelete.setValue( hbmClass.getSqlDelete().getValue() ); + mappingEntity.setSqlDelete( sqlDelete ); } mappingEntity.setRowid( hbmClass.getRowid() ); mappingEntity.setSqlRestriction( hbmClass.getWhere() ); @@ -576,7 +569,8 @@ private void transferBaseEntityInformation( } if ( hbmEntity instanceof Discriminatable discriminatable ) { - TransformationHelper.transfer( discriminatable::getDiscriminatorValue, mappingEntity::setDiscriminatorValue ); + TransformationHelper.transfer( discriminatable::getDiscriminatorValue, + mappingEntity::setDiscriminatorValue ); } if ( hbmEntity.isAbstract() != null ) { @@ -609,9 +603,9 @@ private void applyBasicTypeMapping( JaxbHbmTypeSpecificationType hbmType, Consumer enumTypeConsumer, Consumer> converterConsumer) { - final BasicType type = (BasicType) basicValue.getType(); - if ( type instanceof BasicTypeImpl standardBasicType ) { - if ( enumTypeConsumer != null && type.getReturnedClass().isEnum() ) { + final var basicType = (BasicType) basicValue.getType(); + if ( basicType instanceof BasicTypeImpl standardBasicType ) { + if ( enumTypeConsumer != null && basicType.getReturnedClass().isEnum() ) { enumTypeConsumer.accept( standardBasicType.getJdbcType().isString() ? EnumType.STRING : EnumType.ORDINAL ); } else { @@ -619,7 +613,7 @@ private void applyBasicTypeMapping( jaxbBasicMapping.setJdbcType( standardBasicType.getJdbcType().getClass().getName() ); } } - else if ( type instanceof CustomType ) { + else if ( basicType instanceof CustomType ) { if ( isNotEmpty( hbmTypeAttribute ) ) { jaxbBasicMapping.setType( interpretBasicType( hbmTypeAttribute, @@ -636,7 +630,7 @@ else if ( type instanceof CustomType ) { ) ); } } - else if ( type instanceof ConvertedBasicType convertedType ) { + else if ( basicType instanceof ConvertedBasicType convertedType ) { if ( converterConsumer == null ) { throw new AssertionFailure( "Unexpected context for converted value" ); } @@ -679,88 +673,62 @@ private static void transferBaseTableInfo(Table table, JaxbTableMapping jaxbTabl } - - - - - - - - - - - - - - - - - - @SuppressWarnings("unchecked") private void transferFilterDefinitions() { - final List filterDefs = hbmXmlBinding.getRoot().getFilterDef(); - final JaxbEntityMappingsImpl ormRoot = mappingXmlBinding.getRoot(); - - if ( filterDefs.isEmpty() ) { - return; - } - - for ( JaxbHbmFilterDefinitionType hbmFilterDef : filterDefs ) { - final JaxbFilterDefImpl filterDef = new JaxbFilterDefImpl(); - ormRoot.getFilterDefinitions().add( filterDef ); - filterDef.setName( hbmFilterDef.getName() ); - - boolean foundCondition = false; - for ( Object content : hbmFilterDef.getContent() ) { - if ( content instanceof String string ) { - if ( !isBlank( string ) ) { - foundCondition = true; - filterDef.setDefaultCondition( string.trim() ); + final var filterDefs = hbmXmlBinding.getRoot().getFilterDef(); + final var ormRoot = mappingXmlBinding.getRoot(); + + if ( !filterDefs.isEmpty() ) { + for ( var hbmFilterDef : filterDefs ) { + final var filterDef = new JaxbFilterDefImpl(); + ormRoot.getFilterDefinitions().add( filterDef ); + filterDef.setName( hbmFilterDef.getName() ); + + boolean foundCondition = false; + for ( Object content : hbmFilterDef.getContent() ) { + if ( content instanceof String string ) { + if ( !isBlank( string ) ) { + foundCondition = true; + filterDef.setDefaultCondition( string.trim() ); + } + } + else { + final var hbmFilterParam = ((JAXBElement) content).getValue(); + final var filterParam = new JaxbFilterDefImpl.JaxbFilterParamImpl(); + filterDef.getFilterParams().add( filterParam ); + filterParam.setName( hbmFilterParam.getParameterName() ); + filterParam.setType( hbmFilterParam.getParameterValueTypeName() ); } } - else { - final JaxbHbmFilterParameterType hbmFilterParam = - ( (JAXBElement) content ).getValue(); - final JaxbFilterDefImpl.JaxbFilterParamImpl param = new JaxbFilterDefImpl.JaxbFilterParamImpl(); - filterDef.getFilterParams().add( param ); - param.setName( hbmFilterParam.getParameterName() ); - param.setType( hbmFilterParam.getParameterValueTypeName() ); - } - } - if ( !foundCondition ) { - filterDef.setDefaultCondition( hbmFilterDef.getCondition() ); + if ( !foundCondition ) { + filterDef.setDefaultCondition( hbmFilterDef.getCondition() ); + } } } } private void transferImports() { - final List hbmImports = hbmXmlBinding.getRoot().getImport(); - if ( hbmImports.isEmpty() ) { - return; - } - final JaxbEntityMappingsImpl ormRoot = mappingXmlBinding.getRoot(); - - for ( JaxbHbmClassRenameType hbmImport : hbmImports ) { - final JaxbHqlImportImpl ormImport = new JaxbHqlImportImpl(); - ormRoot.getHqlImports().add( ormImport ); - ormImport.setClazz( hbmImport.getClazz() ); - ormImport.setRename( hbmImport.getRename() ); + final var hbmImports = hbmXmlBinding.getRoot().getImport(); + if ( !hbmImports.isEmpty() ) { + final var ormRoot = mappingXmlBinding.getRoot(); + for ( var hbmImport : hbmImports ) { + final JaxbHqlImportImpl ormImport = new JaxbHqlImportImpl(); + ormRoot.getHqlImports().add( ormImport ); + ormImport.setClazz( hbmImport.getClazz() ); + ormImport.setRename( hbmImport.getRename() ); + } } } private void transferResultSetMappings() { - final List hbmResultMappings = hbmXmlBinding.getRoot().getResultset(); - if ( hbmResultMappings.isEmpty() ) { - return; - } - - final JaxbEntityMappingsImpl ormRoot = mappingXmlBinding.getRoot(); - - for ( JaxbHbmResultSetMappingType hbmResultSet : hbmResultMappings ) { - final JaxbSqlResultSetMappingImpl mapping = transformResultSetMapping( null, hbmResultSet ); - ormRoot.getSqlResultSetMappings().add( mapping ); + final var hbmResultMappings = hbmXmlBinding.getRoot().getResultset(); + if ( !hbmResultMappings.isEmpty() ) { + final var ormRoot = mappingXmlBinding.getRoot(); + for ( var hbmResultSet : hbmResultMappings ) { + final var mapping = transformResultSetMapping( null, hbmResultSet ); + ormRoot.getSqlResultSetMappings().add( mapping ); + } } } @@ -771,7 +739,7 @@ private JaxbSqlResultSetMappingImpl transformResultSetMapping( ? hbmResultSet.getName() : namePrefix + "." + hbmResultSet.getName(); - final JaxbSqlResultSetMappingImpl mapping = new JaxbSqlResultSetMappingImpl(); + final var mapping = new JaxbSqlResultSetMappingImpl(); mapping.setName( resultMappingName ); mapping.setDescription( "SQL ResultSet mapping - " + resultMappingName ); @@ -818,17 +786,17 @@ else if ( hbmReturn instanceof JaxbHbmNativeQueryCollectionLoadReturnType ) { private JaxbEntityResultImpl transferEntityReturnElement( String resultMappingName, JaxbHbmNativeQueryReturnType hbmReturn) { - final JaxbEntityResultImpl entityResult = new JaxbEntityResultImpl(); + final var entityResult = new JaxbEntityResultImpl(); entityResult.setEntityClass( getFullyQualifiedClassName( hbmReturn.getClazz() ) ); - for ( JaxbHbmNativeQueryPropertyReturnType propertyReturn : hbmReturn.getReturnProperty() ) { - final JaxbFieldResultImpl field = new JaxbFieldResultImpl(); + for ( var propertyReturn : hbmReturn.getReturnProperty() ) { + final var field = new JaxbFieldResultImpl(); final List columns = new ArrayList<>(); if ( !isEmpty( propertyReturn.getColumn() ) ) { columns.add( propertyReturn.getColumn() ); } - for ( JaxbHbmNativeQueryPropertyReturnType.JaxbHbmReturnColumn returnColumn : propertyReturn.getReturnColumn() ) { + for ( var returnColumn : propertyReturn.getReturnColumn() ) { columns.add( returnColumn.getName() ); } @@ -855,7 +823,7 @@ private JaxbEntityResultImpl transferEntityReturnElement( private JaxbColumnResultImpl transferScalarReturnElement( String resultMappingName, JaxbHbmNativeQueryScalarReturnType hbmReturn) { - final JaxbColumnResultImpl columnResult = new JaxbColumnResultImpl(); + final var columnResult = new JaxbColumnResultImpl(); columnResult.setName( hbmReturn.getColumn() ); columnResult.setClazz( hbmReturn.getType() ); handleUnsupportedContent( @@ -881,10 +849,10 @@ private void transferFetchProfiles() { } private static JaxbFetchProfileImpl transferFetchProfile(JaxbHbmFetchProfileType hbmFetchProfile) { - final JaxbFetchProfileImpl fetchProfile = new JaxbFetchProfileImpl(); + final var fetchProfile = new JaxbFetchProfileImpl(); fetchProfile.setName( hbmFetchProfile.getName() ); - for ( JaxbHbmFetchProfileType.JaxbHbmFetch hbmFetch : hbmFetchProfile.getFetch() ) { - final JaxbFetchProfileImpl.JaxbFetchImpl fetch = new JaxbFetchProfileImpl.JaxbFetchImpl(); + for ( var hbmFetch : hbmFetchProfile.getFetch() ) { + final var fetch = new JaxbFetchProfileImpl.JaxbFetchImpl(); fetchProfile.getFetch().add( fetch ); fetch.setEntity( hbmFetch.getEntity() ); fetch.setAssociation( hbmFetch.getAssociation() ); @@ -894,18 +862,17 @@ private static JaxbFetchProfileImpl transferFetchProfile(JaxbHbmFetchProfileType } private void transferNamedQueries() { - final List hbmHqlQueries = hbmXmlBinding.getRoot().getQuery(); - if ( hbmHqlQueries.isEmpty() ) { - return; - } - - for ( JaxbHbmNamedQueryType hbmHqlQuery : hbmHqlQueries ) { - mappingXmlBinding.getRoot().getNamedQueries().add( transformNamedQuery( hbmHqlQuery, hbmHqlQuery.getName() ) ); + final var hbmHqlQueries = hbmXmlBinding.getRoot().getQuery(); + if ( !hbmHqlQueries.isEmpty() ) { + for ( var hbmHqlQuery : hbmHqlQueries ) { + mappingXmlBinding.getRoot().getNamedQueries() + .add( transformNamedQuery( hbmHqlQuery, hbmHqlQuery.getName() ) ); + } } } private static JaxbNamedHqlQueryImpl transformNamedQuery(JaxbHbmNamedQueryType hbmQuery, String name) { - final JaxbNamedHqlQueryImpl query = new JaxbNamedHqlQueryImpl(); + final var query = new JaxbNamedHqlQueryImpl(); query.setName( name ); query.setCacheable( hbmQuery.isCacheable() ); query.setCacheMode( hbmQuery.getCacheMode() ); @@ -923,9 +890,9 @@ private static JaxbNamedHqlQueryImpl transformNamedQuery(JaxbHbmNamedQueryType h query.setQuery( qryString ); } else { - @SuppressWarnings("unchecked") final JAXBElement element = (JAXBElement) content; - final JaxbHbmQueryParamType hbmQueryParam = element.getValue(); - final JaxbQueryParamTypeImpl queryParam = new JaxbQueryParamTypeImpl(); + @SuppressWarnings("unchecked") final var element = (JAXBElement) content; + final var hbmQueryParam = element.getValue(); + final var queryParam = new JaxbQueryParamTypeImpl(); query.getQueryParam().add( queryParam ); queryParam.setName( hbmQueryParam.getName() ); queryParam.setType( hbmQueryParam.getType() ); @@ -936,20 +903,19 @@ private static JaxbNamedHqlQueryImpl transformNamedQuery(JaxbHbmNamedQueryType h } private void transferNamedNativeQueries() { - final List hbmNativeQueries = hbmXmlBinding.getRoot().getSqlQuery(); - if ( hbmNativeQueries.isEmpty() ) { - return; - } - - for ( JaxbHbmNamedNativeQueryType hbmQuery : hbmNativeQueries ) { - mappingXmlBinding.getRoot().getNamedNativeQueries().add( transformNamedNativeQuery( hbmQuery, hbmQuery.getName() ) ); + final var hbmNativeQueries = hbmXmlBinding.getRoot().getSqlQuery(); + if ( !hbmNativeQueries.isEmpty() ) { + for ( var hbmQuery : hbmNativeQueries ) { + mappingXmlBinding.getRoot().getNamedNativeQueries() + .add( transformNamedNativeQuery( hbmQuery, hbmQuery.getName() ) ); + } } } private JaxbNamedNativeQueryImpl transformNamedNativeQuery(JaxbHbmNamedNativeQueryType hbmQuery, String queryName) { final String implicitResultSetMappingName = queryName + "-implicitResultSetMapping"; - final JaxbNamedNativeQueryImpl query = new JaxbNamedNativeQueryImpl(); + final var query = new JaxbNamedNativeQueryImpl(); query.setName( queryName ); query.setCacheable( hbmQuery.isCacheable() ); query.setCacheMode( hbmQuery.getCacheMode() ); @@ -972,7 +938,7 @@ private JaxbNamedNativeQueryImpl transformNamedNativeQuery(JaxbHbmNamedNativeQue else if ( content instanceof JAXBElement contentElement ) { final Object element = contentElement.getValue(); if ( element instanceof JaxbHbmQueryParamType hbmQueryParam ) { - final JaxbQueryParamTypeImpl queryParam = new JaxbQueryParamTypeImpl(); + final var queryParam = new JaxbQueryParamTypeImpl(); queryParam.setName( hbmQueryParam.getName() ); queryParam.setType( hbmQueryParam.getType() ); query.getQueryParam().add( queryParam ); @@ -1028,7 +994,7 @@ else if ( element instanceof JaxbHbmNativeQueryJoinReturnType ) { ); } else if ( element instanceof JaxbHbmSynchronizeType hbmSynchronize ) { - final JaxbSynchronizedTableImpl synchronize = new JaxbSynchronizedTableImpl(); + final var synchronize = new JaxbSynchronizedTableImpl(); synchronize.setTable( hbmSynchronize.getTable() ); query.getSynchronizations().add( synchronize ); } @@ -1048,38 +1014,36 @@ else if ( element instanceof JaxbHbmSynchronizeType hbmSynchronize ) { } private void transferDatabaseObjects() { - final List hbmDatabaseObjects = hbmXmlBinding.getRoot().getDatabaseObject(); - if ( hbmDatabaseObjects.isEmpty() ) { - return; - } - - for ( JaxbHbmAuxiliaryDatabaseObjectType hbmDatabaseObject : hbmDatabaseObjects ) { - // NOTE: database-object does not define a name nor a good "identifier" for logging (exportable) - - final JaxbDatabaseObjectImpl databaseObject = new JaxbDatabaseObjectImpl(); - mappingXmlBinding.getRoot().getDatabaseObjects().add( databaseObject ); - - databaseObject.setCreate( hbmDatabaseObject.getCreate() ); - databaseObject.setDrop( hbmDatabaseObject.getDrop() ); - - if ( ! hbmDatabaseObject.getDialectScope().isEmpty() ) { - hbmDatabaseObject.getDialectScope().forEach( (hbmScope) -> { - final JaxbDatabaseObjectScopeImpl scope = new JaxbDatabaseObjectScopeImpl(); - databaseObject.getDialectScopes().add( scope ); - - scope.setName( hbmScope.getName() ); - // hbm.xml does not define min/max versions for its dialect-scope type - } ); + final var hbmDatabaseObjects = hbmXmlBinding.getRoot().getDatabaseObject(); + if ( !hbmDatabaseObjects.isEmpty() ) { + for ( var hbmDatabaseObject : hbmDatabaseObjects ) { + // NOTE: database-object does not define a name nor a good "identifier" for logging (exportable) + + final var databaseObject = new JaxbDatabaseObjectImpl(); + mappingXmlBinding.getRoot().getDatabaseObjects().add( databaseObject ); + + databaseObject.setCreate( hbmDatabaseObject.getCreate() ); + databaseObject.setDrop( hbmDatabaseObject.getDrop() ); + + if ( !hbmDatabaseObject.getDialectScope().isEmpty() ) { + hbmDatabaseObject.getDialectScope().forEach( (hbmScope) -> { + final var scope = new JaxbDatabaseObjectScopeImpl(); + scope.setName( hbmScope.getName() ); + databaseObject.getDialectScopes().add( scope ); + // hbm.xml does not define min/max versions for its dialect-scope type + } ); + } } } } private void transformEntityCaching(JaxbHbmRootEntityType hbmClass, JaxbEntityImpl entity) { - entity.setCaching( new JaxbCachingImpl() ); - entity.getCaching().setRegion( hbmClass.getCache().getRegion() ); - entity.getCaching().setAccess( hbmClass.getCache().getUsage() ); - entity.getCaching().setIncludeLazy( convert( hbmClass.getCache().getInclude() ) ); + final var caching = new JaxbCachingImpl(); + caching.setRegion( hbmClass.getCache().getRegion() ); + caching.setAccess( hbmClass.getCache().getUsage() ); + caching.setIncludeLazy( convert( hbmClass.getCache().getInclude() ) ); + entity.setCaching( caching ); } private boolean convert(JaxbHbmCacheInclusionEnum hbmInclusion) { @@ -1099,15 +1063,15 @@ private boolean convert(JaxbHbmCacheInclusionEnum hbmInclusion) { } private void transferResultSetMappings(String namePrefix, ResultSetMappingContainer container) { - final List resultSetMappings = container.getResultset(); + final var resultSetMappings = container.getResultset(); resultSetMappings.forEach( (hbmMapping) -> { - final JaxbSqlResultSetMappingImpl mapping = transformResultSetMapping( namePrefix, hbmMapping ); + final var mapping = transformResultSetMapping( namePrefix, hbmMapping ); mappingXmlBinding.getRoot().getSqlResultSetMappings().add( mapping ); } ); } private void transferToolingHints(ToolingHintContainer container) { - if ( CollectionHelper.isNotEmpty( container.getToolingHints() ) ) { + if ( isNotEmpty( container.getToolingHints() ) ) { handleUnsupported( "Transformation of (tooling hint) is not supported - `%s`", hbmXmlBinding.getOrigin() @@ -1121,12 +1085,12 @@ private void transferColumnsAndFormulas( ColumnDefaults columnDefaults, String table) { for ( int i = 0; i < value.getSelectables().size(); i++ ) { - final Selectable selectable = value.getSelectables().get( i ); + final var selectable = value.getSelectables().get( i ); if ( selectable instanceof Formula formula ) { target.addFormula( formula.getFormula() ); } else if ( selectable instanceof Column column ) { - final TargetColumnAdapter targetColumnAdapter = target.makeColumnAdapter( columnDefaults ); + final var targetColumnAdapter = target.makeColumnAdapter( columnDefaults ); targetColumnAdapter.setName( column.getQuotedName() ); targetColumnAdapter.setTable( table ); targetColumnAdapter.setLength( convertColumnLength( column.getLength() ) ); @@ -1157,10 +1121,10 @@ private void transferColumnsAndFormulas( target.addFormula( source.getFormulaAttribute() ); } else if ( isNotEmpty( source.getColumnAttribute() ) ) { - final TargetColumnAdapter column = target.makeColumnAdapter( columnDefaults ); - column.setName( source.getColumnAttribute() ); - column.setTable( tableName ); - target.addColumn( column ); + final var targetColumnAdapter = target.makeColumnAdapter( columnDefaults ); + targetColumnAdapter.setName( source.getColumnAttribute() ); + targetColumnAdapter.setTable( tableName ); + target.addColumn( targetColumnAdapter ); } else if ( !source.getColumnOrFormula().isEmpty() ) { for ( Serializable columnOrFormula : source.getColumnOrFormula() ) { @@ -1168,20 +1132,20 @@ else if ( !source.getColumnOrFormula().isEmpty() ) { target.addFormula( string ); } else { - final JaxbHbmColumnType hbmColumn = (JaxbHbmColumnType) columnOrFormula; - final TargetColumnAdapter column = target.makeColumnAdapter( columnDefaults ); - column.setTable( tableName ); - transferColumn( source.wrap( hbmColumn ), column ); - target.addColumn( column ); + final var hbmColumn = (JaxbHbmColumnType) columnOrFormula; + final var targetColumnAdapter = target.makeColumnAdapter( columnDefaults ); + targetColumnAdapter.setTable( tableName ); + transferColumn( source.wrap( hbmColumn ), targetColumnAdapter ); + target.addColumn( targetColumnAdapter ); } } } else if ( isNotEmpty( tableName ) ) { // this is the case of transforming a where the property did not specify columns or formula. // we need to create a column still to pass along the secondary table name - final TargetColumnAdapter column = target.makeColumnAdapter( columnDefaults ); - column.setTable( tableName ); - target.addColumn( column ); + final var targetColumnAdapter = target.makeColumnAdapter( columnDefaults ); + targetColumnAdapter.setTable( tableName ); + target.addColumn( targetColumnAdapter ); } } @@ -1252,9 +1216,9 @@ private void transferDiscriminator( assert discriminatorValue.getSelectables().size() == 1; final boolean forceDiscriminator = bootEntityInfo.getPersistentClass().isForceDiscriminator(); - final DiscriminatorType discriminatorType = determineDiscriminatorType( discriminatorValue ); + final var discriminatorType = determineDiscriminatorType( discriminatorValue ); if ( discriminatorValue.hasFormula() ) { - final JaxbDiscriminatorFormulaImpl jaxbFormula = new JaxbDiscriminatorFormulaImpl(); + final var jaxbFormula = new JaxbDiscriminatorFormulaImpl(); mappingEntity.setDiscriminatorFormula( jaxbFormula ); jaxbFormula.setFragment( ( (Formula) discriminatorValue.getSelectables().get( 0 ) ).getFormula() ); jaxbFormula.setDiscriminatorType( discriminatorType ); @@ -1262,8 +1226,8 @@ private void transferDiscriminator( } else { assert discriminatorValue.getColumns().size() == 1; - final Column column = discriminatorValue.getColumns().get( 0 ); - final JaxbDiscriminatorColumnImpl jaxbColumn = new JaxbDiscriminatorColumnImpl(); + final var column = discriminatorValue.getColumns().get( 0 ); + final var jaxbColumn = new JaxbDiscriminatorColumnImpl(); mappingEntity.setDiscriminatorColumn( jaxbColumn ); jaxbColumn.setName( column.getName() ); jaxbColumn.setDiscriminatorType( discriminatorType ); @@ -1333,7 +1297,7 @@ private void transferBaseAttributes( for ( Object hbmAttributeMapping : hbmAttributeMappings ) { if ( hbmAttributeMapping instanceof JaxbHbmBasicAttributeType basic ) { try { - final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( basic.getName() ); + final var propertyInfo = managedTypeInfo.propertyInfoMap().get( basic.getName() ); attributes.getBasicAttributes().add( transformBasicAttribute( basic, propertyInfo ) ); } catch (Exception e) { @@ -1343,8 +1307,8 @@ private void transferBaseAttributes( else if ( hbmAttributeMapping instanceof JaxbHbmCompositeAttributeType hbmComponent ) { try { final String componentRole = roleBase + "." + hbmComponent.getName(); - final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( componentRole ); - final JaxbEmbeddableImpl jaxbEmbeddable = applyEmbeddable( + final var componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( componentRole ); + final var jaxbEmbeddable = applyEmbeddable( roleBase, hbmComponent, componentTypeInfo @@ -1377,7 +1341,7 @@ else if ( hbmAttributeMapping instanceof JaxbHbmDynamicComponentType dynamicComp } else if ( hbmAttributeMapping instanceof JaxbHbmOneToOneType hbmOneToOne ) { try { - final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmOneToOne.getName() ); + final var propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmOneToOne.getName() ); transferOneToOne( hbmOneToOne, propertyInfo, attributes ); } catch (Exception e) { @@ -1394,7 +1358,7 @@ else if ( hbmAttributeMapping instanceof JaxbHbmManyToOneType hbmManyToOne ) { } else if ( hbmAttributeMapping instanceof JaxbHbmAnyAssociationType any ) { try { - final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( any.getName() ); + final var propertyInfo = managedTypeInfo.propertyInfoMap().get( any.getName() ); attributes.getAnyMappingAttributes().add( transformAnyAttribute( any, propertyInfo ) ); } catch (Exception e) { @@ -1402,7 +1366,7 @@ else if ( hbmAttributeMapping instanceof JaxbHbmAnyAssociationType any ) { } } else if ( hbmAttributeMapping instanceof PluralAttributeInfo hbmCollection ) { - final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmCollection.getName() ); + final var propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmCollection.getName() ); if ( hbmCollection.getElement() != null || hbmCollection.getCompositeElement() != null ) { try { attributes.getElementCollectionAttributes().add( transformElementCollection( roleBase, hbmCollection, propertyInfo ) ); @@ -1443,7 +1407,7 @@ else if ( hbmCollection.getManyToAny() != null ) { } private JaxbBasicImpl transformBasicAttribute(final JaxbHbmBasicAttributeType hbmProp, PropertyInfo propertyInfo) { - final JaxbBasicImpl basic = new JaxbBasicImpl(); + final var basic = new JaxbBasicImpl(); transferBasicAttribute( hbmProp, basic, propertyInfo ); return basic; } @@ -1466,12 +1430,12 @@ private void transferBasicAttribute( basic::setEnumerated, basicValueConverter -> { if ( basicValueConverter instanceof AttributeConverter jpaAttributeConverter ) { - final JaxbConvertImpl jaxbConvert = new JaxbConvertImpl(); + final var jaxbConvert = new JaxbConvertImpl(); jaxbConvert.setConverter( jpaAttributeConverter.getClass().getName() ); basic.setConvert( jaxbConvert ); } else if ( basicValueConverter instanceof JpaAttributeConverter jpaAttributeConverter ) { - final JaxbConvertImpl jaxbConvert = new JaxbConvertImpl(); + final var jaxbConvert = new JaxbConvertImpl(); jaxbConvert.setConverter( jpaAttributeConverter.getConverterJavaType().getTypeName() ); basic.setConvert( jaxbConvert ); } @@ -1563,15 +1527,15 @@ public Boolean isUpdatable() { private JaxbUserTypeImpl interpretBasicType(String typeName, JaxbHbmConfigParameterContainer typeLocalParams, JaxbHbmTypeDefinitionType typeDef) { assert isNotEmpty( typeName ); - final JaxbUserTypeImpl typeNode = new JaxbUserTypeImpl(); + final var typeNode = new JaxbUserTypeImpl(); if ( typeDef == null ) { typeNode.setValue( typeName ); } else { typeNode.setValue( typeDef.getClazz() ); - for ( JaxbHbmConfigParameterType hbmParam : typeDef.getConfigParameters() ) { - final JaxbConfigurationParameterImpl param = new JaxbConfigurationParameterImpl(); + for ( var hbmParam : typeDef.getConfigParameters() ) { + final var param = new JaxbConfigurationParameterImpl(); param.setName( hbmParam.getName() ); param.setValue( hbmParam.getValue() ); typeNode.getParameters().add( param ); @@ -1579,8 +1543,8 @@ private JaxbUserTypeImpl interpretBasicType(String typeName, JaxbHbmConfigParame } if ( typeLocalParams != null ) { - for ( JaxbHbmConfigParameterType hbmParam : typeLocalParams.getConfigParameters() ) { - final JaxbConfigurationParameterImpl param = new JaxbConfigurationParameterImpl(); + for ( var hbmParam : typeLocalParams.getConfigParameters() ) { + final var param = new JaxbConfigurationParameterImpl(); param.setName( hbmParam.getName() ); param.setValue( hbmParam.getValue() ); typeNode.getParameters().add( param ); @@ -1596,7 +1560,7 @@ private JaxbEmbeddableImpl applyEmbeddable( ComponentTypeInfo componentTypeInfo) { final String embeddableClassName = componentTypeInfo.getComponent().getComponentClassName(); if ( isNotEmpty( embeddableClassName ) ) { - final JaxbEmbeddableImpl existing = jaxbEmbeddableByClassName.get( embeddableClassName ); + final var existing = jaxbEmbeddableByClassName.get( embeddableClassName ); if ( existing != null ) { return existing; } @@ -1604,7 +1568,7 @@ private JaxbEmbeddableImpl applyEmbeddable( final String role = roleBase + "." + hbmComponent.getName(); final String embeddableName = determineEmbeddableName( embeddableClassName, hbmComponent.getName() ); - final JaxbEmbeddableImpl jaxbEmbeddable = convertEmbeddable( + final var jaxbEmbeddable = convertEmbeddable( role, embeddableName, embeddableClassName, @@ -1625,9 +1589,9 @@ private JaxbEmbeddableImpl convertEmbeddable( String embeddableName, String embeddableClassName, JaxbHbmCompositeAttributeType hbmComponent) { - final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( role ); + final var componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( role ); - final JaxbEmbeddableImpl embeddable = new JaxbEmbeddableImpl(); + final var embeddable = new JaxbEmbeddableImpl(); embeddable.setMetadataComplete( true ); embeddable.setName( embeddableName ); embeddable.setClazz( embeddableClassName ); @@ -1648,7 +1612,7 @@ private String determineEmbeddableName(String componentClassName, String attribu private JaxbEmbeddedImpl transformEmbedded( JaxbEmbeddableImpl jaxbEmbeddable, JaxbHbmCompositeAttributeType hbmComponent) { - final JaxbEmbeddedImpl embedded = new JaxbEmbeddedImpl(); + final var embedded = new JaxbEmbeddedImpl(); embedded.setName( hbmComponent.getName() ); embedded.setAttributeAccessor( hbmComponent.getAccess() ); embedded.setTarget( jaxbEmbeddable.getName() ); @@ -1656,7 +1620,7 @@ private JaxbEmbeddedImpl transformEmbedded( } private void transferOneToOne(JaxbHbmOneToOneType hbmOneToOne, PropertyInfo propertyInfo, JaxbAttributesContainer attributes) { - final JaxbOneToOneImpl oneToOne = new JaxbOneToOneImpl(); + final var oneToOne = new JaxbOneToOneImpl(); oneToOne.setAttributeAccessor( hbmOneToOne.getAccess() ); oneToOne.setOptional( propertyInfo.bootModelProperty().isOptional() ); oneToOne.setCascade( convertCascadeType( hbmOneToOne.getCascade() ) ); @@ -1687,13 +1651,13 @@ private void transferManyToOne( ManagedTypeInfo managedTypeInfo, JaxbAttributesContainer attributes, JaxbHbmManyToOneType hbmManyToOne) { - final PropertyInfo propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmManyToOne.getName() ); - final JaxbManyToOneImpl jaxbManyToOne = transformManyToOne( hbmManyToOne, propertyInfo ); + final var propertyInfo = managedTypeInfo.propertyInfoMap().get( hbmManyToOne.getName() ); + final var jaxbManyToOne = transformManyToOne( hbmManyToOne, propertyInfo ); attributes.getManyToOneAttributes().add( jaxbManyToOne ); } private JaxbManyToOneImpl transformManyToOne(JaxbHbmManyToOneType hbmNode, PropertyInfo propertyInfo) { - final JaxbManyToOneImpl jaxbManyToOne = new JaxbManyToOneImpl(); + final var jaxbManyToOne = new JaxbManyToOneImpl(); jaxbManyToOne.setName( hbmNode.getName() ); jaxbManyToOne.setOptional( propertyInfo.bootModelProperty().isOptional() ); if ( isNotEmpty( hbmNode.getEntityName() ) ) { @@ -1712,8 +1676,8 @@ private JaxbManyToOneImpl transformManyToOne(JaxbHbmManyToOneType hbmNode, Prope jaxbManyToOne.getPropertyRef().setName( hbmNode.getPropertyRef() ); } - final Property manyToOneProperty = propertyInfo.bootModelProperty(); - final ManyToOne manyToOne = (ManyToOne) manyToOneProperty.getValue(); + final var manyToOneProperty = propertyInfo.bootModelProperty(); + final var manyToOne = (ManyToOne) manyToOneProperty.getValue(); transferColumnsAndFormulas( manyToOne, new ColumnAndFormulaTarget() { @@ -1755,7 +1719,7 @@ private NotFoundAction interpretNotFoundAction(JaxbHbmNotFoundEnum hbmNotFound) private JaxbAnyMappingImpl transformAnyAttribute(JaxbHbmAnyAssociationType source, PropertyInfo propertyInfo) { - final JaxbAnyMappingImpl target = new JaxbAnyMappingImpl(); + final var target = new JaxbAnyMappingImpl(); target.setName( source.getName() ); target.setAttributeAccessor( source.getAccess() ); @@ -1768,7 +1732,7 @@ private JaxbAnyMappingImpl transformAnyAttribute(JaxbHbmAnyAssociationType sourc target.setDiscriminator( new JaxbAnyMappingDiscriminatorImpl() ); source.getMetaValue().forEach( (sourceMapping) -> { - final JaxbAnyDiscriminatorValueMappingImpl mapping = new JaxbAnyDiscriminatorValueMappingImpl(); + final var mapping = new JaxbAnyDiscriminatorValueMappingImpl(); mapping.setDiscriminatorValue( sourceMapping.getValue() ); mapping.setCorrespondingEntityName( sourceMapping.getClazz() ); target.getDiscriminator().getValueMappings().add( mapping ); @@ -1783,7 +1747,7 @@ private JaxbElementCollectionImpl transformElementCollection( String roleBase, PluralAttributeInfo source, PropertyInfo propertyInfo) { - final JaxbElementCollectionImpl target = new JaxbElementCollectionImpl(); + final var target = new JaxbElementCollectionImpl(); transferCollectionCommonInfo( source, target ); transferCollectionTable( source, target ); @@ -1803,13 +1767,13 @@ private void transferCollectionTable( final JaxbElementCollectionImpl target) { target.setCollectionTable( new JaxbCollectionTableImpl() ); - final JaxbCollectionTableImpl collectionTable = target.getCollectionTable(); + final var collectionTable = target.getCollectionTable(); if ( isNotEmpty( source.getTable() ) ) { collectionTable.setName( source.getTable() ); collectionTable.setCatalog( source.getCatalog() ); collectionTable.setSchema( source.getSchema() ); } - final JaxbHbmKeyType key = source.getKey(); + final var key = source.getKey(); if ( key != null ) { collectionTable.setForeignKeys( transformForeignKey( key.getForeignKey() ) ); transferColumnsAndFormulas( @@ -1877,7 +1841,7 @@ private void transferCollectionCommonInfo(PluralAttributeInfo source, JaxbPlural target.setFetch( convert( source.getLazy() ) ); if ( isNotEmpty( source.getCollectionType() ) ) { - final JaxbCollectionUserTypeImpl jaxbCollectionUserType = new JaxbCollectionUserTypeImpl(); + final var jaxbCollectionUserType = new JaxbCollectionUserTypeImpl(); target.setCollectionType( jaxbCollectionUserType ); jaxbCollectionUserType.setType( source.getCollectionType() ); } @@ -1944,7 +1908,7 @@ private void transferListIndex( JaxbHbmIndexType index, JaxbHbmListIndexType listIndex, JaxbPluralAttribute target) { - final JaxbOrderColumnImpl orderColumn = new JaxbOrderColumnImpl(); + final var orderColumn = new JaxbOrderColumnImpl(); target.setOrderColumn( orderColumn ); if ( index != null ) { @@ -1953,7 +1917,7 @@ private void transferListIndex( orderColumn.setName( index.getColumnAttribute() ); } else if ( index.getColumn().size() == 1 ) { - final JaxbHbmColumnType hbmColumn = index.getColumn().get( 0 ); + final var hbmColumn = index.getColumn().get( 0 ); orderColumn.setName( hbmColumn.getName() ); orderColumn.setNullable( invert( hbmColumn.isNotNull() ) ); orderColumn.setColumnDefinition( hbmColumn.getSqlType() ); @@ -1974,7 +1938,7 @@ else if ( listIndex.getColumn() != null ) { private void transferMapKey(JaxbHbmMapType source, JaxbPluralAttribute target) { if ( source.getIndex() != null ) { - final JaxbMapKeyColumnImpl mapKey = new JaxbMapKeyColumnImpl(); + final var mapKey = new JaxbMapKeyColumnImpl(); // TODO: multiple columns? mapKey.setName( source.getIndex().getColumnAttribute() ); target.setMapKeyColumn( mapKey ); @@ -1988,7 +1952,7 @@ else if ( source.getMapKey() != null ) { return; } - if ( CollectionHelper.isNotEmpty( source.getMapKey().getColumnOrFormula() ) ) { + if ( isNotEmpty( source.getMapKey().getColumnOrFormula() ) ) { handleUnsupported( "Transformation of column/formula elements within map-keys is not supported - `%s`", origin() @@ -2107,8 +2071,8 @@ private void transferElementTypeInfo( JaxbHbmBasicCollectionElementType element, PropertyInfo propertyInfo, JaxbElementCollectionImpl target) { - final Collection collectionValue = (Collection) propertyInfo.bootModelProperty().getValue(); - final BasicValue basicValue = (BasicValue) collectionValue.getElement(); + final var collectionValue = (Collection) propertyInfo.bootModelProperty().getValue(); + final var basicValue = (BasicValue) collectionValue.getElement(); applyBasicTypeMapping( basicValue, target, @@ -2117,12 +2081,12 @@ private void transferElementTypeInfo( target::setEnumerated, basicValueConverter -> { if ( basicValueConverter instanceof AttributeConverter jpaAttributeConverter ) { - final JaxbConvertImpl jaxbConvert = new JaxbConvertImpl(); + final var jaxbConvert = new JaxbConvertImpl(); jaxbConvert.setConverter( jpaAttributeConverter.getClass().getName() ); target.getConverts().add( jaxbConvert ); } else if ( basicValueConverter instanceof JpaAttributeConverter jpaAttributeConverter ) { - final JaxbConvertImpl jaxbConvert = new JaxbConvertImpl(); + final var jaxbConvert = new JaxbConvertImpl(); jaxbConvert.setConverter( jpaAttributeConverter.getConverterJavaType().getTypeName() ); target.getConverts().add( jaxbConvert ); } @@ -2143,14 +2107,14 @@ private void transferElementInfo( final String embeddableName = determineEmbeddableName( embeddableClassName, hbmCollection.getName() ); final String partRole = roleBase + "." + hbmCollection.getName() + ".value"; - final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( partRole ); + final var componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( partRole ); target.setTarget( embeddableName ); if ( isNotEmpty( embeddableClassName ) ) { target.setTargetClass( embeddableClassName ); } - final JaxbEmbeddableImpl embeddable = new JaxbEmbeddableImpl(); + final var embeddable = new JaxbEmbeddableImpl(); embeddable.setClazz( embeddableClassName ); embeddable.setName( embeddableName ); embeddable.setAttributes( new JaxbEmbeddableAttributesContainerImpl() ); @@ -2164,7 +2128,7 @@ private void transferElementInfo( } private JaxbOneToManyImpl transformOneToMany(PluralAttributeInfo hbmCollection, PropertyInfo propertyInfo) { - final JaxbOneToManyImpl target = new JaxbOneToManyImpl(); + final var target = new JaxbOneToManyImpl(); transferOneToManyInfo( hbmCollection, hbmCollection.getOneToMany(), target , propertyInfo); return target; } @@ -2184,10 +2148,10 @@ private void transferOneToManyInfo( transferCollectionCommonInfo( hbmAttributeInfo, target ); target.setTargetEntity( isNotEmpty( hbmOneToMany.getClazz() ) ? hbmOneToMany.getClazz() : hbmOneToMany.getEntityName() ); - final Property bootModelProperty = propertyInfo.bootModelProperty(); - final Collection bootModelValue = (Collection) bootModelProperty.getValue(); + final var bootModelProperty = propertyInfo.bootModelProperty(); + final var bootModelValue = (Collection) bootModelProperty.getValue(); - final JaxbHbmKeyType key = hbmAttributeInfo.getKey(); + final var key = hbmAttributeInfo.getKey(); if ( bootModelValue.isInverse() ) { target.setMappedBy( resolveMappedBy( hbmAttributeInfo, bootModelProperty, bootModelValue ) ); @@ -2252,7 +2216,7 @@ public void addFormula(String formula) { target.setOrphanRemoval( isOrphanRemoval( hbmAttributeInfo.getCascade() ) ); target.setCascade( convertCascadeType( hbmAttributeInfo.getCascade() ) ); - for ( JaxbHbmFilterType hbmFilter : hbmAttributeInfo.getFilter() ) { + for ( var hbmFilter : hbmAttributeInfo.getFilter() ) { target.getFilters().add( convert( hbmFilter ) ); } @@ -2260,22 +2224,22 @@ public void addFormula(String formula) { target.setSqlRestriction( hbmAttributeInfo.getWhere() ); } if ( hbmAttributeInfo.getSqlInsert() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlInsert( jaxbCustomSql ); transferCustomSql( hbmAttributeInfo.getSqlInsert(), jaxbCustomSql ); } if ( hbmAttributeInfo.getSqlUpdate() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlUpdate( jaxbCustomSql ); transferCustomSql( hbmAttributeInfo.getSqlUpdate(), jaxbCustomSql ); } if ( hbmAttributeInfo.getSqlDelete() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlDelete( jaxbCustomSql ); transferCustomSql( hbmAttributeInfo.getSqlDelete(), jaxbCustomSql ); } if ( hbmAttributeInfo.getSqlDeleteAll() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlDeleteAll( jaxbCustomSql ); transferCustomSql( hbmAttributeInfo.getSqlDeleteAll(), jaxbCustomSql ); } @@ -2289,9 +2253,9 @@ private String resolveMappedBy( return bootModelValue.getMappedByProperty(); } - final OneToMany element = (OneToMany) bootModelValue.getElement(); + final var element = (OneToMany) bootModelValue.getElement(); final String referencedEntityName = element.getReferencedEntityName(); - final Map, String> attributeMap = transformationState.getMappableAttributesByColumns( referencedEntityName ); + final var attributeMap = transformationState.getMappableAttributesByColumns( referencedEntityName ); return resolveMappedBy( bootModelProperty, bootModelValue, attributeMap ); } @@ -2301,7 +2265,7 @@ private String resolveMappedBy( Map, String> attributeMap) { if ( attributeMap != null ) { final KeyValue collectionKey = bootModelValue.getKey(); - for ( Map.Entry, String> attributeEntry : attributeMap.entrySet() ) { + for ( var attributeEntry : attributeMap.entrySet() ) { if ( matches( collectionKey, attributeEntry.getKey() ) ) { return attributeEntry.getValue(); } @@ -2319,25 +2283,23 @@ private String resolveMappedBy( } private boolean matches(KeyValue collectionKey, List candidate) { - final List collectionKeySelectables = collectionKey.getSelectables(); + final var collectionKeySelectables = collectionKey.getSelectables(); if ( collectionKeySelectables.size() != candidate.size() ) { return false; } // opt-out checking -> looking for a non-match for ( int i = 0; i < collectionKeySelectables.size(); i++ ) { - final Selectable collectionKeySelectable = collectionKeySelectables.get( i ); - final Selectable candidateSelectable = candidate.get( i ); - if ( collectionKeySelectable instanceof Formula || candidateSelectable instanceof Formula ) { - continue; - } - - final Column collectionKeyColumn = (Column) collectionKeySelectable; - final Column candidateColumn = (Column) candidateSelectable; - assert isNotEmpty( collectionKeyColumn.getCanonicalName() ); - assert isNotEmpty( candidateColumn.getCanonicalName() ); - if ( !collectionKeyColumn.getCanonicalName().equals( candidateColumn.getCanonicalName() ) ) { - return false; + final var collectionKeySelectable = collectionKeySelectables.get( i ); + final var candidateSelectable = candidate.get( i ); + if ( !(collectionKeySelectable instanceof Formula) && !(candidateSelectable instanceof Formula) ) { + final var collectionKeyColumn = (Column) collectionKeySelectable; + final var candidateColumn = (Column) candidateSelectable; + assert isNotEmpty( collectionKeyColumn.getCanonicalName() ); + assert isNotEmpty( candidateColumn.getCanonicalName() ); + if ( !collectionKeyColumn.getCanonicalName().equals( candidateColumn.getCanonicalName() ) ) { + return false; + } } } @@ -2352,7 +2314,7 @@ private void transferCustomSql(JaxbHbmCustomSqlDmlType hbmCustomSql, JaxbCustomS } private JaxbManyToManyImpl transformManyToMany(PluralAttributeInfo hbmCollection, PropertyInfo propertyInfo) { - final JaxbManyToManyImpl target = new JaxbManyToManyImpl(); + final var target = new JaxbManyToManyImpl(); transferManyToManyInfo( hbmCollection, hbmCollection.getManyToMany(), propertyInfo, target ); return target; } @@ -2369,17 +2331,17 @@ private void transferManyToManyInfo( handleUnsupported( "`node` no longer supported" ); } - final Property bootModelProperty = propertyInfo.bootModelProperty(); - final Collection bootValue = (Collection) bootModelProperty.getValue(); + final var bootModelProperty = propertyInfo.bootModelProperty(); + final var bootValue = (Collection) bootModelProperty.getValue(); - final JaxbJoinTableImpl joinTable = new JaxbJoinTableImpl(); + final var joinTable = new JaxbJoinTableImpl(); final String tableName = hbmCollection.getTable(); if ( isNotEmpty( tableName ) ) { joinTable.setName( tableName ); } target.setJoinTable( joinTable ); - final JaxbHbmKeyType key = hbmCollection.getKey(); + final var key = hbmCollection.getKey(); if ( key != null ) { joinTable.setForeignKey( transformForeignKey( key.getForeignKey() ) ); transferColumnsAndFormulas( @@ -2468,13 +2430,15 @@ public void addFormula(String formula) { ); transferCollectionCommonInfo( hbmCollection, target ); - target.setTargetEntity( isNotEmpty( manyToMany.getClazz() ) ? manyToMany.getClazz() : manyToMany.getEntityName() ); + target.setTargetEntity( isNotEmpty( manyToMany.getClazz() ) + ? manyToMany.getClazz() + : manyToMany.getEntityName() ); if ( manyToMany.getNotFound() == JaxbHbmNotFoundEnum.IGNORE ) { target.setNotFound( NotFoundAction.IGNORE ); } - for ( JaxbHbmFilterType hbmFilter : hbmCollection.getFilter() ) { + for ( var hbmFilter : hbmCollection.getFilter() ) { target.getFilters().add( convert( hbmFilter ) ); } @@ -2482,29 +2446,29 @@ public void addFormula(String formula) { target.setSqlRestriction( hbmCollection.getWhere() ); } if ( hbmCollection.getSqlInsert() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlInsert( jaxbCustomSql ); transferCustomSql( hbmCollection.getSqlInsert(), jaxbCustomSql ); } if ( hbmCollection.getSqlUpdate() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlUpdate( jaxbCustomSql ); transferCustomSql( hbmCollection.getSqlUpdate(), jaxbCustomSql ); } if ( hbmCollection.getSqlDelete() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlDelete( jaxbCustomSql ); transferCustomSql( hbmCollection.getSqlDelete(), jaxbCustomSql ); } if ( hbmCollection.getSqlDeleteAll() != null ) { - final JaxbCustomSqlImpl jaxbCustomSql = new JaxbCustomSqlImpl(); + final var jaxbCustomSql = new JaxbCustomSqlImpl(); target.setSqlDeleteAll( jaxbCustomSql ); transferCustomSql( hbmCollection.getSqlDeleteAll(), jaxbCustomSql ); } } private JaxbPluralAnyMappingImpl transformPluralAny(PluralAttributeInfo hbmCollection) { - final JaxbPluralAnyMappingImpl target = new JaxbPluralAnyMappingImpl(); + final var target = new JaxbPluralAnyMappingImpl(); transferPluralAny( hbmCollection, hbmCollection.getManyToAny(), target ); return target; } @@ -2521,7 +2485,7 @@ private void transferIdentifier( JaxbEntityImpl mappingXmlEntity, EntityTypeInfo bootEntityInfo, RootClass rootClass) { - final Property identifierProperty = rootClass.getIdentifierProperty(); + final var identifierProperty = rootClass.getIdentifierProperty(); if ( identifierProperty != null ) { // we have either a simple id or an embedded id transferSinglePropertyIdentifier( hbmEntity, mappingXmlEntity, bootEntityInfo, rootClass, identifierProperty ); @@ -2538,12 +2502,12 @@ private void transferSinglePropertyIdentifier( RootClass rootClass, Property identifierProperty) { if ( identifierProperty.getValue() instanceof BasicValue basicValue ) { - final JaxbIdImpl simpleId = new JaxbIdImpl(); + final var simpleId = new JaxbIdImpl(); transferSimpleId( hbmEntity.getId(), simpleId, identifierProperty, basicValue ); mappingXmlEntity.getAttributes().getIdAttributes().add( simpleId ); } else { - final JaxbEmbeddedIdImpl embeddedId = new JaxbEmbeddedIdImpl(); + final var embeddedId = new JaxbEmbeddedIdImpl(); transferEmbeddedId( hbmEntity.getCompositeId(), embeddedId, bootEntityInfo, identifierProperty ); mappingXmlEntity.getAttributes().setEmbeddedIdAttribute( embeddedId ); } @@ -2559,19 +2523,19 @@ private void transferSimpleId( applyBasicTypeMapping( basicValue, target, source.getTypeAttribute(), source.getType(), null,null ); - final JaxbHbmGeneratorSpecificationType hbmGenerator = source.getGenerator(); + final var hbmGenerator = source.getGenerator(); if ( hbmGenerator != null && !"assigned".equals( hbmGenerator.getClazz() ) ) { - final JaxbGeneratedValueImpl jaxbGeneratedValue = new JaxbGeneratedValueImpl(); + final var jaxbGeneratedValue = new JaxbGeneratedValueImpl(); target.setGeneratedValue( jaxbGeneratedValue ); - final JaxbGenericIdGeneratorImpl generator = new JaxbGenericIdGeneratorImpl(); + final var generator = new JaxbGenericIdGeneratorImpl(); target.setGenericGenerator( generator ); generator.setClazz( hbmGenerator.getClazz() ); - final List hbmConfigParameters = hbmGenerator.getConfigParameters(); + final var hbmConfigParameters = hbmGenerator.getConfigParameters(); for ( int i = 0; i < hbmConfigParameters.size(); i++ ) { - final JaxbHbmConfigParameterType hbmConfigParameter = hbmConfigParameters.get( i ); - final JaxbConfigurationParameterImpl jaxbParam = new JaxbConfigurationParameterImpl(); + final var hbmConfigParameter = hbmConfigParameters.get( i ); + final var jaxbParam = new JaxbConfigurationParameterImpl(); generator.getParameters().add( jaxbParam ); jaxbParam.setName( hbmConfigParameter.getName() ); jaxbParam.setValue( hbmConfigParameter.getValue() ); @@ -2630,7 +2594,7 @@ private JaxbEmbeddableImpl transformEmbeddedIdEmbeddable( Property idProperty) { final String embeddableClassName = hbmCompositeId.getClazz(); if ( isNotEmpty( embeddableClassName ) ) { - final JaxbEmbeddableImpl existing = jaxbEmbeddableByClassName.get( embeddableClassName ); + final var existing = jaxbEmbeddableByClassName.get( embeddableClassName ); if ( existing != null ) { return existing; } @@ -2638,8 +2602,8 @@ private JaxbEmbeddableImpl transformEmbeddedIdEmbeddable( final String role = bootEntityInfo.getPersistentClass().getEntityName() + "." + hbmCompositeId.getName(); final String embeddableName = determineEmbeddableName( embeddableClassName, hbmCompositeId.getName() ); - final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( role ); - final JaxbEmbeddableImpl created = transferEmbeddedIdEmbeddable( + final var componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( role ); + final var created = transferEmbeddedIdEmbeddable( role, embeddableName, embeddableClassName, @@ -2656,7 +2620,7 @@ private JaxbEmbeddableImpl transferEmbeddedIdEmbeddable( String embeddableClassName, ComponentTypeInfo componentTypeInfo, JaxbHbmCompositeIdType hbmCompositeId) { - final JaxbEmbeddableImpl jaxbEmbeddable = new JaxbEmbeddableImpl(); + final var jaxbEmbeddable = new JaxbEmbeddableImpl(); jaxbEmbeddable.setName( embeddableName ); jaxbEmbeddable.setClazz( embeddableClassName ); @@ -2674,14 +2638,14 @@ private JaxbEmbeddableImpl transferEmbeddedIdEmbeddable( hbmCompositeId.getKeyPropertyOrKeyManyToOne().forEach( (hbmIdProperty) -> { if ( hbmIdProperty instanceof JaxbHbmCompositeKeyBasicAttributeType hbmKeyProperty ) { - final PropertyInfo keyPropertyInfo = componentTypeInfo.propertyInfoMap().get( hbmKeyProperty.getName() ); + final var keyPropertyInfo = componentTypeInfo.propertyInfoMap().get( hbmKeyProperty.getName() ); jaxbEmbeddable.getAttributes().getBasicAttributes().add( transformCompositeKeyProperty( hbmKeyProperty, keyPropertyInfo ) ); } else if ( hbmIdProperty instanceof JaxbHbmCompositeKeyManyToOneType hbmKeyManyToOne ) { - final PropertyInfo keyPropertyInfo = componentTypeInfo.propertyInfoMap().get( hbmKeyManyToOne.getName() ); + final var keyPropertyInfo = componentTypeInfo.propertyInfoMap().get( hbmKeyManyToOne.getName() ); jaxbEmbeddable.getAttributes().getManyToOneAttributes().add( transformCompositeKeyManyToOne( hbmKeyManyToOne, keyPropertyInfo @@ -2699,7 +2663,7 @@ else if ( hbmIdProperty instanceof JaxbHbmCompositeKeyManyToOneType hbmKeyManyTo private JaxbBasicImpl transformCompositeKeyProperty( JaxbHbmCompositeKeyBasicAttributeType hbmKeyProperty, PropertyInfo keyPropertyInfo) { - final JaxbBasicImpl jaxbBasic = new JaxbBasicImpl(); + final var jaxbBasic = new JaxbBasicImpl(); jaxbBasic.setName( hbmKeyProperty.getName() ); jaxbBasic.setOptional( false ); @@ -2808,7 +2772,7 @@ public Boolean isUpdatable() { private JaxbManyToOneImpl transformCompositeKeyManyToOne( JaxbHbmCompositeKeyManyToOneType hbmKeyManyToOne, PropertyInfo keyManyToOneInfo) { - final JaxbManyToOneImpl jaxbKyManyToOne = new JaxbManyToOneImpl(); + final var jaxbKyManyToOne = new JaxbManyToOneImpl(); jaxbKyManyToOne.setName( hbmKeyManyToOne.getName() ); if ( isNotEmpty( hbmKeyManyToOne.getEntityName() ) ) { @@ -2882,7 +2846,7 @@ private JaxbForeignKeyImpl transformForeignKey(String hbmForeignKeyName) { return null; } - final JaxbForeignKeyImpl jaxbForeignKey = new JaxbForeignKeyImpl(); + final var jaxbForeignKey = new JaxbForeignKeyImpl(); if ( "none".equalsIgnoreCase( hbmForeignKeyName ) ) { jaxbForeignKey.setConstraintMode( ConstraintMode.NO_CONSTRAINT ); } @@ -2897,15 +2861,15 @@ private void transferNonAggregatedCompositeId( JaxbEntityImpl mappingXmlEntity, EntityTypeInfo bootEntityInfo, RootClass rootClass) { - final JaxbHbmCompositeIdType hbmCompositeId = hbmEntity.getCompositeId(); + final var hbmCompositeId = hbmEntity.getCompositeId(); - final Component idClassMapping = rootClass.getIdentifierMapper(); + final var idClassMapping = rootClass.getIdentifierMapper(); if ( idClassMapping != null ) { transferIdClass( hbmCompositeId, idClassMapping, mappingXmlEntity ); } final String idRole = rootClass.getEntityName() + ".id"; - final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( idRole ); + final var componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( idRole ); assert componentTypeInfo != null; hbmCompositeId.getKeyPropertyOrKeyManyToOne().forEach( (hbmIdProperty) -> { @@ -2935,7 +2899,7 @@ private void transferIdClass( private JaxbIdImpl transformNonAggregatedKeyProperty( JaxbHbmCompositeKeyBasicAttributeType hbmIdProperty, PropertyInfo idPropertyInfo) { - final JaxbIdImpl jaxbBasic = new JaxbIdImpl(); + final var jaxbBasic = new JaxbIdImpl(); jaxbBasic.setName( hbmIdProperty.getName() ); transferAccess( hbmIdProperty.getAccess(), @@ -3045,7 +3009,7 @@ private void transferNaturalIdentifiers( return; } - final JaxbNaturalIdImpl naturalId = new JaxbNaturalIdImpl(); + final var naturalId = new JaxbNaturalIdImpl(); transferBaseAttributes( rootClass.getEntityName(), source.getNaturalId().getAttributes(), @@ -3112,11 +3076,11 @@ private void transferVersion( JaxbEntityImpl target, EntityTypeInfo bootEntityInfo, RootClass rootClass) { - final JaxbHbmVersionAttributeType hbmVersion = source.getVersion(); - final JaxbHbmTimestampAttributeType hbmTimestamp = source.getTimestamp(); + final var hbmVersion = source.getVersion(); + final var hbmTimestamp = source.getTimestamp(); if ( hbmVersion != null ) { - final JaxbVersionImpl version = new JaxbVersionImpl(); + final var version = new JaxbVersionImpl(); version.setName( hbmVersion.getName() ); if ( isNotEmpty( hbmVersion.getColumnAttribute() ) ) { version.setColumn( new JaxbColumnImpl() ); @@ -3125,7 +3089,7 @@ private void transferVersion( target.getAttributes().setVersion( version ); } else if ( hbmTimestamp != null ) { - final JaxbVersionImpl version = new JaxbVersionImpl(); + final var version = new JaxbVersionImpl(); version.setName( hbmTimestamp.getName() ); // TODO: multiple columns? if ( isNotEmpty( hbmTimestamp.getColumnAttribute() ) ) { @@ -3142,23 +3106,24 @@ private void transferJoins( JaxbHbmRootEntityType hbmEntity, JaxbEntityImpl mappingEntity, EntityTypeInfo bootEntityInfo) { - for ( JaxbHbmSecondaryTableType hbmJoin : hbmEntity.getJoin() ) { + for ( var hbmJoin : hbmEntity.getJoin() ) { transferSecondaryTable( hbmJoin, mappingEntity ); for ( Serializable hbmProperty : hbmJoin.getAttributes() ) { if ( hbmProperty instanceof JaxbHbmBasicAttributeType hbmBasicAttribute) { - final PropertyInfo propertyInfo = bootEntityInfo.propertyInfoMap().get( hbmBasicAttribute.getName() ); - final JaxbBasicImpl prop = transformBasicAttribute( hbmBasicAttribute, propertyInfo ); + final var propertyInfo = bootEntityInfo.propertyInfoMap().get( hbmBasicAttribute.getName() ); + final var prop = transformBasicAttribute( hbmBasicAttribute, propertyInfo ); if ( prop.getColumn() == null && prop.getFormula() == null ) { - prop.setColumn( new JaxbColumnImpl() ); - prop.getColumn().setTable( propertyInfo.bootModelProperty().getValue().getTable().getName() ); + final var column = new JaxbColumnImpl(); + column.setTable( propertyInfo.bootModelProperty().getValue().getTable().getName() ); + prop.setColumn( column ); } mappingEntity.getAttributes().getBasicAttributes().add( prop ); } else if ( hbmProperty instanceof JaxbHbmCompositeAttributeType hbmComponent ) { final String componentRole = bootEntityInfo.getPersistentClass().getEntityName() + "." + hbmComponent.getName(); - final ComponentTypeInfo componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( componentRole ); - final JaxbEmbeddableImpl jaxbEmbeddable = applyEmbeddable( + final var componentTypeInfo = transformationState.getEmbeddableInfoByRole().get( componentRole ); + final var jaxbEmbeddable = applyEmbeddable( bootEntityInfo.getPersistentClass().getEntityName(), hbmComponent, componentTypeInfo @@ -3166,8 +3131,8 @@ else if ( hbmProperty instanceof JaxbHbmCompositeAttributeType hbmComponent ) { mappingEntity.getAttributes().getEmbeddedAttributes().add( transformEmbedded( jaxbEmbeddable, hbmComponent ) ); } else if ( hbmProperty instanceof JaxbHbmManyToOneType hbmManyToOne ) { - final PropertyInfo propertyInfo = bootEntityInfo.propertyInfoMap().get( hbmManyToOne.getName() ); - final JaxbManyToOneImpl jaxbManyToOne = transformManyToOne( hbmManyToOne, propertyInfo ); + final var propertyInfo = bootEntityInfo.propertyInfoMap().get( hbmManyToOne.getName() ); + final var jaxbManyToOne = transformManyToOne( hbmManyToOne, propertyInfo ); mappingEntity.getAttributes().getManyToOneAttributes().add( jaxbManyToOne ); } else if ( hbmProperty instanceof JaxbHbmAnyAssociationType ) { @@ -3184,7 +3149,7 @@ else if ( hbmProperty instanceof JaxbHbmDynamicComponentType ) { } private void transferSecondaryTable(JaxbHbmSecondaryTableType hbmJoin, JaxbEntityImpl mappingEntity) { - final JaxbSecondaryTableImpl secondaryTable = new JaxbSecondaryTableImpl(); + final var secondaryTable = new JaxbSecondaryTableImpl(); secondaryTable.setCatalog( hbmJoin.getCatalog() ); secondaryTable.setComment( hbmJoin.getComment() ); secondaryTable.setName( hbmJoin.getTable() ); @@ -3193,7 +3158,7 @@ private void transferSecondaryTable(JaxbHbmSecondaryTableType hbmJoin, JaxbEntit secondaryTable.setOwned( !hbmJoin.isInverse() ); final JaxbHbmKeyType key = hbmJoin.getKey(); if ( key != null ) { - final JaxbPrimaryKeyJoinColumnImpl joinColumn = new JaxbPrimaryKeyJoinColumnImpl(); + final var joinColumn = new JaxbPrimaryKeyJoinColumnImpl(); joinColumn.setName( key.getColumnAttribute() ); secondaryTable.getPrimaryKeyJoinColumn().add( joinColumn ); @@ -3247,62 +3212,8 @@ else if (hbmLazy.equals( JaxbHbmLazyWithNoProxyEnum.NO_PROXY )) { fetchable.setFetchMode( fetch ); } - // ToMany - private void transferFetchable( - JaxbHbmLazyWithExtraEnum hbmLazy, - JaxbHbmFetchStyleWithSubselectEnum hbmFetch, - JaxbHbmOuterJoinEnum hbmOuterJoin, - JaxbPluralAttribute fetchable) { - FetchType laziness = FetchType.LAZY; - JaxbPluralFetchModeImpl fetch = JaxbPluralFetchModeImpl.SELECT; - - if (hbmLazy != null) { - if (hbmLazy.equals( JaxbHbmLazyWithExtraEnum.EXTRA )) { - throw new MappingException( "HBM transformation: extra lazy not yet supported.", origin() ); - } - else if (hbmLazy.equals( JaxbHbmLazyWithExtraEnum.FALSE )) { - laziness = FetchType.EAGER; - } - } - - // allow fetch style to override laziness, if necessary - if (hbmFetch == null) { - if (hbmOuterJoin != null && hbmOuterJoin.equals( JaxbHbmOuterJoinEnum.TRUE ) ) { - laziness = FetchType.EAGER; - fetch = JaxbPluralFetchModeImpl.JOIN; - } - } - else { - if (hbmFetch.equals( JaxbHbmFetchStyleWithSubselectEnum.JOIN ) ) { - laziness = FetchType.EAGER; - fetch = JaxbPluralFetchModeImpl.JOIN; - } - else if (hbmFetch.equals( JaxbHbmFetchStyleWithSubselectEnum.SUBSELECT ) ) { - fetch = JaxbPluralFetchModeImpl.SUBSELECT; - } - } - - fetchable.setFetch( laziness ); - fetchable.setFetchMode( fetch ); - } - - // KeyManyToOne - private static FetchType convert(JaxbHbmLazyEnum hbmLazy) { - if ( hbmLazy != null && "false".equalsIgnoreCase( hbmLazy.value() ) ) { - return FetchType.EAGER; - } - else { - // proxy is HBM default - return FetchType.LAZY; - } - } - - private static OnDeleteAction convert(JaxbHbmOnDeleteEnum hbmOnDelete) { - return hbmOnDelete == JaxbHbmOnDeleteEnum.CASCADE ? OnDeleteAction.CASCADE : OnDeleteAction.NO_ACTION; - } - private static JaxbFilterImpl convert(JaxbHbmFilterType hbmFilter) { - final JaxbFilterImpl filter = new JaxbFilterImpl(); + final var filter = new JaxbFilterImpl(); filter.setName( hbmFilter.getName() ); final boolean shouldAutoInjectAliases = hbmFilter.getAutoAliasInjection() == null @@ -3316,8 +3227,8 @@ private static JaxbFilterImpl convert(JaxbHbmFilterType hbmFilter) { filter.setCondition( string ); } else { - final JaxbHbmFilterAliasMappingType hbmAliasMapping = (JaxbHbmFilterAliasMappingType) content; - final JaxbFilterImpl.JaxbAliasesImpl aliasMapping = new JaxbFilterImpl.JaxbAliasesImpl(); + final var hbmAliasMapping = (JaxbHbmFilterAliasMappingType) content; + final var aliasMapping = new JaxbFilterImpl.JaxbAliasesImpl(); aliasMapping.setAlias( hbmAliasMapping.getAlias() ); aliasMapping.setEntity( hbmAliasMapping.getEntity() ); aliasMapping.setTable( hbmAliasMapping.getTable() ); @@ -3328,12 +3239,14 @@ private static JaxbFilterImpl convert(JaxbHbmFilterType hbmFilter) { return filter; } - private static JaxbCascadeTypeImpl convertCascadeType(String s) { - final JaxbCascadeTypeImpl cascadeType = new JaxbCascadeTypeImpl(); + private static JaxbCascadeTypeImpl convertCascadeType(String cascadeStyleName) { + final var cascadeType = new JaxbCascadeTypeImpl(); - if ( isNotEmpty( s ) ) { - s = s.toLowerCase( Locale.ROOT ).replaceAll( " ", "" ); - final String[] split = StringHelper.split( ",", s ); + if ( isNotEmpty( cascadeStyleName ) ) { + cascadeStyleName = + cascadeStyleName.toLowerCase( Locale.ROOT ) + .replaceAll( " ", "" ); + final String[] split = split( ",", cascadeStyleName ); for ( String hbmCascade : split ) { if ( hbmCascade.contains( "all" ) ) { cascadeType.setCascadeAll( new JaxbEmptyTypeImpl() ); @@ -3367,9 +3280,9 @@ private static JaxbCascadeTypeImpl convertCascadeType(String s) { return cascadeType; } - private boolean isOrphanRemoval(String s) { - return isNotEmpty( s ) - && s.toLowerCase( Locale.ROOT ).contains( "orphan" ); + private boolean isOrphanRemoval(String cascadeStyleName) { + return isNotEmpty( cascadeStyleName ) + && cascadeStyleName.toLowerCase( Locale.ROOT ).contains( "orphan" ); } private String getFullyQualifiedClassName(String className) { @@ -3384,7 +3297,7 @@ private String getFullyQualifiedClassName(String className) { if ( isNotEmpty( className ) && className.indexOf( '.' ) < 0 && isNotEmpty( defaultPackageName ) ) { - className = StringHelper.qualify( defaultPackageName, className ); + className = qualify( defaultPackageName, className ); } return className; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java index cb590a258b49..f09a02d13273 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java @@ -13,10 +13,8 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; @@ -32,8 +30,6 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; import org.hibernate.boot.jaxb.internal.MappingBinder; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; -import org.hibernate.boot.jaxb.spi.Binding; -import org.hibernate.boot.jaxb.spi.JaxbBindableMappingDescriptor; import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.TypeContributor; import org.hibernate.boot.model.process.internal.ManagedResourcesImpl; @@ -44,18 +40,13 @@ import org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl; import org.hibernate.boot.model.source.internal.annotations.DomainModelSource; import org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder; -import org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl; import org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorImpl; import org.hibernate.boot.model.source.internal.hbm.MappingDocument; import org.hibernate.boot.model.source.internal.hbm.ModelBinder; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; -import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; -import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult; import org.hibernate.boot.models.xml.spi.XmlPreProcessor; -import org.hibernate.boot.models.xml.spi.XmlProcessingResult; import org.hibernate.boot.models.xml.spi.XmlProcessor; -import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.spi.AdditionalMappingContributions; @@ -66,7 +57,6 @@ import org.hibernate.boot.spi.MappingDefaults; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.dialect.Dialect; import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.internal.util.collections.CollectionHelper; @@ -75,15 +65,12 @@ import org.hibernate.models.internal.MutableClassDetailsRegistry; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; -import org.hibernate.models.spi.ModelsContext; import org.hibernate.type.BasicType; -import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.SqlTypes; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.WrapperArrayHandling; import org.hibernate.type.descriptor.java.ByteArrayJavaType; import org.hibernate.type.descriptor.java.CharacterArrayJavaType; -import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeConstructor; import org.hibernate.type.descriptor.jdbc.JsonArrayJdbcTypeConstructor; @@ -94,9 +81,7 @@ import org.hibernate.type.descriptor.jdbc.XmlAsStringJdbcType; import org.hibernate.type.descriptor.jdbc.UuidAsBinaryJdbcType; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; -import org.hibernate.type.descriptor.sql.DdlType; import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl; -import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry; import org.hibernate.type.internal.NamedBasicTypeImpl; import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.usertype.CompositeUserType; @@ -157,7 +142,7 @@ public static MetadataImplementor build( public static ManagedResources prepare( final MetadataSources sources, final BootstrapContext bootstrapContext) { - final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext ); + final var managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext ); final boolean xmlMappingEnabled = bootstrapContext.getConfigurationService() .getSetting( XML_MAPPING_ENABLED, StandardConverters.BOOLEAN, true ); @@ -182,19 +167,18 @@ public static MetadataImplementor complete( final BootstrapContext bootstrapContext, final MetadataBuildingOptions options) { - final InFlightMetadataCollectorImpl metadataCollector = - new InFlightMetadataCollectorImpl( bootstrapContext, options ); + final var metadataCollector = new InFlightMetadataCollectorImpl( bootstrapContext, options ); handleTypes( bootstrapContext, options, metadataCollector ); - final DomainModelSource domainModelSource = processManagedResources( + final var domainModelSource = processManagedResources( managedResources, metadataCollector, bootstrapContext, options.getMappingDefaults() ); - final MetadataBuildingContextRootImpl rootMetadataBuildingContext = new MetadataBuildingContextRootImpl( + final var rootMetadataBuildingContext = new MetadataBuildingContextRootImpl( "orm", bootstrapContext, options, @@ -220,7 +204,7 @@ public static MetadataImplementor complete( metadataCollector ); - final ClassLoaderService classLoaderService = bootstrapContext.getClassLoaderService(); + final var classLoaderService = bootstrapContext.getClassLoaderService(); processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext ); applyExtraQueryImports( managedResources, metadataCollector ); @@ -235,7 +219,7 @@ public static void coordinateProcessors( MetadataBuildingContextRootImpl rootMetadataBuildingContext, DomainModelSource domainModelSource, InFlightMetadataCollectorImpl metadataCollector) { - final MetadataSourceProcessor processor = new MetadataSourceProcessor() { + final var processor = new MetadataSourceProcessor() { private final MetadataSourceProcessor hbmProcessor = options.isXmlMappingEnabled() ? new HbmMetadataSourceProcessorImpl( managedResources, rootMetadataBuildingContext ) : new NoOpMetadataSourceProcessorImpl(); @@ -373,9 +357,9 @@ public static DomainModelSource processManagedResources( // - allKnownClassNames (technically could be included in xmlPreProcessingResult) // - ModelsContext - final PersistenceUnitMetadata aggregatedPersistenceUnitMetadata = metadataCollector.getPersistenceUnitMetadata(); - final ModelsContext modelsContext = bootstrapContext.getModelsContext(); - final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources( + final var aggregatedPersistenceUnitMetadata = metadataCollector.getPersistenceUnitMetadata(); + final var modelsContext = bootstrapContext.getModelsContext(); + final var xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources( managedResources, aggregatedPersistenceUnitMetadata ); @@ -387,7 +371,7 @@ public static DomainModelSource processManagedResources( ); managedResources.getAnnotatedPackageNames().forEach( (packageName) -> { try { - final Class packageInfoClass = modelsContext.getClassLoading().classForName( packageName + ".package-info" ); + final var packageInfoClass = modelsContext.getClassLoading().classForName( packageName + ".package-info" ); allKnownClassNames.add( packageInfoClass.getName() ); } catch (ClassLoadingException classLoadingException) { @@ -412,17 +396,17 @@ public static DomainModelSource processManagedResources( // - mappedSuperClasses // - embeddables - final ClassDetailsRegistry classDetailsRegistry = modelsContext.getClassDetailsRegistry(); - final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector( + final var classDetailsRegistry = modelsContext.getClassDetailsRegistry(); + final var modelCategorizationCollector = new DomainModelCategorizationCollector( metadataCollector.getGlobalRegistrations(), modelsContext ); - final RootMappingDefaults rootMappingDefaults = new RootMappingDefaults( + final var rootMappingDefaults = new RootMappingDefaults( optionDefaults, aggregatedPersistenceUnitMetadata ); - final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( + final var xmlProcessingResult = XmlProcessor.processXml( xmlPreProcessingResult, aggregatedPersistenceUnitMetadata, modelCategorizationCollector::apply, @@ -477,10 +461,10 @@ private static void applyKnownClass( ClassDetailsRegistry classDetailsRegistry, DomainModelCategorizationCollector modelCategorizationCollector) { modelCategorizationCollector.apply( classDetails ); - if ( classDetails.getSuperClass() != null - && classDetails.getSuperClass() != ClassDetails.OBJECT_CLASS_DETAILS ) { - if ( categorizedClassNames.add( classDetails.getSuperClass().getClassName() ) ) { - applyKnownClass( classDetails.getSuperClass(), categorizedClassNames, classDetailsRegistry, modelCategorizationCollector ); + final var superClass = classDetails.getSuperClass(); + if ( superClass != null && superClass != ClassDetails.OBJECT_CLASS_DETAILS ) { + if ( categorizedClassNames.add( superClass.getClassName() ) ) { + applyKnownClass( superClass, categorizedClassNames, classDetailsRegistry, modelCategorizationCollector ); } } } @@ -491,14 +475,15 @@ private static void processAdditionalMappingContributions( ClassLoaderService classLoaderService, MetadataBuildingContextRootImpl rootMetadataBuildingContext) { - final AdditionalMappingContributionsImpl contributions = new AdditionalMappingContributionsImpl( + final var contributions = new AdditionalMappingContributionsImpl( metadataCollector, options, options.isXmlMappingEnabled() ? new MappingBinder( classLoaderService, () -> false ) : null, rootMetadataBuildingContext ); - final Collection additionalMappingContributors = classLoaderService.loadJavaServices( AdditionalMappingContributor.class ); + final var additionalMappingContributors = + classLoaderService.loadJavaServices( AdditionalMappingContributor.class ); additionalMappingContributors.forEach( (contributor) -> { contributions.setCurrentContributor( contributor.getContributorName() ); try { @@ -570,9 +555,8 @@ public void contributeManagedClass(ClassDetails classDetails) { @Override public void contributeBinding(InputStream xmlStream) { final Origin origin = new Origin( SourceType.INPUT_STREAM, null ); - final Binding binding = mappingBinder.bind( xmlStream, origin ); - - final JaxbBindableMappingDescriptor bindingRoot = binding.getRoot(); + final var binding = mappingBinder.bind( xmlStream, origin ); + final var bindingRoot = binding.getRoot(); if ( bindingRoot instanceof JaxbHbmHibernateMapping hibernateMapping ) { contributeBinding( hibernateMapping ); } @@ -586,30 +570,25 @@ else if ( bindingRoot instanceof JaxbEntityMappingsImpl entityMappings ) { @Override public void contributeBinding(JaxbEntityMappingsImpl mappingJaxbBinding) { - if ( ! options.isXmlMappingEnabled() ) { - return; - } - - if ( additionalJaxbMappings == null ) { - additionalJaxbMappings = new ArrayList<>(); + if ( options.isXmlMappingEnabled() ) { + if ( additionalJaxbMappings == null ) { + additionalJaxbMappings = new ArrayList<>(); + } + additionalJaxbMappings.add( mappingJaxbBinding ); } - additionalJaxbMappings.add( mappingJaxbBinding ); } @Override public void contributeBinding(JaxbHbmHibernateMapping hbmJaxbBinding) { - if ( ! options.isXmlMappingEnabled() ) { - return; + if ( options.isXmlMappingEnabled() ) { + extraHbmXml = true; + hierarchyBuilder.indexMappingDocument( new MappingDocument( + currentContributor, + hbmJaxbBinding, + new Origin( SourceType.OTHER, null ), + rootMetadataBuildingContext + ) ); } - - extraHbmXml = true; - - hierarchyBuilder.indexMappingDocument( new MappingDocument( - currentContributor, - hbmJaxbBinding, - new Origin( SourceType.OTHER, null ), - rootMetadataBuildingContext - ) ); } @Override @@ -655,8 +634,8 @@ public void complete() { // hbm.xml if ( extraHbmXml ) { - final ModelBinder binder = ModelBinder.prepare( rootMetadataBuildingContext ); - for ( EntityHierarchySourceImpl entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { + final var binder = ModelBinder.prepare( rootMetadataBuildingContext ); + for ( var entityHierarchySource : hierarchyBuilder.buildHierarchies() ) { binder.bindEntityHierarchy( entityHierarchySource ); } } @@ -667,13 +646,11 @@ public void complete() { private static void applyExtraQueryImports( ManagedResources managedResources, InFlightMetadataCollectorImpl metadataCollector) { - final Map> extraQueryImports = managedResources.getExtraQueryImports(); - if ( extraQueryImports == null || extraQueryImports.isEmpty() ) { - return; - } - - for ( Map.Entry> entry : extraQueryImports.entrySet() ) { - metadataCollector.addImport( entry.getKey(), entry.getValue().getName() ); + final var extraQueryImports = managedResources.getExtraQueryImports(); + if ( extraQueryImports != null && !extraQueryImports.isEmpty() ) { + for ( var entry : extraQueryImports.entrySet() ) { + metadataCollector.addImport( entry.getKey(), entry.getValue().getName() ); + } } } @@ -694,11 +671,11 @@ private static void handleTypes( BootstrapContext bootstrapContext, MetadataBuildingOptions options, InFlightMetadataCollector metadataCollector) { - final ClassLoaderService classLoaderService = bootstrapContext.getClassLoaderService(); - final TypeConfiguration typeConfiguration = bootstrapContext.getTypeConfiguration(); - final StandardServiceRegistry serviceRegistry = bootstrapContext.getServiceRegistry(); - final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry(); - final TypeContributions typeContributions = new TypeContributions() { + final var classLoaderService = bootstrapContext.getClassLoaderService(); + final var typeConfiguration = bootstrapContext.getTypeConfiguration(); + final var serviceRegistry = bootstrapContext.getServiceRegistry(); + final var jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry(); + final var typeContributions = new TypeContributions() { @Override public TypeConfiguration getTypeConfiguration() { return typeConfiguration; @@ -718,7 +695,7 @@ public void contributeType(CompositeUserType type) { if ( options.getWrapperArrayHandling() == WrapperArrayHandling.LEGACY ) { typeConfiguration.getJavaTypeRegistry().addDescriptor( ByteArrayJavaType.INSTANCE ); typeConfiguration.getJavaTypeRegistry().addDescriptor( CharacterArrayJavaType.INSTANCE ); - final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + final var basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); basicTypeRegistry.addTypeReferenceRegistrationKey( StandardBasicTypes.CHARACTER_ARRAY.getName(), @@ -731,12 +708,12 @@ public void contributeType(CompositeUserType type) { } // add Dialect contributed types - final Dialect dialect = options.getServiceRegistry().requireService( JdbcServices.class ).getDialect(); + final var dialect = options.getServiceRegistry().requireService( JdbcServices.class ).getDialect(); dialect.contribute( typeContributions, options.getServiceRegistry() ); // add TypeContributor contributed types. - for ( TypeContributor contributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) { - contributor.contribute( typeContributions, options.getServiceRegistry() ); + for ( var typeContributor : classLoaderService.loadJavaServices( TypeContributor.class ) ) { + typeContributor.contribute( typeContributions, options.getServiceRegistry() ); } // add fallback type descriptors @@ -808,9 +785,9 @@ public void contributeType(CompositeUserType type) { addFallbackIfNecessary( jdbcTypeRegistry, SqlTypes.MATERIALIZED_CLOB, SqlTypes.CLOB ); addFallbackIfNecessary( jdbcTypeRegistry, SqlTypes.MATERIALIZED_NCLOB, SqlTypes.NCLOB ); - final DdlTypeRegistry ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry(); + final var ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry(); // Fallback to the geometry DdlType when geography is requested - final DdlType geometryType = ddlTypeRegistry.getDescriptor( SqlTypes.GEOMETRY ); + final var geometryType = ddlTypeRegistry.getDescriptor( SqlTypes.GEOMETRY ); if ( geometryType != null ) { ddlTypeRegistry.addDescriptorIfAbsent( new DdlTypeImpl( @@ -823,16 +800,16 @@ public void contributeType(CompositeUserType type) { // add explicit application registered types typeConfiguration.addBasicTypeRegistrationContributions( options.getBasicTypeRegistrations() ); - for ( CompositeUserType compositeUserType : options.getCompositeUserTypes() ) { + for ( var compositeUserType : options.getCompositeUserTypes() ) { metadataCollector.registerCompositeUserType( compositeUserType.returnedClass(), ReflectHelper.getClass( compositeUserType.getClass() ) ); } - final JdbcType timestampWithTimeZoneOverride = getTimestampWithTimeZoneOverride( options, jdbcTypeRegistry ); + final var timestampWithTimeZoneOverride = getTimestampWithTimeZoneOverride( options, jdbcTypeRegistry ); if ( timestampWithTimeZoneOverride != null ) { adaptTimestampTypesToDefaultTimeZoneStorage( typeConfiguration, timestampWithTimeZoneOverride ); } - final JdbcType timeWithTimeZoneOverride = getTimeWithTimeZoneOverride( options, jdbcTypeRegistry ); + final var timeWithTimeZoneOverride = getTimeWithTimeZoneOverride( options, jdbcTypeRegistry ); if ( timeWithTimeZoneOverride != null ) { adaptTimeTypesToDefaultTimeZoneStorage( typeConfiguration, timeWithTimeZoneOverride ); } @@ -871,8 +848,8 @@ private static void adaptToPreferredSqlTypeCode( Class javaType, String name, String... additionalKeys) { - final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); - final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + final var javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); + final var basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); final BasicType basicType = new NamedBasicTypeImpl<>( javaTypeRegistry.getDescriptor( javaType ), jdbcTypeRegistry.getDescriptor( preferredSqlTypeCode ), @@ -887,8 +864,8 @@ private static void adaptToPreferredSqlTypeCode( private static void adaptTimeTypesToDefaultTimeZoneStorage( TypeConfiguration typeConfiguration, JdbcType timestampWithTimeZoneOverride) { - final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); - final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + final var javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); + final var basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); final BasicType offsetDateTimeType = new NamedBasicTypeImpl<>( javaTypeRegistry.getDescriptor( OffsetTime.class ), timestampWithTimeZoneOverride, @@ -905,8 +882,8 @@ private static void adaptTimeTypesToDefaultTimeZoneStorage( private static void adaptTimestampTypesToDefaultTimeZoneStorage( TypeConfiguration typeConfiguration, JdbcType timestampWithTimeZoneOverride) { - final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); - final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); + final var javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); + final var basicTypeRegistry = typeConfiguration.getBasicTypeRegistry(); final BasicType offsetDateTimeType = new NamedBasicTypeImpl<>( javaTypeRegistry.getDescriptor( OffsetDateTime.class ), timestampWithTimeZoneOverride, diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java index d32c3a598b77..fe8a4c15ef18 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributesMetadata.java @@ -16,7 +16,6 @@ import org.hibernate.boot.Metadata; import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSet; @@ -42,9 +41,9 @@ public static LazyAttributesMetadata from( final Map> fetchGroupToAttributesMap = new HashMap<>(); int x = 0; - final List properties = mappedEntity.getPropertyClosure(); + final var properties = mappedEntity.getPropertyClosure(); for ( int i=0; i attributeSet = fetchGroupToAttributesMap.computeIfAbsent( @@ -71,7 +70,7 @@ public static LazyAttributesMetadata from( return new LazyAttributesMetadata( mappedEntity.getEntityName() ); } - for ( Map.Entry> entry : fetchGroupToAttributesMap.entrySet() ) { + for ( var entry : fetchGroupToAttributesMap.entrySet() ) { entry.setValue( unmodifiableSet( entry.getValue() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index eb28dd6f240c..28b95bfe9273 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -1056,18 +1056,18 @@ public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throw userTypeRegistrations.forEach( registration -> registration.registerType( metadataBuilder ) ); } - for ( BasicType basicType : basicTypes ) { + for ( var basicType : basicTypes ) { metadataBuilder.applyBasicType( basicType ); } if ( customFunctionDescriptors != null ) { - for ( Map.Entry entry : customFunctionDescriptors.entrySet() ) { + for ( var entry : customFunctionDescriptors.entrySet() ) { metadataBuilder.applySqlFunction( entry.getKey(), entry.getValue() ); } } if ( auxiliaryDatabaseObjectList != null ) { - for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList ) { + for ( var auxiliaryDatabaseObject : auxiliaryDatabaseObjectList ) { metadataBuilder.applyAuxiliaryDatabaseObject( auxiliaryDatabaseObject ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentBag.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentBag.java index 2826c002567d..acaec3f44675 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentBag.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentBag.java @@ -7,7 +7,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -21,6 +20,8 @@ import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.type.Type; +import static java.util.Collections.emptyMap; + /** * An unordered, un-keyed collection that can contain the same element * multiple times. The Java Collections Framework, curiously, has no @@ -110,8 +111,8 @@ public Iterator entries(CollectionPersister persister) { public void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingState) { assert collection == null; - final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor(); - final CollectionSemantics collectionSemantics = collectionDescriptor.getCollectionSemantics(); + final var collectionDescriptor = attributeMapping.getCollectionDescriptor(); + final var collectionSemantics = collectionDescriptor.getCollectionSemantics(); final int elementCount = loadingState == null ? 0 : loadingState.size(); @@ -135,15 +136,15 @@ public boolean equalsSnapshot(CollectionPersister persister) throws HibernateExc } // HHH-11032 - Group objects by Type.getHashCode() to reduce the complexity of the search - final Map> hashToInstancesBag = groupByEqualityHash( collection, elementType ); - final Map> hashToInstancesSn = groupByEqualityHash( sn, elementType ); + final var hashToInstancesBag = groupByEqualityHash( collection, elementType ); + final var hashToInstancesSn = groupByEqualityHash( sn, elementType ); if ( hashToInstancesBag.size() != hashToInstancesSn.size() ) { return false; } // First iterate over the hashToInstancesBag entries to see if the number // of List values is different for any hash value. - for ( Map.Entry> hashToInstancesBagEntry : hashToInstancesBag.entrySet() ) { + for ( var hashToInstancesBagEntry : hashToInstancesBag.entrySet() ) { final Integer hash = hashToInstancesBagEntry.getKey(); final List instancesBag = hashToInstancesBagEntry.getValue(); final List instancesSn = hashToInstancesSn.get( hash ); @@ -157,7 +158,7 @@ public boolean equalsSnapshot(CollectionPersister persister) throws HibernateExc // 2) the same number of values with the same hash value. // Now check if the number of occurrences of each element is the same. - for ( Map.Entry> hashToInstancesBagEntry : hashToInstancesBag.entrySet() ) { + for ( var hashToInstancesBagEntry : hashToInstancesBag.entrySet() ) { final Integer hash = hashToInstancesBagEntry.getKey(); final List instancesBag = hashToInstancesBagEntry.getValue(); final List instancesSn = hashToInstancesSn.get( hash ); @@ -182,11 +183,11 @@ public boolean equalsSnapshot(CollectionPersister persister) throws HibernateExc */ private Map> groupByEqualityHash(Collection searchedBag, Type elementType) { if ( searchedBag.isEmpty() ) { - return Collections.emptyMap(); + return emptyMap(); } - Map> map = new HashMap<>(); - for ( Object o : searchedBag ) { - map.computeIfAbsent( nullableHashCode( o, elementType ), k -> new ArrayList<>() ).add( o ); + final Map> map = new HashMap<>(); + for ( Object object : searchedBag ) { + map.computeIfAbsent( nullableHashCode( object, elementType ), k -> new ArrayList<>() ).add( object ); } return map; } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentList.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentList.java index 603ac48816d1..b7a0c3a69e3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentList.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentList.java @@ -130,13 +130,12 @@ public void injectLoadedState(PluralAttributeMapping attributeMapping, List l assert isInitializing(); assert list == null; - final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor(); - - this.list = (List) collectionDescriptor.getCollectionSemantics().instantiateRaw( - loadingStateList.size(), - collectionDescriptor - ); + final var collectionDescriptor = attributeMapping.getCollectionDescriptor(); + final var collectionSemantics = collectionDescriptor.getCollectionSemantics(); + //noinspection unchecked + list = (List) collectionSemantics.instantiateRaw( loadingStateList.size(), collectionDescriptor ); + //noinspection unchecked list.addAll( (List) loadingStateList ); } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentMap.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentMap.java index 3fd2b790a45b..1e4edb9bd44c 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentMap.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentMap.java @@ -254,11 +254,14 @@ public void injectLoadedState(PluralAttributeMapping attributeMapping, List l assert isInitializing(); assert map == null; - final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor(); - this.map = (Map) collectionDescriptor.getCollectionSemantics().instantiateRaw( loadingState.size(), collectionDescriptor ); + final var collectionDescriptor = attributeMapping.getCollectionDescriptor(); + final var collectionSemantics = collectionDescriptor.getCollectionSemantics(); + //noinspection unchecked + map = (Map) collectionSemantics.instantiateRaw( loadingState.size(), collectionDescriptor ); for ( int i = 0; i < loadingState.size(); i++ ) { final Object[] keyVal = (Object[]) loadingState.get( i ); + //noinspection unchecked map.put( (K) keyVal[0], (E) keyVal[1] ); } } @@ -438,10 +441,10 @@ public E setValue(E value) { @Override public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException { final List deletes = new ArrayList<>(); - for ( Entry e : ((Map) getSnapshot()).entrySet() ) { - final Object key = e.getKey(); - if ( e.getValue() != null && map.get( key ) == null ) { - deletes.add( indexIsFormula ? e.getValue() : key ); + for ( var entry : ((Map) getSnapshot()).entrySet() ) { + final Object key = entry.getKey(); + if ( entry.getValue() != null && map.get( key ) == null ) { + deletes.add( indexIsFormula ? entry.getValue() : key ); } } return deletes.iterator(); @@ -449,8 +452,8 @@ public Iterator getDeletes(CollectionPersister persister, boolean indexIsForm @Override public boolean hasDeletes(CollectionPersister persister) { - for ( Entry e : ((Map) getSnapshot()).entrySet() ) { - if ( e.getValue() != null && map.get( e.getKey() ) == null ) { + for ( var entry : ((Map) getSnapshot()).entrySet() ) { + if ( entry.getValue() != null && map.get( entry.getKey() ) == null ) { return true; } } diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentSet.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentSet.java index d5e539377ca4..e2df661be8f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentSet.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentSet.java @@ -299,20 +299,17 @@ public String toString() { public void injectLoadedState( PluralAttributeMapping attributeMapping, List loadingStateList) { - final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor(); + final var collectionDescriptor = attributeMapping.getCollectionDescriptor(); + final var collectionSemantics = collectionDescriptor.getCollectionSemantics(); if ( loadingStateList != null ) { - this.set = (Set) attributeMapping.getCollectionDescriptor().getCollectionSemantics().instantiateRaw( - loadingStateList.size(), - collectionDescriptor - ); - - this.set.addAll( (List) loadingStateList ); + //noinspection unchecked + set = (Set) collectionSemantics.instantiateRaw( loadingStateList.size(), collectionDescriptor ); + //noinspection unchecked + set.addAll( (List) loadingStateList ); } else { - this.set = (Set) attributeMapping.getCollectionDescriptor().getCollectionSemantics().instantiateRaw( - 0, - collectionDescriptor - ); + //noinspection unchecked + set = (Set) collectionSemantics.instantiateRaw( 0, collectionDescriptor ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/mutation/internal/PreparedStatementGroupStandard.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/mutation/internal/PreparedStatementGroupStandard.java index 523309af87ab..d50ec4b09b5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/mutation/internal/PreparedStatementGroupStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/mutation/internal/PreparedStatementGroupStandard.java @@ -8,7 +8,6 @@ import java.util.Comparator; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import java.util.function.BiConsumer; @@ -62,7 +61,7 @@ public int getNumberOfStatements() { @Override public int getNumberOfActiveStatements() { int count = 0; - for ( Map.Entry entry : statementMap.entrySet() ) { + for ( var entry : statementMap.entrySet() ) { if ( entry.getValue().getStatement() != null ) { count++; } @@ -99,7 +98,7 @@ public PreparedStatementDetails resolvePreparedStatementDetails(String tableName @Override public boolean hasMatching(Predicate filter) { - for ( Map.Entry entry : statementMap.entrySet() ) { + for ( var entry : statementMap.entrySet() ) { if ( filter.test( entry.getValue() ) ) { return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java index c16b052be5e4..37fc09f6d9d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java @@ -56,7 +56,7 @@ public JndiServiceImpl(Map configurationValues) { private static Hashtable extractJndiProperties(Map configurationValues) { final Hashtable jndiProperties = new Hashtable<>(); - for ( Map.Entry entry : configurationValues.entrySet() ) { + for ( var entry : configurationValues.entrySet() ) { if ( entry.getKey() instanceof String propertyName ) { final Object propertyValue = entry.getValue(); if ( propertyName.startsWith( Environment.JNDI_PREFIX ) ) { @@ -86,7 +86,7 @@ else if ( Environment.JNDI_URL.equals( propertyName ) ) { @Override public Object locate(String jndiName) { - final InitialContext initialContext = buildInitialContext(); + final var initialContext = buildInitialContext(); final Name name = parseName( jndiName, initialContext ); try { return initialContext.lookup( name ); @@ -131,13 +131,10 @@ private Name parseName(String jndiName, Context context) { } private static boolean allowedScheme(final String scheme) { - switch ( scheme ) { - case "java" : - case "osgi" : - return true; - default: - return false; - } + return switch ( scheme ) { + case "java", "osgi" -> true; + default -> false; + }; } private void cleanUp(InitialContext initialContext) { @@ -151,7 +148,7 @@ private void cleanUp(InitialContext initialContext) { @Override public void bind(String jndiName, Object value) { - final InitialContext initialContext = buildInitialContext(); + final var initialContext = buildInitialContext(); final Name name = parseName( jndiName, initialContext ); try { bind( name, value, initialContext ); @@ -219,7 +216,7 @@ private void bind(Name name, Object value, Context context) { @Override public void unbind(String jndiName) { - final InitialContext initialContext = buildInitialContext(); + final var initialContext = buildInitialContext(); final Name name = parseName( jndiName, initialContext ); try { initialContext.unbind( name ); @@ -234,7 +231,7 @@ public void unbind(String jndiName) { @Override public void addListener(String jndiName, NamespaceChangeListener listener) { - final InitialContext initialContext = buildInitialContext(); + final var initialContext = buildInitialContext(); final Name name = parseName( jndiName, initialContext ); try { ( (EventContext) initialContext ).addNamingListener( name, EventContext.OBJECT_SCOPE, listener ); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java index 9586c06fdc32..84709009f8c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java @@ -127,11 +127,11 @@ private void prepareEntityFlushes(EventSource session, PersistenceContext persis LOG.trace( "Processing flush-time cascades" ); final var context = PersistContext.create(); // safe from concurrent modification because of how concurrentEntries() is implemented on IdentityMap - for ( var me : persistenceContext.reentrantSafeEntityEntries() ) { -// for ( Map.Entry me : IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() ) ) { - final var entry = me.getValue(); - if ( flushable( entry ) ) { - cascadeOnFlush( session, entry.getPersister(), me.getKey(), context ); + for ( var entry : persistenceContext.reentrantSafeEntityEntries() ) { +// for ( Map.Entry entry : IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() ) ) { + final var entityEntry = entry.getValue(); + if ( flushable( entityEntry ) ) { + cascadeOnFlush( session, entityEntry.getPersister(), entry.getKey(), context ); } } checkForTransientReferences( session, persistenceContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java b/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java index 0390149946c8..c37876b7e864 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FilterConfiguration.java @@ -4,13 +4,14 @@ */ package org.hibernate.internal; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.mapping.PersistentClass; -import org.hibernate.persister.entity.EntityPersister; + +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; /** * @author Rob Worsnop @@ -51,35 +52,36 @@ public boolean useAutoAliasInjection() { } public Map getAliasTableMap(SessionFactoryImplementor factory) { - Map mergedAliasTableMap = mergeAliasMaps( factory ); + final var mergedAliasTableMap = mergeAliasMaps( factory ); if ( !mergedAliasTableMap.isEmpty() ) { return mergedAliasTableMap; } else if ( persistentClass != null ) { - String table = persistentClass.getTable().getQualifiedName( - factory.getSqlStringGenerationContext() - ); - return Collections.singletonMap( null, table ); + final String tableName = + persistentClass.getTable() + .getQualifiedName( factory.getSqlStringGenerationContext() ); + return singletonMap( null, tableName ); } else { - return Collections.emptyMap(); + return emptyMap(); } } private Map mergeAliasMaps(SessionFactoryImplementor factory) { - final Map ret = new HashMap<>(); + final Map result = new HashMap<>(); if ( aliasTableMap != null ) { - ret.putAll( aliasTableMap ); + result.putAll( aliasTableMap ); } if ( aliasEntityMap != null ) { - for ( Map.Entry entry : aliasEntityMap.entrySet() ) { - final EntityPersister joinable = factory.getMappingMetamodel() - .getEntityDescriptor( entry.getValue() ); - ret.put( entry.getKey(), joinable.getTableName() ); + for ( var entry : aliasEntityMap.entrySet() ) { + final var joinable = + factory.getMappingMetamodel() + .getEntityDescriptor( entry.getValue() ); + result.put( entry.getKey(), joinable.getTableName() ); } } - return ret; + return result; } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FilterHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/FilterHelper.java index f7383d423dac..b9cc6c56dd35 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FilterHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FilterHelper.java @@ -135,7 +135,7 @@ public boolean isAffectedBy(Map enabledFilters) { public boolean isAffectedBy(Map enabledFilters, boolean onlyApplyForLoadByKey) { for ( String filterName : filterNames ) { - Filter filter = enabledFilters.get( filterName ); + final var filter = enabledFilters.get( filterName ); if ( filter != null && ( !onlyApplyForLoadByKey || filter.isAppliedToLoadByKey() ) ) { return true; } @@ -168,7 +168,7 @@ public void applyEnabledFilters( boolean onlyApplyLoadByKeyFilters, TableGroup tableGroup, SqlAstCreationState creationState) { - final FilterPredicate predicate = generateFilterPredicate( + final var predicate = generateFilterPredicate( aliasGenerator, enabledFilters, onlyApplyLoadByKeyFilters, @@ -186,10 +186,10 @@ private FilterPredicate generateFilterPredicate( boolean onlyApplyLoadByKeyFilters, TableGroup tableGroup, SqlAstCreationState creationState) { - final FilterPredicate filterPredicate = new FilterPredicate(); + final var filterPredicate = new FilterPredicate(); for ( int i = 0, max = filterNames.length; i < max; i++ ) { - final Filter enabledFilter = enabledFilters.get( filterNames[i] ); + final var enabledFilter = enabledFilters.get( filterNames[i] ); if ( enabledFilter != null && ( !onlyApplyLoadByKeyFilters || enabledFilter.isAppliedToLoadByKey() ) ) { filterPredicate.applyFragment( render( aliasGenerator, i, tableGroup, creationState ), enabledFilter, parameterNames[i] ); } @@ -203,7 +203,7 @@ private FilterPredicate generateFilterPredicate( } public String render(FilterAliasGenerator aliasGenerator, Map enabledFilters) { - final StringBuilder buffer = new StringBuilder(); + final var buffer = new StringBuilder(); render( buffer, aliasGenerator, enabledFilters ); return buffer.toString(); } @@ -249,7 +249,7 @@ else if ( isTableFromPersistentClass( aliasTableMap ) ) { } else { String newCondition = condition; - for ( Map.Entry entry : aliasTableMap.entrySet() ) { + for ( var entry : aliasTableMap.entrySet() ) { final String tableName = entry.getValue(); newCondition = replaceAlias( tableGroup, creationState, newCondition, diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java b/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java index 142e39aefb7b..db9e2f62b6dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java @@ -16,7 +16,6 @@ import org.hibernate.engine.spi.TypedValue; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.persister.entity.EntityPersister; import org.hibernate.type.Type; /** @@ -39,7 +38,7 @@ public final class EntityPrinter { * @return the entity rendered to a string */ public String toString(String entityName, Object entity) throws HibernateException { - final EntityPersister entityPersister = + final var entityPersister = factory.getMappingMetamodel() .getEntityDescriptor( entityName ); if ( entityPersister == null || !entityPersister.isInstance( entity ) ) { @@ -77,7 +76,7 @@ else if ( !Hibernate.isInitialized( values[i] ) ) { } public String toString(Type[] types, Object[] values) throws HibernateException { - final StringBuilder buffer = new StringBuilder(); + final var buffer = new StringBuilder(); for ( int i = 0; i < types.length; i++ ) { if ( types[i] != null ) { buffer.append( types[i].toLoggableString( values[i], factory ) ).append( ", " ); @@ -88,7 +87,7 @@ public String toString(Type[] types, Object[] values) throws HibernateException public String toString(Map namedTypedValues) throws HibernateException { final Map result = new HashMap<>(); - for ( Map.Entry entry : namedTypedValues.entrySet() ) { + for ( var entry : namedTypedValues.entrySet() ) { final String key = entry.getKey(); final TypedValue value = entry.getValue(); result.put( key, value.getType().toLoggableString( value.getValue(), factory ) ); @@ -102,8 +101,8 @@ public void logEntities(Iterable> entitiesByE if ( LOG.isDebugEnabled() && entitiesByEntityKey.iterator().hasNext() ) { LOG.debug( "Listing entities:" ); int i = 0; - for ( Map.Entry entityKeyAndEntity : entitiesByEntityKey ) { - final EntityHolder holder = entityKeyAndEntity.getValue(); + for ( var entityKeyAndEntity : entitiesByEntityKey ) { + final var holder = entityKeyAndEntity.getValue(); if ( holder.getEntity() == null ) { continue; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/MapBackedClassValue.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/MapBackedClassValue.java index f3d4c46e97ee..cb01427ca31d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/MapBackedClassValue.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/MapBackedClassValue.java @@ -25,7 +25,7 @@ public final class MapBackedClassValue implements ReadOnlyMap,V> { private final ClassValue classValue = new ClassValue<>() { @Override protected V computeValue(final Class type) { - final Map, V> m = map; + final var m = map; if ( m == null ) { throw new IllegalStateException( "This MapBackedClassValue has been disposed" ); } @@ -54,11 +54,11 @@ public V get(Class key) { */ @Override public void dispose() { - Map, V> existing = this.map; - this.map = null; + final var existing = map; + map = null; if ( existing != null ) { - for ( Map.Entry, V> entry : existing.entrySet() ) { - this.classValue.remove( entry.getKey() ); + for ( var entry : existing.entrySet() ) { + classValue.remove( entry.getKey() ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 36107bd78ab5..227dfc4285e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -658,7 +658,7 @@ private void normalizeSettings( // these should have precedence. // NOTE that this occurs after the specialized normalize calls above which // remove any specially-handled settings. - for ( Map.Entry entry : integrationSettingsCopy.entrySet() ) { + for ( var entry : integrationSettingsCopy.entrySet() ) { final String key = entry.getKey(); if ( key != null ) { final Object value = entry.getValue(); @@ -676,7 +676,7 @@ private static void normalizeSharedCacheMode( PersistenceUnitDescriptor persistenceUnit, Map integrationSettingsCopy, MergedSettings mergedSettings) { - final Map configurationSettings = mergedSettings.getConfigurationValues(); + final var configurationSettings = mergedSettings.getConfigurationValues(); // normalize SharedCacheMode final Object intgCacheMode = integrationSettingsCopy.remove( JPA_SHARED_CACHE_MODE ); final Object jakartaIntgCacheMode = integrationSettingsCopy.remove( JAKARTA_SHARED_CACHE_MODE ); @@ -696,7 +696,7 @@ private static void normalizeValidationMode( PersistenceUnitDescriptor persistenceUnit, Map integrationSettingsCopy, MergedSettings mergedSettings) { - final Map configurationSettings = mergedSettings.getConfigurationValues(); + final var configurationSettings = mergedSettings.getConfigurationValues(); // normalize ValidationMode final Object intgValidationMode = integrationSettingsCopy.remove( JPA_VALIDATION_MODE ); final Object jakartaIntgValidationMode = integrationSettingsCopy.remove( JAKARTA_VALIDATION_MODE ); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java b/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java index 01db0f94e336..2cb5490e63ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryTupleTransformer.java @@ -136,9 +136,8 @@ public String toString() { @Override public List> getElements() { - List> elements = new ArrayList<>( size ); - - for ( Map.Entry entry : aliasToValue.entrySet() ) { + final List> elements = new ArrayList<>( size ); + for ( var entry : aliasToValue.entrySet() ) { elements.add( new NativeTupleElementImpl<>( getValueClass( entry.getValue() ), entry.getKey() ) ); } return elements; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionRegistry.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionRegistry.java index 338237805887..f2723a8c9461 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionRegistry.java @@ -53,11 +53,11 @@ public Set getValidFunctionKeys() { */ public Stream> getFunctionsByName() { final Map sortedFunctionMap = new TreeMap<>( CASE_INSENSITIVE_ORDER ); - for ( Map.Entry e : functionMap.unmodifiableEntrySet() ) { - sortedFunctionMap.put( e.getKey(), e.getValue() ); + for ( var entry : functionMap.unmodifiableEntrySet() ) { + sortedFunctionMap.put( entry.getKey(), entry.getValue() ); } - for ( Map.Entry e : alternateKeyMap.unmodifiableEntrySet() ) { - sortedFunctionMap.put( e.getKey(), functionMap.get( e.getValue() ) ); + for ( var entry : alternateKeyMap.unmodifiableEntrySet() ) { + sortedFunctionMap.put( entry.getKey(), functionMap.get( entry.getValue() ) ); } return sortedFunctionMap.entrySet().stream(); } @@ -67,11 +67,11 @@ public Stream> getFunctionsByName() { */ public Stream> getSetReturningFunctionsByName() { final Map sortedFunctionMap = new TreeMap<>( CASE_INSENSITIVE_ORDER ); - for ( Map.Entry e : setReturningFunctionMap.unmodifiableEntrySet() ) { - sortedFunctionMap.put( e.getKey(), e.getValue() ); + for ( var entry : setReturningFunctionMap.unmodifiableEntrySet() ) { + sortedFunctionMap.put( entry.getKey(), entry.getValue() ); } - for ( Map.Entry e : alternateKeyMap.unmodifiableEntrySet() ) { - sortedFunctionMap.put( e.getKey(), setReturningFunctionMap.get( e.getValue() ) ); + for ( var entry : alternateKeyMap.unmodifiableEntrySet() ) { + sortedFunctionMap.put( entry.getKey(), setReturningFunctionMap.get( entry.getValue() ) ); } return sortedFunctionMap.entrySet().stream(); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaType.java index 3ea118b6d375..75e66ce4a9d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/CollectionJavaType.java @@ -56,7 +56,7 @@ public JavaType createJavaType( ParameterizedType parameterizedType, TypeConfiguration typeConfiguration) { final Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); - final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); + final var javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); switch ( semantics.getCollectionClassification() ) { case ARRAY: //noinspection unchecked @@ -155,8 +155,9 @@ public C deepCopy(C value) { } final C copy = semantics.instantiateRaw( value.size(), null ); - for ( Map.Entry entry : value.entrySet() ) { - copy.put( keyPlan.deepCopy( entry.getKey() ), valuePlan.deepCopy( entry.getValue() ) ); + for ( var entry : value.entrySet() ) { + copy.put( keyPlan.deepCopy( entry.getKey() ), + valuePlan.deepCopy( entry.getValue() ) ); } return copy; }