Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
JPA-45 - Apply EntityGraph changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Feb 13, 2013
1 parent 723398f commit a873b07
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 91 deletions.
23 changes: 15 additions & 8 deletions src/main/java/javax/persistence/AttributeNode.java
Expand Up @@ -9,7 +9,7 @@
*/
package javax.persistence;

import javax.persistence.metamodel.Type;
import java.util.Map;

/**
* Represents an attribute node of an entity graph.
Expand All @@ -20,16 +20,23 @@
*/
public interface AttributeNode<T> {
/**
* Return the Type of the attribute node.
* @return Type object for the attribute node
* Return the name of the attribute corresponding to the attribute node.
*
* @return name of the attribute
*/
public Type<T> getType();
public String getAttributeName();

/**
* Return the name of the attribute corresponding to the
* attribute node.
* @return name of the attribute
* Return the Map<Class, Subgraph> of subgraphs associated with this attribute node.
*
* @return Map of subgraphs associated with this attribute node or empty Map if none have been defined
*/
public String getAttributeName();
public Map<Class, Subgraph> getSubgraphs();

/**
* Return the Map<Class, Subgraph> of subgraphs associated with this attribute node's map key.
*
* @return Map of subgraphs associated with this attribute node's map key or empty Map if none have been defined
*/
public Map<Class, Subgraph> getKeySubgraphs();
}
78 changes: 30 additions & 48 deletions src/main/java/javax/persistence/EntityGraph.java
Expand Up @@ -13,24 +13,21 @@
import java.util.List;

