Skip to content

Commit 61c94d9

Browse files
committed
Graphpocalypse: major revision/refactoring of EntityGraph support
- fix up typing issues with key/value subgraphs
1 parent f530548 commit 61c94d9

File tree

12 files changed

+123
-309
lines changed

12 files changed

+123
-309
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.Map;
88

9+
import org.hibernate.metamodel.model.domain.ManagedDomainType;
910
import org.hibernate.metamodel.model.domain.PersistentAttribute;
1011

1112
/**
@@ -19,15 +20,16 @@ public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.Attr
1920

2021
PersistentAttribute<?, J> getAttributeDescriptor();
2122

22-
Map<Class<? extends J>, ? extends SubGraph<? extends J>> getSubGraphs();
23-
Map<Class<? extends J>, ? extends SubGraph<? extends J>> getKeySubGraphs();
23+
Map<Class<?>, ? extends SubGraph<?>> getSubGraphs();
24+
Map<Class<?>, ? extends SubGraph<?>> getKeySubGraphs();
2425

25-
<S extends J> void addSubGraph(Class<S> subType, SubGraph<S> subGraph);
26-
<S extends J> void addKeySubGraph(Class<S> subType, SubGraph<S> subGraph);
26+
SubGraph<?> makeSubGraph();
27+
SubGraph<?> makeKeySubGraph();
2728

28-
SubGraph<J> makeSubGraph();
29-
SubGraph<J> makeKeySubGraph();
29+
<S> SubGraph<S> makeSubGraph(Class<S> type);
30+
<S> SubGraph<S> makeKeySubGraph(Class<S> type);
31+
32+
<S> SubGraph<S> makeSubGraph(ManagedDomainType<S> subtype);
33+
<S> SubGraph<S> makeKeySubGraph(ManagedDomainType<S> subtype);
3034

31-
<S extends J> SubGraph<S> makeSubGraph(Class<S> subtype);
32-
<S extends J> SubGraph<S> makeKeySubGraph(Class<S> subtype);
3335
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,14 @@ default <X> SubGraph<X> addSubgraph(String name, Class<X> type) {
188188
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName);
189189
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type);
190190

191-
<AJ> SubGraph<AJ> addKeySubGraph(PersistentAttribute<? super J,AJ> attribute);
192-
<AJ> SubGraph<AJ> addKeySubGraph(PersistentAttribute<? super J,? super AJ> attribute, Class<AJ> type);
193-
194-
@Override
191+
@Override @Deprecated(forRemoval = true)
195192
default <X> SubGraph<X> addKeySubgraph(Attribute<? super J, X> attribute) {
196-
return addKeySubGraph( (PersistentAttribute<? super J, X>) attribute );
193+
throw new UnsupportedOperationException("This operation will be removed in JPA 4");
197194
}
198195

199-
@Override
196+
@Override @Deprecated(forRemoval = true)
200197
default <X> SubGraph<? extends X> addKeySubgraph(Attribute<? super J, X> attribute, Class<? extends X> type) {
201-
return addKeySubGraph( (PersistentAttribute<? super J, X>) attribute, type );
198+
throw new UnsupportedOperationException("This operation will be removed in JPA 4");
202199
}
203200

204201
@Override

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public interface RootGraph<J> extends Graph<J>, EntityGraph<J> {
2929
* @deprecated Planned for removal in JPA 4
3030
*/
3131
@Override @Deprecated(forRemoval = true)
32-
default <T1> SubGraph<? extends T1> addSubclassSubgraph(Class<? extends T1> type) {
33-
throw new UnsupportedOperationException("This operation will be removed in JPA 4");
32+
@SuppressWarnings("unchecked") // The JPA method was defined with an incorrect generic signature
33+
default <T> SubGraph<? extends T> addSubclassSubgraph(Class<? extends T> type) {
34+
return (SubGraph<? extends T>) addTreatedSubgraph( (Class<? extends J>) type );
3435
}
3536
}

hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author Steve Ebersole
3838
*/
3939
public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements GraphImplementor<J> {
40+
4041
private final ManagedDomainType<J> managedType;
4142
private Map<PersistentAttribute<? super J,?>, AttributeNodeImplementor<?>> attributeNodes;
4243

@@ -109,6 +110,7 @@ private <T> void addAttributeNode(PersistentAttribute<? super J, ?> attribute, A
109110
else {
110111
// we assume the subgraph has been properly copied if needed
111112
node.getSubGraphMap().forEach( (subtype, subgraph) -> attributeNode.addSubGraph( subgraph ) );
113+
node.getKeySubGraphMap().forEach( (subtype, subgraph) -> attributeNode.addKeySubGraph( subgraph ) );
112114
}
113115
}
114116

@@ -247,19 +249,19 @@ public <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName) {
247249
}
248250

249251
@Override
250-
public <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName, Class<AJ> subType) {
251-
return findOrCreateAttributeNode( attributeName ).makeSubGraph( subType );
252+
public <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName, Class<AJ> subtype) {
253+
return findOrCreateAttributeNode( attributeName ).makeSubGraph( subtype );
252254
}
253255

254256
@Override
255257
public <AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttribute<? super J, AJ> attribute) {
256-
return findOrCreateAttributeNode( attribute ).makeSubGraph();
258+
return findOrCreateAttributeNode( attribute ).makeSubGraph( attribute.getJavaType() );
257259
}
258260

259261
@Override
260262
public <AJ> SubGraphImplementor<AJ> addSubGraph(
261-
PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> subType) {
262-
return findOrCreateAttributeNode( attribute ).makeSubGraph( subType );
263+
PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> subtype) {
264+
return findOrCreateAttributeNode( attribute ).makeSubGraph( subtype );
263265
}
264266

265267
@Override
@@ -280,17 +282,6 @@ public <AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName, Class<A
280282
return findOrCreateAttributeNode( attributeName ).makeKeySubGraph( subtype );
281283
}
282284

283-
@Override
284-
public <AJ> SubGraphImplementor<AJ> addKeySubGraph(PersistentAttribute<? super J, AJ> attribute) {
285-
return findOrCreateAttributeNode( attribute ).makeKeySubGraph();
286-
}
287-
288-
@Override
289-
public <AJ> SubGraphImplementor<AJ> addKeySubGraph(
290-
PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> subType) {
291-
return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subType );
292-
}
293-
294285
////////////////// TODO //////////////////
295286

296287
@Override

0 commit comments

Comments
 (0)