Top Description Fields Constructors Methods
org.eclipse.persistence.queries

public Class FetchGroup

extends AttributeGroup
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.queries.EntityFetchGroup
Imports
java.util.Collection, .HashMap, .Iterator, .Map, org.eclipse.persistence.core.queries.CoreAttributeGroup, org.eclipse.persistence.descriptors.FetchGroupManager, org.eclipse.persistence.internal.localization.ExceptionLocalization, org.eclipse.persistence.internal.queries.AttributeItem, .EntityFetchGroup, org.eclipse.persistence.sessions.Session, .UnitOfWork

A FetchGroup is a performance enhancement that allows a group of attributes of an object to be loaded on demand, which means that the data for an attribute might not loaded from the underlying data source until an explicit access call for the attribute first occurs. It avoids loading all data of the object's attributes, in which the user is interested in only a subset of them. A great deal of caution and careful system use case analysis should be use when using the fetch group feature, as the extra round-trip would well offset the gain from the deferred loading in many cases.

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:

When a query is executed only one FetchGroup will be used. The order of precedence is:

  1. If a FetchGroup is specified on a query it will be used.
  2. If no FetchGroup is specified but a FetchGroup name is specified and the FetchGroupManager has a group by this name it will be used.
  3. If neither a FetchGroup nor a FetchGroup name is specified on the query an the FetchGroupManager has a default group then it will be used.
  4. If none of these conditions are met then no FetchGroup will be used when executing a query.

Note

This includes the execution of queries to populate lazy and eager relationships.

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 is configured the FetchGroup will also function as a LoadGroup causing all of its specified relationships to be populated prior to returning the results from the query execution.

Author
King Wang, dclarke, ailitchev
Since
TopLink 10.1.3
See Also
FetchGroupManager, QueryHints.FETCH_GROUP, LoadGroup

Field Summary

Modifier and TypeField and Description
protected EntityFetchGroup
entityFetchGroup

Caches the EntityFetch group for this FetchGroup

protected FetchGroupTracker
rootEntity

Stores a reference to the root entity for an Aggregate Object relationship.

private boolean
shouldLoad

Indicates whether this group should be also used as a LoadGroup when processing the query result.

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
addAttribute(String
A simple attribute, array or attributes forming a path
attributeNameOrPath
,
CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>
- an AttributeGroup to be added.
group
)

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute.

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.
public void
addAttribute(String
A simple attribute, array or attributes forming a path
attributeNameOrPath
,
Collection<? extends CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>>
- a collection of AttributeGroups to be added.
groups
)

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute.

Add an attribute and the corresponding list of AttributeGroups.
public void
addAttributeKey(String
A simple attribute, array or attributes forming a path to a Map key
attributeNameOrPath
,
CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>
- an AttributeGroup to be added.
group
)

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttributeKey.

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.
public FetchGroup
clone()

Overrides org.eclipse.persistence.queries.AttributeGroup.clone.

Creates and returns a copy of this object.
public EntityFetchGroup

Returns:

the entityFetchGroup
getEntityFetchGroup
(FetchGroupManager fetchGroupManager)

INTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroup

public FetchGroup
getGroup(String attributeNameOrPath)

Overrides org.eclipse.persistence.queries.AttributeGroup.getGroup.

Returns FetchGroup corresponding to the passed (possibly nested) attribute.
public FetchGroupTracker

Returns:

the rootEntity
getRootEntity
()

INTERNAL:

public boolean
public boolean
protected FetchGroup
newGroup(String name, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> parent)

Overrides org.eclipse.persistence.queries.AttributeGroup.newGroup.

Subclass may create different types.
public String
onUnfetchedAttribute(FetchGroupTracker entity, String attributeName)

INTERNAL: Called on attempt to get value of an attribute that hasn't been fetched yet.

public String
onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName)

INTERNAL: Called on attempt to assign value to an attribute that hasn't been fetched yet.

public void
setRootEntity(FetchGroupTracker
the rootEntity to set
rootEntity
)

INTERNAL:

public 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.

public void
setShouldLoadAll(boolean shouldLoad)

Configure this group to also act as a LoadGroup the same as setShouldLoad(boolean).

protected void
setSubclassShouldLoad(boolean shouldLoad)

passes should load to subclasses.

public boolean

Returns:

true if this group will be used as a LoadGroupwhen processing the results of a query to force the specified relationships to be loaded.
shouldLoad
()

public LoadGroup
public LoadGroup
Inherited from org.eclipse.persistence.queries.AttributeGroup:
addAttributefindGroupgetItemisConcurrentisCopyGroupisLoadGroupisSupersetOfnewItemnewItemtoCopyGrouptoCopyGrouptoFetchGrouptoFetchGrouptoLoadGroup

Field Detail

entityFetchGroupback to summary
protected EntityFetchGroup entityFetchGroup

Caches the EntityFetch group for this FetchGroup

rootEntityback to summary
protected FetchGroupTracker rootEntity

Stores a reference to the root entity for an Aggregate Object relationship. This ensures that partially loaded aggregates can be triggered.

shouldLoadback to summary
private boolean shouldLoad

