Skip to content

Commit ff6d79c

Browse files
committed
HHH-16115 - Develop an intermediate metamodel binding model
HHH-16116 - Bind intermediate metamodel into PersistentClass, et al.
1 parent 8e8bc00 commit ff6d79c

File tree

12 files changed

+212
-23
lines changed

12 files changed

+212
-23
lines changed

hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.boot.archive.spi.InputStreamAccess;
2424
import org.hibernate.boot.internal.MetadataBuilderImpl;
2525
import org.hibernate.boot.jaxb.internal.XmlSources;
26+
import org.hibernate.boot.jaxb.spi.BindableMappingDescriptor;
2627
import org.hibernate.boot.jaxb.spi.Binding;
2728
import org.hibernate.boot.jaxb.spi.XmlSource;
2829
import org.hibernate.boot.registry.BootstrapServiceRegistry;
@@ -64,7 +65,7 @@ public class MetadataSources implements Serializable {
6465

6566
private XmlMappingBinderAccess xmlMappingBinderAccess;
6667

67-
private List<Binding<?>> xmlBindings;
68+
private List<Binding<BindableMappingDescriptor>> xmlBindings;
6869
private LinkedHashSet<Class<?>> annotatedClasses;
6970
private LinkedHashSet<String> annotatedClassNames;
7071
private LinkedHashSet<String> annotatedPackages;
@@ -120,7 +121,7 @@ public XmlMappingBinderAccess getXmlMappingBinderAccess() {
120121
return xmlMappingBinderAccess;
121122
}
122123

123-
public List<Binding<?>> getXmlBindings() {
124+
public List<Binding<BindableMappingDescriptor>> getXmlBindings() {
124125
return xmlBindings == null ? Collections.emptyList() : xmlBindings;
125126
}
126127

@@ -371,7 +372,8 @@ public MetadataSources addFile(File file) {
371372
* @return this (for method chaining purposes)
372373
*/
373374
public MetadataSources addXmlBinding(Binding<?> binding) {
374-
getXmlBindingsForWrite().add( binding );
375+
//noinspection unchecked
376+
getXmlBindingsForWrite().add( (Binding<BindableMappingDescriptor>) binding );
375377
return this;
376378
}
377379

@@ -547,7 +549,7 @@ public MetadataSources addJar(File jar) {
547549
return this;
548550
}
549551

550-
private List<Binding<?>> getXmlBindingsForWrite() {
552+
private List<Binding<BindableMappingDescriptor>> getXmlBindingsForWrite() {
551553
if ( xmlBindings == null ) {
552554
xmlBindings = new ArrayList<>();
553555
}

hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,10 @@ public ConverterRegistry getConverterRegistry() {
513513
return this;
514514
}
515515

516+
public AttributeConverterManager getAttributeConverterManager() {
517+
return attributeConverterManager;
518+
}
519+
516520
@Override
517521
public void addAttributeConverter(Class<? extends AttributeConverter<?,?>> converterClass) {
518522
attributeConverterManager.addConverter(

hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AttributeConverterManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public class AttributeConverterManager implements ConverterAutoApplyHandler {
4646
private Map<Class<?>, ConverterDescriptor> attributeConverterDescriptorsByClass;
4747
private Map<Class<?>, RegisteredConversion> registeredConversionsByDomainType;
4848

49+
public RegisteredConversion findRegisteredConversion(Class<?> domainType) {
50+
if ( registeredConversionsByDomainType == null ) {
51+
return null;
52+
}
53+
return registeredConversionsByDomainType.get( domainType );
54+
}
55+
4956
public void addConverter(ConverterDescriptor descriptor) {
5057
if ( log.isTraceEnabled() ) {
5158
log.tracef( "Starting AttributeConverterManager#addConverter : `%s`",

hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private void addMappedSuperClassInMetadata(PersistentClass persistentClass) {
317317
//add MappedSuperclass if not already there
318318
mappedSuperclass = buildingContext.getMetadataCollector().getMappedSuperclass( type );
319319
if ( mappedSuperclass == null ) {
320-
mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity );
320+
mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity, persistentClass.getImplicitTable() );
321321
mappedSuperclass.setMappedClass( type );
322322
buildingContext.getMetadataCollector().addMappedSuperclass( type, mappedSuperclass );
323323
}

hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ public boolean equals(Object o) {
242242
return getCanonicalName().equals( that.getCanonicalName() );
243243
}
244244

245+
public boolean matches(String name) {
246+
return isQuoted()
247+
? text.equals( name )
248+
: text.equalsIgnoreCase( name );
249+
}
250+
245251
@Override
246252
public int hashCode() {
247253
return isQuoted ? text.hashCode() : text.toLowerCase( Locale.ENGLISH ).hashCode();

hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ManagedResourcesImpl.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717

1818
import org.hibernate.Internal;
1919
import org.hibernate.boot.MetadataSources;
20+
import org.hibernate.boot.jaxb.spi.BindableMappingDescriptor;
2021
import org.hibernate.boot.jaxb.spi.Binding;
2122
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
2223
import org.hibernate.boot.model.process.spi.ManagedResources;
2324
import org.hibernate.boot.spi.BootstrapContext;
2425

26+
import jakarta.persistence.AttributeConverter;
27+
2528
/**
2629
* @author Steve Ebersole
2730
*/
2831
public class ManagedResourcesImpl implements ManagedResources {
29-
private Map<Class, ConverterDescriptor> attributeConverterDescriptorMap = new HashMap<>();
30-
private Set<Class> annotatedClassReferences = new LinkedHashSet<>();
31-
private Set<String> annotatedClassNames = new LinkedHashSet<>();
32-
private Set<String> annotatedPackageNames = new LinkedHashSet<>();
33-
private List<Binding> mappingFileBindings = new ArrayList<>();
32+
private final Map<Class<? extends AttributeConverter>, ConverterDescriptor> attributeConverterDescriptorMap = new HashMap<>();
33+
private final Set<Class<?>> annotatedClassReferences = new LinkedHashSet<>();
34+
private final Set<String> annotatedClassNames = new LinkedHashSet<>();
35+
private final Set<String> annotatedPackageNames = new LinkedHashSet<>();
36+
private final List<Binding<BindableMappingDescriptor>> mappingFileBindings = new ArrayList<>();
3437
private Map<String, Class<?>> extraQueryImports;
3538

3639
public static ManagedResourcesImpl baseline(MetadataSources sources, BootstrapContext bootstrapContext) {
@@ -44,7 +47,7 @@ public static ManagedResourcesImpl baseline(MetadataSources sources, BootstrapCo
4447
return impl;
4548
}
4649

47-
private ManagedResourcesImpl() {
50+
public ManagedResourcesImpl() {
4851
}
4952

5053
@Override
@@ -53,7 +56,7 @@ public Collection<ConverterDescriptor> getAttributeConverterDescriptors() {
5356
}
5457

5558
@Override
56-
public Collection<Class> getAnnotatedClassReferences() {
59+
public Collection<Class<?>> getAnnotatedClassReferences() {
5760
return Collections.unmodifiableSet( annotatedClassReferences );
5861
}
5962

@@ -68,7 +71,7 @@ public Collection<String> getAnnotatedPackageNames() {
6871
}
6972

7073
@Override
71-
public Collection<Binding> getXmlMappingBindings() {
74+
public Collection<Binding<BindableMappingDescriptor>> getXmlMappingBindings() {
7275
return Collections.unmodifiableList( mappingFileBindings );
7376
}
7477

@@ -87,7 +90,7 @@ public void addAttributeConverterDefinition(ConverterDescriptor descriptor) {
8790
}
8891

8992
@Internal
90-
public void addAnnotatedClassReference(Class annotatedClassReference) {
93+
public void addAnnotatedClassReference(Class<?> annotatedClassReference) {
9194
annotatedClassReferences.add( annotatedClassReference );
9295
}
9396

@@ -102,7 +105,7 @@ public void addAnnotatedPackageName(String annotatedPackageName) {
102105
}
103106

104107
@Internal
105-
public void addXmlBinding(Binding binding) {
108+
public void addXmlBinding(Binding<BindableMappingDescriptor> binding) {
106109
mappingFileBindings.add( binding );
107110
}
108111
}

hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/ManagedResources.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Collection;
1010
import java.util.Map;
1111

12+
import org.hibernate.boot.jaxb.spi.BindableMappingDescriptor;
1213
import org.hibernate.boot.jaxb.spi.Binding;
1314
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
1415

@@ -40,7 +41,7 @@ public interface ManagedResources {
4041
*
4142
* @return The list of entity/component classes known by Class reference.
4243
*/
43-
Collection<Class> getAnnotatedClassReferences();
44+
Collection<Class<?>> getAnnotatedClassReferences();
4445

4546
/**
4647
* Informational access to any entity and component classes in the user domain model known by name.
@@ -64,7 +65,7 @@ public interface ManagedResources {
6465
*
6566
* @return The list of bindings for all known XML mapping files.
6667
*/
67-
Collection<Binding> getXmlMappingBindings();
68+
Collection<Binding<BindableMappingDescriptor>> getXmlMappingBindings();
6869

6970
Map<String,Class<?>> getExtraQueryImports();
7071
}

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/HbmMetadataSourceProcessorImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Set;
1313

1414
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
15+
import org.hibernate.boot.jaxb.spi.BindableMappingDescriptor;
1516
import org.hibernate.boot.jaxb.spi.Binding;
1617
import org.hibernate.boot.model.process.spi.ManagedResources;
1718
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
@@ -40,16 +41,15 @@ public HbmMetadataSourceProcessorImpl(
4041
this( managedResources.getXmlMappingBindings(), rootBuildingContext );
4142
}
4243

43-
@SuppressWarnings("unchecked")
4444
public HbmMetadataSourceProcessorImpl(
45-
Collection<Binding> xmlBindings,
45+
Collection<Binding<BindableMappingDescriptor>> xmlBindings,
4646
MetadataBuildingContext rootBuildingContext) {
4747
this.rootBuildingContext = rootBuildingContext;
4848
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
4949

5050
this.mappingDocuments = new ArrayList<>();
5151

52-
for ( Binding xmlBinding : xmlBindings ) {
52+
for ( Binding<BindableMappingDescriptor> xmlBinding : xmlBindings ) {
5353
if ( !(xmlBinding.getRoot() instanceof JaxbHbmHibernateMapping) ) {
5454
continue;
5555
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.mapping;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Commonality between {@link PersistentClass} and {@link MappedSuperclass},
13+
* what JPA calls an {@linkplain jakarta.persistence.metamodel.IdentifiableType identifiable type}.
14+
*
15+
* @author Steve Ebersole
16+
*/
17+
public interface IdentifiableTypeClass extends TableContainer {
18+
IdentifiableTypeClass getSuperType();
19+
List<IdentifiableTypeClass> getSubTypes();
20+
21+
List<Property> getDeclaredProperties();
22+
23+
Table getImplicitTable();
24+
25+
void applyProperty(Property property);
26+
}

hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@
1717
*
1818
* @author Emmanuel Bernard
1919
*/
20-
public class MappedSuperclass {
20+
public class MappedSuperclass implements IdentifiableTypeClass {
2121
private final MappedSuperclass superMappedSuperclass;
2222
private final PersistentClass superPersistentClass;
2323
private final List<Property> declaredProperties;
24+
private final Table implicitTable;
2425
private Class<?> mappedClass;
2526
private Property identifierProperty;
2627
private Property version;
2728
private Component identifierMapper;
2829

29-
public MappedSuperclass(MappedSuperclass superMappedSuperclass, PersistentClass superPersistentClass) {
30+
public MappedSuperclass(
31+
MappedSuperclass superMappedSuperclass,
32+
PersistentClass superPersistentClass,
33+
Table implicitTable) {
3034
this.superMappedSuperclass = superMappedSuperclass;
3135
this.superPersistentClass = superPersistentClass;
36+
this.implicitTable = implicitTable;
3237
this.declaredProperties = new ArrayList<>();
3338
}
3439

@@ -205,4 +210,49 @@ && getSuperPersistentClass().isPropertyDefinedInHierarchy( name ) ) {
205210
public void prepareForMappingModel() {
206211
declaredProperties.sort( Comparator.comparing( Property::getName ) );
207212
}
213+
214+
@Override
215+
public Table findTable(String name) {
216+
return null;
217+
}
218+
219+
@Override
220+
public Table getTable(String name) {
221+
return null;
222+
}
223+
224+
@Override
225+
public Join findSecondaryTable(String name) {
226+
return null;
227+
}
228+
229+
@Override
230+
public Join getSecondaryTable(String name) {
231+
return null;
232+
}
233+
234+
@Override
235+
public IdentifiableTypeClass getSuperType() {
236+
if ( superPersistentClass != null ) {
237+
return superPersistentClass;
238+
}
239+
return superMappedSuperclass;
240+
}
241+
242+
@Override
243+
public List<IdentifiableTypeClass> getSubTypes() {
244+
throw new UnsupportedOperationException( "Not implemented yet" );
245+
}
246+
247+
@Override
248+
public Table getImplicitTable() {
249+
return implicitTable;
250+
}
251+
252+
@Override
253+
public void applyProperty(Property property) {
254+
assert property.getValue().getTable() != null;
255+
assert property.getValue().getTable().equals( getImplicitTable() );
256+
addDeclaredProperty( property );
257+
}
208258
}

0 commit comments

Comments
 (0)