Skip to content

Commit 7f34241

Browse files
committed
factor out GraphParserEntityXXXXXResolver interfaces
1 parent b069483 commit 7f34241

File tree

11 files changed

+73
-43
lines changed

11 files changed

+73
-43
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/NamedGraphCreator.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
*/
55
package org.hibernate.boot.model;
66

7+
import org.hibernate.graph.spi.GraphParserEntityClassResolver;
8+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
79
import org.hibernate.graph.spi.RootGraphImplementor;
8-
import org.hibernate.metamodel.model.domain.EntityDomainType;
9-
10-
import java.util.function.Function;
1110

1211
/**
1312
* @author Steve Ebersole
1413
*/
1514
@FunctionalInterface
1615
public interface NamedGraphCreator {
1716
RootGraphImplementor<?> createEntityGraph(
18-
Function<Class<?>, EntityDomainType<?>> entityDomainClassResolver,
19-
Function<String, EntityDomainType<?>> entityDomainNameResolver);
17+
GraphParserEntityClassResolver entityDomainClassResolver,
18+
GraphParserEntityNameResolver entityDomainNameResolver);
2019
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import org.hibernate.boot.model.NamedGraphCreator;
1212
import org.hibernate.graph.internal.RootGraphImpl;
1313
import org.hibernate.graph.spi.AttributeNodeImplementor;
14+
import org.hibernate.graph.spi.GraphParserEntityClassResolver;
15+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
1416
import org.hibernate.graph.spi.GraphImplementor;
1517
import org.hibernate.graph.spi.RootGraphImplementor;
1618
import org.hibernate.graph.spi.SubGraphImplementor;
1719
import org.hibernate.metamodel.model.domain.EntityDomainType;
1820

19-
import java.util.function.Function;
20-
2121
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
2222
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
2323

@@ -38,10 +38,10 @@ class NamedGraphCreatorJpa implements NamedGraphCreator {
3838

3939
@Override
4040
public RootGraphImplementor<?> createEntityGraph(
41-
Function<Class<?>, EntityDomainType<?>> entityDomainClassResolver,
42-
Function<String, EntityDomainType<?>> entityDomainNameResolver) {
41+
GraphParserEntityClassResolver entityDomainClassResolver,
42+
GraphParserEntityNameResolver entityDomainNameResolver) {
4343
return createGraph( (EntityDomainType<?>)
44-
entityDomainNameResolver.apply( jpaEntityName ) );
44+
entityDomainNameResolver.resolveEntityName( jpaEntityName ) );
4545
}
4646

