HHH-15251 - Unified mapping XSD based on JPA 3.1

- more work on HbmXmlTransformer
This commit is contained in:
Steve Ebersole 2022-05-25 00:06:28 -05:00
parent 7b9931f106
commit 309edd9e32
1 changed files with 41 additions and 40 deletions

View File

@ -214,16 +214,16 @@ public class HbmXmlTransformer {
transfer( hbmXmlMapping::getDefaultCascade, ormRoot::setDefaultCascade ); transfer( hbmXmlMapping::getDefaultCascade, ormRoot::setDefaultCascade );
transfer( hbmXmlMapping::isDefaultLazy, ormRoot::setDefaultLazy ); transfer( hbmXmlMapping::isDefaultLazy, ormRoot::setDefaultLazy );
transferTypeDefs();
transferIdentifierGenerators(); transferIdentifierGenerators();
transferTypeDefs();
transferFilterDefinitions(); transferFilterDefinitions();
transferFetchProfiles();
transferImports(); transferImports();
transferEntities();
transferResultSetMappings(); transferResultSetMappings();
transferNamedQueries(); transferNamedQueries();
transferNamedNativeQueries(); transferNamedNativeQueries();
transferFetchProfiles();
transferDatabaseObjects(); transferDatabaseObjects();
transferEntities();
return ormRoot; return ormRoot;
} }
@ -285,7 +285,7 @@ public class HbmXmlTransformer {
for ( JaxbHbmIdentifierGeneratorDefinitionType hbmGenerator : hbmXmlMapping.getIdentifierGenerator() ) { for ( JaxbHbmIdentifierGeneratorDefinitionType hbmGenerator : hbmXmlMapping.getIdentifierGenerator() ) {
JaxbLogger.JAXB_LOGGER.debugf( JaxbLogger.JAXB_LOGGER.debugf(
"STarting transformation of identifier-generator mapping `%s` - `%s`", "Starting transformation of identifier-generator mapping `%s` - `%s`",
hbmGenerator.getName(), hbmGenerator.getName(),
origin origin
); );
@ -805,13 +805,18 @@ public class HbmXmlTransformer {
entity.setMutable( hbmClass.isMutable() ); entity.setMutable( hbmClass.isMutable() );
entity.setTable( new JaxbTable() ); if ( hbmClass.getTable() != null ) {
entity.getTable().setCatalog( hbmClass.getCatalog() ); entity.setTable( new JaxbTable() );
entity.getTable().setSchema( hbmClass.getSchema() ); transfer( hbmClass::getTable, entity.getTable()::setName );
entity.getTable().setName( hbmClass.getTable() ); }
entity.getTable().setComment( hbmClass.getComment() ); else {
entity.getTable().setCheck( hbmClass.getCheck() ); transfer( hbmClass::getSubselect, entity::setTableExpression );
entity.setTableExpression( hbmClass.getSubselect() ); }
transfer( hbmClass::getCatalog, entity.getTable()::setCatalog );
transfer( hbmClass::getSchema, entity.getTable()::setSchema );
transfer( hbmClass::getComment, entity.getTable()::setComment );
transfer( hbmClass::getCheck, entity.getTable()::setCheck );
for ( JaxbHbmSynchronizeType hbmSync : hbmClass.getSynchronize() ) { for ( JaxbHbmSynchronizeType hbmSync : hbmClass.getSynchronize() ) {
final JaxbSynchronizedTable sync = new JaxbSynchronizedTable(); final JaxbSynchronizedTable sync = new JaxbSynchronizedTable();
@ -862,10 +867,12 @@ public class HbmXmlTransformer {
entity.setOptimisticLock( hbmClass.getOptimisticLock() ); entity.setOptimisticLock( hbmClass.getOptimisticLock() );
transferDiscriminator( hbmClass, entity );
entity.setDiscriminatorValue( hbmClass.getDiscriminatorValue() ); entity.setDiscriminatorValue( hbmClass.getDiscriminatorValue() );
entity.setPolymorphism( convert( hbmClass.getPolymorphism() ) ); entity.setPolymorphism( convert( hbmClass.getPolymorphism() ) );
transferDiscriminator( hbmClass, entity );
transferAttributes( hbmClass, entity );
if ( hbmClass.getCache() != null ) { if ( hbmClass.getCache() != null ) {
transformEntityCaching( hbmClass, entity ); transformEntityCaching( hbmClass, entity );
} }
@ -891,8 +898,6 @@ public class HbmXmlTransformer {
entity.getFetchProfile().add( transferFetchProfile( hbmFetchProfile ) ); entity.getFetchProfile().add( transferFetchProfile( hbmFetchProfile ) );
} }
transferAttributes( hbmClass, entity );
for ( JaxbHbmJoinedSubclassEntityType hbmSubclass : hbmClass.getJoinedSubclass() ) { for ( JaxbHbmJoinedSubclassEntityType hbmSubclass : hbmClass.getJoinedSubclass() ) {
entity.setInheritance( new JaxbInheritance() ); entity.setInheritance( new JaxbInheritance() );
entity.getInheritance().setStrategy( InheritanceType.JOINED ); entity.getInheritance().setStrategy( InheritanceType.JOINED );
@ -1218,12 +1223,12 @@ public class HbmXmlTransformer {
for ( Object hbmAttributeMapping : hbmAttributeMappings ) { for ( Object hbmAttributeMapping : hbmAttributeMappings ) {
if ( hbmAttributeMapping instanceof JaxbHbmBasicAttributeType ) { if ( hbmAttributeMapping instanceof JaxbHbmBasicAttributeType ) {
final JaxbHbmBasicAttributeType basic = (JaxbHbmBasicAttributeType) hbmAttributeMapping; final JaxbHbmBasicAttributeType basic = (JaxbHbmBasicAttributeType) hbmAttributeMapping;
attributes.getBasicAttributes().add( convertBasicAttribute( basic ) ); attributes.getBasicAttributes().add( transformBasicAttribute( basic ) );
} }
else if ( hbmAttributeMapping instanceof JaxbHbmCompositeAttributeType ) { else if ( hbmAttributeMapping instanceof JaxbHbmCompositeAttributeType ) {
final JaxbHbmCompositeAttributeType hbmComponent = (JaxbHbmCompositeAttributeType) hbmAttributeMapping; final JaxbHbmCompositeAttributeType hbmComponent = (JaxbHbmCompositeAttributeType) hbmAttributeMapping;
ormRoot.getEmbeddables().add( convertEmbeddable( hbmComponent ) ); ormRoot.getEmbeddables().add( convertEmbeddable( hbmComponent ) );
attributes.getEmbeddedAttributes().add( convertEmbedded( hbmComponent ) ); attributes.getEmbeddedAttributes().add( transformEmbedded( hbmComponent ) );
} }
else if ( hbmAttributeMapping instanceof JaxbHbmPropertiesType ) { else if ( hbmAttributeMapping instanceof JaxbHbmPropertiesType ) {
final JaxbHbmPropertiesType hbmProperties = (JaxbHbmPropertiesType) hbmAttributeMapping; final JaxbHbmPropertiesType hbmProperties = (JaxbHbmPropertiesType) hbmAttributeMapping;
@ -1231,25 +1236,22 @@ public class HbmXmlTransformer {
} }
else if ( hbmAttributeMapping instanceof JaxbHbmDynamicComponentType ) { else if ( hbmAttributeMapping instanceof JaxbHbmDynamicComponentType ) {
final String name = ( (JaxbHbmDynamicComponentType) hbmAttributeMapping ).getName(); final String name = ( (JaxbHbmDynamicComponentType) hbmAttributeMapping ).getName();
handleUnsupportedContent( handleUnsupported(
String.format( "<dynamic-component/> mappings not supported for transformation [name=%s]",
Locale.ROOT, name
"<dynamic-component/> mappings not supported for transformation [name=%s]",
name
)
); );
} }
else if ( hbmAttributeMapping instanceof JaxbHbmOneToOneType ) { else if ( hbmAttributeMapping instanceof JaxbHbmOneToOneType ) {
final JaxbHbmOneToOneType o2o = (JaxbHbmOneToOneType) hbmAttributeMapping; final JaxbHbmOneToOneType o2o = (JaxbHbmOneToOneType) hbmAttributeMapping;
transformOneToOne( o2o, attributes ); transferOneToOne( o2o, attributes );
} }
else if ( hbmAttributeMapping instanceof JaxbHbmManyToOneType ) { else if ( hbmAttributeMapping instanceof JaxbHbmManyToOneType ) {
final JaxbHbmManyToOneType m2o = (JaxbHbmManyToOneType) hbmAttributeMapping; final JaxbHbmManyToOneType m2o = (JaxbHbmManyToOneType) hbmAttributeMapping;
attributes.getManyToOneAttributes().add( convertManyToOne( m2o ) ); attributes.getManyToOneAttributes().add( transformManyToOne( m2o ) );
} }
else if ( hbmAttributeMapping instanceof JaxbHbmAnyAssociationType ) { else if ( hbmAttributeMapping instanceof JaxbHbmAnyAssociationType ) {
final JaxbHbmAnyAssociationType any = (JaxbHbmAnyAssociationType) hbmAttributeMapping; final JaxbHbmAnyAssociationType any = (JaxbHbmAnyAssociationType) hbmAttributeMapping;
attributes.getDiscriminatedAssociations().add( convertAnyAttribute( any ) ); attributes.getDiscriminatedAssociations().add( transformAnyAttribute( any ) );
} }
else if ( hbmAttributeMapping instanceof PluralAttributeInfo ) { else if ( hbmAttributeMapping instanceof PluralAttributeInfo ) {
@ -1257,23 +1259,22 @@ public class HbmXmlTransformer {
if ( pluralAttributeInfo.getElement() != null if ( pluralAttributeInfo.getElement() != null
|| pluralAttributeInfo.getCompositeElement() != null ) { || pluralAttributeInfo.getCompositeElement() != null ) {
attributes.getElementCollectionAttributes().add( convertElementCollection( pluralAttributeInfo ) ); attributes.getElementCollectionAttributes().add( transformElementCollection( pluralAttributeInfo ) );
} }
else if ( pluralAttributeInfo.getOneToMany() != null ) { else if ( pluralAttributeInfo.getOneToMany() != null ) {
attributes.getOneToManyAttributes().add( convertOneToManyCollection( pluralAttributeInfo ) ); attributes.getOneToManyAttributes().add( transformOneToManyCollection( pluralAttributeInfo ) );
} }
else if ( pluralAttributeInfo.getManyToMany() != null ) { else if ( pluralAttributeInfo.getManyToMany() != null ) {
attributes.getManyToManyAttributes().add( convertManyToManyCollection( pluralAttributeInfo ) ); attributes.getManyToManyAttributes().add( transformManyToManyCollection( pluralAttributeInfo ) );
} }
else if ( pluralAttributeInfo.getManyToAny() != null ) { else if ( pluralAttributeInfo.getManyToAny() != null ) {
attributes.getPluralDiscriminatedAssociations() attributes.getPluralDiscriminatedAssociations().add( transformManyToAnyCollection( pluralAttributeInfo ) );
.add( convertManyToAnyCollection( pluralAttributeInfo ) );
} }
} }
} }
} }
private JaxbBasic convertBasicAttribute(final JaxbHbmBasicAttributeType hbmProp) { private JaxbBasic transformBasicAttribute(final JaxbHbmBasicAttributeType hbmProp) {
final JaxbBasic basic = new JaxbBasic(); final JaxbBasic basic = new JaxbBasic();
transferBasicAttribute( hbmProp, basic ); transferBasicAttribute( hbmProp, basic );
return basic; return basic;
@ -1397,14 +1398,14 @@ public class HbmXmlTransformer {
return embeddable; return embeddable;
} }
private JaxbEmbedded convertEmbedded(JaxbHbmCompositeAttributeType hbmComponent) { private JaxbEmbedded transformEmbedded(JaxbHbmCompositeAttributeType hbmComponent) {
final JaxbEmbedded embedded = new JaxbEmbedded(); final JaxbEmbedded embedded = new JaxbEmbedded();
embedded.setName( hbmComponent.getName() ); embedded.setName( hbmComponent.getName() );
embedded.setAttributeAccessor( hbmComponent.getAccess() ); embedded.setAttributeAccessor( hbmComponent.getAccess() );
return embedded; return embedded;
} }
private void transformOneToOne(JaxbHbmOneToOneType hbmOneToOne, AttributesContainer attributes) { private void transferOneToOne(JaxbHbmOneToOneType hbmOneToOne, AttributesContainer attributes) {
if ( !hbmOneToOne.getFormula().isEmpty() || !StringHelper.isEmpty( hbmOneToOne.getFormulaAttribute() ) ) { if ( !hbmOneToOne.getFormula().isEmpty() || !StringHelper.isEmpty( hbmOneToOne.getFormulaAttribute() ) ) {
handleUnsupported( handleUnsupported(
"Transformation of formulas within one-to-ones are not supported - `%s`", "Transformation of formulas within one-to-ones are not supported - `%s`",
@ -1437,7 +1438,7 @@ public class HbmXmlTransformer {
attributes.getOneToOneAttributes().add( oneToOne ); attributes.getOneToOneAttributes().add( oneToOne );
} }
private JaxbManyToOne convertManyToOne(final JaxbHbmManyToOneType hbmM2O) { private JaxbManyToOne transformManyToOne(final JaxbHbmManyToOneType hbmM2O) {
final JaxbManyToOne m2o = new JaxbManyToOne(); final JaxbManyToOne m2o = new JaxbManyToOne();
m2o.setAttributeAccessor( hbmM2O.getAccess() ); m2o.setAttributeAccessor( hbmM2O.getAccess() );
m2o.setCascade( convertCascadeType( hbmM2O.getCascade() ) ); m2o.setCascade( convertCascadeType( hbmM2O.getCascade() ) );
@ -1502,7 +1503,7 @@ public class HbmXmlTransformer {
} }
private JaxbHbmAnyMapping convertAnyAttribute(JaxbHbmAnyAssociationType source) { private JaxbHbmAnyMapping transformAnyAttribute(JaxbHbmAnyAssociationType source) {
final JaxbHbmAnyMapping target = new JaxbHbmAnyMapping(); final JaxbHbmAnyMapping target = new JaxbHbmAnyMapping();
target.setName( source.getName() ); target.setName( source.getName() );
@ -1526,7 +1527,7 @@ public class HbmXmlTransformer {
return target; return target;
} }
private JaxbElementCollection convertElementCollection(final PluralAttributeInfo source) { private JaxbElementCollection transformElementCollection(final PluralAttributeInfo source) {
final JaxbElementCollection target = new JaxbElementCollection(); final JaxbElementCollection target = new JaxbElementCollection();
transferCollectionTable( source, target ); transferCollectionTable( source, target );
transferCollectionBasicInfo( source, target ); transferCollectionBasicInfo( source, target );
@ -1785,15 +1786,15 @@ public class HbmXmlTransformer {
return null; return null;
} }
private JaxbOneToMany convertOneToManyCollection(PluralAttributeInfo pluralAttributeInfo) { private JaxbOneToMany transformOneToManyCollection(PluralAttributeInfo pluralAttributeInfo) {
throw new MappingException( "OneToMany transformation not yet implemented", origin ); throw new MappingException( "OneToMany transformation not yet implemented", origin );
} }
private JaxbManyToMany convertManyToManyCollection(PluralAttributeInfo pluralAttributeInfo) { private JaxbManyToMany transformManyToManyCollection(PluralAttributeInfo pluralAttributeInfo) {
throw new MappingException( "ManyToMany transformation not yet implemented", origin ); throw new MappingException( "ManyToMany transformation not yet implemented", origin );
} }
private JaxbHbmManyToAny convertManyToAnyCollection(PluralAttributeInfo pluralAttributeInfo) { private JaxbHbmManyToAny transformManyToAnyCollection(PluralAttributeInfo pluralAttributeInfo) {
throw new MappingException( "ManyToAny transformation not yet implemented", origin ); throw new MappingException( "ManyToAny transformation not yet implemented", origin );
} }
@ -2067,7 +2068,7 @@ public class HbmXmlTransformer {
for ( Serializable attributeMapping : hbmJoin.getAttributes() ) { for ( Serializable attributeMapping : hbmJoin.getAttributes() ) {
if ( attributeMapping instanceof JaxbHbmBasicAttributeType ) { if ( attributeMapping instanceof JaxbHbmBasicAttributeType ) {
final JaxbBasic prop = convertBasicAttribute( (JaxbHbmBasicAttributeType) attributeMapping ); final JaxbBasic prop = transformBasicAttribute( (JaxbHbmBasicAttributeType) attributeMapping );
if ( prop.getColumn() != null ) { if ( prop.getColumn() != null ) {
prop.getColumn().setTable( hbmJoin.getTable() ); prop.getColumn().setTable( hbmJoin.getTable() );
} }