/**
* This type represents the root of an entity graph that will be used
* as a template to define the attribute nodes and boundaries of a
* graph of entities and entity relationships. The root must be an
* entity type.
* This type represents the root of an entity graph that will be used as a template to define the attribute nodes
* and boundaries of a graph of entities and entity relationships. The root must be an entity type.
*
* The methods to add subgraphs implicitly create the corresponding attribute nodes as well; such attribute nodes
* should not be redundantly specified.
*
* @param <T> The type of the root entity.
*
* @since JPA 2.1
*/
public interface EntityGraph<T> {
/**
* Return the name of a named EntityGraph (an entity graph
* defined by means of the NamedEntityGraph annotation,
* XML descriptor element, or added by means of the
* addNamedEntityGraph method. Returns null if the EntityGraph
* Return the name of a named EntityGraph - an entity graph defined by means of the NamedEntityGraph annotation,
* XML descriptor element, or added by means of the addNamedEntityGraph method. Returns null if the EntityGraph
* is not a named EntityGraph.
* The methods to add subgraphs implicitly create the
* corresponding attribute nodes as well; such attribute nodes
* should not be redundantly specified.
*/
public String getName();

Expand All @@ -54,9 +51,8 @@ public interface EntityGraph<T> {
public void addAttributeNodes(Attribute<T, ?>... attribute);

/**
* Add a node to the graph that corresponds to a managed
* type. This allows for construction of multi-node entity graphs
* that include related managed types.
* Add a node to the graph that corresponds to a managed type. This allows for construction of multi-node
* entity graphs that include related managed types.
*
* @param attribute attribute
*
Expand All @@ -68,11 +64,9 @@ public interface EntityGraph<T> {
public <X> Subgraph<X> addSubgraph(Attribute<T, X> attribute);

/**
* Add a node to the graph that corresponds to a managed
* type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity
* graph. Subclass subgraphs will automatically include the
* specified attributes of superclass subgraphs.
* Add a node to the graph that corresponds to a managed type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity graph. Subclass subgraphs will automatically include the
* specified attributes of superclass subgraphs
*
* @param attribute attribute
* @param type entity subclass
Expand All @@ -85,9 +79,8 @@ public interface EntityGraph<T> {
public <X> Subgraph<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type);

/**
* Add a node to the graph that corresponds to a managed
* type. This allows for construction of multi-node entity graphs
* that include related managed types.
* Add a node to the graph that corresponds to a managed type. This allows for construction of multi-node
* entity graphs that include related managed types.
*
* @param attributeName name of the attribute
*
Expand All @@ -100,11 +93,9 @@ public interface EntityGraph<T> {
public <X> Subgraph<X> addSubgraph(String attributeName);

/**
* Add a node to the graph that corresponds to a managed
* type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity graph.
* Subclass subgraphs will automatically include the specified
* attributes of superclass subgraphs.
* Add a node to the graph that corresponds to a managed type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity graph. Subclass subgraphs will automatically include the
* specified attributes of superclass subgraphs.
*
* @param attributeName name of the attribute
* @param type entity subclass
Expand All @@ -118,11 +109,9 @@ public interface EntityGraph<T> {
public <X> Subgraph<X> addSubgraph(String attributeName, Class<X> type);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type. This allows for construction of
* multi-node entity graphs that include related managed types.
* Use of this method implicitly adds the corresponding attribute
* node to the graph.
* Add a node to the graph that corresponds to a map key that is a managed type. This allows for construction of
* multi-node entity graphs that include related managed types. Use of this method implicitly adds the
* corresponding attribute node to the graph.
*
* @param attribute attribute
*
Expand All @@ -134,11 +123,9 @@ public interface EntityGraph<T> {
public <X> Subgraph<X> addKeySubgraph(Attribute<T, X> attribute);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related
* managed types. Subclass subgraphs will include the specified
* attributes of superclass subgraphs.
* Add a node to the graph that corresponds to a map key that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related managed types. Subclass subgraphs will include
* the specified attributes of superclass subgraphs.
*
* @param attribute attribute
* @param type entity subclass
Expand All @@ -151,8 +138,7 @@ public interface EntityGraph<T> {
public <X> Subgraph<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type. This allows for construction of
* Add a node to the graph that corresponds to a map key that is a managed type. This allows for construction of
* multi-node entity graphs that include related managed types.
*
* @param attributeName name of the attribute
Expand All @@ -166,11 +152,9 @@ public interface EntityGraph<T> {
public <X> Subgraph<X> addKeySubgraph(String attributeName);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related
* managed types. Subclass subgraphs will automatically include
* the specified attributes of superclass subgraphs
* Add a node to the graph that corresponds to a map key that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related managed types. Subclass subgraphs will
* automatically include the specified attributes of superclass subgraphs
*
* @param attributeName name of the attribute
* @param type entity subclass
Expand All @@ -184,10 +168,8 @@ public interface EntityGraph<T> {
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type);

/**
* Add additional attributes to this entity graph that
* correspond to attributes of subclasses of this EntityGraph's
* entity type. Subclass subgraphs will automatically include
* the specified attributes of superclass subgraphs.
* Add additional attributes to this entity graph that correspond to attributes of subclasses of this EntityGraph's
* entity type. Subclass subgraphs will automatically include the specified attributes of superclass subgraphs.
*
* @param type entity subclass
*
Expand Down
86 changes: 51 additions & 35 deletions src/main/java/javax/persistence/Subgraph.java
Expand Up @@ -13,8 +13,8 @@
import java.util.List;

/**
* This type represents a AttributeNode of an EntityGraph that corresponds to a Managed Type. Using this class, an
* entity subgraph can be embedded within an EntityGraph.
* This type represents a subgraph for an attribute node that corresponds to a Managed Type. Using this class,
* an entity subgraph can be embedded within an EntityGraph.
*
* @param <T> The type of the attribute.
*
Expand All @@ -23,134 +23,150 @@
public interface Subgraph<T> extends AttributeNode<T> {
/**
* Add one or more attribute nodes to the entity graph.
*
* @param attributeName name of the attribute
*
* @throws IllegalArgumentException if the attribute is not an attribute of this managed type.
* @throws IllegalStateException if the EntityGraph has been statically defined
*/
public void addAttributeNodes(String ... attributeName);

/**
* Add one or more attribute nodes to the entity graph.
*
* @param attribute attribute
*
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public void addAttributeNodes(Attribute<T, ?> ... attribute);

/**
* Add a node to the graph that corresponds to a managed
* type. This allows for construction of multi-node entity graphs
* that include related managed types.
* Add a node to the graph that corresponds to a managed type. This allows for construction of multi-node entity
* graphs that include related managed types.
*
* @param attribute attribute
*
* @return subgraph for the attribute
*
* @throws IllegalArgumentException if the attribute's target type is not a managed type
* @throws IllegalStateException if the EntityGraph has been statically defined
*/
public <X> Subgraph<X> addSubgraph(Attribute<T, X> attribute);

/**
* Add a node to the graph that corresponds to a managed
* type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity
* graph. Subclass subgraphs will automatically include the
* Add a node to the graph that corresponds to a managed type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity graph. Subclass subgraphs will automatically include the
* specified attributes of superclass subgraphs
*
* @param attribute attribute
* @param type entity subclass
*
* @return subgraph for the attribute
*
* @throws IllegalArgumentException if the attribute's target type is not a managed type
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<? extends X> addSubgraph(Attribute<T, X> attribute, Class<? extends X> type);

/**
* Add a node to the graph that corresponds to a managed
* type. This allows for construction of multi-node entity graphs
* that include related managed types.
* Add a node to the graph that corresponds to a managed type. This allows for construction of multi-node entity
* graphs that include related managed types.
*
* @param attributeName name of the attribute
*
* @return subgraph for the attribute
*
* @throws IllegalArgumentException if the attribute is not an attribute of this managed type.
* @throws IllegalArgumentException if the attribute's target type is not a managed type
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<X> addSubgraph(String attributeName);

/**
* Add a node to the graph that corresponds to a managed
* type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity
* graph. Subclass subgraphs will automatically include the
* Add a node to the graph that corresponds to a managed type with inheritance. This allows for multiple subclass
* subgraphs to be defined for this node of the entity graph. Subclass subgraphs will automatically include the
* specified attributes of superclass subgraphs
*
* @param attributeName name of the attribute
* @param type entity subclass
*
* @return subgraph for the attribute
*
* @throws IllegalArgumentException if the attribute is not an attribute of this managed type.
* @throws IllegalArgumentException if the attribute's target type is not a managed type
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<X> addSubgraph(String attributeName, Class<X> type);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type. This allows for construction of
* Add a node to the graph that corresponds to a map key that is a managed type. This allows for construction of
* multinode entity graphs that include related managed types.
*
* @param attribute attribute
*
* @return subgraph for the key attribute
*
* @throws IllegalArgumentException if the attribute's target type is not a managed type entity
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<X> addKeySubgraph(Attribute<T, X> attribute);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related
* managed types. Subclass subgraphs will automatically include
* the specified attributes of superclass subgraphs
* Add a node to the graph that corresponds to a map key that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related managed types. Subclass subgraphs will
* automatically include the specified attributes of superclass subgraphs
*
* @param attribute attribute
* @param type entity subclass
*
* @return subgraph for the attribute
* @throws IllegalArgumentException if the attribute's target type is not a managed type entity
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<? extends X> addKeySubgraph(Attribute<T, X> attribute, Class<? extends X> type);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type. This allows for construction of
* Add a node to the graph that corresponds to a map key that is a managed type. This allows for construction of
* multi-node entity graphs that include related managed types.
*
* @param attributeName name of the attribute
*
* @return subgraph for the key attribute
*
* @throws IllegalArgumentException if the attribute is not an attribute of this entity.
* @throws IllegalArgumentException if the attribute's target type is not a managed type
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<X> addKeySubgraph(String attributeName);

/**
* Add a node to the graph that corresponds to a map key
* that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related
* managed types. Subclass subgraphs will include the specified
* attributes of superclass subgraphs
* Add a node to the graph that corresponds to a map key that is a managed type with inheritance. This allows for
* construction of multi-node entity graphs that include related managed types. Subclass subgraphs will include
* the specified attributes of superclass subgraphs
*
* @param attributeName name of the attribute
* @param type entity subclass
*
* @return subgraph for the attribute
*
* @throws IllegalArgumentException if the attribute is not an attribute of this entity.
* @throws IllegalArgumentException if the attribute's target type is not a managed type
* @throws IllegalStateException if this EntityGraph has been statically defined
*/
public <X> Subgraph<X> addKeySubgraph(String attributeName, Class<X> type);

/**
* Return the attribute nodes corresponding to the attributes of
* this managed type that are included in the subgraph.
* @return list of attribute nodes included in the subgraph
* Return the attribute nodes corresponding to the attributes of this managed type that are included in the
* subgraph.
*
* @return list of attribute nodes included in the subgraph or empty list if none have been defined
*/
public List<AttributeNode<?>> getAttributeNodes();

/**
* Return the type of for which this subgraph was defined.
*
* @return managed type referenced by the subgraph
*/
public Class<T> getClassType();

}
}

0 comments on commit a873b07

Please sign in to comment.