HHH-16115 - Develop an intermediate metamodel binding model

This commit is contained in:
Steve Ebersole 2023-03-03 18:08:41 -06:00
parent 6d719003ce
commit 9049b531b7
5 changed files with 212 additions and 20 deletions

View File

@ -0,0 +1,24 @@
/*
* 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.jaxb.mapping.marshall;
import org.hibernate.metamodel.CollectionClassification;
/**
* JAXB marshalling for {@link CollectionClassification}
*
* @author Steve Ebersole
*/
public class CollectionClassificationMarshalling {
public static CollectionClassification fromXml(String name) {
return CollectionClassification.interpretSetting( name.replace( '-', '_' ) );
}
public static String toXml(CollectionClassification classification) {
return classification.name().replace( '_', '-' );
}
}

View File

@ -112,7 +112,7 @@ public class JPAXMLOverriddenMetadataProvider implements MetadataProvider {
}
defaults.put( EntityListeners.class, entityListeners );
for ( JaxbEntityMappings entityMappings : xmlContext.getAllDocuments() ) {
List<JaxbSequenceGenerator> jaxbSequenceGenerators = entityMappings.getSequenceGenerator();
List<JaxbSequenceGenerator> jaxbSequenceGenerators = entityMappings.getSequenceGenerators();
List<SequenceGenerator> sequenceGenerators = (List<SequenceGenerator>) defaults.get( SequenceGenerator.class );
if ( sequenceGenerators == null ) {
sequenceGenerators = new ArrayList<>();
@ -122,7 +122,7 @@ public class JPAXMLOverriddenMetadataProvider implements MetadataProvider {
sequenceGenerators.add( JPAXMLOverriddenAnnotationReader.buildSequenceGeneratorAnnotation( element ) );
}
List<JaxbTableGenerator> jaxbTableGenerators = entityMappings.getTableGenerator();
List<JaxbTableGenerator> jaxbTableGenerators = entityMappings.getTableGenerators();
List<TableGenerator> tableGenerators = (List<TableGenerator>) defaults.get( TableGenerator.class );
if ( tableGenerators == null ) {
tableGenerators = new ArrayList<>();

View File

@ -584,6 +584,25 @@ public final class StringHelper {
return isEmpty( prefix ) ? name : prefix + '.' + name;
}
/**
* Qualifies {@code name} with {@code prefix} separated by a '.' if<ul>
* <li>{@code name} is not already qualified</li>
* <li>{@code prefix} is not null</li>
* </ul>
*
* @apiNote Similar to {@link #qualifyConditionally}, except that here we explicitly
* check whether {@code name} is already qualified.
*/
public static String qualifyConditionallyIfNot(String prefix, String name) {
if ( name == null ) {
throw new NullPointerException( "name was null attempting to build qualified name" );
}
if ( name.indexOf( '.' ) > 0 || isEmpty( prefix ) ) {
return name;
}
return prefix + '.' + name;
}
public static String[] qualify(String prefix, String[] names) {
if ( prefix == null ) {
return names;

View File

@ -87,10 +87,15 @@
<!-- hbm : whether entities should be lazy (by default) or not -->
<xsd:element name="default-lazy" type="xsd:boolean" minOccurs="0" />
<!-- hbm: <type-def/> definitions -->
<!-- hbm: disabled for now to see if we can move away from String-base type mappings in XML also -->
<!-- <xsd:element name="type-def" type="orm:hbm-type-def" minOccurs="0" maxOccurs="unbounded" /> -->
<!-- hbm: Definitions of filer -->
<xsd:element name="java-type" type="orm:java-type-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="jdbc-type" type="orm:jdbc-type-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="user-type" type="orm:user-type-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="composite-user-type" type="orm:composite-user-type-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="collection-user-type" type="orm:collection-user-type-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="conversion" type="orm:converter-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="embeddable-instantiator" type="orm:embeddable-instantiator-registration" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="filter-def" type="orm:filter-def" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="fetch-profile" type="orm:fetch-profile" minOccurs="0" maxOccurs="unbounded" />
@ -154,6 +159,110 @@
<xsd:attribute name="maximumVersion" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="java-type-registration">
<xsd:annotation>
<xsd:documentation>
See @JavaTypeRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="class" use="required" type="xsd:string"/>
<xsd:attribute name="descriptor" use="required" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="jdbc-type-registration">
<xsd:annotation>
<xsd:documentation>
See @JdbcTypeRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="code" type="xsd:int"/>
<xsd:attribute name="descriptor" use="required" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="user-type-registration">
<xsd:annotation>
<xsd:documentation>
See @TypeRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="class" use="required" type="xsd:string"/>
<xsd:attribute name="descriptor" use="required" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="composite-user-type-registration">
<xsd:annotation>
<xsd:documentation>
See @CompositeTypeRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="class" use="required" type="xsd:string"/>
<xsd:attribute name="descriptor" use="required" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="collection-user-type-registration">
<xsd:annotation>
<xsd:documentation>
See @CollectionTypeRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="param" minOccurs="0" maxOccurs="unbounded" type="configuration-parameter"/>
</xsd:sequence>
<xsd:attribute name="classification" use="required" type="orm:collection-classifications"/>
<xsd:attribute name="descriptor" use="required" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="configuration-parameter">
<xsd:annotation>
<xsd:documentation>
Configuration parameter user-types
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="value" use="required" type="xsd:string"/>
</xsd:complexType>
<xsd:simpleType name="collection-classifications">
<xsd:annotation>
<xsd:documentation>
See `@org.hibernate.metamodel.CollectionClassification`
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="array"/>
<xsd:enumeration value="bag"/>
<xsd:enumeration value="id-bag"/>
<xsd:enumeration value="list"/>
<xsd:enumeration value="set"/>
<xsd:enumeration value="sorted-set"/>
<xsd:enumeration value="ordered-set"/>
<xsd:enumeration value="map"/>
<xsd:enumeration value="sorted-map"/>
<xsd:enumeration value="ordered-map"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="converter-registration">
<xsd:annotation>
<xsd:documentation>
See @ConverterRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="converter" use="required" type="xsd:string"/>
<xsd:attribute name="class" type="xsd:string"/>
<xsd:attribute name="auto-apply" type="xsd:boolean" default="true"/>
</xsd:complexType>
<xsd:complexType name="embeddable-instantiator-registration">
<xsd:annotation>
<xsd:documentation>
See @EmbeddableInstantiatorRegistration
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="embeddableClass" use="required" type="xsd:string"/>
<xsd:attribute name="instantiator" use="required" type="xsd:string"/>
</xsd:complexType>
<!-- **************************************************** -->
@ -282,10 +391,10 @@
<!-- hbm : declare a SQL fragment to append to SELECT queries as a filter for this entity : @Where -->
<xsd:element name="where" type="xsd:string" minOccurs="0"/>
<xsd:element name="loader" type="orm:custom-loader" minOccurs="0" maxOccurs="1"/>
<xsd:element name="sql-insert" type="orm:custom-sql" minOccurs="0" maxOccurs="1"/>
<xsd:element name="sql-update" type="orm:custom-sql" minOccurs="0" maxOccurs="1"/>
<xsd:element name="sql-delete" type="orm:custom-sql" minOccurs="0" maxOccurs="1"/>
<xsd:element name="loader" type="orm:custom-loader" minOccurs="0"/>
<xsd:element name="sql-insert" type="orm:custom-sql" minOccurs="0"/>
<xsd:element name="sql-update" type="orm:custom-sql" minOccurs="0"/>
<xsd:element name="sql-delete" type="orm:custom-sql" minOccurs="0"/>
<!-- hbm : should INSERT statements be dynamically generated : @DynamicInsert -->
<xsd:element name="dynamic-insert" type="xsd:boolean" minOccurs="0"/>
@ -318,7 +427,7 @@
<xsd:element name="polymorphism" type="orm:polymorphism-type" default="implicit" minOccurs="0" />
<xsd:element name="discriminator-value" type="orm:discriminator-value" minOccurs="0"/>
<xsd:choice minOccurs="0" maxOccurs="1">
<xsd:choice minOccurs="0">
<xsd:element name="discriminator-column" type="orm:discriminator-column" />
<!-- hbm: support for Hibernate formula mapping -->
<xsd:element name="discriminator-formula" type="xsd:string" />
@ -353,7 +462,7 @@
<xsd:element name="named-entity-graph" type="orm:named-entity-graph" minOccurs="0" maxOccurs="unbounded"/>
<!-- hbm: intended for use when mapping dynamic (MAP) models -->
<xsd:element name="extends" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="extends" type="xsd:string" minOccurs="0"/>
<xsd:element name="filter" type="orm:hbm-filter" minOccurs="0" maxOccurs="unbounded" />
@ -2122,7 +2231,7 @@
<xsd:simpleType name="versionType">
<xsd:restriction base="xsd:token">
<xsd:pattern value="[0-9]+(\.[0-9]+)*"/>
<xsd:pattern value="\d+(\.\d+)*"/>
</xsd:restriction>
</xsd:simpleType>
@ -2161,7 +2270,7 @@
<xsd:attribute name="type" use="required" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="condition" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="condition" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string"/>
@ -2481,9 +2590,9 @@
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="type" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="column" type="orm:column" minOccurs="0" maxOccurs="1" />
<xsd:element name="mapping" type="orm:hbm-any-discriminator-value-mapping" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="type" type="xsd:string" minOccurs="0"/>
<xsd:element name="column" type="orm:column" minOccurs="0"/>
<xsd:element name="mapping" type="orm:hbm-any-discriminator-value-mapping" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
@ -2494,7 +2603,7 @@
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="type" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="type" type="xsd:string" minOccurs="0"/>
<xsd:element name="column" type="orm:column" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
@ -2705,4 +2814,5 @@
<xsd:enumeration value="never"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</xsd:schema>

View File

@ -29,6 +29,12 @@
<bindings node=".//xsd:element[@name='identifier-generator']">
<property name="genericGenerators"/>
</bindings>
<bindings node=".//xsd:element[@name='sequence-generator']">
<property name="sequenceGenerators"/>
</bindings>
<bindings node=".//xsd:element[@name='table-generator']">
<property name="tableGenerators"/>
</bindings>
<bindings node=".//xsd:element[@name='database-object']">
<property name="databaseObjects"/>
</bindings>
@ -59,6 +65,33 @@
<bindings node=".//xsd:element[@name='converter']">
<property name="converters"/>
</bindings>
<bindings node=".//xsd:element[@name='java-type']">
<property name="javaTypeRegistrations"/>
</bindings>
<bindings node=".//xsd:element[@name='jdbc-type']">
<property name="jdbcTypeRegistrations"/>
</bindings>
<bindings node=".//xsd:element[@name='user-type']">
<property name="userTypeRegistrations"/>
</bindings>
<bindings node=".//xsd:element[@name='composite-user-type']">
<property name="compositeUserTypeRegistrations"/>
</bindings>
<bindings node=".//xsd:element[@name='collection-user-type']">
<property name="collectionUserTypeRegistrations"/>
</bindings>
<bindings node=".//xsd:element[@name='embeddable-instantiator']">
<property name="embeddableInstantiatorRegistrations"/>
</bindings>
<bindings node=".//xsd:element[@name='conversion']">
<property name="converterRegistrations"/>
</bindings>
</bindings>
<bindings node="//xsd:complexType[@name='collection-user-type-registration']">
<bindings node=".//xsd:element[@name='param']">
<property name="parameters"/>
</bindings>
</bindings>
<bindings node="//xsd:complexType[@name='entity']">
@ -384,6 +417,12 @@
printMethod="org.hibernate.boot.jaxb.mapping.marshall.ConstraintModeMarshalling.toXml" />
</bindings>
<bindings node="//xsd:simpleType[@name='collection-classifications']">
<javaType name="org.hibernate.metamodel.CollectionClassification"
parseMethod="org.hibernate.boot.jaxb.mapping.marshall.CollectionClassificationMarshalling.fromXml"
printMethod="org.hibernate.boot.jaxb.mapping.marshall.CollectionClassificationMarshalling.toXml" />
</bindings>
</bindings>
@ -392,4 +431,4 @@
<serializable />
</globalBindings>
</bindings>
</bindings>