77import java .util .List ;
88
99import jakarta .persistence .metamodel .Attribute ;
10+ import jakarta .persistence .metamodel .MapAttribute ;
1011import jakarta .persistence .metamodel .PluralAttribute ;
1112import org .hibernate .metamodel .model .domain .ManagedDomainType ;
1213import org .hibernate .metamodel .model .domain .MapPersistentAttribute ;
1314import org .hibernate .metamodel .model .domain .PersistentAttribute ;
1415import org .hibernate .metamodel .model .domain .PluralPersistentAttribute ;
1516
1617/**
17- * A container for {@link AttributeNode} references.
18- *
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.
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.
2335 *
2436 * @author Strong Liu
2537 * @author Steve Ebersole
2638 * @author Andrea Boriero
39+ * @author Gavin King
2740 *
2841 * @see RootGraph
2942 * @see SubGraph
3346public interface Graph <J > extends GraphNode <J >, jakarta .persistence .Graph <J > {
3447
3548 /**
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.
49+ * The {@linkplain jakarta.persistence.metamodel.ManagedType managed type}
50+ * of the node.
4451 *
4552 * @return the {@code ManagedType} being graphed here.
4653 */
4754 ManagedDomainType <J > getGraphedType ();
4855
4956 /**
50- * Create a named root {@link Graph} if the given name is not null .
57+ * Create a named {@linkplain RootGraph root graph} representing this node .
5158 *
52- * @param mutable controls whether the resulting {@code Graph} is mutable
59+ * @param mutable controls whether the resulting graph is mutable
5360 *
5461 * @throws CannotBecomeEntityGraphException If the named attribute is not entity-valued
5562 *
@@ -60,20 +67,32 @@ RootGraph<J> makeRootGraph(String name, boolean mutable)
6067 throws CannotBecomeEntityGraphException ;
6168
6269 /**
63- * Create a new (mutable or immutable) {@link SubGraph} rooted at
64- * this {@link Graph}.
70+ * Create a new {@linkplain SubGraph subgraph} representing this node.
6571 *
6672 * @deprecated This will be removed
6773 */
6874 @ Deprecated (since = "7.0" , forRemoval = true )
6975 SubGraph <J > makeSubGraph (boolean mutable );
7076
77+ /**
78+ * Make a copy of this graph node, with the given mutability.
79+ * <p>
80+ * If this graph is immutable, and the argument is {@code false},
81+ * simply return this instance.
82+ */
7183 @ Override
7284 Graph <J > makeCopy (boolean mutable );
7385
7486
7587 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76- // AttributeNode handling
88+ // AttributeNodes
89+
90+ /**
91+ * All {@linkplain AttributeNode nodes} belonging to this container.
92+ *
93+ * @see #getAttributeNodes
94+ */
95+ List <? extends AttributeNode <?>> getAttributeNodeList ();
7796
7897 /**
7998 * Find an already existing AttributeNode by attributeName within
@@ -112,8 +131,8 @@ default boolean hasAttributeNode(Attribute<? super J, ?> attribute) {
112131 }
113132
114133 /**
115- * Add an {@link AttributeNode} (with no associated {@link SubGraph})
116- * to this container by attribute reference .
134+ * Add an {@link AttributeNode} representing the given {@link PersistentAttribute}
135+ * to this node of the graph without creating any associated {@link SubGraph} .
117136 *
118137 * @see #addAttributeNode(Attribute)
119138 */
@@ -126,53 +145,135 @@ default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute)
126145
127146
128147 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129- // Subgraph nodes
148+ // Subgraphs
130149
150+ /**
151+ * Create and return a new (mutable) {@link SubGraph} representing
152+ * the given subtype of the type of this node, or return an existing
153+ * such {@link SubGraph} if there is one.
154+ *
155+ * @see jakarta.persistence.EntityGraph#addTreatedSubgraph(Class)
156+ */
131157 <Y extends J > SubGraph <Y > addTreatedSubGraph (Class <Y > type );
132158
159+ /**
160+ * Create and return a new (mutable) {@link SubGraph} representing
161+ * the given subtype of the type of this node, or return an existing
162+ * such {@link SubGraph} if there is one.
163+ */
133164 <Y extends J > SubGraph <Y > addTreatedSubGraph (ManagedDomainType <Y > type );
134165
135166 /**
136167 * Create and return a new (mutable) {@link SubGraph} associated with
137- * the named {@link AttributeNode}.
168+ * the named {@link Attribute}, or return an existing such {@link SubGraph}
169+ * if there is one.
138170 *
139- * @apiNote If no such AttributeNode exists yet, it is created.
171+ * @see #addSubgraph(String)
140172 */
141173 @ Deprecated
142174 <AJ > SubGraph <AJ > addSubGraph (String attributeName )
143175 throws CannotContainSubGraphException ;
144176
177+ /**
178+ * Create and return a new (mutable) {@link SubGraph} associated with
179+ * the named {@link Attribute}, and with the given type, which may be
180+ * a subtype of the attribute type, or return an existing such
181+ * {@link SubGraph} if there is one.
182+ *
183+ * @see #addSubgraph(String, Class)
184+ */
145185 <AJ > SubGraph <AJ > addSubGraph (String attributeName , Class <AJ > type )
146186 throws CannotContainSubGraphException ;
147187
148188 /**
149189 * Create and return a new (mutable) {@link SubGraph} associated with
150- * the {@link AttributeNode} for the given attribute.
190+ * the given {@link PersistentAttribute}, or return an existing such
191+ * {@link SubGraph} if there is one.
151192 *
152- * @apiNote If no such AttributeNode exists yet, it is created.
193+ * @see #addSubgraph(Attribute)
153194 */
154195 <AJ > SubGraph <AJ > addSubGraph (PersistentAttribute <? super J , AJ > attribute )
155196 throws CannotContainSubGraphException ;
156197
198+ /**
199+ * Create and return a new (mutable) {@link SubGraph} associated with
200+ * the given {@link PersistentAttribute}, and with the given type,
201+ * which may be a subtype of the attribute type, or return an existing
202+ * such {@link SubGraph} if there is one.
203+ *
204+ * @see #addSubgraph(Attribute, Class)
205+ */
157206 <AJ > SubGraph <AJ > addSubGraph (PersistentAttribute <? super J , ? super AJ > attribute , Class <AJ > type )
158207 throws CannotContainSubGraphException ;
159208
209+ /**
210+ * Create and return a new (mutable) {@link SubGraph} associated with
211+ * the given {@link PersistentAttribute}, and with the given type,
212+ * which may be a subtype of the attribute type, or return an existing
213+ * such {@link SubGraph} if there is one.
214+ */
160215 <AJ > SubGraph <AJ > addSubGraph (PersistentAttribute <? super J , ? super AJ > attribute , ManagedDomainType <AJ > type )
161216 throws CannotContainSubGraphException ;
162217
218+ /**
219+ * Create and return a new (mutable) {@link SubGraph} associated with
220+ * the element of the given collection, and with the given type, which
221+ * may be a subtype of the attribute type, or return an existing such
222+ * {@link SubGraph} if there is one.
223+ *
224+ * @see #addTreatedElementSubgraph(PluralAttribute, Class)
225+ */
163226 <AJ > SubGraph <AJ > addElementSubGraph (PluralPersistentAttribute <? super J , ?, ? super AJ > attribute , Class <AJ > type )
164227 throws CannotContainSubGraphException ;
165228
229+ /**
230+ * Create and return a new (mutable) {@link SubGraph} associated with
231+ * the element of the given collection, and with the given type, which
232+ * may be a subtype of the attribute type, or return an existing such
233+ * {@link SubGraph} if there is one.
234+ */
166235 <AJ > SubGraph <AJ > addElementSubGraph (PluralPersistentAttribute <? super J , ?, ? super AJ > attribute , ManagedDomainType <AJ > type )
167236 throws CannotContainSubGraphException ;
168237
238+ /**
239+ * Create and return a new (mutable) {@link SubGraph} associated with
240+ * the key of the named map or return an existing such {@link SubGraph}
241+ * if there is one.
242+ *
243+ * @see #addKeySubgraph(String)
244+ */
169245 @ Deprecated
170246 <AJ > SubGraph <AJ > addKeySubGraph (String attributeName )
171247 throws CannotContainSubGraphException ;
172248
249+ /**
250+ * Create and return a new (mutable) {@link SubGraph} associated with
251+ * the key of the named map, and with the given type, which may be a
252+ * subtype of the attribute type, or return an existing such
253+ * {@link SubGraph} if there is one.
254+ *
255+ * @see #addKeySubgraph(String, Class)
256+ */
173257 <AJ > SubGraph <AJ > addKeySubGraph (String attributeName , Class <AJ > type )
174258 throws CannotContainSubGraphException ;
175259
260+ /**
261+ * Create and return a new (mutable) {@link SubGraph} associated with
262+ * the key of the named map, and with the given type, which may be a
263+ * subtype of the attribute type, or return an existing such
264+ * {@link SubGraph} if there is one.
265+ *
266+ * @see #addTreatedMapKeySubgraph(MapAttribute, Class)
267+ */
268+ <AJ > SubGraph <AJ > addKeySubGraph (MapPersistentAttribute <? super J , ? super AJ , ?> attribute , Class <AJ > type )
269+ throws CannotContainSubGraphException ;
270+
271+ /**
272+ * Create and return a new (mutable) {@link SubGraph} associated with
273+ * the key of the named map, and with the given type, which may be a
274+ * subtype of the attribute type, or return an existing such
275+ * {@link SubGraph} if there is one.
276+ */
176277 <AJ > SubGraph <AJ > addKeySubGraph (MapPersistentAttribute <? super J , ? super AJ , ?> attribute , ManagedDomainType <AJ > type )
177278 throws CannotContainSubGraphException ;
178279
0 commit comments