|
6 | 6 |
|
7 | 7 | import org.antlr.v4.runtime.CharStreams; |
8 | 8 | import org.antlr.v4.runtime.CommonTokenStream; |
| 9 | +import org.checkerframework.checker.nullness.qual.NonNull; |
9 | 10 | import org.checkerframework.checker.nullness.qual.Nullable; |
10 | 11 | import org.hibernate.UnknownEntityTypeException; |
11 | 12 | import org.hibernate.annotations.NamedEntityGraph; |
12 | 13 | import org.hibernate.boot.model.NamedGraphCreator; |
13 | 14 | import org.hibernate.grammars.graph.GraphLanguageLexer; |
14 | 15 | import org.hibernate.grammars.graph.GraphLanguageParser; |
15 | 16 | import org.hibernate.graph.InvalidGraphException; |
16 | | -import org.hibernate.graph.internal.parse.EntityNameResolver; |
17 | 17 | import org.hibernate.graph.internal.parse.GraphParsing; |
18 | 18 | import org.hibernate.graph.spi.RootGraphImplementor; |
19 | 19 | import org.hibernate.metamodel.model.domain.EntityDomainType; |
@@ -48,33 +48,39 @@ public RootGraphImplementor<?> createEntityGraph( |
48 | 48 | final var parser = new GraphLanguageParser( new CommonTokenStream( lexer ) ); |
49 | 49 | final var graphContext = parser.graph(); |
50 | 50 |
|
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(); |
62 | 52 | if ( entityType == null ) { |
63 | | - if ( graphContext.typeIndicator() == null ) { |
| 53 | + if ( typeIndicator == null ) { |
64 | 54 | throw new InvalidGraphException( "Expecting graph text to include an entity name : " + annotation.graph() ); |
65 | 55 | } |
66 | | - final String jpaEntityName = graphContext.typeIndicator().TYPE_NAME().toString(); |
| 56 | + final String jpaEntityName = typeIndicator.TYPE_NAME().toString(); |
67 | 57 | final var entityDomainType = entityDomainNameResolver.apply( jpaEntityName ); |
68 | 58 | 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 ); |
70 | 60 | } |
71 | 61 | else { |
72 | | - if ( graphContext.typeIndicator() != null ) { |
| 62 | + if ( typeIndicator != null ) { |
73 | 63 | throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + annotation.graph() ); |
74 | 64 | } |
75 | 65 | final var entityDomainType = entityDomainClassResolver.apply( entityType ); |
76 | 66 | 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; |
78 | 83 | } |
| 84 | + throw new UnknownEntityTypeException( entityName ); |
79 | 85 | } |
80 | 86 | } |
0 commit comments