clean up lots of warnings in org.hibernate.graph
This commit is contained in:
parent
bc901f5162
commit
1e05e8444e
|
@ -12,26 +12,27 @@ import jakarta.persistence.Subgraph;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate extension to the JPA entity-graph AttributeNode contract.
|
* Extends the JPA-defined {@link AttributeNode} with additional operations.
|
||||||
*
|
*
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.AttributeNode<J> {
|
public interface AttributeNode<J> extends GraphNode<J>, jakarta.persistence.AttributeNode<J> {
|
||||||
|
|
||||||
PersistentAttribute<?, J> getAttributeDescriptor();
|
PersistentAttribute<?, J> getAttributeDescriptor();
|
||||||
|
|
||||||
Map<Class<? extends J>, SubGraph<? extends J>> getSubGraphs();
|
Map<Class<? extends J>, SubGraph<? extends J>> getSubGraphs();
|
||||||
Map<Class<? extends J>, SubGraph<? extends J>> getKeySubGraphs();
|
Map<Class<? extends J>, SubGraph<? extends J>> getKeySubGraphs();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
default Map<Class, Subgraph> getSubgraphs() {
|
default Map<Class, Subgraph> getSubgraphs() {
|
||||||
return (Map) getSubGraphs();
|
return (Map) getSubGraphs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
default Map<Class, Subgraph> getKeySubgraphs() {
|
default Map<Class, Subgraph> getKeySubgraphs() {
|
||||||
return (Map) getKeySubGraphs();
|
return (Map) getKeySubGraphs();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,19 +14,26 @@ import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A container for {@link AttributeNode} references.
|
* A container for {@link AttributeNode} references.
|
||||||
* <p>
|
*
|
||||||
* Acts as a "bridge" between JPA's {@link jakarta.persistence.EntityGraph}
|
* @apiNote Acts as an abstraction over the JPA-defined interfaces
|
||||||
* and {@link jakarta.persistence.Subgraph}.
|
* {@link jakarta.persistence.EntityGraph} and
|
||||||
|
* {@link jakarta.persistence.Subgraph}, which have no
|
||||||
|
* common supertype.
|
||||||
*
|
*
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
|
*
|
||||||
|
* @see RootGraph
|
||||||
|
* @see SubGraph
|
||||||
|
* @see jakarta.persistence.EntityGraph
|
||||||
|
* @see jakarta.persistence.Subgraph
|
||||||
*/
|
*/
|
||||||
public interface Graph<J> extends GraphNode<J> {
|
public interface Graph<J> extends GraphNode<J> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a subgraph rooted at a plural attribute, allowing
|
* Add a subgraph rooted at a plural attribute, allowing further
|
||||||
* further nodes to be added to the subgraph.
|
* nodes to be added to the subgraph.
|
||||||
*
|
*
|
||||||
* @apiNote This method is missing in JPA, and nodes cannot be
|
* @apiNote This method is missing in JPA, and nodes cannot be
|
||||||
* added in a typesafe way to subgraphs representing
|
* added in a typesafe way to subgraphs representing
|
||||||
|
@ -52,10 +59,12 @@ public interface Graph<J> extends GraphNode<J> {
|
||||||
*
|
*
|
||||||
* @throws CannotBecomeEntityGraphException If the named attribute is not entity-valued
|
* @throws CannotBecomeEntityGraphException If the named attribute is not entity-valued
|
||||||
*/
|
*/
|
||||||
RootGraph<J> makeRootGraph(String name, boolean mutable) throws CannotBecomeEntityGraphException;
|
RootGraph<J> makeRootGraph(String name, boolean mutable)
|
||||||
|
throws CannotBecomeEntityGraphException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a (mutable or immutable) {@link SubGraph} rooted at this {@link Graph}.
|
* Create a new (mutable or immutable) {@link SubGraph} rooted at
|
||||||
|
* this {@link Graph}.
|
||||||
*/
|
*/
|
||||||
SubGraph<J> makeSubGraph(boolean mutable);
|
SubGraph<J> makeSubGraph(boolean mutable);
|
||||||
|
|
||||||
|
@ -67,37 +76,38 @@ public interface Graph<J> extends GraphNode<J> {
|
||||||
// AttributeNode handling
|
// AttributeNode handling
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ultimately only needed for implementing {@link jakarta.persistence.EntityGraph#getAttributeNodes()}
|
* Ultimately only needed for implementing
|
||||||
|
* {@link jakarta.persistence.EntityGraph#getAttributeNodes()}
|
||||||
* and {@link jakarta.persistence.Subgraph#getAttributeNodes()}
|
* and {@link jakarta.persistence.Subgraph#getAttributeNodes()}
|
||||||
*/
|
*/
|
||||||
List<AttributeNode<?>> getGraphAttributeNodes();
|
List<AttributeNode<?>> getGraphAttributeNodes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find an already existing AttributeNode by attributeName within this
|
* Find an already existing AttributeNode by attributeName within
|
||||||
* container
|
* this container
|
||||||
*/
|
*/
|
||||||
<AJ> AttributeNode<AJ> findAttributeNode(String attributeName);
|
<AJ> AttributeNode<AJ> findAttributeNode(String attributeName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find an already existing AttributeNode by corresponding attribute
|
* Find an already existing AttributeNode by corresponding attribute
|
||||||
* reference, within this container
|
* reference, within this container.
|
||||||
*/
|
*/
|
||||||
<AJ> AttributeNode<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
<AJ> AttributeNode<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all existing AttributeNodes within this container
|
* Get a list of all existing AttributeNodes within this container.
|
||||||
*/
|
*/
|
||||||
List<AttributeNode<?>> getAttributeNodeList();
|
List<AttributeNode<?>> getAttributeNodeList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an AttributeNode (with no associated SubGraphNodes) to this container
|
* Add an {@link AttributeNode} (with no associated {@link SubGraph})
|
||||||
* by attribute name
|
* to this container by attribute name.
|
||||||
*/
|
*/
|
||||||
<AJ> AttributeNode<AJ> addAttributeNode(String attributeName);
|
<AJ> AttributeNode<AJ> addAttributeNode(String attributeName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an AttributeNode (with no associated SubGraphNode) to this container
|
* Add an {@link AttributeNode} (with no associated {@link SubGraph})
|
||||||
* by Attribute reference
|
* to this container by attribute reference.
|
||||||
*/
|
*/
|
||||||
<AJ> AttributeNode<AJ> addAttributeNode(PersistentAttribute<? extends J,AJ> attribute);
|
<AJ> AttributeNode<AJ> addAttributeNode(PersistentAttribute<? extends J,AJ> attribute);
|
||||||
|
|
||||||
|
@ -107,31 +117,39 @@ public interface Graph<J> extends GraphNode<J> {
|
||||||
// sub graph nodes
|
// sub graph nodes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a (mutable) SubGraphNode associated with the named AttributeNode.
|
* Create and return a new (mutable) {@link SubGraph} associated with
|
||||||
* The created SubGraphNode is returned
|
* the named {@link AttributeNode}.
|
||||||
*
|
*
|
||||||
* @apiNote If no such AttributeNode exists yet, it is created.
|
* @apiNote If no such AttributeNode exists yet, it is created.
|
||||||
*/
|
*/
|
||||||
<AJ> SubGraph<AJ> addSubGraph(String attributeName) throws CannotContainSubGraphException;
|
<AJ> SubGraph<AJ> addSubGraph(String attributeName)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
|
|
||||||
<AJ> SubGraph<AJ> addSubGraph(String attributeName, Class<AJ> type) throws CannotContainSubGraphException;
|
<AJ> SubGraph<AJ> addSubGraph(String attributeName, Class<AJ> type)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a (mutable) SubGraphNode associated with the AttributeNode for the given
|
* Create and return a new (mutable) {@link SubGraph} associated with
|
||||||
* Attribute. The created SubGraphNode is returned
|
* the {@link AttributeNode} for the given attribute.
|
||||||
*
|
*
|
||||||
* @apiNote If no such AttributeNode exists yet, it is created.
|
* @apiNote If no such AttributeNode exists yet, it is created.
|
||||||
*/
|
*/
|
||||||
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute) throws CannotContainSubGraphException;
|
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
|
|
||||||
<AJ> SubGraph<? extends AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute, Class<? extends AJ> type) throws CannotContainSubGraphException;
|
<AJ> SubGraph<? extends AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute, Class<? extends AJ> type)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// key sub graph nodes
|
// key sub graph nodes
|
||||||
|
|
||||||
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName) throws CannotContainSubGraphException;
|
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName)
|
||||||
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type) throws CannotContainSubGraphException;
|
throws CannotContainSubGraphException;
|
||||||
|
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
|
|
||||||
<AJ> SubGraph<AJ> addKeySubGraph(PersistentAttribute<? extends J,AJ> attribute) throws CannotContainSubGraphException;
|
<AJ> SubGraph<AJ> addKeySubGraph(PersistentAttribute<? extends J,AJ> attribute)
|
||||||
<AJ> SubGraph<? extends AJ> addKeySubGraph(PersistentAttribute<? extends J,AJ> attribute, Class<? extends AJ> type) throws CannotContainSubGraphException;
|
throws CannotContainSubGraphException;
|
||||||
|
<AJ> SubGraph<? extends AJ> addKeySubGraph(PersistentAttribute<? extends J,AJ> attribute, Class<? extends AJ> type)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,12 @@
|
||||||
package org.hibernate.graph;
|
package org.hibernate.graph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commonality between {@link AttributeNode} and {@link Graph}.
|
* Common operations of {@link AttributeNode} and {@link Graph}.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
*
|
||||||
|
* @see AttributeNode
|
||||||
|
* @see Graph
|
||||||
*/
|
*/
|
||||||
public interface GraphNode<J> {
|
public interface GraphNode<J> {
|
||||||
boolean isMutable();
|
boolean isMutable();
|
||||||
|
|
|
@ -15,18 +15,18 @@ import jakarta.persistence.metamodel.Attribute;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate extension to the JPA {@link EntityGraph} contract.
|
* Extends the JPA-defined {@link EntityGraph} with additional operations.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
|
*
|
||||||
|
* @see SubGraph
|
||||||
*/
|
*/
|
||||||
public interface RootGraph<J> extends Graph<J>, EntityGraph<J> {
|
public interface RootGraph<J> extends Graph<J>, EntityGraph<J> {
|
||||||
|
|
||||||
// todo (6.0) : do we want to consolidate this functionality on AttributeNodeContainer?
|
// boolean appliesTo(String entityName);
|
||||||
|
//
|
||||||
boolean appliesTo(String entityName);
|
// boolean appliesTo(Class<?> entityType);
|
||||||
|
|
||||||
boolean appliesTo(Class entityType);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
RootGraph<J> makeRootGraph(String name, boolean mutable);
|
RootGraph<J> makeRootGraph(String name, boolean mutable);
|
||||||
|
@ -37,44 +37,38 @@ public interface RootGraph<J> extends Graph<J>, EntityGraph<J> {
|
||||||
<T1> SubGraph<? extends T1> addSubclassSubgraph(Class<? extends T1> type);
|
<T1> SubGraph<? extends T1> addSubclassSubgraph(Class<? extends T1> type);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
default List<AttributeNode<?>> getAttributeNodes() {
|
default List<AttributeNode<?>> getAttributeNodes() {
|
||||||
return (List) getAttributeNodeList();
|
return (List) getAttributeNodeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void addAttributeNodes(String... names) {
|
default void addAttributeNodes(String... names) {
|
||||||
if ( names == null ) {
|
if ( names != null ) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( String name : names ) {
|
for ( String name : names ) {
|
||||||
addAttributeNode( name );
|
addAttributeNode( name );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default void addAttributeNodes(Attribute<J, ?>... attributes) {
|
default void addAttributeNodes(Attribute<J, ?>... attributes) {
|
||||||
if ( attributes == null ) {
|
if ( attributes != null ) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Attribute<J, ?> attribute : attributes ) {
|
for ( Attribute<J, ?> attribute : attributes ) {
|
||||||
addAttributeNode( (PersistentAttribute) attribute );
|
addAttributeNode( (PersistentAttribute<J,?>) attribute );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default <X> SubGraph<X> addSubgraph(Attribute<J, X> attribute) {
|
default <X> SubGraph<X> addSubgraph(Attribute<J, X> attribute) {
|
||||||
//noinspection unchecked
|
return addSubGraph( (PersistentAttribute<J,X>) attribute );
|
||||||
return addSubGraph( (PersistentAttribute) attribute );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default <X> SubGraph<? extends X> addSubgraph(Attribute<J, X> attribute, Class<? extends X> type) {
|
default <X> SubGraph<? extends X> addSubgraph(Attribute<J, X> attribute, Class<? extends X> type) {
|
||||||
//noinspection unchecked
|
return addSubGraph( (PersistentAttribute<J,X>) attribute, type );
|
||||||
return addSubGraph( (PersistentAttribute) attribute, type );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,14 +83,12 @@ public interface RootGraph<J> extends Graph<J>, EntityGraph<J> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default <X> SubGraph<X> addKeySubgraph(Attribute<J, X> attribute) {
|
default <X> SubGraph<X> addKeySubgraph(Attribute<J, X> attribute) {
|
||||||
//noinspection unchecked
|
return addKeySubGraph( (PersistentAttribute<J,X>) attribute );
|
||||||
return addKeySubGraph( (PersistentAttribute) attribute );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default <X> SubGraph<? extends X> addKeySubgraph(Attribute<J, X> attribute, Class<? extends X> type) {
|
default <X> SubGraph<? extends X> addKeySubgraph(Attribute<J, X> attribute, Class<? extends X> type) {
|
||||||
//noinspection unchecked
|
return addKeySubGraph( (PersistentAttribute<J,X>) attribute, type );
|
||||||
return addKeySubGraph( (PersistentAttribute) attribute, type );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,19 +7,23 @@
|
||||||
package org.hibernate.graph;
|
package org.hibernate.graph;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jakarta.persistence.Subgraph;
|
||||||
import jakarta.persistence.metamodel.Attribute;
|
import jakarta.persistence.metamodel.Attribute;
|
||||||
|
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate extension to the JPA entity-graph Subgraph contract.
|
* Extends the JPA-defined {@link Subgraph} with additional operations.
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
|
*
|
||||||
|
* @see RootGraph
|
||||||
*/
|
*/
|
||||||
public interface SubGraph<J> extends Graph<J>, jakarta.persistence.Subgraph<J> {
|
public interface SubGraph<J> extends Graph<J>, Subgraph<J> {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
default List<jakarta.persistence.AttributeNode<?>> getAttributeNodes() {
|
default List<jakarta.persistence.AttributeNode<?>> getAttributeNodes() {
|
||||||
return (List) getAttributeNodeList();
|
return (List) getAttributeNodeList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
package org.hibernate.graph.internal;
|
package org.hibernate.graph.internal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -26,6 +25,8 @@ import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for {@link RootGraph} and {@link SubGraph} implementations.
|
* Base class for {@link RootGraph} and {@link SubGraph} implementations.
|
||||||
*
|
*
|
||||||
|
@ -66,10 +67,9 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
|
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
|
||||||
if ( getGraphedType() instanceof EntityDomainType ) {
|
if ( getGraphedType() instanceof EntityDomainType ) {
|
||||||
return new RootGraphImpl( name, mutable, this );
|
return new RootGraphImpl<>( name, mutable, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CannotBecomeEntityGraphException(
|
throw new CannotBecomeEntityGraphException(
|
||||||
|
@ -79,15 +79,14 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void merge(GraphImplementor<J>... others) {
|
public void merge(GraphImplementor<? extends J> other) {
|
||||||
if ( others == null ) {
|
if ( other == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( GraphImplementor<J> other : others ) {
|
|
||||||
for ( AttributeNodeImplementor<?> attributeNode : other.getAttributeNodeImplementors() ) {
|
for ( AttributeNodeImplementor<?> attributeNode : other.getAttributeNodeImplementors() ) {
|
||||||
final AttributeNodeImplementor localAttributeNode = findAttributeNode(
|
final AttributeNodeImplementor<?> localAttributeNode = findAttributeNode(
|
||||||
(PersistentAttribute) attributeNode.getAttributeDescriptor()
|
(PersistentAttribute<? extends J,?>) attributeNode.getAttributeDescriptor()
|
||||||
);
|
);
|
||||||
if ( localAttributeNode != null ) {
|
if ( localAttributeNode != null ) {
|
||||||
// keep the local one, but merge in the incoming one
|
// keep the local one, but merge in the incoming one
|
||||||
|
@ -97,7 +96,6 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
addAttributeNode( attributeNode.makeCopy( true ) );
|
addAttributeNode( attributeNode.makeCopy( true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,14 +119,11 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
attrNodeMap.put( incomingAttributeNode.getAttributeDescriptor(), attributeNode );
|
attrNodeMap.put( incomingAttributeNode.getAttributeDescriptor(), attributeNode );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// because... Java
|
@SuppressWarnings("rawtypes")
|
||||||
final AttributeNodeImplementor attributeNodeFinal = attributeNode;
|
final AttributeNodeImplementor attributeNodeFinal = attributeNode;
|
||||||
incomingAttributeNode.visitSubGraphs(
|
incomingAttributeNode.visitSubGraphs(
|
||||||
(subType, subGraph) -> attributeNodeFinal.addSubGraph(
|
|
||||||
subType,
|
|
||||||
// we assume the subGraph has been properly copied if needed
|
// we assume the subGraph has been properly copied if needed
|
||||||
subGraph
|
(subType, subGraph) -> attributeNodeFinal.addSubGraph( subGraph )
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,33 +134,24 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
|
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
|
||||||
final PersistentAttribute<? super J, ?> attribute = managedType.findAttributeInSuperTypes( attributeName );
|
final PersistentAttribute<? super J, ?> attribute = managedType.findAttributeInSuperTypes( attributeName );
|
||||||
if ( attribute == null ) {
|
return attribute == null ? null : findAttributeNode( (PersistentAttribute<? extends J, AJ>) attribute );
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return findAttributeNode( (PersistentAttribute) attribute );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute) {
|
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute) {
|
||||||
if ( attrNodeMap == null ) {
|
return attrNodeMap == null ? null : (AttributeNodeImplementor<AJ>) attrNodeMap.get( attribute );
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (AttributeNodeImplementor) attrNodeMap.get( attribute );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public List<AttributeNode<?>> getGraphAttributeNodes() {
|
public List<AttributeNode<?>> getGraphAttributeNodes() {
|
||||||
return (List) getAttributeNodeImplementors();
|
return (List) getAttributeNodeImplementors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AttributeNodeImplementor<?>> getAttributeNodeImplementors() {
|
public List<AttributeNodeImplementor<?>> getAttributeNodeImplementors() {
|
||||||
return attrNodeMap == null
|
return attrNodeMap == null ? emptyList() : new ArrayList<>( attrNodeMap.values() );
|
||||||
? Collections.emptyList()
|
|
||||||
: new ArrayList<>( attrNodeMap.values() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -185,12 +171,12 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
||||||
public <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute) {
|
public <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute) {
|
||||||
verifyMutability();
|
verifyMutability();
|
||||||
|
|
||||||
AttributeNodeImplementor attrNode = null;
|
AttributeNodeImplementor<AJ> attrNode = null;
|
||||||
if ( attrNodeMap == null ) {
|
if ( attrNodeMap == null ) {
|
||||||
attrNodeMap = new HashMap<>();
|
attrNodeMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
attrNode = attrNodeMap.get( attribute );
|
attrNode = (AttributeNodeImplementor<AJ>) attrNodeMap.get( attribute );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( attrNode == null ) {
|
if ( attrNode == null ) {
|
||||||
|
|
|
@ -6,16 +6,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.graph.internal;
|
package org.hibernate.graph.internal;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.hibernate.graph.CannotContainSubGraphException;
|
import org.hibernate.graph.CannotContainSubGraphException;
|
||||||
import org.hibernate.graph.SubGraph;
|
import org.hibernate.graph.SubGraph;
|
||||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||||
|
import org.hibernate.graph.spi.GraphImplementor;
|
||||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
import org.hibernate.metamodel.model.domain.DomainType;
|
||||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
@ -23,6 +24,8 @@ import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the JPA AttributeNode contract
|
* Hibernate implementation of the JPA AttributeNode contract
|
||||||
*
|
*
|
||||||
|
@ -69,25 +72,13 @@ public class AttributeNodeImpl<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Map<Class<? extends J>, SubGraphImplementor<? extends J>> getSubGraphMap() {
|
public Map<Class<? extends J>, SubGraphImplementor<? extends J>> getSubGraphMap() {
|
||||||
if ( subGraphMap == null ) {
|
return subGraphMap == null ? emptyMap() : subGraphMap;
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return subGraphMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Map<Class<? extends J>, SubGraphImplementor<? extends J>> getKeySubGraphMap() {
|
public Map<Class<? extends J>, SubGraphImplementor<? extends J>> getKeySubGraphMap() {
|
||||||
if ( keySubGraphMap == null ) {
|
return keySubGraphMap == null ? emptyMap() : keySubGraphMap;
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return keySubGraphMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,23 +98,19 @@ public class AttributeNodeImpl<J>
|
||||||
|
|
||||||
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedDomainType<S> type) {
|
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedDomainType<S> type) {
|
||||||
assert type != null;
|
assert type != null;
|
||||||
|
|
||||||
log.debugf( "Making sub-graph : ( (%s) %s )", type.getTypeName(), getAttributeName() );
|
log.debugf( "Making sub-graph : ( (%s) %s )", type.getTypeName(), getAttributeName() );
|
||||||
|
|
||||||
final SubGraphImplementor<S> subGraph = type.makeSubGraph();
|
final SubGraphImplementor<S> subGraph = type.makeSubGraph();
|
||||||
internalAddSubGraph( type.getJavaType(), subGraph );
|
internalAddSubGraph( subGraph );
|
||||||
|
|
||||||
return subGraph;
|
return subGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T extends J> ManagedDomainType<T> valueGraphTypeAsManaged() {
|
private <T extends J> ManagedDomainType<T> valueGraphTypeAsManaged() {
|
||||||
final SimpleDomainType<J> valueGraphType = (SimpleDomainType) getAttributeDescriptor().getValueGraphType();
|
final DomainType<?> valueGraphType = getAttributeDescriptor().getValueGraphType();
|
||||||
|
|
||||||
if ( valueGraphType instanceof ManagedDomainType ) {
|
if ( valueGraphType instanceof ManagedDomainType ) {
|
||||||
return (ManagedDomainType) valueGraphType;
|
return (ManagedDomainType<T>) valueGraphType;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
throw new CannotContainSubGraphException(
|
throw new CannotContainSubGraphException(
|
||||||
String.format(
|
String.format(
|
||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
|
@ -133,42 +120,37 @@ public class AttributeNodeImpl<J>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger( AttributeNodeImpl.class );
|
private static final Logger log = Logger.getLogger( AttributeNodeImpl.class );
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(Class<S> subType) {
|
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(Class<S> subType) {
|
||||||
verifyMutability();
|
verifyMutability();
|
||||||
|
|
||||||
final ManagedDomainType<S> managedType = valueGraphTypeAsManaged();
|
final ManagedDomainType<S> managedType = valueGraphTypeAsManaged();
|
||||||
|
return internalMakeSubgraph( managedType.findSubType( subType == null ? managedType.getJavaType() : subType ) );
|
||||||
if ( subType == null ) {
|
|
||||||
subType = managedType.getJavaType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return internalMakeSubgraph( managedType.findSubType( subType ) );
|
protected void internalAddSubGraph(SubGraphImplementor<? extends J> subGraph) {
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected <S extends J> void internalAddSubGraph(Class<S> subType, SubGraphImplementor<S> subGraph) {
|
|
||||||
log.tracef( "Adding sub-graph : ( (%s) %s )", subGraph.getGraphedType().getTypeName(), getAttributeName() );
|
log.tracef( "Adding sub-graph : ( (%s) %s )", subGraph.getGraphedType().getTypeName(), getAttributeName() );
|
||||||
|
|
||||||
if ( subGraphMap == null ) {
|
if ( subGraphMap == null ) {
|
||||||
subGraphMap = new HashMap<>();
|
subGraphMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
final SubGraphImplementor<? extends J> previous = subGraphMap.put( subGraph.getClassType(), subGraph );
|
||||||
final SubGraphImplementor<? extends J> previous = subGraphMap.put( subType, (SubGraphImplementor) subGraph );
|
|
||||||
if ( previous != null ) {
|
if ( previous != null ) {
|
||||||
log.debugf( "Adding sub-graph [%s] over-wrote existing [%s]", subGraph, previous );
|
log.debugf( "Adding sub-graph [%s] over-wrote existing [%s]", subGraph, previous );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <S extends J> void addSubGraph(Class<S> subType, SubGraph<S> subGraph) {
|
public <S extends J> void addSubGraph(Class<S> subType, SubGraph<S> subGraph) {
|
||||||
verifyMutability();
|
verifyMutability();
|
||||||
|
assert subGraph.getClassType() == subType;
|
||||||
|
internalAddSubGraph( (SubGraphImplementor<S>) subGraph );
|
||||||
|
}
|
||||||
|
|
||||||
internalAddSubGraph( subType, (SubGraphImplementor) subGraph );
|
@Override
|
||||||
|
public void addSubGraph(SubGraphImplementor<? extends J> subGraph) {
|
||||||
|
internalAddSubGraph( subGraph );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,44 +169,27 @@ public class AttributeNodeImpl<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedDomainType<S> type) {
|
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedDomainType<S> type) {
|
||||||
|
|
||||||
log.debugf( "Making key sub-graph : ( (%s) %s )", type.getTypeName(), getAttributeName() );
|
log.debugf( "Making key sub-graph : ( (%s) %s )", type.getTypeName(), getAttributeName() );
|
||||||
|
|
||||||
final SubGraphImplementor<S> subGraph = type.makeSubGraph();
|
final SubGraphImplementor<S> subGraph = type.makeSubGraph();
|
||||||
internalAddKeySubGraph( type.getJavaType(), subGraph );
|
internalAddKeySubGraph( subGraph );
|
||||||
|
|
||||||
return subGraph;
|
return subGraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(Class<S> type) {
|
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(Class<S> type) {
|
||||||
verifyMutability();
|
verifyMutability();
|
||||||
|
|
||||||
final ManagedDomainType<S> managedType = keyGraphTypeAsManaged();
|
final ManagedDomainType<S> managedType = keyGraphTypeAsManaged();
|
||||||
|
final ManagedDomainType<S> subType = type == null ? managedType : managedType.findSubType( type );
|
||||||
final ManagedDomainType<S> subType;
|
|
||||||
|
|
||||||
if ( type == null ) {
|
|
||||||
subType = managedType;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
subType = managedType.findSubType( type );
|
|
||||||
}
|
|
||||||
|
|
||||||
subType.getJavaType();
|
subType.getJavaType();
|
||||||
|
|
||||||
return internalMakeKeySubgraph( subType );
|
return internalMakeKeySubgraph( subType );
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
protected void internalAddKeySubGraph(SubGraph<? extends J> subGraph) {
|
||||||
protected <S extends J> void internalAddKeySubGraph(Class<S> subType, SubGraph<S> subGraph) {
|
log.tracef( "Adding key sub-graph : ( (%s) %s )", subGraph.getClassType().getName(), getAttributeName() );
|
||||||
log.tracef( "Adding key sub-graph : ( (%s) %s )", subType.getName(), getAttributeName() );
|
|
||||||
|
|
||||||
if ( keySubGraphMap == null ) {
|
if ( keySubGraphMap == null ) {
|
||||||
keySubGraphMap = new HashMap<>();
|
keySubGraphMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
final SubGraphImplementor<? extends J> previous =
|
||||||
final SubGraphImplementor<? extends J> previous = keySubGraphMap.put( subType, (SubGraphImplementor) subGraph );
|
keySubGraphMap.put( subGraph.getClassType(), (SubGraphImplementor<? extends J>) subGraph );
|
||||||
if ( previous != null ) {
|
if ( previous != null ) {
|
||||||
log.debugf( "Adding key sub-graph [%s] over-wrote existing [%]", subGraph, previous );
|
log.debugf( "Adding key sub-graph [%s] over-wrote existing [%]", subGraph, previous );
|
||||||
}
|
}
|
||||||
|
@ -232,12 +197,11 @@ public class AttributeNodeImpl<J>
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T extends J> ManagedDomainType<T> keyGraphTypeAsManaged() {
|
private <T extends J> ManagedDomainType<T> keyGraphTypeAsManaged() {
|
||||||
final SimpleDomainType<J> keyGraphType = (SimpleDomainType) getAttributeDescriptor().getKeyGraphType();
|
final SimpleDomainType<?> keyGraphType = getAttributeDescriptor().getKeyGraphType();
|
||||||
|
|
||||||
if ( keyGraphType instanceof ManagedDomainType ) {
|
if ( keyGraphType instanceof ManagedDomainType ) {
|
||||||
return (ManagedDomainType) keyGraphType;
|
return (ManagedDomainType<T>) keyGraphType;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
throw new CannotContainSubGraphException(
|
throw new CannotContainSubGraphException(
|
||||||
String.format(
|
String.format(
|
||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
|
@ -249,45 +213,43 @@ public class AttributeNodeImpl<J>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <S extends J> void addKeySubGraph(Class<S> subType, SubGraph<S> subGraph) {
|
|
||||||
internalAddKeySubGraph( subType, subGraph );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
public <S extends J> void addKeySubGraph(Class<S> subType, SubGraph<S> subGraph) {
|
||||||
|
assert subGraph.getClassType() == subType;
|
||||||
|
internalAddKeySubGraph( subGraph );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public AttributeNodeImplementor<J> makeCopy(boolean mutable) {
|
public AttributeNodeImplementor<J> makeCopy(boolean mutable) {
|
||||||
return new AttributeNodeImpl<>(
|
return new AttributeNodeImpl<>(
|
||||||
mutable,
|
mutable,
|
||||||
this.attribute,
|
this.attribute,
|
||||||
makeMapCopy( mutable, (Map) subGraphMap ),
|
makeMapCopy( mutable, subGraphMap ),
|
||||||
makeMapCopy( mutable, (Map) keySubGraphMap ),
|
makeMapCopy( mutable, keySubGraphMap ),
|
||||||
jpaMetamodel()
|
jpaMetamodel()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <S extends J> Map<Class<S>, SubGraphImplementor<S>> makeMapCopy(
|
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> makeMapCopy(
|
||||||
boolean mutable,
|
boolean mutable,
|
||||||
Map<Class<S>, SubGraphImplementor<S>> nodeMap) {
|
Map<Class<? extends J>, SubGraphImplementor<? extends J>> nodeMap) {
|
||||||
if ( nodeMap == null ) {
|
if ( nodeMap == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return CollectionHelper.makeCopy(
|
return nodeMap.entrySet().stream()
|
||||||
nodeMap,
|
.map(entry -> Map.entry(entry.getKey(), entry.getValue().makeCopy( mutable )))
|
||||||
type -> type,
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
subGraph -> subGraph.makeCopy( mutable )
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void merge(AttributeNodeImplementor<?> attributeNode) {
|
public void merge(AttributeNodeImplementor<?> attributeNode) {
|
||||||
attributeNode.visitSubGraphs(
|
attributeNode.visitSubGraphs(
|
||||||
(incomingSubType, incomingGraph) -> {
|
(incomingSubType, incomingGraph) -> {
|
||||||
SubGraphImplementor existing = null;
|
SubGraphImplementor<?> existing = null;
|
||||||
if ( subGraphMap == null ) {
|
if ( subGraphMap == null ) {
|
||||||
subGraphMap = new HashMap<>();
|
subGraphMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
@ -296,17 +258,17 @@ public class AttributeNodeImpl<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( existing != null ) {
|
if ( existing != null ) {
|
||||||
existing.merge( incomingGraph );
|
existing.merge( (GraphImplementor) incomingGraph );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
internalAddSubGraph( (Class) incomingSubType, (SubGraphImplementor) incomingGraph.makeCopy( true ) );
|
internalAddSubGraph( (SubGraphImplementor) incomingGraph.makeCopy( true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
attributeNode.visitKeySubGraphs(
|
attributeNode.visitKeySubGraphs(
|
||||||
(incomingSubType, incomingGraph) -> {
|
(incomingSubType, incomingGraph) -> {
|
||||||
SubGraphImplementor existing = null;
|
SubGraphImplementor<?> existing = null;
|
||||||
if ( keySubGraphMap == null ) {
|
if ( keySubGraphMap == null ) {
|
||||||
keySubGraphMap = new HashMap<>();
|
keySubGraphMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
@ -315,10 +277,10 @@ public class AttributeNodeImpl<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( existing != null ) {
|
if ( existing != null ) {
|
||||||
existing.merge( incomingGraph );
|
existing.merge( (GraphImplementor) incomingGraph );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
internalAddKeySubGraph( (Class) incomingSubType, (SubGraphImplementor) incomingGraph.makeCopy( true ) );
|
internalAddKeySubGraph( (SubGraphImplementor) incomingGraph.makeCopy( true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,12 +35,7 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
public RootGraphImpl(String name, EntityDomainType<J> entityType, JpaMetamodel jpaMetamodel) {
|
public RootGraphImpl(String name, EntityDomainType<J> entityType, JpaMetamodel jpaMetamodel) {
|
||||||
this(
|
this( name, entityType, true, jpaMetamodel );
|
||||||
name,
|
|
||||||
entityType,
|
|
||||||
true,
|
|
||||||
jpaMetamodel
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RootGraphImpl(String name, boolean mutable, GraphImplementor<J> original) {
|
public RootGraphImpl(String name, boolean mutable, GraphImplementor<J> original) {
|
||||||
|
@ -65,11 +60,7 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
|
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
|
||||||
if ( ! mutable && ! isMutable() ) {
|
return !mutable && !isMutable() ? this : super.makeRootGraph( name, mutable );
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.makeRootGraph( name, mutable );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,13 +69,13 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean appliesTo(EntityDomainType<? super J> entityType) {
|
public boolean appliesTo(EntityDomainType<?> entityType) {
|
||||||
final ManagedDomainType<J> managedTypeDescriptor = getGraphedType();
|
final ManagedDomainType<J> managedTypeDescriptor = getGraphedType();
|
||||||
if ( managedTypeDescriptor.equals( entityType ) ) {
|
if ( managedTypeDescriptor.equals( entityType ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentifiableDomainType<? super J> superType = entityType.getSupertype();
|
IdentifiableDomainType<?> superType = entityType.getSupertype();
|
||||||
while ( superType != null ) {
|
while ( superType != null ) {
|
||||||
if ( managedTypeDescriptor.equals( superType ) ) {
|
if ( managedTypeDescriptor.equals( superType ) ) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -101,7 +92,7 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean appliesTo(Class type) {
|
public boolean appliesTo(Class<?> type) {
|
||||||
return appliesTo( jpaMetamodel().entity( type ) );
|
return appliesTo( jpaMetamodel().entity( type ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,12 @@ public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImpleme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean appliesTo(ManagedDomainType<? super J> managedType) {
|
public boolean appliesTo(ManagedDomainType<?> managedType) {
|
||||||
if ( this.getGraphedType().equals( managedType ) ) {
|
if ( getGraphedType().equals( managedType ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagedDomainType superType = managedType.getSuperType();
|
ManagedDomainType<?> superType = managedType.getSuperType();
|
||||||
while ( superType != null ) {
|
while ( superType != null ) {
|
||||||
if ( superType.equals( managedType ) ) {
|
if ( superType.equals( managedType ) ) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -62,7 +62,7 @@ public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImpleme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean appliesTo(Class<? super J> javaType) {
|
public boolean appliesTo(Class<?> javaType) {
|
||||||
return appliesTo( jpaMetamodel().managedType( javaType ) );
|
return appliesTo( jpaMetamodel().managedType( javaType ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import org.hibernate.graph.SubGraph;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration version of the AttributeNode contract
|
* Integration version of the {@link AttributeNode} contract
|
||||||
*
|
*
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -24,11 +24,11 @@ public interface AttributeNodeImplementor<J> extends AttributeNode<J>, GraphNode
|
||||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getSubGraphMap();
|
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getSubGraphMap();
|
||||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getKeySubGraphMap();
|
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getKeySubGraphMap();
|
||||||
|
|
||||||
default void visitSubGraphs(BiConsumer<Class<?>, SubGraphImplementor<?>> consumer) {
|
default void visitSubGraphs(BiConsumer<Class<? extends J>, SubGraphImplementor<? extends J>> consumer) {
|
||||||
getSubGraphMap().forEach( consumer );
|
getSubGraphMap().forEach( consumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
default void visitKeySubGraphs(BiConsumer<Class<?>, SubGraphImplementor<?>> consumer) {
|
default void visitKeySubGraphs(BiConsumer<Class<? extends J>, SubGraphImplementor<? extends J>> consumer) {
|
||||||
getKeySubGraphMap().forEach( consumer );
|
getKeySubGraphMap().forEach( consumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public interface AttributeNodeImplementor<J> extends AttributeNode<J>, GraphNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
default Map<Class, Subgraph> getSubgraphs() {
|
default Map<Class, Subgraph> getSubgraphs() {
|
||||||
return (Map) getSubGraphMap();
|
return (Map) getSubGraphMap();
|
||||||
}
|
}
|
||||||
|
@ -76,4 +76,6 @@ public interface AttributeNodeImplementor<J> extends AttributeNode<J>, GraphNode
|
||||||
<S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedDomainType<S> subtype);
|
<S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedDomainType<S> subtype);
|
||||||
|
|
||||||
void merge(AttributeNodeImplementor<?> attributeNode);
|
void merge(AttributeNodeImplementor<?> attributeNode);
|
||||||
|
|
||||||
|
void addSubGraph(SubGraphImplementor<? extends J> subGraph);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,19 +18,19 @@ import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration version of the Graph contract
|
* Integration version of the {@link Graph} contract
|
||||||
*
|
*
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
boolean appliesTo(ManagedDomainType<? super J> managedType);
|
|
||||||
|
|
||||||
boolean appliesTo(Class<? super J> javaType);
|
boolean appliesTo(ManagedDomainType<?> managedType);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
boolean appliesTo(Class<?> javaType);
|
||||||
void merge(GraphImplementor<J>... others);
|
|
||||||
|
void merge(GraphImplementor<? extends J> other);
|
||||||
|
|
||||||
JpaMetamodel jpaMetamodel();
|
JpaMetamodel jpaMetamodel();
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
// Co-variant returns
|
// Co-variant returns
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) throws CannotBecomeEntityGraphException;
|
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable)
|
||||||
|
throws CannotBecomeEntityGraphException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
SubGraphImplementor<J> makeSubGraph(boolean mutable);
|
SubGraphImplementor<J> makeSubGraph(boolean mutable);
|
||||||
|
@ -60,7 +61,7 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
List<AttributeNodeImplementor<?>> getAttributeNodeImplementors();
|
List<AttributeNodeImplementor<?>> getAttributeNodeImplementors();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
default List<AttributeNode<?>> getAttributeNodeList() {
|
default List<AttributeNode<?>> getAttributeNodeList() {
|
||||||
return (List) getAttributeNodeImplementors();
|
return (List) getAttributeNodeImplementors();
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,8 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
<AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
<AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(String attributeName) throws CannotContainSubGraphException;
|
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(String attributeName)
|
||||||
|
throws CannotContainSubGraphException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? extends J, AJ> attribute)
|
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? extends J, AJ> attribute)
|
||||||
|
@ -80,7 +82,7 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(String name) {
|
default <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(String name) {
|
||||||
return findOrCreateAttributeNode( (PersistentAttribute) getGraphedType().getAttribute( name ) );
|
return findOrCreateAttributeNode( (PersistentAttribute<? extends J,AJ>) getGraphedType().getAttribute( name ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
<AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
<AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||||
|
@ -91,8 +93,9 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName) throws CannotContainSubGraphException {
|
default <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName)
|
||||||
return (SubGraphImplementor) findOrCreateAttributeNode( attributeName ).makeSubGraph();
|
throws CannotContainSubGraphException {
|
||||||
|
return (SubGraphImplementor<AJ>) findOrCreateAttributeNode( attributeName ).makeSubGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,7 +124,7 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default <AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName) {
|
default <AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName) {
|
||||||
return (SubGraphImplementor) findOrCreateAttributeNode( attributeName ).makeKeySubGraph();
|
return (SubGraphImplementor<AJ>) findOrCreateAttributeNode( attributeName ).makeKeySubGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,7 +140,8 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||||
@Override
|
@Override
|
||||||
default <AJ> SubGraphImplementor<? extends AJ> addKeySubGraph(
|
default <AJ> SubGraphImplementor<? extends AJ> addKeySubGraph(
|
||||||
PersistentAttribute<? extends J, AJ> attribute,
|
PersistentAttribute<? extends J, AJ> attribute,
|
||||||
Class<? extends AJ> subType) throws CannotContainSubGraphException {
|
Class<? extends AJ> subType)
|
||||||
|
throws CannotContainSubGraphException {
|
||||||
return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subType );
|
return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subType );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ package org.hibernate.graph.spi;
|
||||||
import org.hibernate.graph.GraphNode;
|
import org.hibernate.graph.GraphNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration version of the GraphNode contract
|
* Integration version of the {@link GraphNode} contract
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Strong Liu
|
* @author Strong Liu
|
||||||
|
|
|
@ -11,18 +11,20 @@ import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration version of the RootGraph contract
|
* Integration version of the {@link RootGraph} contract
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface RootGraphImplementor<J> extends RootGraph<J>, GraphImplementor<J> {
|
public interface RootGraphImplementor<J> extends RootGraph<J>, GraphImplementor<J> {
|
||||||
boolean appliesTo(EntityDomainType<? super J> entityType);
|
|
||||||
|
boolean appliesTo(String entityName);
|
||||||
|
|
||||||
|
boolean appliesTo(EntityDomainType<?> entityType);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
default boolean appliesTo(ManagedDomainType<?> managedType) {
|
||||||
default boolean appliesTo(ManagedDomainType<? super J> managedType) {
|
|
||||||
assert managedType instanceof EntityDomainType;
|
assert managedType instanceof EntityDomainType;
|
||||||
return appliesTo( (EntityDomainType) managedType );
|
return appliesTo( (EntityDomainType<?>) managedType );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.hibernate.graph.SubGraph;
|
||||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration version of the SubGraph contract
|
* Integration version of the {@link SubGraph} contract
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -22,15 +22,12 @@ public interface SubGraphImplementor<J> extends SubGraph<J>, GraphImplementor<J>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default SubGraphImplementor<J> makeSubGraph(boolean mutable) {
|
default SubGraphImplementor<J> makeSubGraph(boolean mutable) {
|
||||||
if ( ! mutable && ! isMutable() ) {
|
return !mutable && !isMutable() ? this : makeCopy( mutable );
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return makeCopy( mutable );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) throws CannotBecomeEntityGraphException;
|
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable)
|
||||||
|
throws CannotBecomeEntityGraphException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
<AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName);
|
<AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||||
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This package defines an internal SPI abstracting over implementations
|
||||||
|
* of the APIs defined in {@link org.hibernate.graph}.
|
||||||
|
*/
|
||||||
|
@Incubating
|
||||||
|
package org.hibernate.graph.spi;
|
||||||
|
|
||||||
|
import org.hibernate.Incubating;
|
|
@ -9,7 +9,6 @@ package org.hibernate.sql.results.internal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.hibernate.engine.FetchStyle;
|
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.graph.GraphSemantic;
|
import org.hibernate.graph.GraphSemantic;
|
||||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||||
|
@ -30,10 +29,10 @@ import org.hibernate.sql.results.graph.Fetchable;
|
||||||
public class StandardEntityGraphTraversalStateImpl implements EntityGraphTraversalState {
|
public class StandardEntityGraphTraversalStateImpl implements EntityGraphTraversalState {
|
||||||
|
|
||||||
private final GraphSemantic graphSemantic;
|
private final GraphSemantic graphSemantic;
|
||||||
private GraphImplementor currentGraphContext;
|
private GraphImplementor<?> currentGraphContext;
|
||||||
|
|
||||||
public StandardEntityGraphTraversalStateImpl(GraphSemantic graphSemantic, RootGraphImplementor rootGraphImplementor) {
|
public StandardEntityGraphTraversalStateImpl(GraphSemantic graphSemantic, RootGraphImplementor<?> rootGraphImplementor) {
|
||||||
Objects.requireNonNull(graphSemantic, "graphSemantic cannot be null");
|
Objects.requireNonNull( graphSemantic, "graphSemantic cannot be null" );
|
||||||
Objects.requireNonNull( rootGraphImplementor, "rootGraphImplementor cannot be null" );
|
Objects.requireNonNull( rootGraphImplementor, "rootGraphImplementor cannot be null" );
|
||||||
this.graphSemantic = graphSemantic;
|
this.graphSemantic = graphSemantic;
|
||||||
this.currentGraphContext = rootGraphImplementor;
|
this.currentGraphContext = rootGraphImplementor;
|
||||||
|
@ -51,25 +50,19 @@ public class StandardEntityGraphTraversalStateImpl implements EntityGraphTravers
|
||||||
return new TraversalResult( currentGraphContext, new FetchStrategy( FetchTiming.IMMEDIATE, true ) );
|
return new TraversalResult( currentGraphContext, new FetchStrategy( FetchTiming.IMMEDIATE, true ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
final GraphImplementor previousContextRoot = currentGraphContext;
|
final GraphImplementor<?> previousContextRoot = currentGraphContext;
|
||||||
AttributeNodeImplementor attributeNode = null;
|
final AttributeNodeImplementor<?> attributeNode = appliesTo( fetchParent )
|
||||||
if ( appliesTo( fetchParent ) ) {
|
? currentGraphContext.findAttributeNode( fetchable.getFetchableName() )
|
||||||
attributeNode = currentGraphContext.findAttributeNode( fetchable.getFetchableName() );
|
: null;
|
||||||
}
|
|
||||||
|
|
||||||
currentGraphContext = null;
|
currentGraphContext = null;
|
||||||
FetchStrategy fetchStrategy = null;
|
final FetchStrategy fetchStrategy;
|
||||||
|
|
||||||
if ( attributeNode != null ) {
|
if ( attributeNode != null ) {
|
||||||
|
|
||||||
fetchStrategy = new FetchStrategy( FetchTiming.IMMEDIATE, true );
|
fetchStrategy = new FetchStrategy( FetchTiming.IMMEDIATE, true );
|
||||||
|
final Map<? extends Class<?>, ? extends SubGraphImplementor<?>> subgraphMap;
|
||||||
final Map<Class<?>, SubGraphImplementor> subgraphMap;
|
|
||||||
final Class<?> subgraphMapKey;
|
final Class<?> subgraphMapKey;
|
||||||
|
|
||||||
if ( fetchable instanceof PluralAttributeMapping ) {
|
if ( fetchable instanceof PluralAttributeMapping ) {
|
||||||
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
|
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
|
||||||
|
|
||||||
if ( exploreKeySubgraph ) {
|
if ( exploreKeySubgraph ) {
|
||||||
subgraphMap = attributeNode.getKeySubGraphMap();
|
subgraphMap = attributeNode.getKeySubGraphMap();
|
||||||
subgraphMapKey = getEntityCollectionPartJavaClass( pluralAttributeMapping.getIndexDescriptor() );
|
subgraphMapKey = getEntityCollectionPartJavaClass( pluralAttributeMapping.getIndexDescriptor() );
|
||||||
|
@ -88,9 +81,12 @@ public class StandardEntityGraphTraversalStateImpl implements EntityGraphTravers
|
||||||
currentGraphContext = subgraphMap.get( subgraphMapKey );
|
currentGraphContext = subgraphMap.get( subgraphMapKey );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( fetchStrategy == null && graphSemantic == GraphSemantic.FETCH ) {
|
else if ( graphSemantic == GraphSemantic.FETCH ) {
|
||||||
fetchStrategy = new FetchStrategy( FetchTiming.DELAYED, false );
|
fetchStrategy = new FetchStrategy( FetchTiming.DELAYED, false );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
fetchStrategy = null;
|
||||||
|
}
|
||||||
return new TraversalResult( previousContextRoot, fetchStrategy );
|
return new TraversalResult( previousContextRoot, fetchStrategy );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,10 +101,7 @@ public class StandardEntityGraphTraversalStateImpl implements EntityGraphTravers
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean appliesTo(FetchParent fetchParent) {
|
private boolean appliesTo(FetchParent fetchParent) {
|
||||||
if ( currentGraphContext == null ) {
|
return currentGraphContext != null && fetchParent.appliesTo( currentGraphContext );
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fetchParent.appliesTo( currentGraphContext );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class EntityGraphsTest extends AbstractEntityGraphTest {
|
public class EntityGraphsTest extends AbstractEntityGraphTest {
|
||||||
|
|
||||||
private final <T> void checkMerge(Class<T> rootType, EntityGraph<T> expected, @SuppressWarnings("unchecked") EntityGraph<T>... graphs) {
|
private <T> void checkMerge(Class<T> rootType, EntityGraph<T> expected, EntityGraph<T>... graphs) {
|
||||||
EntityManager entityManager = getOrCreateEntityManager();
|
EntityManager entityManager = getOrCreateEntityManager();
|
||||||
EntityGraph<T> actual = EntityGraphs.merge( entityManager, rootType, graphs );
|
EntityGraph<T> actual = EntityGraphs.merge( entityManager, rootType, graphs );
|
||||||
Assert.assertTrue( EntityGraphs.areEqual( expected, actual ) );
|
Assert.assertTrue( EntityGraphs.areEqual( expected, actual ) );
|
||||||
|
|
Loading…
Reference in New Issue