7
7
import java .util .List ;
8
8
9
9
import jakarta .persistence .metamodel .Attribute ;
10
+ import jakarta .persistence .metamodel .MapAttribute ;
10
11
import jakarta .persistence .metamodel .PluralAttribute ;
11
12
import org .hibernate .metamodel .model .domain .ManagedDomainType ;
12
13
import org .hibernate .metamodel .model .domain .MapPersistentAttribute ;
13
14
import org .hibernate .metamodel .model .domain .PersistentAttribute ;
14
15
import org .hibernate .metamodel .model .domain .PluralPersistentAttribute ;
15
16
16
17
/**
17
- * A container for {@link AttributeNode} references.
18
+ * Represents a {@link jakarta.persistence.metamodel.ManagedType managed type} in an
19
+ * {@linkplain Graph entity graph}, acting as a container for:
20
+ * <ul>
21
+ * <li>{@link AttributeNode} references representing fetched attributes, and
22
+ * <li><em>treated subgraphs</em>, each represented by a child instance of
23
+ * {@link SubGraph}.
24
+ * </ul>
25
+ * <p>
26
+ * A treated (narrowed) subgraph allows fetching to be specified for any attribute of
27
+ * any subtype of the type represented by this graph. The usual way to create a treated
28
+ * subgraph is by calling {@link jakarta.persistence.EntityGraph#addTreatedSubgraph(Class)}
29
+ * or {@link #addTreatedSubGraph(Class)}. There are various shortcut operations such as
30
+ * {@link jakarta.persistence.EntityGraph#addTreatedSubgraph(Attribute, Class)} and
31
+ * {@link #addSubGraph(PersistentAttribute, Class)} which combine creation of a subgraph
32
+ * with creation of a treated subgraph.
33
+ * <p>
34
+ * Extends the JPA-defined {@link jakarta.persistence.Graph} with additional operations.
18
35
*
19
- * @apiNote Acts as an abstraction over the JPA-defined interfaces
20
- * {@link jakarta.persistence.EntityGraph} and
21
- * {@link jakarta.persistence.Subgraph}, which have no
22
- * common supertype.
36
+ * @apiNote Historically, both {@link jakarta.persistence.EntityGraph} and this interface
37
+ * declared operations with incorrect generic types, leading to unsound code. This was
38
+ * rectified in JPA 3.2 and Hibernate 7, with possible breakage to older code.
23
39
*
24
40
* @author Strong Liu
25
41
* @author Steve Ebersole
26
42
* @author Andrea Boriero
43
+ * @author Gavin King
27
44
*
28
45
* @see RootGraph
29
46
* @see SubGraph
33
50
public interface Graph <J > extends GraphNode <J >, jakarta .persistence .Graph <J > {
34
51
35
52
/**
36
- * Get a list of all existing AttributeNodes within this container.
37
- *
38
- * @see #getAttributeNodes
39
- */
40
- List <? extends AttributeNode <?>> getAttributeNodeList ();
41
-
42
- /**
43
- * Graphs apply only to {@link jakarta.persistence.metamodel.ManagedType}s.
53
+ * The {@linkplain jakarta.persistence.metamodel.ManagedType managed type}
54
+ * of the node.
44
55
*
45
56
* @return the {@code ManagedType} being graphed here.
46
57
*/
47
58
ManagedDomainType <J > getGraphedType ();
48
59
49
60
/**
50
- * Create a named root {@link Graph} if the given name is not null .
61
+ * Create a named {@linkplain RootGraph root graph} representing this node .
51
62
*
52
- * @param mutable controls whether the resulting {@code Graph} is mutable
63
+ * @param mutable controls whether the resulting graph is mutable
53
64
*
54
65
* @throws CannotBecomeEntityGraphException If the named attribute is not entity-valued
55
66
*
@@ -60,20 +71,32 @@ RootGraph<J> makeRootGraph(String name, boolean mutable)
60
71
throws CannotBecomeEntityGraphException ;
61
72
62
73
/**
63
- * Create a new (mutable or immutable) {@link SubGraph} rooted at
64
- * this {@link Graph}.
74
+ * Create a new {@linkplain SubGraph subgraph} representing this node.
65
75
*
66
76
* @deprecated This will be removed
67
77
*/
68
78
@ Deprecated (since = "7.0" , forRemoval = true )
69
79
SubGraph <J > makeSubGraph (boolean mutable );
70
80
81
+ /**
82
+ * Make a copy of this graph node, with the given mutability.
83
+ * <p>
84
+ * If this graph is immutable, and the argument is {@code false},
85
+ * simply return this instance.
86
+ */
71
87
@ Override
72
88
Graph <J > makeCopy (boolean mutable );
73
89
74
90
75
91
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76
- // AttributeNode handling
92
+ // AttributeNodes
93
+
94
+ /**
95
+ * All {@linkplain AttributeNode nodes} belonging to this container.
96
+ *
97
+ * @see #getAttributeNodes
98
+ */
99
+ List <? extends AttributeNode <?>> getAttributeNodeList ();
77
100
78
101
/**
79
102
* Find an already existing AttributeNode by attributeName within
@@ -112,8 +135,8 @@ default boolean hasAttributeNode(Attribute<? super J, ?> attribute) {
112
135
}
113
136
114
137
/**
115
- * Add an {@link AttributeNode} (with no associated {@link SubGraph})
116
- * to this container by attribute reference .
138
+ * Add an {@link AttributeNode} representing the given {@link PersistentAttribute}
139
+ * to this node of the graph without creating any associated {@link SubGraph} .
117
140
*
118
141
* @see #addAttributeNode(Attribute)
119
142
*/
@@ -126,53 +149,135 @@ default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute)
126
149
127
150
128
151
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129
- // Subgraph nodes
152
+ // Subgraphs
130
153
154
+ /**
155
+ * Create and return a new (mutable) {@link SubGraph} representing
156
+ * the given subtype of the type of this node, or return an existing
157
+ * such {@link SubGraph} if there is one.
158
+ *
159
+ * @see jakarta.persistence.EntityGraph#addTreatedSubgraph(Class)
160
+ */
131
161
<Y extends J > SubGraph <Y > addTreatedSubGraph (Class <Y > type );
132
162
163
+ /**
164
+ * Create and return a new (mutable) {@link SubGraph} representing
165
+ * the given subtype of the type of this node, or return an existing
166
+ * such {@link SubGraph} if there is one.
167
+ */
133
168
<Y extends J > SubGraph <Y > addTreatedSubGraph (ManagedDomainType <Y > type );
134
169
135
170
/**
136
171
* Create and return a new (mutable) {@link SubGraph} associated with
137
- * the named {@link AttributeNode}.
172
+ * the named {@link Attribute}, or return an existing such {@link SubGraph}
173
+ * if there is one.
138
174
*
139
- * @apiNote If no such AttributeNode exists yet, it is created.
175
+ * @see #addSubgraph(String)
140
176
*/
141
177
@ Deprecated
142
178
<AJ > SubGraph <AJ > addSubGraph (String attributeName )
143
179
throws CannotContainSubGraphException ;
144
180
181
+ /**
182
+ * Create and return a new (mutable) {@link SubGraph} associated with
183
+ * the named {@link Attribute}, and with the given type, which may be
184
+ * a subtype of the attribute type, or return an existing such
185
+ * {@link SubGraph} if there is one.
186
+ *
187
+ * @see #addSubgraph(String, Class)
188
+ */
145
189
<AJ > SubGraph <AJ > addSubGraph (String attributeName , Class <AJ > type )
146
190
throws CannotContainSubGraphException ;
147
191
148
192
/**
149
193
* Create and return a new (mutable) {@link SubGraph} associated with
150
- * the {@link AttributeNode} for the given attribute.
194
+ * the given {@link PersistentAttribute}, or return an existing such
195
+ * {@link SubGraph} if there is one.
151
196
*
152
- * @apiNote If no such AttributeNode exists yet, it is created.
197
+ * @see #addSubgraph(Attribute)
153
198
*/
154
199
<AJ > SubGraph <AJ > addSubGraph (PersistentAttribute <? super J , AJ > attribute )
155
200
throws CannotContainSubGraphException ;
156
201
202
+ /**
203
+ * Create and return a new (mutable) {@link SubGraph} associated with
204
+ * the given {@link PersistentAttribute}, and with the given type,
205
+ * which may be a subtype of the attribute type, or return an existing
206
+ * such {@link SubGraph} if there is one.
207
+ *
208
+ * @see #addSubgraph(Attribute, Class)
209
+ */
157
210
<AJ > SubGraph <AJ > addSubGraph (PersistentAttribute <? super J , ? super AJ > attribute , Class <AJ > type )
158
211
throws CannotContainSubGraphException ;
159
212
213
+ /**
214
+ * Create and return a new (mutable) {@link SubGraph} associated with
215
+ * the given {@link PersistentAttribute}, and with the given type,
216
+ * which may be a subtype of the attribute type, or return an existing
217
+ * such {@link SubGraph} if there is one.
218
+ */
160
219
<AJ > SubGraph <AJ > addSubGraph (PersistentAttribute <? super J , ? super AJ > attribute , ManagedDomainType <AJ > type )
161
220
throws CannotContainSubGraphException ;
162
221
222
+ /**
223
+ * Create and return a new (mutable) {@link SubGraph} associated with
224
+ * the element of the given collection, and with the given type, which
225
+ * may be a subtype of the attribute type, or return an existing such
226
+ * {@link SubGraph} if there is one.
227
+ *
228
+ * @see #addTreatedElementSubgraph(PluralAttribute, Class)
229
+ */
163
230
<AJ > SubGraph <AJ > addElementSubGraph (PluralPersistentAttribute <? super J , ?, ? super AJ > attribute , Class <AJ > type )
164
231
throws CannotContainSubGraphException ;
165
232
233
+ /**
234
+ * Create and return a new (mutable) {@link SubGraph} associated with
235
+ * the element of the given collection, and with the given type, which
236
+ * may be a subtype of the attribute type, or return an existing such
237
+ * {@link SubGraph} if there is one.
238
+ */
166
239
<AJ > SubGraph <AJ > addElementSubGraph (PluralPersistentAttribute <? super J , ?, ? super AJ > attribute , ManagedDomainType <AJ > type )
167
240
throws CannotContainSubGraphException ;
168
241
242
+ /**
243
+ * Create and return a new (mutable) {@link SubGraph} associated with
244
+ * the key of the named map or return an existing such {@link SubGraph}
245
+ * if there is one.
246
+ *
247
+ * @see #addKeySubgraph(String)
248
+ */
169
249
@ Deprecated
170
250
<AJ > SubGraph <AJ > addKeySubGraph (String attributeName )
171
251
throws CannotContainSubGraphException ;
172
252
253
+ /**
254
+ * Create and return a new (mutable) {@link SubGraph} associated with
255
+ * the key of the named map, and with the given type, which may be a
256
+ * subtype of the attribute type, or return an existing such
257
+ * {@link SubGraph} if there is one.
258
+ *
259
+ * @see #addKeySubgraph(String, Class)
260
+ */
173
261
<AJ > SubGraph <AJ > addKeySubGraph (String attributeName , Class <AJ > type )
174
262
throws CannotContainSubGraphException ;
175
263
264
+ /**
265
+ * Create and return a new (mutable) {@link SubGraph} associated with
266
+ * the key of the named map, and with the given type, which may be a
267
+ * subtype of the attribute type, or return an existing such
268
+ * {@link SubGraph} if there is one.
269
+ *
270
+ * @see #addTreatedMapKeySubgraph(MapAttribute, Class)
271
+ */
272
+ <AJ > SubGraph <AJ > addKeySubGraph (MapPersistentAttribute <? super J , ? super AJ , ?> attribute , Class <AJ > type )
273
+ throws CannotContainSubGraphException ;
274
+
275
+ /**
276
+ * Create and return a new (mutable) {@link SubGraph} associated with
277
+ * the key of the named map, and with the given type, which may be a
278
+ * subtype of the attribute type, or return an existing such
279
+ * {@link SubGraph} if there is one.
280
+ */
176
281
<AJ > SubGraph <AJ > addKeySubGraph (MapPersistentAttribute <? super J , ? super AJ , ?> attribute , ManagedDomainType <AJ > type )
177
282
throws CannotContainSubGraphException ;
178
283
0 commit comments