Indicates whether this group should be also used as a LoadGroup when processing the query result.

Constructor Detail

FetchGroupback to summary
public FetchGroup()
FetchGroupback to summary
public FetchGroup(String name)

Method Detail

addAttributeback to summary
public void addAttribute(String attributeNameOrPath, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> group)

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute.

Doc from org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute.

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.

Example: group.addAttribute("firstName", group1);
group.addAttribute("manager.address", group2);
Note that existing group corresponding to attributeNameOrPath will be overridden with the passed group.

Parameters
attributeNameOrPath:String

A simple attribute, array or attributes forming a path

group:CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>

- an AttributeGroup to be added.

Annotations
@Override
addAttributeback to summary
public void addAttribute(String attributeNameOrPath, Collection<? extends CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>> groups)

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute.

Doc from org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttribute.

Add an attribute and the corresponding list of AttributeGroups. Multiple groups are added in the case of inheritance

Parameters
attributeNameOrPath:String

A simple attribute, array or attributes forming a path

groups:Collection<? extends CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>>

- a collection of AttributeGroups to be added.

Annotations
@Override
addAttributeKeyback to summary
public void addAttributeKey(String attributeNameOrPath, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> group)

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttributeKey.

Doc from org.eclipse.persistence.core.queries.CoreAttributeGroup.addAttributeKey.

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.

Example: group.addAttribute("firstName", group1);
group.addAttribute("manager.address", group2);
Note that existing group corresponding to attributeNameOrPath will be overridden with the passed group.

Parameters
attributeNameOrPath:String

A simple attribute, array or attributes forming a path to a Map key

group:CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>

- an AttributeGroup to be added.

Annotations
@Override
cloneback to summary
public FetchGroup clone()

Overrides org.eclipse.persistence.queries.AttributeGroup.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:FetchGroup

a clone of this instance.

Annotations
@Override
getEntityFetchGroupback to summary
public EntityFetchGroup getEntityFetchGroup(FetchGroupManager fetchGroupManager)

INTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroup

Returns:EntityFetchGroup

the entityFetchGroup

getGroupback to summary
public FetchGroup getGroup(String attributeNameOrPath)

Overrides org.eclipse.persistence.queries.AttributeGroup.getGroup.

Returns FetchGroup corresponding to the passed (possibly nested) attribute.

Annotations
@Override
getRootEntityback to summary
public FetchGroupTracker getRootEntity()

INTERNAL:

Returns:FetchGroupTracker

the rootEntity

isEntityFetchGroupback to summary
public boolean isEntityFetchGroup()
isFetchGroupback to summary
public boolean isFetchGroup()

Overrides org.eclipse.persistence.core.queries.CoreAttributeGroup.isFetchGroup.

Annotations
@Override
newGroupback to summary
protected FetchGroup newGroup(String name, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> parent)

Overrides org.eclipse.persistence.queries.AttributeGroup.newGroup.

Doc from org.eclipse.persistence.queries.AttributeGroup.newGroup.

Subclass may create different types.

Annotations
@Override
onUnfetchedAttributeback to summary
public String onUnfetchedAttribute(FetchGroupTracker entity, String attributeName)

INTERNAL: Called on attempt to get value of an attribute that hasn't been fetched yet. Returns an error message in case jakarta.persistence.EntityNotFoundException should be thrown by the calling method, null otherwise.

This method is typically only invoked through woven code in the persistence object introduced when FetchGroupTracker is woven into the entity.

onUnfetchedAttributeForSetback to summary
public String onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName)

INTERNAL: Called on attempt to assign value to an attribute that hasn't been fetched yet. Returns an error message in case jakarta.persistence.EntityNotFoundException should be thrown by the calling method, null otherwise.

This method is typically only invoked through woven code in the persistence object introduced when FetchGroupTracker is woven into the entity.

setRootEntityback to summary
public void setRootEntity(FetchGroupTracker rootEntity)

INTERNAL:

Parameters
rootEntity:FetchGroupTracker

the rootEntity to set

setShouldLoadback to summary
public 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. All subsequent attributes added to this group that create a nested group will have this value applied to them.

See Also
to configure #shouldLoad() on nested groups
setShouldLoadAllback to summary
public void setShouldLoadAll(boolean shouldLoad)

Configure this group to also act as a LoadGroup the same as setShouldLoad(boolean). Additionally this method will apply the provided boolean value to all nested groups already added.

See Also
to only configure this grup without effecting existing nested groups.
setSubclassShouldLoadback to summary
protected void setSubclassShouldLoad(boolean shouldLoad)

passes should load to subclasses.

See Also
to configure #shouldLoad() on nested groups
shouldLoadback to summary
public boolean shouldLoad()
Returns:boolean

true if this group will be used as a LoadGroupwhen processing the results of a query to force the specified relationships to be loaded.

toLoadGroupback to summary
public LoadGroup toLoadGroup(Map<AttributeGroup, LoadGroup> cloneMap, boolean loadOnly)

Overrides org.eclipse.persistence.queries.AttributeGroup.toLoadGroup.

Annotations
@Override
toLoadGroupLoadOnlyback to summary
public LoadGroup toLoadGroupLoadOnly()