From 07db16cf7f004898021907a5d171421a7ebec866 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 18 Jun 2024 02:26:32 -0500 Subject: [PATCH] HHH-18060 - HbmXmlTransformer HHH-18281 - Translate and mostly filter parameter type handling --- .../jaxb/hbm/transform/HbmXmlTransformer.java | 118 +++--- .../transform/TransformationPreprocessor.java | 9 + .../hbm/transform/TransformationState.java | 14 + .../boot/jaxb/mapping/spi/JaxbEntity.java | 2 +- .../jaxb/mapping/spi/JaxbPluralAttribute.java | 2 +- .../internal/FilterAnnotation.java | 4 +- .../internal/FilterJoinTableAnnotation.java | 4 +- .../models/annotations/spi/FilterDetails.java | 4 +- .../internal/GlobalRegistrationsImpl.java | 9 +- .../models/xml/internal/FilterProcessing.java | 8 +- .../internal/SimpleTypeInterpretation.java | 339 ++++++++++++++++++ .../xml/internal/XmlAnnotationHelper.java | 249 +++---------- .../org/hibernate/xsd/mapping/mapping-7.0.xsd | 10 +- .../models/xml/XmlProcessingSmokeTests.java | 2 +- 14 files changed, 516 insertions(+), 258 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/SimpleTypeInterpretation.java 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 50964c866b..6b3f9d9595 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 @@ -39,6 +39,7 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCompositeCollectionElementType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmCompositeIdType; 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.JaxbHbmDiscriminatorSubclassEntityType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDynamicComponentType; @@ -91,6 +92,8 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSimpleIdType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSubclassEntityBaseDefinition; 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; @@ -103,6 +106,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingKeyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainer; import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicMapping; import org.hibernate.boot.jaxb.mapping.spi.JaxbCachingImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbCascadeTypeImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbCheckConstraintImpl; @@ -127,10 +131,10 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbFetchProfileImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbFieldResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterDefImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbForeignKeyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbGeneratedValueImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbGenericIdGeneratorImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbHqlImportImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbIdClassImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbIdImpl; @@ -256,7 +260,6 @@ public class HbmXmlTransformer { transfer( hbmXmlMapping::isDefaultLazy, ormRoot::setDefaultLazy ); transferIdentifierGenerators(); - transferTypeDefs(); transferFilterDefinitions(); transferImports(); transferEntities(); @@ -320,7 +323,7 @@ public class HbmXmlTransformer { Locale.ROOT, message, messageArgs - ) + ) + " (" + origin + ")" ); case PICK -> { if ( pickHandler != null ) { @@ -332,17 +335,6 @@ public class HbmXmlTransformer { } } - private void transferTypeDefs() { - if ( hbmXmlMapping.getTypedef().isEmpty() ) { - return; - } - - handleUnsupported( - "Transformation of type-def mapping not supported - `%s`", - origin - ); - } - private void transferIdentifierGenerators() { if ( hbmXmlMapping.getIdentifierGenerator().isEmpty() ) { return; @@ -1385,22 +1377,7 @@ public class HbmXmlTransformer { basic.setAttributeAccessor( hbmProp.getAccess() ); basic.setOptimisticLock( hbmProp.isOptimisticLock() ); - if ( isNotEmpty( hbmProp.getTypeAttribute() ) ) { - basic.setType( new JaxbUserTypeImpl() ); - basic.getType().setValue( hbmProp.getTypeAttribute() ); - } - else { - if ( hbmProp.getType() != null ) { - basic.setType( new JaxbUserTypeImpl() ); - basic.getType().setValue( hbmProp.getType().getName() ); - for ( JaxbHbmConfigParameterType hbmParam : hbmProp.getType().getConfigParameters() ) { - final JaxbConfigurationParameterImpl param = new JaxbConfigurationParameterImpl(); - param.setName( hbmParam.getName() ); - param.setValue( hbmParam.getValue() ); - basic.getType().getParameters().add( param ); - } - } - } + applyBasicType( basic, hbmProp.getTypeAttribute(), hbmProp.getType() ); transferColumnsAndFormulas( new ColumnAndFormulaSource() { @@ -1484,6 +1461,56 @@ public class HbmXmlTransformer { ); } + private void applyBasicType(JaxbBasicMapping target, String hbmTypeAttribute, JaxbHbmTypeSpecificationType hbmTypeNode) { + if ( isNotEmpty( hbmTypeAttribute ) ) { + final JaxbUserTypeImpl typeNode = interpretBasicType( + hbmTypeAttribute, + null, + transformationState.getTypeDefinitionMap().get( hbmTypeAttribute ) + ); + target.setType( typeNode ); + } + + if ( hbmTypeNode != null ) { + final JaxbUserTypeImpl typeNode = interpretBasicType( + hbmTypeNode.getName(), + hbmTypeNode, + transformationState.getTypeDefinitionMap().get( hbmTypeNode.getName() ) + ); + target.setType( typeNode ); + } + } + + private JaxbUserTypeImpl interpretBasicType(String typeName, JaxbHbmConfigParameterContainer typeLocalParams, JaxbHbmTypeDefinitionType typeDef) { + assert StringHelper.isNotEmpty( typeName ); + + final JaxbUserTypeImpl typeNode = new JaxbUserTypeImpl(); + + if ( typeDef == null ) { + typeNode.setValue( typeName ); + } + else { + typeNode.setValue( typeDef.getClazz() ); + for ( JaxbHbmConfigParameterType hbmParam : typeDef.getConfigParameters() ) { + final JaxbConfigurationParameterImpl param = new JaxbConfigurationParameterImpl(); + param.setName( hbmParam.getName() ); + param.setValue( hbmParam.getValue() ); + typeNode.getParameters().add( param ); + } + } + + if ( typeLocalParams != null ) { + for ( JaxbHbmConfigParameterType hbmParam : typeLocalParams.getConfigParameters() ) { + final JaxbConfigurationParameterImpl param = new JaxbConfigurationParameterImpl(); + param.setName( hbmParam.getName() ); + param.setValue( hbmParam.getValue() ); + typeNode.getParameters().add( param ); + } + } + + return typeNode; + } + private JaxbEmbeddableImpl applyEmbeddable(JaxbEntityMappingsImpl ormRoot, JaxbHbmCompositeAttributeType hbmComponent) { final String embeddableClassName = hbmComponent.getClazz(); if ( StringHelper.isNotEmpty( embeddableClassName ) ) { @@ -2057,9 +2084,6 @@ public class HbmXmlTransformer { if ( StringHelper.isNotEmpty( hbmAttributeInfo.getCollectionType() ) ) { handleUnsupported( "Collection-type is not supported for transformation" ); } - if ( CollectionHelper.isNotEmpty( hbmAttributeInfo.getFilter() ) ) { - handleUnsupported( "Filters are not supported for transformation" ); - } if ( StringHelper.isNotEmpty( hbmAttributeInfo.getWhere() ) ) { handleUnsupported( "SQL restrictions are not supported for transformation" ); } @@ -2082,9 +2106,6 @@ public class HbmXmlTransformer { if ( !(hbmOneToMany.getNode() == null || hbmOneToMany.getNode().isBlank() ) ) { handleUnsupported( "`node` not supported for transformation" ); } - if ( hbmOneToMany.getNotFound() != null ) { - target.setNotFound( interpretNotFoundAction( hbmOneToMany.getNotFound() ) ); - } transferCollectionBasicInfo( hbmAttributeInfo, target ); target.setTargetEntity( StringHelper.isNotEmpty( hbmOneToMany.getClazz() ) ? hbmOneToMany.getClazz() : hbmOneToMany.getEntityName() ); @@ -2104,8 +2125,16 @@ public class HbmXmlTransformer { // oneToMany.setOnDelete( ?? ); } + if ( hbmOneToMany.getNotFound() != null ) { + target.setNotFound( interpretNotFoundAction( hbmOneToMany.getNotFound() ) ); + } + target.setOrphanRemoval( isOrphanRemoval( hbmAttributeInfo.getCascade() ) ); target.setCascade( convertCascadeType( hbmAttributeInfo.getCascade() ) ); + + for ( JaxbHbmFilterType hbmFilter : hbmAttributeInfo.getFilter() ) { + target.getFilters().add( convert( hbmFilter ) ); + } } private JaxbManyToManyImpl transformManyToMany(PluralAttributeInfo hbmCollection) { @@ -2121,9 +2150,6 @@ public class HbmXmlTransformer { if ( StringHelper.isNotEmpty( hbmCollection.getCollectionType() ) ) { handleUnsupported( "Collection-type is not supported for transformation" ); } - if ( CollectionHelper.isNotEmpty( hbmCollection.getFilter() ) ) { - handleUnsupported( "Filters are not supported for transformation" ); - } if ( StringHelper.isNotEmpty( hbmCollection.getWhere() ) ) { handleUnsupported( "SQL restrictions are not supported for transformation" ); } @@ -2152,6 +2178,10 @@ public class HbmXmlTransformer { transferCollectionBasicInfo( hbmCollection, target ); target.setTargetEntity( StringHelper.isNotEmpty( manyToMany.getClazz() ) ? manyToMany.getClazz() : manyToMany.getEntityName() ); + + for ( JaxbHbmFilterType hbmFilter : hbmCollection.getFilter() ) { + target.getFilters().add( convert( hbmFilter ) ); + } } private JaxbPluralAnyMappingImpl transformPluralAny(PluralAttributeInfo hbmCollection) { @@ -2285,9 +2315,7 @@ public class HbmXmlTransformer { } } -// if ( isNotEmpty( source.getTypeAttribute() ) || source.getType() != null ) { -// handleUnsupported( " specified type which is not supported" ); -// } + applyBasicType( target, source.getTypeAttribute(), source.getType() ); target.setUnsavedValue( source.getUnsavedValue() ); @@ -2632,8 +2660,8 @@ public class HbmXmlTransformer { return hbmOnDelete == JaxbHbmOnDeleteEnum.CASCADE ? OnDeleteAction.CASCADE : OnDeleteAction.NO_ACTION; } - private JaxbHbmFilterImpl convert(JaxbHbmFilterType hbmFilter) { - final JaxbHbmFilterImpl filter = new JaxbHbmFilterImpl(); + private JaxbFilterImpl convert(JaxbHbmFilterType hbmFilter) { + final JaxbFilterImpl filter = new JaxbFilterImpl(); filter.setName( hbmFilter.getName() ); final boolean shouldAutoInjectAliases = hbmFilter.getAutoAliasInjection() == null @@ -2648,7 +2676,7 @@ public class HbmXmlTransformer { } else { final JaxbHbmFilterAliasMappingType hbmAliasMapping = (JaxbHbmFilterAliasMappingType) content; - final JaxbHbmFilterImpl.JaxbAliasesImpl aliasMapping = new JaxbHbmFilterImpl.JaxbAliasesImpl(); + final JaxbFilterImpl.JaxbAliasesImpl aliasMapping = new JaxbFilterImpl.JaxbAliasesImpl(); aliasMapping.setAlias( hbmAliasMapping.getAlias() ); aliasMapping.setEntity( hbmAliasMapping.getEntity() ); aliasMapping.setTable( hbmAliasMapping.getTable() ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationPreprocessor.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationPreprocessor.java index ecde2f1581..4277e607c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationPreprocessor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationPreprocessor.java @@ -40,10 +40,19 @@ public class TransformationPreprocessor { final EntityMappingConsumer entityMappingConsumer = new EntityMappingConsumer( transformationState ); final Map rootClassesMap = new HashMap<>(); + collectGlobalState( hbmXmlBindings, transformationState ); processStructuredHierarchies( hbmXmlBindings, rootClassesMap, entityMappingConsumer ); processSeparatedHierarchies( hbmXmlBindings, rootClassesMap, entityMappingConsumer ); } + private static void collectGlobalState( + List> hbmXmlBindings, + TransformationState transformationState) { + hbmXmlBindings.forEach( (hbmBinding) -> { + hbmBinding.getRoot().getTypedef().forEach( transformationState::acceptTypeDefinition ); + } ); + } + private static void processStructuredHierarchies( Collection> hbmXmlBindings, Map rootClassesMap, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationState.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationState.java index 0e2c564279..fd67bcc8b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationState.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TransformationState.java @@ -13,7 +13,9 @@ import java.util.Map; import org.hibernate.boot.jaxb.Origin; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmEntityBaseDefinition; +import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterDefinitionType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; +import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTypeDefinitionType; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; import org.hibernate.boot.jaxb.spi.Binding; @@ -30,6 +32,9 @@ class TransformationState { private final Map entityMap = new HashMap<>(); private final Map entityXref = new HashMap<>(); + private final Map typeDefMap = new HashMap<>(); + private final Map filterDefMap = new HashMap<>(); + public TransformationState(List> hbmBindings) { this.hbmBindings = hbmBindings; this.mappingBindings = CollectionHelper.arrayList( hbmBindings.size() ); @@ -119,6 +124,7 @@ class TransformationState { return resolved; } + public List> getHbmBindings() { return hbmBindings; } @@ -134,4 +140,12 @@ class TransformationState { public Map getEntityXref() { return entityXref; } + + public Map getTypeDefinitionMap() { + return typeDefMap; + } + + public void acceptTypeDefinition(JaxbHbmTypeDefinitionType hbmTypeDef) { + typeDefMap.put( hbmTypeDef.getName(), hbmTypeDef ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java index bd4dfca6fc..bbe5879306 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbEntity.java @@ -112,7 +112,7 @@ public interface JaxbEntity extends JaxbEntityOrMappedSuperclass { List getNamedEntityGraphs(); - List getFilters(); + List getFilters(); List getFetchProfiles(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbPluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbPluralAttribute.java index e73bd876c4..9d8985d126 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbPluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/mapping/spi/JaxbPluralAttribute.java @@ -91,7 +91,7 @@ public interface JaxbPluralAttribute extends JaxbPersistentAttribute, JaxbLockab JaxbCustomSqlImpl getSqlDeleteAll(); void setSqlDeleteAll(JaxbCustomSqlImpl sqlDeleteAll); - List getFilters(); + List getFilters(); @Override default Boolean isOptional() { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java index dbb9e694f5..124ea2e476 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java @@ -9,7 +9,7 @@ package org.hibernate.boot.models.annotations.internal; import java.lang.annotation.Annotation; import org.hibernate.annotations.Filter; -import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.annotations.spi.FilterDetails; import org.hibernate.boot.models.xml.internal.FilterProcessing; @@ -111,7 +111,7 @@ public class FilterAnnotation implements Filter, FilterDetails { @Override - public void apply(JaxbHbmFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext) { + public void apply(JaxbFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext) { name( jaxbFilter.getName() ); if ( StringHelper.isNotEmpty( jaxbFilter.getCondition() ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java index 9fab1a48b3..9e9d54f770 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java @@ -9,7 +9,7 @@ package org.hibernate.boot.models.annotations.internal; import java.lang.annotation.Annotation; import org.hibernate.annotations.FilterJoinTable; -import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterImpl; import org.hibernate.boot.models.annotations.spi.FilterDetails; import org.hibernate.boot.models.xml.internal.FilterProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; @@ -109,7 +109,7 @@ public class FilterJoinTableAnnotation implements FilterJoinTable, FilterDetails } @Override - public void apply(JaxbHbmFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext) { + public void apply(JaxbFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext) { name( jaxbFilter.getName() ); if ( StringHelper.isNotEmpty( jaxbFilter.getCondition() ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java index edc65300ae..f9522679f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java @@ -6,7 +6,7 @@ */ package org.hibernate.boot.models.annotations.spi; -import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterImpl; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; /** @@ -18,5 +18,5 @@ import org.hibernate.boot.models.xml.spi.XmlDocumentContext; * @author Steve Ebersole */ public interface FilterDetails { - void apply(JaxbHbmFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext); + void apply(JaxbFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java index 623a4a86d1..1840df270c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java @@ -578,18 +578,17 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { parameterResolvers = new HashMap<>(); for ( JaxbFilterDefImpl.JaxbFilterParamImpl jaxbParameter : jaxbParameters ) { - final ClassDetails targetClassDetails = XmlAnnotationHelper.resolveJavaType( + final ClassDetails targetClassDetails = XmlAnnotationHelper.resolveSimpleJavaType( jaxbParameter.getType(), sourceModelContext.getClassDetailsRegistry() ); paramJdbcMappings.put( jaxbParameter.getName(), targetClassDetails ); if ( isNotEmpty( jaxbParameter.getResolver() ) ) { - final ClassDetails resolverClassDetails = XmlAnnotationHelper.resolveJavaType( - jaxbParameter.getType(), - sourceModelContext.getClassDetailsRegistry() + parameterResolvers.put( + jaxbParameter.getName(), + sourceModelContext.getClassDetailsRegistry().resolveClassDetails( jaxbParameter.getResolver() ) ); - parameterResolvers.put( jaxbParameter.getName(), resolverClassDetails ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java index 9b3ace6567..5f11052041 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java @@ -9,7 +9,7 @@ package org.hibernate.boot.models.xml.internal; import java.util.List; import org.hibernate.annotations.SqlFragmentAlias; -import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.annotations.internal.SqlFragmentAliasAnnotation; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; @@ -24,7 +24,7 @@ public class FilterProcessing { private static final SqlFragmentAlias[] NO_ALIASES = new SqlFragmentAlias[0]; public static SqlFragmentAlias[] collectSqlFragmentAliases( - List jaxbAliases, + List jaxbAliases, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbAliases ) ) { return NO_ALIASES; @@ -32,12 +32,12 @@ public class FilterProcessing { final SqlFragmentAlias[] result = new SqlFragmentAlias[jaxbAliases.size()]; for ( int i = 0; i < jaxbAliases.size(); i++ ) { - final SqlFragmentAliasAnnotation alias = (SqlFragmentAliasAnnotation) HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( + final SqlFragmentAliasAnnotation alias = HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( xmlDocumentContext.getModelBuildingContext() ); result[i] = alias; - final JaxbHbmFilterImpl.JaxbAliasesImpl jaxbAlias = jaxbAliases.get( i ); + final JaxbFilterImpl.JaxbAliasesImpl jaxbAlias = jaxbAliases.get( i ); alias.alias( jaxbAlias.getAlias() ); if ( StringHelper.isNotEmpty( jaxbAlias.getTable() ) ) { alias.table( jaxbAlias.getTable() ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/SimpleTypeInterpretation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/SimpleTypeInterpretation.java new file mode 100644 index 0000000000..927428e874 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/SimpleTypeInterpretation.java @@ -0,0 +1,339 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.xml.internal; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.InetAddress; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.Currency; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; +import java.util.UUID; + +import org.hibernate.internal.util.StringHelper; +import org.hibernate.type.descriptor.java.BasicJavaType; +import org.hibernate.type.descriptor.java.BigDecimalJavaType; +import org.hibernate.type.descriptor.java.BigIntegerJavaType; +import org.hibernate.type.descriptor.java.BlobJavaType; +import org.hibernate.type.descriptor.java.BooleanJavaType; +import org.hibernate.type.descriptor.java.ByteJavaType; +import org.hibernate.type.descriptor.java.CalendarJavaType; +import org.hibernate.type.descriptor.java.CharacterJavaType; +import org.hibernate.type.descriptor.java.ClassJavaType; +import org.hibernate.type.descriptor.java.ClobJavaType; +import org.hibernate.type.descriptor.java.CurrencyJavaType; +import org.hibernate.type.descriptor.java.DoubleJavaType; +import org.hibernate.type.descriptor.java.DurationJavaType; +import org.hibernate.type.descriptor.java.FloatJavaType; +import org.hibernate.type.descriptor.java.InetAddressJavaType; +import org.hibernate.type.descriptor.java.InstantJavaType; +import org.hibernate.type.descriptor.java.IntegerJavaType; +import org.hibernate.type.descriptor.java.JdbcDateJavaType; +import org.hibernate.type.descriptor.java.JdbcTimeJavaType; +import org.hibernate.type.descriptor.java.JdbcTimestampJavaType; +import org.hibernate.type.descriptor.java.LocalDateJavaType; +import org.hibernate.type.descriptor.java.LocalDateTimeJavaType; +import org.hibernate.type.descriptor.java.LocalTimeJavaType; +import org.hibernate.type.descriptor.java.LocaleJavaType; +import org.hibernate.type.descriptor.java.LongJavaType; +import org.hibernate.type.descriptor.java.NClobJavaType; +import org.hibernate.type.descriptor.java.OffsetDateTimeJavaType; +import org.hibernate.type.descriptor.java.OffsetTimeJavaType; +import org.hibernate.type.descriptor.java.ShortJavaType; +import org.hibernate.type.descriptor.java.StringJavaType; +import org.hibernate.type.descriptor.java.TimeZoneJavaType; +import org.hibernate.type.descriptor.java.UUIDJavaType; +import org.hibernate.type.descriptor.java.UrlJavaType; +import org.hibernate.type.descriptor.java.YearJavaType; +import org.hibernate.type.descriptor.java.ZoneIdJavaType; +import org.hibernate.type.descriptor.java.ZoneOffsetJavaType; +import org.hibernate.type.descriptor.java.ZonedDateTimeJavaType; + +/** + * @author Steve Ebersole + */ +public enum SimpleTypeInterpretation { + BOOLEAN( Boolean.class, BooleanJavaType.class ), + BYTE( Byte.class, ByteJavaType.class ), + SHORT( Short.class, ShortJavaType.class ), + INTEGER( Integer.class, IntegerJavaType.class ), + LONG( Long.class, LongJavaType.class ), + DOUBLE( Double.class, DoubleJavaType.class ), + FLOAT( Float.class, FloatJavaType.class ), + BIG_INTEGER( BigInteger.class, BigIntegerJavaType.class ), + BIG_DECIMAL( BigDecimal.class, BigDecimalJavaType.class ), + CHARACTER( Character.class, CharacterJavaType.class ), + STRING( String.class, StringJavaType.class ), + INSTANT( Instant.class, InstantJavaType.class ), + DURATION( Duration.class, DurationJavaType.class ), + YEAR( Year.class, YearJavaType.class ), + LOCAL_DATE_TIME( LocalDateTime.class, LocalDateTimeJavaType.class ), + LOCAL_DATE( LocalDate.class, LocalDateJavaType.class ), + LOCAL_TIME( LocalTime.class, LocalTimeJavaType.class ), + OFFSET_DATE_TIME( OffsetDateTime.class, OffsetDateTimeJavaType.class ), + OFFSET_TIME( OffsetTime.class, OffsetTimeJavaType.class ), + ZONED_DATE_TIME( ZonedDateTime.class, ZonedDateTimeJavaType.class ), + ZONE_ID( ZoneId.class, ZoneIdJavaType.class ), + ZONE_OFFSET( ZoneOffset.class, ZoneOffsetJavaType.class ), + UUID( UUID .class, UUIDJavaType.class ), + URL( java.net.URL.class, UrlJavaType.class ), + INET_ADDRESS( InetAddress.class, InetAddressJavaType.class ), + CURRENCY( Currency.class, CurrencyJavaType.class ), + LOCALE( Locale.class, LocaleJavaType.class ), + CLASS( Class.class, ClassJavaType.class ), + BLOB( Blob.class, BlobJavaType.class ), + CLOB( Clob.class, ClobJavaType.class ), + NCLOB( NClob.class, NClobJavaType.class ), + JDBC_TIMESTAMP( Timestamp.class, JdbcTimestampJavaType.class ), + JDBC_DATE( Date.class, JdbcDateJavaType.class ), + JDBC_TIME( Time.class, JdbcTimeJavaType.class ), + CALENDAR( Calendar.class, CalendarJavaType.class ), + TIME_ZONE( TimeZone.class, TimeZoneJavaType.class ) + ; + + SimpleTypeInterpretation(Class javaType, Class> javaTypeDescriptorType) { + this.javaType = javaType; + this.javaTypeDescriptorType = javaTypeDescriptorType; + } + + private final Class javaType; + private final Class> javaTypeDescriptorType; + + public Class getJavaType() { + return javaType; + } + + public Class> getJavaTypeDescriptorType() { + return javaTypeDescriptorType; + } + + public static SimpleTypeInterpretation interpret(String name) { + assert StringHelper.isNotEmpty( name ); + + + if ( name.equalsIgnoreCase( "boolean" ) + || Boolean.class.getName().equals( name ) ) { + return BOOLEAN; + } + + if ( name.equalsIgnoreCase( "byte" ) + || Byte.class.getName().equals( name ) ) { + return BYTE; + } + + if ( name.equalsIgnoreCase( "short" ) + || Short.class.getName().equals( name ) ) { + return SHORT; + } + + if ( name.equalsIgnoreCase( "int" ) + || name.equalsIgnoreCase( "integer" ) + || Integer.class.getName().equals( name ) ) { + return INTEGER; + } + + if ( name.equalsIgnoreCase( "long" ) + || Long.class.getName().equals( name ) ) { + return LONG; + } + + if ( name.equalsIgnoreCase( "double" ) + || Double.class.getName().equals( name ) ) { + return DOUBLE; + } + + if ( name.equalsIgnoreCase( "float" ) + || Float.class.getName().equals( name ) ) { + return FLOAT; + } + + if ( name.equalsIgnoreCase( "biginteger" ) + || name.equalsIgnoreCase( "big_integer" ) + || BigInteger.class.getName().equals( name ) ) { + return BIG_INTEGER; + } + + if ( name.equalsIgnoreCase( "bigdecimal" ) + || name.equalsIgnoreCase( "big_decimal" ) + || BigDecimal.class.getName().equals( name ) ) { + return BIG_DECIMAL; + } + + if ( name.equalsIgnoreCase( "char" ) + || name.equalsIgnoreCase( "character" ) + || Character.class.getName().equalsIgnoreCase( name ) ) { + return CHARACTER; + } + + if ( name.equalsIgnoreCase( "string" ) + || String.class.getName().equalsIgnoreCase( name ) ) { + return STRING; + } + + if ( name.equalsIgnoreCase( "instant" ) + || Instant.class.getName().equals( name ) ) { + return INSTANT; + } + + if ( name.equalsIgnoreCase( "duration" ) + || Duration.class.getName().equals( name ) ) { + return DURATION; + } + + if ( name.equalsIgnoreCase( "year" ) + || Year.class.getName().equals( name ) ) { + return YEAR; + } + + if ( name.equalsIgnoreCase( "localdatetime" ) + || name.equalsIgnoreCase( "local_date_time" ) + || LocalDateTime.class.getName().equals( name ) ) { + return LOCAL_DATE_TIME; + } + + if ( name.equalsIgnoreCase( "localdate" ) + || name.equalsIgnoreCase( "local_date" ) + || LocalDate.class.getName().equals( name ) ) { + return LOCAL_DATE; + } + + if ( name.equalsIgnoreCase( "localtime" ) + || name.equalsIgnoreCase( "local_time" ) + || LocalTime.class.getName().equals( name ) ) { + return LOCAL_TIME; + } + + if ( name.equalsIgnoreCase( "zoneddatetime" ) + || name.equalsIgnoreCase( "zoned_date_time" ) + || ZonedDateTime.class.getName().equals( name ) ) { + return ZONED_DATE_TIME; + } + + if ( name.equalsIgnoreCase( "offsetdatetime" ) + || name.equalsIgnoreCase( "offset_date_time" ) + || OffsetDateTime.class.getName().equals( name ) ) { + return OFFSET_DATE_TIME; + } + + if ( name.equalsIgnoreCase( "offsettime" ) + || name.equalsIgnoreCase( "offset_time" ) + || OffsetTime.class.getName().equals( name ) ) { + return OFFSET_TIME; + } + + if ( name.equalsIgnoreCase( "zoneid" ) + || name.equalsIgnoreCase( "zone_id" ) + || ZoneId.class.getName().equals( name ) ) { + return ZONE_ID; + } + + if ( name.equalsIgnoreCase( "zoneoffset" ) + || name.equalsIgnoreCase( "zone_offset" ) + || ZoneOffset.class.getName().equals( name ) ) { + return ZONE_OFFSET; + } + + if ( name.equalsIgnoreCase( "uuid" ) + || UUID.class.getName().equals( name ) ) { + return UUID; + } + + if ( name.equalsIgnoreCase( "url" ) + || java.net.URL.class.getName().equals( name ) ) { + return URL; + } + + if ( name.equalsIgnoreCase( "inet" ) + || name.equalsIgnoreCase( "inetaddress" ) + || name.equalsIgnoreCase( "inet_address" ) + || InetAddress.class.getName().equals( name ) ) { + return INET_ADDRESS; + } + + if ( name.equalsIgnoreCase( "currency" ) + || Currency.class.getName().equals( name ) ) { + return CURRENCY; + } + + if ( name.equalsIgnoreCase( "locale" ) + || Locale.class.getName().equals( name ) ) { + return LOCALE; + } + + if ( name.equalsIgnoreCase( "class" ) + || Class.class.getName().equals( name ) ) { + return CLASS; + } + + if ( name.equalsIgnoreCase( "blob" ) + || Blob.class.getName().equals( name ) ) { + return BLOB; + } + + if ( name.equalsIgnoreCase( "clob" ) + || Clob.class.getName().equals( name ) ) { + return CLOB; + } + + if ( name.equalsIgnoreCase( "nclob" ) + || NClob.class.getName().equals( name ) ) { + return NCLOB; + } + + if ( name.equalsIgnoreCase( "timestamp" ) + || name.equalsIgnoreCase( "time_stamp" ) + || java.util.Date.class.getName().equals( name ) + || Timestamp.class.getName().equals( name ) ) { + return JDBC_TIMESTAMP; + } + + if ( name.equalsIgnoreCase( "date" ) + || java.sql.Date.class.getName().equals( name ) ) { + return JDBC_DATE; + } + + if ( name.equalsIgnoreCase( "time" ) + || java.sql.Time.class.getName().equals( name ) ) { + return JDBC_TIME; + } + + if ( name.equalsIgnoreCase( "calendar" ) + || name.equalsIgnoreCase( "gregoriancalendar" ) + || name.equalsIgnoreCase( "gregorian_calendar" ) + || Calendar.class.getName().equals( name ) + || GregorianCalendar.class.getName().equals( name ) ) { + return CALENDAR; + } + + if ( name.equalsIgnoreCase( "timezone" ) + || name.equalsIgnoreCase( "time_zone" ) + || TimeZone.class.getName().equals( name ) ) { + return TIME_ZONE; + } + + return null; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java index 66a5e0922f..619aec16ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java @@ -10,30 +10,8 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.math.BigDecimal; import java.math.BigInteger; -import java.net.InetAddress; -import java.net.URL; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.NClob; -import java.sql.Timestamp; -import java.time.Duration; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.OffsetDateTime; -import java.time.OffsetTime; -import java.time.Year; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Currency; -import java.util.GregorianCalendar; import java.util.List; -import java.util.Locale; -import java.util.TimeZone; import java.util.UUID; import java.util.function.Consumer; @@ -64,9 +42,9 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerContainerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityOrMappedSuperclass; +import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbGeneratedValueImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbGenericIdGeneratorImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbIdClassImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbIndexImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumnImpl; @@ -292,173 +270,52 @@ public class XmlAnnotationHelper { XmlDocumentContext xmlDocumentContext) { if ( jaxbType == null || StringHelper.isEmpty( jaxbType.getValue() ) ) { cases.handleNone( jaxbType, memberDetails, xmlDocumentContext ); + return; } - else if ( jaxbType.getValue().equalsIgnoreCase( "char" ) - || jaxbType.getValue().equalsIgnoreCase( "character" ) - || Character.class.getName().equalsIgnoreCase( jaxbType.getValue() ) ) { - cases.handleCharacter( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "string" ) - || String.class.getName().equalsIgnoreCase( jaxbType.getValue() ) ) { - cases.handleString( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "byte" ) - || Byte.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleByte( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "boolean" ) - || Boolean.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleBoolean( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "short" ) - || Short.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleShort( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "int" ) - || jaxbType.getValue().equalsIgnoreCase( "integer" ) - || Integer.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleInteger( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "long" ) - || Long.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleLong( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "double" ) - || Double.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleDouble( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "float" ) - || Float.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleFloat( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "biginteger" ) - || jaxbType.getValue().equalsIgnoreCase( "big_integer" ) - || BigInteger.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleBigInteger( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "bigdecimal" ) - || jaxbType.getValue().equalsIgnoreCase( "big_decimal" ) - || BigDecimal.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleBigDecimal( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "uuid" ) - || UUID.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleUuid( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "url" ) - || URL.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleUrl( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "inet" ) - || jaxbType.getValue().equalsIgnoreCase( "inetaddress" ) - || jaxbType.getValue().equalsIgnoreCase( "inet_address" ) - || InetAddress.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleInetAddress( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "currency" ) - || Currency.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleCurrency( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "locale" ) - || Locale.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleLocale( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "class" ) - || Class.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleClass( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "blob" ) - || Blob.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleBlob( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "clob" ) - || Clob.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleClob( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "nclob" ) - || NClob.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleNClob( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "instant" ) - || Instant.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleInstant( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "duration" ) - || Duration.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleDuration( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "year" ) - || Year.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleYear( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "localdatetime" ) - || jaxbType.getValue().equalsIgnoreCase( "local_date_time" ) - || LocalDateTime.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleLocalDateTime( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "localdate" ) - || jaxbType.getValue().equalsIgnoreCase( "local_date" ) - || LocalDate.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleLocalDate( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "localtime" ) - || jaxbType.getValue().equalsIgnoreCase( "local_time" ) - || LocalTime.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleLocalTime( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "zoneddatetime" ) - || jaxbType.getValue().equalsIgnoreCase( "zoned_date_time" ) - || ZonedDateTime.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleZonedDateTime( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "offsetdatetime" ) - || jaxbType.getValue().equalsIgnoreCase( "offset_date_time" ) - || OffsetDateTime.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleOffsetDateTime( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "offsettime" ) - || jaxbType.getValue().equalsIgnoreCase( "offset_time" ) - || OffsetTime.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleOffsetTime( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "zoneid" ) - || jaxbType.getValue().equalsIgnoreCase( "zone_id" ) - || ZoneId.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleZoneId( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "zoneoffset" ) - || jaxbType.getValue().equalsIgnoreCase( "zone_offset" ) - || ZoneOffset.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleZoneOffset( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "timestamp" ) - || jaxbType.getValue().equalsIgnoreCase( "time_stamp" ) - || java.util.Date.class.getName().equals( jaxbType.getValue() ) - || Timestamp.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleTimestamp( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "date" ) - || java.sql.Date.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleDate( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "time" ) - || java.sql.Time.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleTime( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "calendar" ) - || jaxbType.getValue().equalsIgnoreCase( "gregoriancalendar" ) - || jaxbType.getValue().equalsIgnoreCase( "gregorian_calendar" ) - || Calendar.class.getName().equals( jaxbType.getValue() ) - || GregorianCalendar.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleCalendar( jaxbType, memberDetails, xmlDocumentContext ); - } - else if ( jaxbType.getValue().equalsIgnoreCase( "timezone" ) - || jaxbType.getValue().equalsIgnoreCase( "time_zone" ) - || TimeZone.class.getName().equals( jaxbType.getValue() ) ) { - cases.handleTimeZone( jaxbType, memberDetails, xmlDocumentContext ); - } - else { + + final SimpleTypeInterpretation interpretation = SimpleTypeInterpretation.interpret( jaxbType.getValue() ); + if ( interpretation == null ) { cases.handleGeneral( jaxbType, memberDetails, xmlDocumentContext ); + return; + } + + switch ( interpretation ) { + case BOOLEAN -> cases.handleBoolean( jaxbType, memberDetails, xmlDocumentContext ); + case BYTE -> cases.handleByte( jaxbType, memberDetails, xmlDocumentContext ); + case SHORT -> cases.handleShort( jaxbType, memberDetails, xmlDocumentContext ); + case INTEGER -> cases.handleInteger( jaxbType, memberDetails, xmlDocumentContext ); + case LONG -> cases.handleLong( jaxbType, memberDetails, xmlDocumentContext ); + case DOUBLE -> cases.handleDouble( jaxbType, memberDetails, xmlDocumentContext ); + case FLOAT -> cases.handleFloat( jaxbType, memberDetails, xmlDocumentContext ); + case BIG_INTEGER -> cases.handleBigInteger( jaxbType, memberDetails, xmlDocumentContext ); + case BIG_DECIMAL -> cases.handleBigDecimal( jaxbType, memberDetails, xmlDocumentContext ); + case CHARACTER -> cases.handleCharacter( jaxbType, memberDetails, xmlDocumentContext ); + case STRING -> cases.handleString( jaxbType, memberDetails, xmlDocumentContext ); + case INSTANT -> cases.handleInstant( jaxbType, memberDetails, xmlDocumentContext ); + case DURATION -> cases.handleDuration( jaxbType, memberDetails, xmlDocumentContext ); + case YEAR -> cases.handleYear( jaxbType, memberDetails, xmlDocumentContext ); + case LOCAL_DATE_TIME -> cases.handleLocalDateTime( jaxbType, memberDetails, xmlDocumentContext ); + case LOCAL_DATE -> cases.handleLocalDate( jaxbType, memberDetails, xmlDocumentContext ); + case LOCAL_TIME -> cases.handleLocalTime( jaxbType, memberDetails, xmlDocumentContext ); + case OFFSET_DATE_TIME -> cases.handleOffsetDateTime( jaxbType, memberDetails, xmlDocumentContext ); + case OFFSET_TIME -> cases.handleOffsetTime( jaxbType, memberDetails, xmlDocumentContext ); + case ZONED_DATE_TIME -> cases.handleZonedDateTime( jaxbType, memberDetails, xmlDocumentContext ); + case ZONE_ID -> cases.handleZoneId( jaxbType, memberDetails, xmlDocumentContext ); + case ZONE_OFFSET -> cases.handleZoneOffset( jaxbType, memberDetails, xmlDocumentContext ); + case UUID -> cases.handleUuid( jaxbType, memberDetails, xmlDocumentContext ); + case URL -> cases.handleUrl( jaxbType, memberDetails, xmlDocumentContext ); + case INET_ADDRESS -> cases.handleInetAddress( jaxbType, memberDetails, xmlDocumentContext ); + case CURRENCY -> cases.handleCurrency( jaxbType, memberDetails, xmlDocumentContext ); + case LOCALE -> cases.handleLocale( jaxbType, memberDetails, xmlDocumentContext ); + case CLASS -> cases.handleClass( jaxbType, memberDetails, xmlDocumentContext ); + case BLOB -> cases.handleBlob( jaxbType, memberDetails, xmlDocumentContext ); + case CLOB -> cases.handleClob( jaxbType, memberDetails, xmlDocumentContext ); + case NCLOB -> cases.handleNClob( jaxbType, memberDetails, xmlDocumentContext ); + case JDBC_TIMESTAMP -> cases.handleTimestamp( jaxbType, memberDetails, xmlDocumentContext ); + case JDBC_DATE -> cases.handleDate( jaxbType, memberDetails, xmlDocumentContext ); + case JDBC_TIME -> cases.handleTime( jaxbType, memberDetails, xmlDocumentContext ); + case CALENDAR -> cases.handleCalendar( jaxbType, memberDetails, xmlDocumentContext ); + case TIME_ZONE -> cases.handleTimeZone( jaxbType, memberDetails, xmlDocumentContext ); } } @@ -1076,6 +933,18 @@ public class XmlAnnotationHelper { ); } + /** + * Used in cases where we might need to account for legacy "simple type naming" or "named basic types" such as + * {@code type="string"}. + */ + public static ClassDetails resolveSimpleJavaType(String value, ClassDetailsRegistry classDetailsRegistry) { + final SimpleTypeInterpretation simpleInterpretation = SimpleTypeInterpretation.interpret( value ); + if ( simpleInterpretation != null ) { + return classDetailsRegistry.resolveClassDetails( simpleInterpretation.getJavaType().getName() ); + } + return resolveJavaType( null, value, classDetailsRegistry ); + } + public static ClassDetails resolveJavaType(String value, ClassDetailsRegistry classDetailsRegistry) { return resolveJavaType( null, value, classDetailsRegistry ); } @@ -1224,7 +1093,7 @@ public class XmlAnnotationHelper { } public static void applyFilters( - List jaxbFilters, + List jaxbFilters, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbFilters ) ) { @@ -1248,7 +1117,7 @@ public class XmlAnnotationHelper { } public static void applyJoinTableFilters( - List jaxbFilters, + List jaxbFilters, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbFilters ) ) { diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd index ff66255c1d..2c14f0e4cc 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-7.0.xsd @@ -411,7 +411,7 @@ - + @@ -1599,7 +1599,7 @@ - + @@ -2034,7 +2034,7 @@ - + - + Applies a filter defined by hbm-filter-def usage @@ -3308,7 +3308,7 @@ - + diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java index 1adba41e3a..bc924b2bfe 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java @@ -177,7 +177,7 @@ public class XmlProcessingSmokeTests { assertThat( amountFilter.getDefaultCondition() ).isEqualTo( "amount = :amount" ); assertThat( amountFilter.getParameterTypes() ).hasSize( 1 ); final ClassDetails amountParameterType = amountFilter.getParameterTypes().get( "amount" ); - assertThat( amountParameterType.getClassName() ).isEqualTo( int.class.getName() ); + assertThat( amountParameterType.getClassName() ).isEqualTo( Integer.class.getName() ); final FilterDefRegistration nameFilter = filterDefRegistrations.get( "name_filter" ); assertThat( nameFilter.getDefaultCondition() ).isEqualTo( "name = :name" );