Skip to content

Commit 47d28d1

Browse files
committed
get rid of unnecessary EntityNameResolverSessionFactory + extract methods
1 parent fa56009 commit 47d28d1

File tree

3 files changed

+24
-42
lines changed

3 files changed

+24
-42
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import org.antlr.v4.runtime.CharStreams;
88
import org.antlr.v4.runtime.CommonTokenStream;
9+
import org.checkerframework.checker.nullness.qual.NonNull;
910
import org.checkerframework.checker.nullness.qual.Nullable;
1011
import org.hibernate.UnknownEntityTypeException;
1112
import org.hibernate.annotations.NamedEntityGraph;
1213
import org.hibernate.boot.model.NamedGraphCreator;
1314
import org.hibernate.grammars.graph.GraphLanguageLexer;
1415
import org.hibernate.grammars.graph.GraphLanguageParser;
1516
import org.hibernate.graph.InvalidGraphException;
16-
import org.hibernate.graph.internal.parse.EntityNameResolver;
1717
import org.hibernate.graph.internal.parse.GraphParsing;
1818
import org.hibernate.graph.spi.RootGraphImplementor;
1919
import org.hibernate.metamodel.model.domain.EntityDomainType;
@@ -48,33 +48,39 @@ public RootGraphImplementor<?> createEntityGraph(
4848
final var parser = new GraphLanguageParser( new CommonTokenStream( lexer ) );
4949
final var graphContext = parser.graph();
5050

51-
final var entityNameResolver = new EntityNameResolver() {
52-
@Override
53-
public EntityDomainType<?> resolveEntityName(String entityName) {
54-
final var entityDomainType = (EntityDomainType<?>) entityDomainNameResolver.apply( entityName );
55-
if ( entityDomainType != null ) {
56-
return entityDomainType;
57-
}
58-
throw new UnknownEntityTypeException( entityName );
59-
}
60-
};
61-
51+
final var typeIndicator = graphContext.typeIndicator();
6252
if ( entityType == null ) {
63-
if ( graphContext.typeIndicator() == null ) {
53+
if ( typeIndicator == null ) {
6454
throw new InvalidGraphException( "Expecting graph text to include an entity name : " + annotation.graph() );
6555
}
66-
final String jpaEntityName = graphContext.typeIndicator().TYPE_NAME().toString();
56+
final String jpaEntityName = typeIndicator.TYPE_NAME().toString();
6757
final var entityDomainType = entityDomainNameResolver.apply( jpaEntityName );
6858
final String name = this.name == null ? jpaEntityName : this.name;
69-
return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(), entityNameResolver );
59+
return parse( entityDomainNameResolver, name, entityDomainType, graphContext );
7060
}
7161
else {
72-
if ( graphContext.typeIndicator() != null ) {
62+
if ( typeIndicator != null ) {
7363
throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + annotation.graph() );
7464
}
7565
final var entityDomainType = entityDomainClassResolver.apply( entityType );
7666
final String name = this.name == null ? entityDomainType.getName() : this.name;
77-
return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(), entityNameResolver );
67+
return parse( entityDomainNameResolver, name, entityDomainType, graphContext );
68+
}
69+
}
70+
71+
private static @NonNull RootGraphImplementor<?> parse(
72+
Function<String, EntityDomainType<?>> entityDomainNameResolver, String name, EntityDomainType<?> entityDomainType,
73+
GraphLanguageParser.GraphContext graphContext) {
74+
return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(),
75+
entityName -> resolve( entityName, entityDomainNameResolver ) );
76+
}
77+
78+
private static @NonNull EntityDomainType<?> resolve(
79+
String entityName, Function<String, EntityDomainType<?>> entityDomainNameResolver) {
80+
final var entityDomainType = (EntityDomainType<?>) entityDomainNameResolver.apply( entityName );
81+
if ( entityDomainType != null ) {
82+
return entityDomainType;
7883
}
84+
throw new UnknownEntityTypeException( entityName );
7985
}
8086
}

hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolverSessionFactory.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public GraphParser(EntityNameResolver entityNameResolver) {
4141
* @see GraphParser#GraphParser(EntityNameResolver)
4242
*/
4343
public GraphParser(SessionFactoryImplementor sessionFactory) {
44-
this( new EntityNameResolverSessionFactory( sessionFactory ) );
44+
this( sessionFactory.getJpaMetamodel()::findEntityType );
4545
}
4646

4747
public Stack<GraphImplementor<?>> getGraphStack() {

0 commit comments

Comments
 (0)