Skip to content

Commit d784d6a

Browse files
committed
clean up the MappingMetamodel interface
- deprecate some operations - remove some already-deprecated operations
1 parent 9a219c2 commit d784d6a

File tree

6 files changed

+15
-99
lines changed

6 files changed

+15
-99
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ public void close() throws HibernateException {
757757
}
758758
}
759759
);
760-
runtimeMetamodels.getMappingMetamodel().close();
760+
// runtimeMetamodels.getMappingMetamodel().close();
761761
}
762762

763763
if ( queryEngine != null ) {

hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.stream.Stream;
1111

1212
import org.hibernate.Incubating;
13+
import org.hibernate.Internal;
1314
import org.hibernate.graph.RootGraph;
1415
import org.hibernate.graph.spi.RootGraphImplementor;
1516
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
@@ -42,6 +43,7 @@ public interface MappingMetamodel extends Metamodel {
4243
// SQM model -> Mapping model
4344

4445
// todo (6.0) : POC intended for use in SQM to SQL translation
46+
@Internal
4547
MappingModelExpressible<?> resolveMappingExpressible(
4648
SqmExpressible<?> sqmExpressible,
4749
Function<NavigablePath,
@@ -61,6 +63,8 @@ MappingModelExpressible<?> resolveMappingExpressible(
6163
* Visit all entity mapping descriptors defined in the model
6264
*/
6365
void forEachEntityDescriptor(Consumer<EntityPersister> action);
66+
67+
@Deprecated(forRemoval = true, since = "7")
6468
Stream<EntityPersister> streamEntityDescriptors();
6569

6670
/**
@@ -123,30 +127,11 @@ MappingModelExpressible<?> resolveMappingExpressible(
123127
* direct entity name.
124128
*
125129
* @throws org.hibernate.UnknownEntityTypeException If a matching EntityPersister cannot be located
126-
*/
127-
EntityPersister locateEntityDescriptor(Class<?> byClass);
128-
129-
/**
130-
* @see #locateEntityDescriptor
131-
*
132-
* @deprecated use {@link #locateEntityDescriptor(Class)} instead
133-
*/
134-
@Deprecated(since = "6.0")
135-
default EntityPersister locateEntityPersister(Class<?> byClass) {
136-
return locateEntityDescriptor( byClass );
137-
}
138-
139-
/**
140-
* Locate the entity persister by name.
141-
*
142-
* @return The located EntityPersister, never {@code null}
143-
*
144-
* @throws org.hibernate.UnknownEntityTypeException If a matching EntityPersister cannot be located
145130
*
146-
* @deprecated - use {@link #getEntityDescriptor(String)} instead
131+
* @deprecated No longer used
147132
*/
148-
@Deprecated(since = "6.0")
149-
EntityPersister locateEntityPersister(String byName);
133+
@Deprecated(forRemoval = true, since = "7")
134+
EntityPersister locateEntityDescriptor(Class<?> byClass);
150135

151136
String getImportedName(String name);
152137

@@ -158,6 +143,8 @@ default EntityPersister locateEntityPersister(Class<?> byClass) {
158143
* Visit the mapping descriptors for all collections defined in the model
159144
*/
160145
void forEachCollectionDescriptor(Consumer<CollectionPersister> action);
146+
147+
@Deprecated(forRemoval = true, since = "7")
161148
Stream<CollectionPersister> streamCollectionDescriptors();
162149

163150
/**

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.hibernate.HibernateException;
2222
import org.hibernate.MappingException;
2323
import org.hibernate.UnknownEntityTypeException;
24-
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
25-
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
2624
import org.hibernate.boot.spi.MetadataImplementor;
2725
import org.hibernate.cache.spi.CacheImplementor;
2826
import org.hibernate.cache.spi.access.CollectionDataAccess;
@@ -104,8 +102,6 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
104102
//NOTE: we suppress deprecation warnings because at the moment we
105103
//implement a deprecated API so have to override deprecated things
106104

107-
private static final String[] EMPTY_IMPLEMENTORS = EMPTY_STRING_ARRAY;
108-
109105
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110106
// JpaMetamodel
111107

@@ -145,22 +141,8 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
145141
//
146142
// To account for this, we track both paradigms here...
147143

148-
/*
149-
* There can be multiple instances of an Embeddable type, each one being relative to its parent entity.
150-
*/
151-
152-
/**
153-
* That's not strictly correct in the JPA standard since for a given Java type we could have
154-
* multiple instances of an embeddable type. Some embeddable might override attributes, but we
155-
* can only return a single EmbeddableTypeImpl for a given Java object class.
156-
* <p>
157-
* A better approach would be if the parent class and attribute name would be included as well
158-
* when trying to locate the embeddable type.
159-
*/
160-
// private final Map<Class<?>, EmbeddableDomainType<?>> jpaEmbeddableTypeMap = new ConcurrentHashMap<>();
161-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144+
// There can be multiple instances of an Embeddable type, each one being relative to its parent entity.
162145

163-
private final Map<String, String[]> implementorsCache = new ConcurrentHashMap<>();
164146
private final Map<TupleType<?>, MappingModelExpressible<?>> tupleTypeCache = new ConcurrentHashMap<>();
165147

166148
public MappingMetamodelImpl(TypeConfiguration typeConfiguration, ServiceRegistry serviceRegistry) {
@@ -370,7 +352,7 @@ public void forEachEntityDescriptor(Consumer<EntityPersister> action) {
370352
}
371353
}
372354

373-
@Override
355+
@Override @Deprecated(forRemoval=true) @SuppressWarnings( "removal" )
374356
public Stream<EntityPersister> streamEntityDescriptors() {
375357
return Arrays.stream( entityPersisterMap.values() );
376358
}
@@ -430,7 +412,7 @@ public EntityPersister getEntityDescriptor(Class<?> entityJavaType) {
430412
return entityPersister;
431413
}
432414

433-
@Override
415+
@Override @Deprecated(forRemoval = true) @SuppressWarnings( "removal" )
434416
public EntityPersister locateEntityDescriptor(Class<?> byClass) {
435417
EntityPersister entityPersister = entityPersisterMap.get( byClass.getName() );
436418
if ( entityPersister == null ) {
@@ -542,43 +524,6 @@ public <E extends Enum<E>> E enumValue(EnumJavaType<E> enumType, String enumValu
542524
return jpaMetamodel.enumValue( enumType, enumValueName );
543525
}
544526

545-
public String[] getImplementors(String className) throws MappingException {
546-
// computeIfAbsent() can be a contention point and we expect all the values to be in the map at some point so
547-
// let's do an optimistic check first
548-
String[] implementors = implementorsCache.get( className );
549-
if ( implementors != null ) {
550-
return Arrays.copyOf( implementors, implementors.length );
551-
}
552-
553-
try {
554-
final Class<?> clazz =
555-
jpaMetamodel.getServiceRegistry().requireService( ClassLoaderService.class )
556-
.classForName( className );
557-
implementors = doGetImplementors( clazz );
558-
if ( implementors.length > 0 ) {
559-
implementorsCache.putIfAbsent( className, implementors );
560-
return Arrays.copyOf( implementors, implementors.length );
561-
}
562-
else {
563-
return EMPTY_IMPLEMENTORS;
564-
}
565-
}
566-
catch (ClassLoadingException e) {
567-
return new String[] { className }; // we don't cache anything for dynamic classes
568-
}
569-
}
570-
571-
572-
573-
@Override
574-
public EntityPersister locateEntityPersister(String byName) {
575-
final EntityPersister entityPersister = entityPersisterMap.get( byName );
576-
if ( entityPersister == null ) {
577-
throw new UnknownEntityTypeException( "Unable to locate persister: " + byName );
578-
}
579-
return entityPersister;
580-
}
581-
582527
@Override
583528
public String getImportedName(String name) {
584529
final String qualifiedName = jpaMetamodel.qualifyImportableName( name );
@@ -590,7 +535,7 @@ public void forEachCollectionDescriptor(Consumer<CollectionPersister> action) {
590535
collectionPersisterMap.values().forEach( action );
591536
}
592537

593-
@Override
538+
@Override @Deprecated(forRemoval=true) @SuppressWarnings( "removal" )
594539
public Stream<CollectionPersister> streamCollectionDescriptors() {
595540
return collectionPersisterMap.values().stream();
596541
}
@@ -847,9 +792,4 @@ public String[] getAllEntityNames() {
847792
public String[] getAllCollectionRoles() {
848793
return ArrayHelper.toStringArray( collectionPersisterMap.keySet() );
849794
}
850-
851-
@Override
852-
public void close() {
853-
// anything to do ?
854-
}
855795
}

hibernate-core/src/main/java/org/hibernate/metamodel/spi/MappingMetamodelImplementor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,4 @@ default String[] getAllCollectionRoles(){
5555
.map( CollectionPersister::getRole )
5656
.toArray( String[]::new );
5757
}
58-
59-
default void close() {
60-
61-
}
62-
6358
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entitynonentity/EntityNonEntityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testMix() {
5050
@JiraKey( value = "HHH-9856" )
5151
public void testGetAndFindNonEntityThrowsIllegalArgumentException() {
5252
try {
53-
sessionFactory().getMappingMetamodel().locateEntityPersister(Cellular.class);
53+
sessionFactory().getMappingMetamodel().findEntityDescriptor(Cellular.class);
5454
sessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor( Cellular.class );
5555

5656
}

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,6 @@ public EntityPersister getEntityDescriptor(String entityName) {
701701
return createEntityPersister(entityName);
702702
}
703703

704-
@Override
705-
public EntityPersister locateEntityPersister(String entityName)
706-
throws MappingException {
707-
return createEntityPersister(entityName);
708-
}
709-
710704
@Override
711705
public CollectionPersister getCollectionDescriptor(String role) {
712706
return createCollectionPersister(role);

0 commit comments

Comments
 (0)