public class FetchGroup extends AttributeGroup
FetchGroup usage is only possible when an entity class implements the FetchGroupTracker interface so that the FetchGroup can be stored in the entity. The entity must also use the provided check methods to ensure the attributes are loaded prior to use. In general this support is enabled through weaving of the entity classes. If an entity class does not implement FetchGroupTracker no FetchGroup functionality will be supported and attempted use of a FetchGroup in a query will not result in the expected behavior.
FetchGroups are defined in 3 ways:
FetchGroupManager.getDefaultFetchGroup() is created and stored on the FetchGroupManager during metadata processing if any of the basic (DirectToFieldMapping) are configured to be loaded directly.FetchGroupManager. For JPA users this can be accomplished using annotation (@FetchGroup) or in an eclipselink-orm.xml. For JPA and native users named groups can be defined in code and added to the FetchGroupManager.addFetchGroup(FetchGroup). Adding named groups in code is typically done in a DescriptorCustomizerand should be done before the session is initialized at login. To use a named FetchGroup on a query the native ObjectLevelReadQuery.setFetchGroupName(String) can be used of for JPA users the QueryHints#FETCH_GROUP_NAME an be used.ObjectLevelReadQuery.setFetchGroup(FetchGroup) while JPA users generally use the QueryHints#FETCH_GROUP.When a query is executed only one FetchGroup will be used. The order of precedence is:
Loading: A FetchGroup can optionally specify that it needs its included relationships loaded. This can be done using setShouldLoad(boolean) and setShouldLoadAll(boolean) as well as the corresponding configurations in the @FetchGroup annotation and the <fetch-group> element in the eclipselink-orm.xml. When this si configured the FetchGroup will also function as a LoadGroup causing all of its specified relationships to be populated prior to returning the results form the query execution.
FetchGroupManager, QueryHints#FETCH_GROUP, LoadGroup, Serialized Form| Constructor and Description |
|---|
FetchGroup() |
FetchGroup(java.lang.String name) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAttribute(java.lang.String attributeNameOrPath, java.util.Collection<? extends CoreAttributeGroup> groups)
Add an attribute and the corresponding list of AttributeGroups.
|
void |
addAttribute(java.lang.String attributeNameOrPath, CoreAttributeGroup group)
Add a basic attribute or nested attribute with each String representing an attribute on the path to what needs to be included in the AttributeGroup.
|
void |
addAttributeKey(java.lang.String attributeNameOrPath, CoreAttributeGroup group)
Add a basic attribute or nested attribute with each String representing the key of an attribute of type Map on the path to what needs to be included in the AttributeGroup.
|
FetchGroup |
clone() |
java.util.Set<java.lang.String> |
getAttributes()
Deprecated.
|
org.eclipse.persistence.internal.queries.EntityFetchGroup |
getEntityFetchGroup(FetchGroupManager fetchGroupManager)
INTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroup
|
FetchGroup |
getGroup(java.lang.String attributeNameOrPath)
Returns FetchGroup corresponding to the passed (possibly nested) attribute.
|
FetchGroupTracker |
getRootEntity()
INTERNAL:
|
boolean |
isEntityFetchGroup() |
boolean |
isFetchGroup() |
java.lang.String |
onUnfetchedAttribute(FetchGroupTracker entity, java.lang.String attributeName)
INTERNAL: Called on attempt to get value of an attribute that hasn't been fetched yet.
|
java.lang.String |
onUnfetchedAttributeForSet(FetchGroupTracker entity, java.lang.String attributeName)
INTERNAL: Called on attempt to assign value to an attribute that hasn't been fetched yet.
|
void |
setRootEntity(FetchGroupTracker rootEntity)
INTERNAL:
|
void |
setShouldLoad(boolean shouldLoad)
Configure this group to also act as a
LoadGroup when set to true and load all of the specified relationships so that the entities returned from the query where this group was used have the requested relationships populated. |
void |
setShouldLoadAll(boolean shouldLoad)
Configure this group to also act as a
LoadGroup the same as setShouldLoad(boolean). |
boolean |
shouldLoad() |
LoadGroup |
toLoadGroup(java.util.Map<AttributeGroup,LoadGroup> cloneMap, boolean loadOnly) |
LoadGroup |
toLoadGroupLoadOnly() |
addAttribute, findGroup, getItem, isConcurrent, isCopyGroup, isLoadGroup, isSupersetOf, toCopyGroup, toCopyGroup, toFetchGroup, toFetchGroup, toLoadGroupaddAttribute, addAttributes, clone, containsAttribute, containsAttributeInternal, convertClassNamesToClasses, equals, getAllItems, getAttributeNames, getItems, getName, getSubClassGroups, getType, getTypeName, hasInheritance, hasItems, insertSubClass, isSupersetOf, isValidated, removeAttribute, setAllSubclasses, setAttributeNames, setName, toStringpublic FetchGroup()
public FetchGroup(java.lang.String name)
@Deprecated public java.util.Set<java.lang.String> getAttributes()
CoreAttributeGroup.getAttributeNames()public java.lang.String onUnfetchedAttribute(FetchGroupTracker entity, java.lang.String attributeName)
This method is typically only invoked through woven code in the persistence object introduced when FetchGroupTracker is woven into the entity.
public java.lang.String onUnfetchedAttributeForSet(FetchGroupTracker entity, java.lang.String attributeName)
This method is typically only invoked through woven code in the persistence object introduced when FetchGroupTracker is woven into the entity.
public FetchGroupTracker getRootEntity()
public void setRootEntity(FetchGroupTracker rootEntity)
rootEntity - the rootEntity to setpublic void setShouldLoad(boolean shouldLoad)
LoadGroup when set to true and load all of the specified relationships so that the entities returned from the query where this group was used have the requested relationships populated. All subsequent attributes added to this group that create a nested group will have this value applied to them.public void setShouldLoadAll(boolean shouldLoad)
LoadGroup the same as setShouldLoad(boolean). Additionally this method will apply the provided boolean value to all nested groups already added.public boolean shouldLoad()
LoadGroupwhen processing the results of a query to force the specified relationships to be loaded.public boolean isFetchGroup()
isFetchGroup in class CoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem>public boolean isEntityFetchGroup()
public LoadGroup toLoadGroupLoadOnly()
public FetchGroup clone()
clone in class AttributeGrouppublic LoadGroup toLoadGroup(java.util.Map<AttributeGroup,LoadGroup> cloneMap, boolean loadOnly)
toLoadGroup in class AttributeGrouppublic org.eclipse.persistence.internal.queries.EntityFetchGroup getEntityFetchGroup(FetchGroupManager fetchGroupManager)
public FetchGroup getGroup(java.lang.String attributeNameOrPath)
getGroup in class AttributeGroup
public void addAttribute(java.lang.String attributeNameOrPath,
CoreAttributeGroup group)
CoreAttributeGroupExample: group.addAttribute("firstName", group1); Note that existing group corresponding to attributeNameOrPath will be overridden with the passed group.
group.addAttribute("manager.address", group2);
addAttribute in class CoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem>group - - an AttributeGroup to be added.
public void addAttribute(java.lang.String attributeNameOrPath,
java.util.Collection<? extends CoreAttributeGroup> groups)
CoreAttributeGroupaddAttribute in class CoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem>
public void addAttributeKey(java.lang.String attributeNameOrPath,
CoreAttributeGroup group)
CoreAttributeGroupExample: group.addAttribute("firstName", group1); Note that existing group corresponding to attributeNameOrPath will be overridden with the passed group.
group.addAttribute("manager.address", group2);
addAttributeKey in class CoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem>group - - an AttributeGroup to be added.