Graphpocalypse: deprecated funkily-named methods of Graph

All of these methods now exist in the JPA supertype,
 without the funky naming. We need to guide users away
 from the non-standard ones, especially in light of the
 ugliness.
This commit is contained in:
Gavin King 2025-01-02 21:32:46 +01:00
parent 4251dd8612
commit 5b7673d862
8 changed files with 442 additions and 149 deletions

View File

@ -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<J> extends GraphNode<J>, jakarta.persistence.Attr
/**
* All value subgraphs rooted at this node.
* <p>
* Includes treated subgraphs.
*
* @see jakarta.persistence.AttributeNode#getSubgraphs
*/
@ -58,6 +61,8 @@ public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.Attr
/**
* All key subgraphs rooted at this node.
* <p>
* Includes treated subgraphs.
*
* @see jakarta.persistence.AttributeNode#getKeySubgraphs
*/
@ -89,6 +94,11 @@ public interface AttributeNode<J> extends GraphNode<J>, 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.
* <p>
* 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
*/
<S> SubGraph<S> makeSubGraph(Class<S> subtype);
@ -96,6 +106,11 @@ public interface AttributeNode<J> extends GraphNode<J>, 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.
* <p>
* 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
*/
<S> SubGraph<S> makeKeySubGraph(Class<S> subtype);
@ -103,13 +118,25 @@ public interface AttributeNode<J> extends GraphNode<J>, 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.
* <p>
* 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
*/
<S> SubGraph<S> makeSubGraph(ManagedDomainType<S> subtype);
@Incubating
<S> SubGraph<S> makeSubGraph(ManagedType<S> 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.
* <p>
* 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
*/
<S> SubGraph<S> makeKeySubGraph(ManagedDomainType<S> subtype);
@Incubating
<S> SubGraph<S> makeKeySubGraph(ManagedType<S> subtype);
}

View File

