diff --git a/hibernate-core/src/main/java/org/hibernate/graph/AttributeNode.java b/hibernate-core/src/main/java/org/hibernate/graph/AttributeNode.java index 8aaa100167d6..94e0fbaad964 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/AttributeNode.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/AttributeNode.java @@ -6,7 +6,8 @@ import jakarta.persistence.Subgraph; -import org.hibernate.metamodel.model.domain.ManagedDomainType; +import jakarta.persistence.metamodel.ManagedType; +import org.hibernate.Incubating; import org.hibernate.metamodel.model.domain.PersistentAttribute; import java.util.Map; @@ -51,6 +52,8 @@ public interface AttributeNode extends GraphNode, jakarta.persistence.Attr /** * All value subgraphs rooted at this node. + *

+ * Includes treated subgraphs. * * @see jakarta.persistence.AttributeNode#getSubgraphs */ @@ -58,6 +61,8 @@ public interface AttributeNode extends GraphNode, jakarta.persistence.Attr /** * All key subgraphs rooted at this node. + *

+ * Includes treated subgraphs. * * @see jakarta.persistence.AttributeNode#getKeySubgraphs */ @@ -89,6 +94,11 @@ public interface AttributeNode extends GraphNode, jakarta.persistence.Attr * Create and return a new value {@link SubGraph} rooted at this node, * with the given type, which may be a subtype of the value type, * or return an existing such {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the value type, the result + * is a treated subgraph. + * + * @param subtype The type or treated type of the value type */ SubGraph makeSubGraph(Class subtype); @@ -96,6 +106,11 @@ public interface AttributeNode extends GraphNode, jakarta.persistence.Attr * Create and return a new value {@link SubGraph} rooted at this node, * with the given type, which may be a subtype of the key type, * or return an existing such {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the key type, the result + * is a treated subgraph. + * + * @param subtype The type or treated type of the key type */ SubGraph makeKeySubGraph(Class subtype); @@ -103,13 +118,25 @@ public interface AttributeNode extends GraphNode, jakarta.persistence.Attr * Create and return a new value {@link SubGraph} rooted at this node, * with the given type, which may be a subtype of the value type, * or return an existing such {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the value type, the result + * is a treated subgraph. + * + * @param subtype The type or treated type of the value type */ - SubGraph makeSubGraph(ManagedDomainType subtype); + @Incubating + SubGraph makeSubGraph(ManagedType subtype); /** * Create and return a new value {@link SubGraph} rooted at this node, * with the given type, which may be a subtype of the key type, * or return an existing such {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the key type, the result + * is a treated subgraph. + * + * @param subtype The type or treated type of the key type */ - SubGraph makeKeySubGraph(ManagedDomainType subtype); + @Incubating + SubGraph makeKeySubGraph(ManagedType subtype); } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java b/hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java index 5ba437f6ca99..233a601a6de2 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java @@ -141,7 +141,7 @@ public static void setFetchGraph(TypedQuery query, EntityGraph graph) * @since 7.0 */ public Subgraph addTreatedSubgraph(Graph graph, Class subtype) { - return ((org.hibernate.graph.Graph) graph).addTreatedSubGraph( subtype ); + return ((org.hibernate.graph.Graph) graph).addTreatedSubgraph( subtype ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/graph/Graph.java b/hibernate-core/src/main/java/org/hibernate/graph/Graph.java index 09a8a894a9d6..78b89466ed79 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/Graph.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/Graph.java @@ -7,12 +7,13 @@ import java.util.List; import jakarta.persistence.metamodel.Attribute; +import jakarta.persistence.metamodel.ManagedType; import jakarta.persistence.metamodel.MapAttribute; import jakarta.persistence.metamodel.PluralAttribute; +import org.hibernate.Incubating; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.MapPersistentAttribute; import org.hibernate.metamodel.model.domain.PersistentAttribute; -import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; /** * Represents a {@link jakarta.persistence.metamodel.ManagedType managed type} in an @@ -26,10 +27,9 @@ * A treated (narrowed) subgraph allows fetching to be specified for any attribute of * any subtype of the type represented by this graph. The usual way to create a treated * subgraph is by calling {@link jakarta.persistence.EntityGraph#addTreatedSubgraph(Class)} - * or {@link #addTreatedSubGraph(Class)}. There are various shortcut operations such as - * {@link jakarta.persistence.EntityGraph#addTreatedSubgraph(Attribute, Class)} and - * {@link #addSubGraph(PersistentAttribute, Class)} which combine creation of a subgraph - * with creation of a treated subgraph. + * or {@link #addTreatedSubgraph(Class)}. There are various shortcut operations such as + * {@link jakarta.persistence.EntityGraph#addTreatedSubgraph(Attribute, Class)} which + * combine creation of a subgraph with creation of a treated subgraph. *

* Extends the JPA-defined {@link jakarta.persistence.Graph} with additional operations. * @@ -99,57 +99,45 @@ RootGraph makeRootGraph(String name, boolean mutable) List> getAttributeNodeList(); /** - * Find an already existing AttributeNode by attributeName within - * this container - * - * @see #getAttributeNode(String) + * Find an existing {@link AttributeNode} by name within this container. */ - AttributeNode findAttributeNode(String attributeName); + @Override + AttributeNode getAttributeNode(String attributeName); /** - * Find an already existing AttributeNode by corresponding attribute + * Find an existing {@link AttributeNode} by corresponding attribute * reference, within this container. - * - * @see #getAttributeNode(Attribute) */ - AttributeNode findAttributeNode(PersistentAttribute attribute); - @Override - default AttributeNode getAttributeNode(String attributeName) { - return findAttributeNode( attributeName ); - } - - @Override - default AttributeNode getAttributeNode(Attribute attribute) { - return findAttributeNode( (PersistentAttribute) attribute ); - } + AttributeNode getAttributeNode(Attribute attribute); - @Override - default boolean hasAttributeNode(String attributeName) { - return getAttributeNode( attributeName ) != null; - } - - @Override - default boolean hasAttributeNode(Attribute attribute) { - return getAttributeNode( attribute ) != null; - } + /** + * Find an existing {@link AttributeNode} by name within this container. + * + * @deprecated Use {@link #getAttributeNode(String)} + */ + @Deprecated(since = "7.0") + AttributeNode findAttributeNode(String attributeName); /** - * Add an {@link AttributeNode} representing the given {@link PersistentAttribute} - * to this node of the graph without creating any associated {@link SubGraph}. + * Find an existing {@link AttributeNode} by corresponding attribute + * reference, within this container. * - * @see #addAttributeNode(Attribute) + * @deprecated Use {@link #getAttributeNode(Attribute)} */ - AttributeNode addAttributeNode(PersistentAttribute attribute); + @Deprecated(since = "7.0") + AttributeNode findAttributeNode(PersistentAttribute attribute); + /** + * Add an {@link AttributeNode} representing the given {@link Attribute} to + * this node of the graph without creating any associated {@link SubGraph}. + */ @Override - default AttributeNode addAttributeNode(Attribute attribute) { - return addAttributeNode( (PersistentAttribute) attribute ); - } + AttributeNode addAttributeNode(Attribute attribute); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Subgraphs + // Treated subgraphs /** * Create and return a new (mutable) {@link SubGraph} representing @@ -158,23 +146,57 @@ default AttributeNode addAttributeNode(Attribute attribute) * * @see jakarta.persistence.EntityGraph#addTreatedSubgraph(Class) */ - SubGraph addTreatedSubGraph(Class type); + SubGraph addTreatedSubgraph(Class type); /** * Create and return a new (mutable) {@link SubGraph} representing * the given subtype of the type of this node, or return an existing * such {@link SubGraph} if there is one. */ - SubGraph addTreatedSubGraph(ManagedDomainType type); + @Incubating + SubGraph addTreatedSubgraph(ManagedType type); + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Attribute subgraphs + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the named {@link Attribute}, or return an existing such {@link SubGraph} + * if there is one. + * + * @param attributeName The name of an attribute of the represented type + */ + @Override + default SubGraph addSubgraph(String attributeName) { + return addSubGraph( attributeName ); + } + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the named {@link Attribute}, and with the given type, which may be + * a subtype of the attribute type, or return an existing such + * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the attribute type, the + * result is a treated subgraph. + * + * @param attributeName The name of an attribute of the represented type + * @param type A subtype of the attribute type + */ + @Override + SubGraph addSubgraph(String attributeName, Class type); /** * Create and return a new (mutable) {@link SubGraph} associated with * the named {@link Attribute}, or return an existing such {@link SubGraph} * if there is one. * - * @see #addSubgraph(String) + * @param attributeName The name of an attribute of the represented type + * + * @deprecated Use {@link #addSubgraph(String)} */ - @Deprecated + @Deprecated(since = "7.0") SubGraph addSubGraph(String attributeName) throws CannotContainSubGraphException; @@ -183,19 +205,78 @@ SubGraph addSubGraph(String attributeName) * the named {@link Attribute}, and with the given type, which may be * a subtype of the attribute type, or return an existing such * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the attribute type, the + * result is a treated subgraph. + * + * @param attributeName The name of an attribute of the represented type + * @param type A subtype of the attribute type * - * @see #addSubgraph(String, Class) + * @deprecated Use {@link #addSubgraph(String, Class)} */ + @Deprecated(since = "7.0") SubGraph addSubGraph(String attributeName, Class type) throws CannotContainSubGraphException; /** * Create and return a new (mutable) {@link SubGraph} associated with - * the given {@link PersistentAttribute}, or return an existing such + * the given {@link Attribute} of the represented type, or return an + * existing such {@link SubGraph} if there is one. + * + * @param attribute An attribute of the represented type + * + * @see #addSubgraph(Attribute) + */ + @Override + SubGraph addSubgraph(Attribute attribute) + throws CannotContainSubGraphException; + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the given {@link Attribute}, and with the given type, which may be + * a subtype of the attribute type, or return an existing such + * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the attribute type, the + * result is a treated subgraph. + * + * @param attribute An attribute of the represented type + * @param type A subtype of the attribute type + * + * @see #addSubgraph(Attribute, Class) + */ + @Override + SubGraph addTreatedSubgraph(Attribute attribute, Class type) + throws CannotContainSubGraphException; + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the given {@link Attribute}, and with the given type, which may be + * a subtype of the attribute type, or return an existing such * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the attribute type, the + * result is a treated subgraph. + * + * @param attribute An attribute of the represented type + * @param type A subtype of the attribute type + */ + @Incubating + SubGraph addTreatedSubgraph(Attribute attribute, ManagedType type) + throws CannotContainSubGraphException; + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the given {@link Attribute} of the represented type, or return an + * existing such {@link SubGraph} if there is one. + * + * @param attribute An attribute of the represented type * * @see #addSubgraph(Attribute) + * + * @deprecated Use {@link #addSubgraph(Attribute)} */ + @Deprecated(since = "7.0") SubGraph addSubGraph(PersistentAttribute attribute) throws CannotContainSubGraphException; @@ -204,30 +285,76 @@ SubGraph addSubGraph(PersistentAttribute attribute) * the given {@link PersistentAttribute}, and with the given type, * which may be a subtype of the attribute type, or return an existing * such {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the attribute type, the + * result is a treated subgraph. + * + * @param attribute An attribute of the represented type + * @param type A subtype of the attribute type * * @see #addSubgraph(Attribute, Class) + * + * @deprecated Use {@link #addTreatedSubgraph(Attribute, Class)} */ + @Deprecated(since = "7.0") SubGraph addSubGraph(PersistentAttribute attribute, Class type) throws CannotContainSubGraphException; + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Element subgraphs + /** * Create and return a new (mutable) {@link SubGraph} associated with - * the given {@link PersistentAttribute}, and with the given type, - * which may be a subtype of the attribute type, or return an existing + * the element of the named {@link PluralAttribute}, or return an + * existing such {@link SubGraph} if there is one. + * + * @param attributeName The name of a collection-valued attribute of the + * represented type + */ + @Override + SubGraph addElementSubgraph(String attributeName); + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the element of the named {@link PluralAttribute}, and with the given + * type, which may be a subtype of the element type, or return an existing * such {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the attribute type, the + * result is a treated subgraph. + * + * @param attributeName The name of a collection-valued attribute of the + * represented type + * @param type A subtype of the element type */ - SubGraph addSubGraph(PersistentAttribute attribute, ManagedDomainType type) - throws CannotContainSubGraphException; + @Override + SubGraph addElementSubgraph(String attributeName, Class type); + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the element of the given collection, or return an existing such + * {@link SubGraph} if there is one. + * + * @param attribute A collection-valued attribute of the represented type + */ + @Override + SubGraph addElementSubgraph(PluralAttribute attribute); /** * Create and return a new (mutable) {@link SubGraph} associated with * the element of the given collection, and with the given type, which - * may be a subtype of the attribute type, or return an existing such + * may be a subtype of the element type, or return an existing such * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the element type, the result + * is a treated subgraph. * - * @see #addTreatedElementSubgraph(PluralAttribute, Class) + * @param attribute A collection-valued attribute of the represented type + * @param type A subtype of the element type */ - SubGraph addElementSubGraph(PluralPersistentAttribute attribute, Class type) + @Override + SubGraph addTreatedElementSubgraph(PluralAttribute attribute, Class type) throws CannotContainSubGraphException; /** @@ -235,18 +362,54 @@ SubGraph addElementSubGraph(PluralPersistentAttribute + * If the given type is a proper subtype of the element type, the result + * is a treated subgraph. + * + * @param attribute A collection-valued attribute of the represented type + * @param type A subtype of the element type */ - SubGraph addElementSubGraph(PluralPersistentAttribute attribute, ManagedDomainType type) + @Incubating + SubGraph addTreatedElementSubgraph(PluralAttribute attribute, ManagedType type) throws CannotContainSubGraphException; + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Key subgraphs + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the key of the named map or return an existing such {@link SubGraph} + * if there is one. + * + * @param attributeName The name of an attribute of the represented type + */ + @Override + SubGraph addKeySubgraph(String attributeName); + + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the key of the named map, and with the given type, which may be a + * subtype of the attribute type, or return an existing such + * {@link SubGraph} if there is one. + * + * @param attributeName The name of a map-valued attribute of the + * represented type + * @param type A subtype of the key type + */ + @Override + SubGraph addKeySubgraph(String attributeName, Class type); + /** * Create and return a new (mutable) {@link SubGraph} associated with * the key of the named map or return an existing such {@link SubGraph} * if there is one. * - * @see #addKeySubgraph(String) + * @param attributeName The name of an attribute of the represented type + * + * @deprecated Use {@link #addKeySubgraph(String)} */ - @Deprecated + @Deprecated(since = "7.0") SubGraph addKeySubGraph(String attributeName) throws CannotContainSubGraphException; @@ -255,82 +418,105 @@ SubGraph addKeySubGraph(String attributeName) * the key of the named map, and with the given type, which may be a * subtype of the attribute type, or return an existing such * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the key type, the result + * is a treated subgraph. + * + * @param attributeName The name of a map-valued attribute of the + * represented type + * @param type A subtype of the key type * - * @see #addKeySubgraph(String, Class) + * @deprecated Use {@link #addKeySubgraph(String, Class)} */ + @Deprecated(since = "7.0") SubGraph addKeySubGraph(String attributeName, Class type) throws CannotContainSubGraphException; + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the key of the named map, or return an existing such {@link SubGraph} + * if there is one. + * + * @param attribute A map-valued attribute of the represented type + */ + @Override + SubGraph addMapKeySubgraph(MapAttribute attribute); + /** * Create and return a new (mutable) {@link SubGraph} associated with * the key of the named map, and with the given type, which may be a * subtype of the attribute type, or return an existing such * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the key type, the result + * is a treated subgraph. * - * @see #addTreatedMapKeySubgraph(MapAttribute, Class) + * @param attribute A map-valued attribute of the represented type + * @param type A subtype of the key type */ - SubGraph addKeySubGraph(MapPersistentAttribute attribute, Class type) - throws CannotContainSubGraphException; + @Override + SubGraph addTreatedMapKeySubgraph(MapAttribute attribute, Class type); /** * Create and return a new (mutable) {@link SubGraph} associated with * the key of the named map, and with the given type, which may be a * subtype of the attribute type, or return an existing such * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the key type, the result + * is a treated subgraph. + * + * @param attribute A map-valued attribute of the represented type + * @param type A subtype of the key type */ - SubGraph addKeySubGraph(MapPersistentAttribute attribute, ManagedDomainType type) + @Incubating + SubGraph addTreatedMapKeySubgraph(MapAttribute attribute, ManagedType type) throws CannotContainSubGraphException; - @Override - default SubGraph addTreatedSubgraph(Attribute attribute, Class type) { - return addSubGraph( (PersistentAttribute) attribute ).addTreatedSubGraph( type ); - } - - @Override - default SubGraph addSubgraph(Attribute attribute) { - return addSubGraph( (PersistentAttribute) attribute ); - } - - @Override - default SubGraph addSubgraph(Attribute attribute, Class type) { - return addSubGraph( (PersistentAttribute) attribute ).addTreatedSubGraph( type ); - } - - @Override - default SubGraph addSubgraph(String name) { - return addSubGraph( name ); - } - - @Override - default SubGraph addSubgraph(String name, Class type) { - return addSubGraph( name ).addTreatedSubGraph( type ); - } + /** + * Create and return a new (mutable) {@link SubGraph} associated with + * the key of the named map, and with the given type, which may be a + * subtype of the attribute type, or return an existing such + * {@link SubGraph} if there is one. + *

+ * If the given type is a proper subtype of the key type, the result + * is a treated subgraph. + * + * @param attribute A map-valued attribute of the represented type + * @param type A subtype of the key type + * + * @deprecated Use {@link #addTreatedMapKeySubgraph(MapAttribute, Class)} + */ + @Deprecated(since = "7.0") + SubGraph addKeySubGraph(MapPersistentAttribute attribute, Class type) + throws CannotContainSubGraphException; - @Override - default SubGraph addKeySubgraph(String name) { - return addKeySubGraph( name ); - } - @Override - default SubGraph addKeySubgraph(String name, Class type) { - return addKeySubGraph( name ).addTreatedSubGraph( type ); - } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Misc deprecated /** - * Add a subgraph rooted at a plural attribute, allowing further nodes - * to be added to the subgraph. + * Create and return a new (mutable) {@link SubGraph} associated with + * the element of the given collection, or return an existing such + * {@link SubGraph} if there is one. * - * @apiNote {@link #addElementSubgraph(PluralAttribute)} was added - * in JPA 3.2, and so this method is no longer really needed + * @deprecated {@link #addElementSubgraph(PluralAttribute)} was added + * in JPA 3.2, and so this method is no longer needed * * @since 6.3 * * @see #addElementSubgraph(PluralAttribute) */ + @Deprecated(since = "7.0", forRemoval = true) default SubGraph addPluralSubgraph(PluralAttribute attribute) { return addSubGraph( attribute.getName(), attribute.getBindableJavaType() ); } + @Override @Deprecated(forRemoval = true) + default SubGraph addSubgraph(Attribute attribute, Class type) { + return addSubGraph( (PersistentAttribute) attribute ).addTreatedSubgraph( type ); + } + @Override @Deprecated(forRemoval = true) default SubGraph addKeySubgraph(Attribute attribute) { throw new UnsupportedOperationException( "This operation will be removed in JPA 4" ); diff --git a/hibernate-core/src/main/java/org/hibernate/graph/RootGraph.java b/hibernate-core/src/main/java/org/hibernate/graph/RootGraph.java index 5a6c250cbaa7..0685ce7d620f 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/RootGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/RootGraph.java @@ -33,9 +33,4 @@ public interface RootGraph extends Graph, EntityGraph { default SubGraph addSubclassSubgraph(Class type) { return (SubGraph) addTreatedSubgraph( (Class) type ); } - - @Override - default SubGraph addTreatedSubgraph(Class type) { - return addTreatedSubGraph( type ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java index 97783563760a..0d8d2d8b4972 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/AbstractGraph.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +import jakarta.persistence.metamodel.ManagedType; import jakarta.persistence.metamodel.MapAttribute; import jakarta.persistence.metamodel.PluralAttribute; import jakarta.persistence.metamodel.Type; @@ -306,7 +307,7 @@ public SubGraphImplementor addSubGraph(PersistentAttribute SubGraphImplementor addSubGraph(PersistentAttribute attribute, ManagedDomainType subtype) { + public SubGraphImplementor addTreatedSubgraph(PersistentAttribute attribute, ManagedType subtype) { return findOrCreateAttributeNode( attribute ).makeSubGraph( subtype ); } @@ -316,7 +317,7 @@ public SubGraphImplementor addElementSubGraph(PluralPersistentAttribute } @Override - public SubGraphImplementor addElementSubGraph(PluralPersistentAttribute attribute, ManagedDomainType type) { + public SubGraphImplementor addTreatedElementSubgraph(PluralPersistentAttribute attribute, ManagedType type) { return findOrCreateAttributeNode( attribute ).makeSubGraph( type ); } @@ -326,7 +327,7 @@ public SubGraphImplementor addKeySubGraph(MapPersistentAttribute SubGraphImplementor addKeySubGraph(MapPersistentAttribute attribute, ManagedDomainType subtype) { + public SubGraphImplementor addTreatedMapKeySubgraph(MapPersistentAttribute attribute, ManagedType subtype) { return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subtype ); } @@ -350,7 +351,7 @@ public SubGraphImplementor addMapKeySubgraph(MapAttribute SubGraphImplementor addTreatedMapKeySubgraph( MapAttribute attribute, Class type) { - return addMapKeySubgraph( attribute ).addTreatedSubGraph( type ); + return addMapKeySubgraph( attribute ).addTreatedSubgraph( type ); } @Override @SuppressWarnings("unchecked") // The JPA API is unsafe by nature @@ -373,11 +374,16 @@ public SubGraphImplementor addElementSubgraph(String attributeName, Class public SubGraphImplementor addTreatedElementSubgraph( PluralAttribute attribute, Class type) { - return addElementSubgraph( attribute ).addTreatedSubGraph( type ); + return addElementSubgraph( attribute ).addTreatedSubgraph( type ); } @Override - public SubGraphImplementor addTreatedSubGraph(ManagedDomainType type) { + public SubGraphImplementor addTreatedSubgraph(Attribute attribute, Class type) { + return addSubgraph( attribute ).addTreatedSubgraph( type ); + } + + @Override + public SubGraphImplementor addTreatedSubgraph(ManagedType type) { verifyMutability(); if ( getGraphedType().equals( type ) ) { //noinspection unchecked @@ -387,7 +393,7 @@ public SubGraphImplementor addTreatedSubGraph(ManagedDomainType final Class javaType = type.getJavaType(); final SubGraphImplementor castSubgraph = getTreatedSubgraphForPut( javaType ); if ( castSubgraph == null ) { - final SubGraphImpl subgraph = new SubGraphImpl<>( type, true ); + final SubGraphImpl subgraph = new SubGraphImpl<>( (ManagedDomainType) type, true ); treatedSubgraphs.put( javaType, subgraph ); return subgraph; } @@ -398,8 +404,8 @@ public SubGraphImplementor addTreatedSubGraph(ManagedDomainType } @Override - public SubGraphImplementor addTreatedSubGraph(Class type) { - return addTreatedSubGraph( getGraphedType().getMetamodel().managedType( type ) ); + public SubGraphImplementor addTreatedSubgraph(Class type) { + return addTreatedSubgraph( getGraphedType().getMetamodel().managedType( type ) ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java index 334504569f8f..fef40f45ca36 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/AttributeNodeImpl.java @@ -4,6 +4,7 @@ */ package org.hibernate.graph.internal; +import jakarta.persistence.metamodel.ManagedType; import org.hibernate.graph.CannotContainSubGraphException; import org.hibernate.graph.spi.AttributeNodeImplementor; import org.hibernate.graph.spi.SubGraphImplementor; @@ -93,21 +94,21 @@ public SubGraphImplementor makeSubGraph(Class subtype) { } @SuppressWarnings("unchecked") final Class castSuptype = (Class) subtype; - final SubGraphImplementor result = makeSubGraph().addTreatedSubGraph( castSuptype ); + final SubGraphImplementor result = makeSubGraph().addTreatedSubgraph( castSuptype ); //noinspection unchecked return (SubGraphImplementor) result; } @Override - public SubGraphImplementor makeSubGraph(ManagedDomainType subtype) { + public SubGraphImplementor makeSubGraph(ManagedType subtype) { final ManagedDomainType managedType = asManagedType( valueGraphType ); - final Class javaType = subtype.getBindableJavaType(); + final Class javaType = subtype.getJavaType(); if ( !managedType.getBindableJavaType().isAssignableFrom( javaType ) ) { throw new IllegalArgumentException( "Not a subtype: " + javaType.getName() ); } @SuppressWarnings("unchecked") final ManagedDomainType castType = (ManagedDomainType) subtype; - final SubGraphImplementor result = makeSubGraph().addTreatedSubGraph( castType ); + final SubGraphImplementor result = makeSubGraph().addTreatedSubgraph( castType ); //noinspection unchecked return (SubGraphImplementor) result; } @@ -131,22 +132,22 @@ public SubGraphImplementor makeKeySubGraph(Class subtype) { } @SuppressWarnings("unchecked") final Class castType = (Class) subtype; - final SubGraphImplementor result = makeKeySubGraph().addTreatedSubGraph( castType ); + final SubGraphImplementor result = makeKeySubGraph().addTreatedSubgraph( castType ); //noinspection unchecked return (SubGraphImplementor) result; } @Override - public SubGraphImplementor makeKeySubGraph(ManagedDomainType subtype) { + public SubGraphImplementor makeKeySubGraph(ManagedType subtype) { checkMap(); final ManagedDomainType type = asManagedType( keyGraphType ); - final Class javaType = subtype.getBindableJavaType(); + final Class javaType = subtype.getJavaType(); if ( !type.getBindableJavaType().isAssignableFrom( javaType ) ) { throw new IllegalArgumentException( "Not a key subtype: " + javaType.getName() ); } @SuppressWarnings("unchecked") final ManagedDomainType castType = (ManagedDomainType) subtype; - final SubGraphImplementor result = makeKeySubGraph().addTreatedSubGraph( castType ); + final SubGraphImplementor result = makeKeySubGraph().addTreatedSubgraph( castType ); //noinspection unchecked return (SubGraphImplementor) result; } diff --git a/hibernate-core/src/main/java/org/hibernate/graph/spi/AttributeNodeImplementor.java b/hibernate-core/src/main/java/org/hibernate/graph/spi/AttributeNodeImplementor.java index e3119af3db2a..9a1a0966797a 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/spi/AttributeNodeImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/spi/AttributeNodeImplementor.java @@ -4,8 +4,8 @@ */ package org.hibernate.graph.spi; +import jakarta.persistence.metamodel.ManagedType; import org.hibernate.graph.AttributeNode; -import org.hibernate.metamodel.model.domain.ManagedDomainType; import java.util.Map; @@ -34,10 +34,10 @@ public interface AttributeNodeImplementor extends AttributeNode, GraphNode SubGraphImplementor makeKeySubGraph(Class subtype); @Override - SubGraphImplementor makeSubGraph(ManagedDomainType subtype); + SubGraphImplementor makeSubGraph(ManagedType subtype); @Override - SubGraphImplementor makeKeySubGraph(ManagedDomainType subtype); + SubGraphImplementor makeKeySubGraph(ManagedType subtype); void merge(AttributeNodeImplementor other); diff --git a/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphImplementor.java b/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphImplementor.java index d351b874a45e..b1d6be723bb0 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/spi/GraphImplementor.java @@ -7,10 +7,15 @@ import java.util.List; import java.util.Map; +import jakarta.persistence.metamodel.Attribute; +import jakarta.persistence.metamodel.ManagedType; +import jakarta.persistence.metamodel.MapAttribute; +import jakarta.persistence.metamodel.PluralAttribute; +import org.hibernate.Incubating; import org.hibernate.Internal; -import org.hibernate.graph.CannotBecomeEntityGraphException; +import org.hibernate.graph.AttributeNode; import org.hibernate.graph.Graph; -import org.hibernate.metamodel.model.domain.ManagedDomainType; +import org.hibernate.graph.SubGraph; import org.hibernate.metamodel.model.domain.MapPersistentAttribute; import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; @@ -30,11 +35,12 @@ public interface GraphImplementor extends Graph, GraphNodeImplementor { @Internal void mergeInternal(GraphImplementor graph); - @Override @Deprecated(forRemoval = true) - RootGraphImplementor makeRootGraph(String name, boolean mutable) - throws CannotBecomeEntityGraphException; + @Override + @Deprecated(forRemoval = true) + RootGraphImplementor makeRootGraph(String name, boolean mutable); - @Override @Deprecated(forRemoval = true) + @Override + @Deprecated(forRemoval = true) SubGraphImplementor makeSubGraph(boolean mutable); @Override @@ -55,7 +61,6 @@ RootGraphImplementor makeRootGraph(String name, boolean mutable) AttributeNodeImplementor findOrCreateAttributeNode(PersistentAttribute attribute); - @Override AttributeNodeImplementor addAttributeNode(PersistentAttribute attribute); @Override @@ -70,14 +75,13 @@ RootGraphImplementor makeRootGraph(String name, boolean mutable) @Override SubGraphImplementor addSubGraph(PersistentAttribute attribute, Class subtype); - @Override - SubGraphImplementor addSubGraph(PersistentAttribute attribute, ManagedDomainType subtype); + SubGraphImplementor addTreatedSubgraph(PersistentAttribute attribute, ManagedType subtype); - @Override + @Incubating SubGraphImplementor addElementSubGraph(PluralPersistentAttribute attribute, Class type); - @Override - SubGraphImplementor addElementSubGraph(PluralPersistentAttribute attribute, ManagedDomainType type); + @Incubating + SubGraphImplementor addTreatedElementSubgraph(PluralPersistentAttribute attribute, ManagedType type); @Override SubGraphImplementor addKeySubGraph(String attributeName); @@ -88,13 +92,87 @@ RootGraphImplementor makeRootGraph(String name, boolean mutable) @Override SubGraphImplementor addKeySubGraph(MapPersistentAttribute attribute, Class subtype); - @Override - SubGraphImplementor addKeySubGraph(MapPersistentAttribute attribute, ManagedDomainType subtype); + SubGraphImplementor addTreatedMapKeySubgraph(MapPersistentAttribute attribute, ManagedType subtype); @Override - SubGraphImplementor addTreatedSubGraph(Class type); + SubGraphImplementor addTreatedSubgraph(Class type); - SubGraphImplementor addTreatedSubGraph(ManagedDomainType type); + SubGraphImplementor addTreatedSubgraph(ManagedType type); Map, SubGraphImplementor> getSubGraphs(); + + @Override + default AttributeNode getAttributeNode(String attributeName) { + return findAttributeNode( attributeName ); + } + + @Override + default AttributeNode getAttributeNode(Attribute attribute) { + return findAttributeNode( (PersistentAttribute) attribute ); + } + + @Override + default AttributeNode addAttributeNode(Attribute attribute) { + return addAttributeNode( (PersistentAttribute) attribute ); + } + + @Override + default SubGraphImplementor addSubgraph(String attributeName, Class type) { + return addSubGraph( attributeName ).addTreatedSubgraph( type ); + } + + @Override + default SubGraphImplementor addSubgraph(Attribute attribute) { + return addSubGraph( (PersistentAttribute) attribute ); + } + + @Override + default SubGraphImplementor addTreatedSubgraph(Attribute attribute, Class type) { + return addSubGraph( (PersistentAttribute) attribute ).addTreatedSubgraph( type ); + } + + @Override + default SubGraph addTreatedSubgraph(Attribute attribute, ManagedType type) { + return addSubGraph( (PersistentAttribute) attribute ).addTreatedSubgraph( type ); + } + + @Override + default SubGraphImplementor addTreatedElementSubgraph(PluralAttribute attribute, Class type) { + return addElementSubGraph( (PluralPersistentAttribute) attribute, type ); + } + + @Override + default SubGraph addTreatedElementSubgraph(PluralAttribute attribute, ManagedType type) { + return addTreatedElementSubgraph( (PluralPersistentAttribute) attribute, type ); + } + + @Override + default SubGraphImplementor addKeySubgraph(String attributeName) { + return addKeySubGraph( attributeName ); + } + + @Override + default SubGraphImplementor addKeySubgraph(String attributeName, Class type) { + return addKeySubGraph( attributeName ).addTreatedSubgraph( type ); + } + + @Override + default SubGraphImplementor addTreatedMapKeySubgraph(MapAttribute attribute, Class type) { + return addKeySubGraph( (MapPersistentAttribute) attribute, type ); + } + + @Override + default SubGraph addTreatedMapKeySubgraph(MapAttribute attribute, ManagedType type) { + return addTreatedMapKeySubgraph( (MapPersistentAttribute) attribute, type ); + } + + @Override + default boolean hasAttributeNode(String attributeName) { + return getAttributeNode( attributeName ) != null; + } + + @Override + default boolean hasAttributeNode(Attribute attribute) { + return getAttributeNode( attribute ) != null; + } }