Skip to content

Commit 7cb3e4d

Browse files
committed
Graphpocalypse: major revision/refactoring of EntityGraph support
- sort out handling of mutability - try to minimize diff
1 parent 24fe60e commit 7cb3e4d

File tree

12 files changed

+230
-247
lines changed

12 files changed

+230
-247
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
package org.hibernate.graph;
66

77

8+
import jakarta.persistence.Subgraph;
89
import org.hibernate.metamodel.model.domain.ManagedDomainType;
910
import org.hibernate.metamodel.model.domain.PersistentAttribute;
1011

1112
import java.util.Map;
1213

14+
import static java.util.Collections.unmodifiableMap;
15+
1316
/**
1417
* Extends the JPA-defined {@link AttributeNode} with additional operations.
1518
*
@@ -24,6 +27,16 @@ public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.Attr
2427
Map<Class<?>, ? extends SubGraph<?>> getSubGraphs();
2528
Map<Class<?>, ? extends SubGraph<?>> getKeySubGraphs();
2629

30+
@Override
31+
default @SuppressWarnings("rawtypes") Map<Class, Subgraph> getSubgraphs() {
32+
return unmodifiableMap( getSubGraphs() );
33+
}
34+
35+
@Override
36+
default @SuppressWarnings("rawtypes") Map<Class, Subgraph> getKeySubgraphs() {
37+
return unmodifiableMap( getKeySubGraphs() );
38+
}
39+
2740
SubGraph<?> makeSubGraph();
2841
SubGraph<?> makeKeySubGraph();
2942

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ default boolean hasAttributeNode(Attribute<? super J, ?> attribute) {
117117
*
118118
* @see #addAttributeNode(Attribute)
119119
*/
120-
<AJ> AttributeNode<AJ> addAttributeNode(PersistentAttribute<? super J,AJ> attribute)
121-
throws CannotContainSubGraphException;
120+
<AJ> AttributeNode<AJ> addAttributeNode(PersistentAttribute<? super J,AJ> attribute);
122121

123122
@Override
124123
default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute) {
@@ -140,32 +139,42 @@ default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute)
140139
* @apiNote If no such AttributeNode exists yet, it is created.
141140
*/
142141
@Deprecated
143-
<AJ> SubGraph<AJ> addSubGraph(String attributeName);
142+
<AJ> SubGraph<AJ> addSubGraph(String attributeName)
143+
throws CannotContainSubGraphException;
144144

145-
<AJ> SubGraph<AJ> addSubGraph(String attributeName, Class<AJ> type);
145+
<AJ> SubGraph<AJ> addSubGraph(String attributeName, Class<AJ> type)
146+
throws CannotContainSubGraphException;
146147

147148
/**
148149
* Create and return a new (mutable) {@link SubGraph} associated with
149150
* the {@link AttributeNode} for the given attribute.
150151
*
151152
* @apiNote If no such AttributeNode exists yet, it is created.
152153
*/
153-
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, AJ> attribute);
154+
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, AJ> attribute)
155+
throws CannotContainSubGraphException;
154156

155-
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> type);
157+
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> type)
158+
throws CannotContainSubGraphException;
156159

157-
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedDomainType<AJ> type);
160+
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedDomainType<AJ> type)
161+
throws CannotContainSubGraphException;
158162

159-
<AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, Class<AJ> type);
163+
<AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, Class<AJ> type)
164+
throws CannotContainSubGraphException;
160165

161-
<AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedDomainType<AJ> type);
166+
<AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedDomainType<AJ> type)
167+
throws CannotContainSubGraphException;
162168

163169
@Deprecated
164-
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName);
170+
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName)
171+
throws CannotContainSubGraphException;
165172

166-
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type);
173+
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type)
174+
throws CannotContainSubGraphException;
167175

168-
<AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedDomainType<AJ> type);
176+
<AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedDomainType<AJ> type)
177+
throws CannotContainSubGraphException;
169178

170179
@Override
171180
default <Y> SubGraph<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> type) {
@@ -219,11 +228,11 @@ default <AJ> SubGraph<AJ> addPluralSubgraph(PluralAttribute<? super J, ?, AJ> at
219228

220229
@Override @Deprecated(forRemoval = true)
221230
default <X> SubGraph<X> addKeySubgraph(Attribute<? super J, X> attribute) {
222-
throw new UnsupportedOperationException("This operation will be removed in JPA 4");
231+
throw new UnsupportedOperationException( "This operation will be removed in JPA 4" );
223232
}
224233

225234
@Override @Deprecated(forRemoval = true)
226235
default <X> SubGraph<? extends X> addKeySubgraph(Attribute<? super J, X> attribute, Class<? extends X> type) {
227-
throw new UnsupportedOperationException("This operation will be removed in JPA 4");
236+
throw new UnsupportedOperationException( "This operation will be removed in JPA 4" );
228237
}
229238
}

0 commit comments

Comments
 (0)