@ -141,7 +141,7 @@ public static <R> void setFetchGraph(TypedQuery<R> query, EntityGraph<R> graph)
* @since 7.0
*/
public <S> Subgraph<S> addTreatedSubgraph(Graph<? super S> graph, Class<S> subtype) {
return ((org.hibernate.graph.Graph<? super S>) graph).addTreatedSubGraph( subtype );
return ((org.hibernate.graph.Graph<? super S>) graph).addTreatedSubgraph( subtype );
}
/**

View File

@ -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.
* <p>
* Extends the JPA-defined {@link jakarta.persistence.Graph} with additional operations.
*
@ -99,57 +99,45 @@ RootGraph<J> makeRootGraph(String name, boolean mutable)
List<? extends AttributeNode<?>> getAttributeNodeList();
/**
* Find an already existing AttributeNode by attributeName within
* this container
*
* @see #getAttributeNode(String)
* Find an existing {@link AttributeNode} by name within this container.
*/
@Override
<Y> AttributeNode<Y> getAttributeNode(String attributeName);
/**
* Find an existing {@link AttributeNode} by corresponding attribute
* reference, within this container.
*/
@Override
<Y> AttributeNode<Y> getAttributeNode(Attribute<? super J, Y> attribute);
/**
* Find an existing {@link AttributeNode} by name within this container.
*
* @deprecated Use {@link #getAttributeNode(String)}
*/
@Deprecated(since = "7.0")
<AJ> AttributeNode<AJ> findAttributeNode(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)
* @deprecated Use {@link #getAttributeNode(Attribute)}
*/
@Deprecated(since = "7.0")
<AJ> AttributeNode<AJ> findAttributeNode(PersistentAttribute<? super J, AJ> attribute);
@Override
default <Y> AttributeNode<Y> getAttributeNode(String attributeName) {
return findAttributeNode( attributeName );
}
@Override
default <Y> AttributeNode<Y> getAttributeNode(Attribute<? super J, Y> attribute) {
return findAttributeNode( (PersistentAttribute<? super J, Y>) attribute );
}
@Override
default boolean hasAttributeNode(String attributeName) {
return getAttributeNode( attributeName ) != null;
}
@Override
default boolean hasAttributeNode(Attribute<? super J, ?> attribute) {
return getAttributeNode( attribute ) != null;
}
/**
* Add an {@link AttributeNode} representing the given {@link PersistentAttribute}
* to this node of the graph without creating any associated {@link SubGraph}.
*
* @see #addAttributeNode(Attribute)
* Add an {@link AttributeNode} representing the given {@link Attribute} to
* this node of the graph without creating any associated {@link SubGraph}.
*/
<AJ> AttributeNode<AJ> addAttributeNode(PersistentAttribute<? super J,AJ> attribute);
@Override
default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute) {
return addAttributeNode( (PersistentAttribute<? super J,Y>) attribute );
}
<Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Subgraphs
// Treated subgraphs
/**
* Create and return a new (mutable) {@link SubGraph} representing
@ -158,23 +146,57 @@ default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute)
*
* @see jakarta.persistence.EntityGraph#addTreatedSubgraph(Class)
*/
<Y extends J> SubGraph<Y> addTreatedSubGraph(Class<Y> type);
<Y extends J> SubGraph<Y> addTreatedSubgraph(Class<Y> 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.
*/
<Y extends J> SubGraph<Y> addTreatedSubGraph(ManagedDomainType<Y> type);
@Incubating
<Y extends J> SubGraph<Y> addTreatedSubgraph(ManagedType<Y> 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.
*
* @see #addSubgraph(String)
* @param attributeName The name of an attribute of the represented type
*/
@Deprecated
@Override
default <X> SubGraph<X> 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.
* <p>
* 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
<X> SubGraph<X> addSubgraph(String attributeName, Class<X> 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.
*
* @param attributeName The name of an attribute of the represented type
*
* @deprecated Use {@link #addSubgraph(String)}
*/
@Deprecated(since = "7.0")
<AJ> SubGraph<AJ> addSubGraph(String attributeName)
throws CannotContainSubGraphException;
@ -183,19 +205,78 @@ <AJ> SubGraph<AJ> 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.
* <p>
* If the given type is a proper subtype of the attribute type, the
* result is a treated subgraph.
*
* @see #addSubgraph(String, Class)
* @param attributeName The name of an attribute of the represented type
* @param type A subtype of the attribute type
*
* @deprecated Use {@link #addSubgraph(String, Class)}
*/
@Deprecated(since = "7.0")
<AJ> SubGraph<AJ> addSubGraph(String attributeName, Class<AJ> type)
throws CannotContainSubGraphException;
/**
* Create and return a new (mutable) {@link SubGraph} associated with
* the given {@link PersistentAttribute}, or return an existing such
* {@link SubGraph} if there is one.
* 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
<X> SubGraph<X> addSubgraph(Attribute<? super J, X> 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.
* <p>
* 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
<Y> SubGraph<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> 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.
* <p>
* 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
<AJ> SubGraph<AJ> addTreatedSubgraph(Attribute<? super J, ? super AJ> attribute, ManagedType<AJ> 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")
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, AJ> attribute)
throws CannotContainSubGraphException;
@ -204,30 +285,76 @@ <AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, AJ> 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.
* <p>
* 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")
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> type)
throws CannotContainSubGraphException;
/**
* 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
* such {@link SubGraph} if there is one.
*/
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedDomainType<AJ> type)
throws CannotContainSubGraphException;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Element subgraphs
/**
* 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
* 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
<X> SubGraph<X> 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.
* <p>
* 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
*/
@Override
<X> SubGraph<X> addElementSubgraph(String attributeName, Class<X> 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.
*
* @see #addTreatedElementSubgraph(PluralAttribute, Class)
* @param attribute A collection-valued attribute of the represented type
*/
<AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, Class<AJ> type)
@Override
<E> SubGraph<E> addElementSubgraph(PluralAttribute<? super J, ?, E> 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 element type, or return an existing such
* {@link SubGraph} if there is one.
* <p>
* 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
*/
@Override
<E> SubGraph<E> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super E> attribute, Class<E> type)
throws CannotContainSubGraphException;
/**
@ -235,18 +362,54 @@ <AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? s
* 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
* {@link SubGraph} if there is one.
* <p>
* 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
*/
<AJ> SubGraph<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedDomainType<AJ> type)
@Incubating
<AJ> SubGraph<AJ> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super AJ> attribute, ManagedType<AJ> 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.
*
* @see #addKeySubgraph(String)
* @param attributeName The name of an attribute of the represented type
*/
@Deprecated
@Override
<X> SubGraph<X> 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
<X> SubGraph<X> addKeySubgraph(String attributeName, Class<X> 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.
*
* @param attributeName The name of an attribute of the represented type
*
* @deprecated Use {@link #addKeySubgraph(String)}
*/
@Deprecated(since = "7.0")
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName)
throws CannotContainSubGraphException;
@ -255,21 +418,59 @@ <AJ> SubGraph<AJ> 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.
* <p>
* If the given type is a proper subtype of the key type, the result
* is a treated subgraph.
*
* @see #addKeySubgraph(String, Class)
* @param attributeName The name of a map-valued attribute of the
* represented type
* @param type A subtype of the key type
*
* @deprecated Use {@link #addKeySubgraph(String, Class)}
*/
@Deprecated(since = "7.0")
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> 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
<K> SubGraph<K> addMapKeySubgraph(MapAttribute<? super J, K, ?> 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.
* <p>
* 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
*/
<AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, Class<AJ> type)
@Override
<K> SubGraph<K> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super K, ?> attribute, Class<K> 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.
* <p>
* 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
*/
@Incubating
<AJ> SubGraph<AJ> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super AJ, ?> attribute, ManagedType<AJ> type)
throws CannotContainSubGraphException;
/**
@ -277,60 +478,45 @@ <AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?
* 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.
* <p>
* 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)}
*/
<AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedDomainType<AJ> type)
@Deprecated(since = "7.0")
<AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, Class<AJ> type)
throws CannotContainSubGraphException;
@Override
default <Y> SubGraph<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> type) {
return addSubGraph( (PersistentAttribute<? super J, ? super Y>) attribute ).addTreatedSubGraph( type );
}
@Override
default <X> SubGraph<X> addSubgraph(Attribute<? super J, X> attribute) {
return addSubGraph( (PersistentAttribute<? super J, X>) attribute );
}
@Override
default <X> SubGraph<? extends X> addSubgraph(Attribute<? super J, X> attribute, Class<? extends X> type) {
return addSubGraph( (PersistentAttribute<? super J, X>) attribute ).addTreatedSubGraph( type );
}
@Override
default <X> SubGraph<X> addSubgraph(String name) {
return addSubGraph( name );
}
@Override
default <X> SubGraph<X> addSubgraph(String name, Class<X> type) {
return addSubGraph( name ).addTreatedSubGraph( type );
}
@Override
default <X> SubGraph<X> addKeySubgraph(String name) {
return addKeySubGraph( name );
}
@Override
default <X> SubGraph<X> addKeySubgraph(String name, Class<X> 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 <AJ> SubGraph<AJ> addPluralSubgraph(PluralAttribute<? super J, ?, AJ> attribute) {
return addSubGraph( attribute.getName(), attribute.getBindableJavaType() );
}
@Override @Deprecated(forRemoval = true)
default <X> SubGraph<? extends X> addSubgraph(Attribute<? super J, X> attribute, Class<? extends X> type) {
return addSubGraph( (PersistentAttribute<? super J, X>) attribute ).addTreatedSubgraph( type );
}
@Override @Deprecated(forRemoval = true)
default <X> SubGraph<X> addKeySubgraph(Attribute<? super J, X> attribute) {
throw new UnsupportedOperationException( "This operation will be removed in JPA 4" );

View File

@ -33,9 +33,4 @@ public interface RootGraph<J> extends Graph<J>, EntityGraph<J> {
default <T> SubGraph<? extends T> addSubclassSubgraph(Class<? extends T> type) {
return (SubGraph<? extends T>) addTreatedSubgraph( (Class<? extends J>) type );
}
@Override
default <S extends J> SubGraph<S> addTreatedSubgraph(Class<S> type) {
return addTreatedSubGraph( type );
}
}

View File

@ -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 <AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttribute<? super J, ?
}
@Override
public <AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedDomainType<AJ> subtype) {
public <AJ> SubGraphImplementor<AJ> addTreatedSubgraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedType<AJ> subtype) {
return findOrCreateAttributeNode( attribute ).makeSubGraph( subtype );
}
@ -316,7 +317,7 @@ public <AJ> SubGraphImplementor<AJ> addElementSubGraph(PluralPersistentAttribute
}
@Override
public <AJ> SubGraphImplementor<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedDomainType<AJ> type) {
public <AJ> SubGraphImplementor<AJ> addTreatedElementSubgraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedType<AJ> type) {
return findOrCreateAttributeNode( attribute ).makeSubGraph( type );
}
@ -326,7 +327,7 @@ public <AJ> SubGraphImplementor<AJ> addKeySubGraph(MapPersistentAttribute<? supe
}
@Override
public <AJ> SubGraphImplementor<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedDomainType<AJ> subtype) {
public <AJ> SubGraphImplementor<AJ> addTreatedMapKeySubgraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedType<AJ> subtype) {
return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subtype );
}
@ -350,7 +351,7 @@ public <K> SubGraphImplementor<K> addMapKeySubgraph(MapAttribute<? super J, K, ?
public <K> SubGraphImplementor<K> addTreatedMapKeySubgraph(
MapAttribute<? super J, ? super K, ?> attribute,
Class<K> 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 <X> SubGraphImplementor<X> addElementSubgraph(String attributeName, Class
public <E> SubGraphImplementor<E> addTreatedElementSubgraph(
PluralAttribute<? super J, ?, ? super E> attribute,
Class<E> type) {
return addElementSubgraph( attribute ).addTreatedSubGraph( type );
return addElementSubgraph( attribute ).addTreatedSubgraph( type );
}
@Override
public <S extends J> SubGraphImplementor<S> addTreatedSubGraph(ManagedDomainType<S> type) {
public <Y> SubGraphImplementor<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> type) {
return addSubgraph( attribute ).addTreatedSubgraph( type );
}
@Override
public <S extends J> SubGraphImplementor<S> addTreatedSubgraph(ManagedType<S> type) {
verifyMutability();
if ( getGraphedType().equals( type ) ) {
//noinspection unchecked
@ -387,7 +393,7 @@ public <S extends J> SubGraphImplementor<S> addTreatedSubGraph(ManagedDomainType
final Class<S> javaType = type.getJavaType();
final SubGraphImplementor<S> castSubgraph = getTreatedSubgraphForPut( javaType );
if ( castSubgraph == null ) {
final SubGraphImpl<S> subgraph = new SubGraphImpl<>( type, true );
final SubGraphImpl<S> subgraph = new SubGraphImpl<>( (ManagedDomainType<S>) type, true );
treatedSubgraphs.put( javaType, subgraph );
return subgraph;
}
@ -398,8 +404,8 @@ public <S extends J> SubGraphImplementor<S> addTreatedSubGraph(ManagedDomainType
}
@Override
public <S extends J> SubGraphImplementor<S> addTreatedSubGraph(Class<S> type) {
return addTreatedSubGraph( getGraphedType().getMetamodel().managedType( type ) );
public <S extends J> SubGraphImplementor<S> addTreatedSubgraph(Class<S> type) {
return addTreatedSubgraph( getGraphedType().getMetamodel().managedType( type ) );
}
@Override

View File

@ -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 <S> SubGraphImplementor<S> makeSubGraph(Class<S> subtype) {
}
@SuppressWarnings("unchecked")
final Class<? extends V> castSuptype = (Class<? extends V>) subtype;
final SubGraphImplementor<? extends V> result = makeSubGraph().addTreatedSubGraph( castSuptype );
final SubGraphImplementor<? extends V> result = makeSubGraph().addTreatedSubgraph( castSuptype );
//noinspection unchecked
return (SubGraphImplementor<S>) result;
}
@Override
public <S> SubGraphImplementor<S> makeSubGraph(ManagedDomainType<S> subtype) {
public <S> SubGraphImplementor<S> makeSubGraph(ManagedType<S> subtype) {
final ManagedDomainType<V> managedType = asManagedType( valueGraphType );
final Class<S> javaType = subtype.getBindableJavaType();
final Class<S> javaType = subtype.getJavaType();
if ( !managedType.getBindableJavaType().isAssignableFrom( javaType ) ) {
throw new IllegalArgumentException( "Not a subtype: " + javaType.getName() );
}
@SuppressWarnings("unchecked")
final ManagedDomainType<? extends V> castType = (ManagedDomainType<? extends V>) subtype;
final SubGraphImplementor<? extends V> result = makeSubGraph().addTreatedSubGraph( castType );
final SubGraphImplementor<? extends V> result = makeSubGraph().addTreatedSubgraph( castType );
//noinspection unchecked
return (SubGraphImplementor<S>) result;
}
@ -131,22 +132,22 @@ public <S> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype) {
}
@SuppressWarnings("unchecked")
final Class<? extends K> castType = (Class<? extends K>) subtype;
final SubGraphImplementor<? extends K> result = makeKeySubGraph().addTreatedSubGraph( castType );
final SubGraphImplementor<? extends K> result = makeKeySubGraph().addTreatedSubgraph( castType );
//noinspection unchecked
return (SubGraphImplementor<S>) result;
}
@Override
public <S> SubGraphImplementor<S> makeKeySubGraph(ManagedDomainType<S> subtype) {
public <S> SubGraphImplementor<S> makeKeySubGraph(ManagedType<S> subtype) {
checkMap();
final ManagedDomainType<K> type = asManagedType( keyGraphType );
final Class<S> javaType = subtype.getBindableJavaType();
final Class<S> javaType = subtype.getJavaType();
if ( !type.getBindableJavaType().isAssignableFrom( javaType ) ) {
throw new IllegalArgumentException( "Not a key subtype: " + javaType.getName() );
}
@SuppressWarnings("unchecked")
final ManagedDomainType<? extends K> castType = (ManagedDomainType<? extends K>) subtype;
final SubGraphImplementor<? extends K> result = makeKeySubGraph().addTreatedSubGraph( castType );
final SubGraphImplementor<? extends K> result = makeKeySubGraph().addTreatedSubgraph( castType );
//noinspection unchecked
return (SubGraphImplementor<S>) result;
}

View File

@ -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<J> extends AttributeNode<J>, GraphNode
<S> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype);
@Override
<S> SubGraphImplementor<S> makeSubGraph(ManagedDomainType<S> subtype);
<S> SubGraphImplementor<S> makeSubGraph(ManagedType<S> subtype);
@Override
<S> SubGraphImplementor<S> makeKeySubGraph(ManagedDomainType<S> subtype);
<S> SubGraphImplementor<S> makeKeySubGraph(ManagedType<S> subtype);
void merge(AttributeNodeImplementor<J> other);

View File

@ -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<J> extends Graph<J>, GraphNodeImplementor<J> {
@Internal
void mergeInternal(GraphImplementor<J> graph);
@Override @Deprecated(forRemoval = true)
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable)
throws CannotBecomeEntityGraphException;
@Override
@Deprecated(forRemoval = true)
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable);
@Override @Deprecated(forRemoval = true)
@Override
@Deprecated(forRemoval = true)
SubGraphImplementor<J> makeSubGraph(boolean mutable);
@Override
@ -55,7 +61,6 @@ RootGraphImplementor<J> makeRootGraph(String name, boolean mutable)
<AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? super J, AJ> attribute);
@Override
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? super J, AJ> attribute);
@Override
@ -70,14 +75,13 @@ RootGraphImplementor<J> makeRootGraph(String name, boolean mutable)
@Override
<AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> subtype);
@Override
<AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedDomainType<AJ> subtype);
<AJ> SubGraphImplementor<AJ> addTreatedSubgraph(PersistentAttribute<? super J, ? super AJ> attribute, ManagedType<AJ> subtype);
@Override
@Incubating
<AJ> SubGraphImplementor<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, Class<AJ> type);
@Override
<AJ> SubGraphImplementor<AJ> addElementSubGraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedDomainType<AJ> type);
@Incubating
<AJ> SubGraphImplementor<AJ> addTreatedElementSubgraph(PluralPersistentAttribute<? super J, ?, ? super AJ> attribute, ManagedType<AJ> type);
@Override
<AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName);
@ -88,13 +92,87 @@ RootGraphImplementor<J> makeRootGraph(String name, boolean mutable)
@Override
<AJ> SubGraphImplementor<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, Class<AJ> subtype);
@Override
<AJ> SubGraphImplementor<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedDomainType<AJ> subtype);
<AJ> SubGraphImplementor<AJ> addTreatedMapKeySubgraph(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, ManagedType<AJ> subtype);
@Override
<Y extends J> SubGraphImplementor<Y> addTreatedSubGraph(Class<Y> type);
<Y extends J> SubGraphImplementor<Y> addTreatedSubgraph(Class<Y> type);
<Y extends J> SubGraphImplementor<Y> addTreatedSubGraph(ManagedDomainType<Y> type);
<Y extends J> SubGraphImplementor<Y> addTreatedSubgraph(ManagedType<Y> type);
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getSubGraphs();
@Override
default <Y> AttributeNode<Y> getAttributeNode(String attributeName) {
return findAttributeNode( attributeName );
}
@Override
default <Y> AttributeNode<Y> getAttributeNode(Attribute<? super J, Y> attribute) {
return findAttributeNode( (PersistentAttribute<? super J, Y>) attribute );
}
@Override
default <Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute) {
return addAttributeNode( (PersistentAttribute<? super J, Y>) attribute );
}
@Override
default <X> SubGraphImplementor<X> addSubgraph(String attributeName, Class<X> type) {
return addSubGraph( attributeName ).addTreatedSubgraph( type );
}
@Override
default <X> SubGraphImplementor<X> addSubgraph(Attribute<? super J, X> attribute) {
return addSubGraph( (PersistentAttribute<? super J, X>) attribute );
}
@Override
default <Y> SubGraphImplementor<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> type) {
return addSubGraph( (PersistentAttribute<? super J, ? super Y>) attribute ).addTreatedSubgraph( type );
}
@Override
default <AJ> SubGraph<AJ> addTreatedSubgraph(Attribute<? super J, ? super AJ> attribute, ManagedType<AJ> type) {
return addSubGraph( (PersistentAttribute<? super J, ? super AJ>) attribute ).addTreatedSubgraph( type );
}
@Override
default <E> SubGraphImplementor<E> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super E> attribute, Class<E> type) {
return addElementSubGraph( (PluralPersistentAttribute<? super J, ?, ? super E>) attribute, type );
}
@Override
default <AJ> SubGraph<AJ> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super AJ> attribute, ManagedType<AJ> type) {
return addTreatedElementSubgraph( (PluralPersistentAttribute<? super J, ?, ? super AJ>) attribute, type );
}
@Override
default <X> SubGraphImplementor<X> addKeySubgraph(String attributeName) {
return addKeySubGraph( attributeName );
}
@Override
default <X> SubGraphImplementor<X> addKeySubgraph(String attributeName, Class<X> type) {
return addKeySubGraph( attributeName ).addTreatedSubgraph( type );
}
@Override
default <K> SubGraphImplementor<K> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super K, ?> attribute, Class<K> type) {
return addKeySubGraph( (MapPersistentAttribute<? super J, ? super K, ?>) attribute, type );
}
@Override
default <AJ> SubGraph<AJ> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super AJ, ?> attribute, ManagedType<AJ> type) {
return addTreatedMapKeySubgraph( (MapPersistentAttribute<? super J, ? super AJ, ?>) attribute, type );
}
@Override
default boolean hasAttributeNode(String attributeName) {
return getAttributeNode( attributeName ) != null;
}
@Override
default boolean hasAttributeNode(Attribute<? super J, ?> attribute) {
return getAttributeNode( attribute ) != null;
}
}