4747
private <T> @NonNull RootGraphImplementor<T> createGraph(EntityDomainType<T> rootEntityType) {

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import org.hibernate.grammars.graph.GraphLanguageLexer;
1515
import org.hibernate.grammars.graph.GraphLanguageParser;
1616
import org.hibernate.graph.InvalidGraphException;
17+
import org.hibernate.graph.spi.GraphParserEntityClassResolver;
18+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
1719
import org.hibernate.graph.internal.parse.GraphParsing;
1820
import org.hibernate.graph.spi.RootGraphImplementor;
1921
import org.hibernate.metamodel.model.domain.EntityDomainType;
2022

21-
import java.util.function.Function;
22-
2323
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
2424

2525
/**
@@ -42,8 +42,8 @@ class NamedGraphCreatorParsed implements NamedGraphCreator {
4242

4343
@Override
4444
public RootGraphImplementor<?> createEntityGraph(
45-
Function<Class<?>, EntityDomainType<?>> entityDomainClassResolver,
46-
Function<String, EntityDomainType<?>> entityDomainNameResolver) {
45+
GraphParserEntityClassResolver entityDomainClassResolver,
46+
GraphParserEntityNameResolver entityDomainNameResolver) {
4747
final var lexer = new GraphLanguageLexer( CharStreams.fromString( annotation.graph() ) );
4848
final var parser = new GraphLanguageParser( new CommonTokenStream( lexer ) );
4949
final var graphContext = parser.graph();
@@ -54,33 +54,39 @@ public RootGraphImplementor<?> createEntityGraph(
5454
throw new InvalidGraphException( "Expecting graph text to include an entity name : " + annotation.graph() );
5555
}
5656
final String jpaEntityName = typeIndicator.TYPE_NAME().toString();
57-
final var entityDomainType = entityDomainNameResolver.apply( jpaEntityName );
57+
final var entityDomainType = entityDomainNameResolver.resolveEntityName( jpaEntityName );
5858
final String name = this.name == null ? jpaEntityName : this.name;
5959
return parse( entityDomainNameResolver, name, entityDomainType, graphContext );
6060
}
6161
else {
6262
if ( typeIndicator != null ) {
6363
throw new InvalidGraphException( "Expecting graph text to not include an entity name : " + annotation.graph() );
6464
}
65-
final var entityDomainType = entityDomainClassResolver.apply( entityType );
65+
final var entityDomainType = entityDomainClassResolver.resolveEntityClass( entityType );
6666
final String name = this.name == null ? entityDomainType.getName() : this.name;
6767
return parse( entityDomainNameResolver, name, entityDomainType, graphContext );
6868
}
6969
}
7070

7171
private static @NonNull RootGraphImplementor<?> parse(
72-
Function<String, EntityDomainType<?>> entityDomainNameResolver, String name, EntityDomainType<?> entityDomainType,
72+
GraphParserEntityNameResolver entityDomainNameResolver,
73+
String name,
74+
EntityDomainType<?> entityDomainType,
7375
GraphLanguageParser.GraphContext graphContext) {
7476
return GraphParsing.parse( name, entityDomainType, graphContext.attributeList(),
7577
entityName -> resolve( entityName, entityDomainNameResolver ) );
7678
}
7779

7880
private static @NonNull EntityDomainType<?> resolve(
79-
String entityName, Function<String, EntityDomainType<?>> entityDomainNameResolver) {
80-
final var entityDomainType = (EntityDomainType<?>) entityDomainNameResolver.apply( entityName );
81-
if ( entityDomainType != null ) {
81+
String entityName, GraphParserEntityNameResolver entityDomainNameResolver) {
82+
final var entityDomainType =
83+
(EntityDomainType<?>)
84+
entityDomainNameResolver.resolveEntityName( entityName );
85+
if ( entityDomainType == null ) {
86+
throw new UnknownEntityTypeException( entityName );
87+
}
88+
else {
8289
return entityDomainType;
8390
}
84-
throw new UnknownEntityTypeException( entityName );
8591
}
8692
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ public static void parseInto(
291291
* Parses the textual graph representation as {@linkplain GraphParser described above}
292292
* into the specified graph.
293293
*
294-
* @param <T> The Java type for the ManagedType described by `graph`
295-
*
296294
* @param graph The target graph. This is the graph that will be populated
297295
* by this process
298296
* @param graphText Textual representation of the graph

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.hibernate.graph.GraphNode;
1111
import org.hibernate.graph.InvalidGraphException;
1212
import org.hibernate.graph.spi.AttributeNodeImplementor;
13+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
1314
import org.hibernate.graph.spi.GraphImplementor;
1415
import org.hibernate.graph.spi.SubGraphImplementor;
1516
import org.hibernate.internal.util.StringHelper;
@@ -24,21 +25,21 @@
2425
* @author Steve Ebersole
2526
*/
2627
public class GraphParser extends GraphLanguageParserBaseVisitor<GraphNode<?>> {
27-
private final EntityNameResolver entityNameResolver;
28+
private final GraphParserEntityNameResolver entityNameResolver;
2829

2930
private final Stack<GraphImplementor<?>> graphStack = new StandardStack<>();
3031
private final Stack<AttributeNodeImplementor<?,?,?>> attributeNodeStack = new StandardStack<>();
3132
private final Stack<SubGraphGenerator> graphSourceStack = new StandardStack<>();
3233

33-
public GraphParser(EntityNameResolver entityNameResolver) {
34+
public GraphParser(GraphParserEntityNameResolver entityNameResolver) {
3435
this.entityNameResolver = entityNameResolver;
3536
}
3637

3738
/**
3839
* @apiNote It is important that this form only be used after the session-factory is fully
3940
* initialized, especially the {@linkplain SessionFactoryImplementor#getJpaMetamodel()} JPA metamodel}.
4041
*
41-
* @see GraphParser#GraphParser(EntityNameResolver)
42+
* @see GraphParser#GraphParser(GraphParserEntityNameResolver)
4243
*/
4344
public GraphParser(SessionFactoryImplementor sessionFactory) {
4445
this( sessionFactory.getJpaMetamodel()::findEntityType );

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hibernate.grammars.graph.GraphLanguageParser.GraphContext;
1515
import org.hibernate.graph.InvalidGraphException;
1616
import org.hibernate.graph.internal.RootGraphImpl;
17+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
1718
import org.hibernate.graph.spi.GraphImplementor;
1819
import org.hibernate.graph.spi.RootGraphImplementor;
1920
import org.hibernate.metamodel.model.domain.EntityDomainType;
@@ -86,7 +87,7 @@ public static <T> RootGraphImplementor<T> parse(
8687
public static <T> RootGraphImplementor<T> parse(
8788
EntityDomainType<T> rootType,
8889
GraphLanguageParser.AttributeListContext attributeListContext,
89-
EntityNameResolver entityNameResolver) {
90+
GraphParserEntityNameResolver entityNameResolver) {
9091
return parse( null, rootType, attributeListContext, entityNameResolver );
9192
}
9293

@@ -100,7 +101,7 @@ public static <T> RootGraphImplementor<T> parse(
100101
@Nullable String name,
101102
EntityDomainType<T> rootType,
102103
GraphLanguageParser.AttributeListContext attributeListContext,
103-
EntityNameResolver entityNameResolver) {
104+
GraphParserEntityNameResolver entityNameResolver) {
104105
final RootGraphImpl<T> targetGraph = new RootGraphImpl<>( name, rootType );
105106
visitGraph( targetGraph, entityNameResolver, attributeListContext );
106107
return targetGraph;
@@ -126,7 +127,7 @@ public static void parseInto(
126127

127128
private static void visitGraph(
128129
GraphImplementor<?> targetGraph,
129-
EntityNameResolver entityNameResolver,
130+
GraphParserEntityNameResolver entityNameResolver,
130131
GraphLanguageParser.AttributeListContext attributeList) {
131132
// Build an instance of this class as a visitor
132133
final var visitor = new GraphParser( entityNameResolver );

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package org.hibernate.graph.internal.parse;
66

77

8+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
89
import org.hibernate.metamodel.model.domain.ManagedDomainType;
910

1011
/**
@@ -22,8 +23,8 @@ public enum PathQualifierType {
2223
: attributeNode.addValueSubgraph().addTreatedSubgraph( managedType( subtypeName, entityNameResolver ) )
2324
);
2425

25-
private static <T> ManagedDomainType<T> managedType(String subtypeName, EntityNameResolver entityNameResolver) {
26-
final var entityDomainType = entityNameResolver.resolveEntityName( subtypeName );
26+
private static <T> ManagedDomainType<T> managedType(String subtypeName, GraphParserEntityNameResolver resolver) {
27+
final var entityDomainType = resolver.resolveEntityName( subtypeName );
2728
if ( entityDomainType == null ) {
2829
throw new IllegalArgumentException( "Unknown managed type: " + subtypeName );
2930
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package org.hibernate.graph.internal.parse;
66

77
import org.hibernate.graph.spi.AttributeNodeImplementor;
8+
import org.hibernate.graph.spi.GraphParserEntityNameResolver;
89
import org.hibernate.graph.spi.SubGraphImplementor;
910

1011
/**
@@ -15,5 +16,5 @@ public interface SubGraphGenerator {
1516
SubGraphImplementor<?> createSubGraph(
1617
AttributeNodeImplementor<?,?,?> attributeNode,
1718
String subTypeName,
18-
EntityNameResolver entityNameResolver);
19+
GraphParserEntityNameResolver entityNameResolver);
1920
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.graph.spi;
6+
7+
import org.hibernate.Incubating;
8+
import org.hibernate.metamodel.model.domain.EntityDomainType;
9+
10+
/**
11+
* @author Gavin King
12+
*
13+
* @since 7.2
14+
*/
15+
@Incubating
16+
@FunctionalInterface
17+
public interface GraphParserEntityClassResolver {
18+
EntityDomainType<?> resolveEntityClass(Class<?> entityClass);
19+
}

hibernate-core/src/main/java/org/hibernate/graph/internal/parse/EntityNameResolver.java renamed to hibernate-core/src/main/java/org/hibernate/graph/spi/GraphParserEntityNameResolver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.graph.internal.parse;
5+
package org.hibernate.graph.spi;
66

7+
import org.hibernate.Incubating;
78
import org.hibernate.metamodel.model.domain.EntityDomainType;
89

910
/**
1011
* @author Steve Ebersole
12+
*
13+
* @since 7.2
1114
*/
15+
@Incubating
1216
@FunctionalInterface
13-
public interface EntityNameResolver {
17+
public interface GraphParserEntityNameResolver {
1418
EntityDomainType<?> resolveEntityName(String entityName);
1519
}

0 commit comments

Comments
 (0)