Package org.datanucleus
Class FetchPlan
- java.lang.Object
-
- org.datanucleus.FetchPlan
-
- All Implemented Interfaces:
java.io.Serializable
public class FetchPlan extends java.lang.Object implements java.io.Serializable
FetchPlan for fields for use internally. A FetchPlan has a series of FetchPlanForClass objects being the fetch plan for particular classes. Each FetchPlanForClass defines a series of fields of that class that are part of the fetch plan. There are two types of fetch groups under consideration here.- Static fetch groups, defined in MetaData (XML/Annotations).
- Dynamic fetch groups, defined via an API.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALL
Constant defining all fields(package private) ClassLoaderResolver
clr
ClassLoader resolver.static java.lang.String
DEFAULT
Constant defining the fields in the default fetch group.static int
DETACH_LOAD_FIELDS
Members that are not loaded but are in the current fetch plan should be loaded before detachment.static int
DETACH_UNLOAD_FIELDS
Members that are loaded but not in current fetch plan should be unloaded before detachment.(package private) int
detachmentOptions
Options to be used during detachment.(package private) java.lang.Class[]
detachmentRootClasses
The classes used as the roots for detachment (DetachAllOnCommit).(package private) java.util.Collection<java.lang.Object>
detachmentRoots
The instances used as the roots for detachment (DetachAllOnCommit).(package private) java.util.Set<FetchGroup>
dynamicGroups
The "dynamic" fetch groups in the current FetchPlan.(package private) ExecutionContext
ec
Execution Context that this FetchPlan relates to.static int
FETCH_SIZE_GREEDY
Fetch size to load all possible.static int
FETCH_SIZE_OPTIMAL
Fetch size for the implementation to decide how many to load.(package private) java.util.Map<java.lang.String,FetchPlanForClass>
fetchPlansByClassName
FetchPlanForClass keyed by the class name.(package private) int
fetchSize
The Fetch size.(package private) java.util.Set<java.lang.String>
groupNames
Names of the "defined" fetch groups in the current FetchPlan.private java.util.Map<AbstractClassMetaData,java.util.Map<java.util.BitSet,java.lang.Boolean>>
isToCallPostLoadFetchPlanByCmd
Cache the result of FetchPlanImpl.isToCallPostLoadFetchPlan(): for a given set of loaded members of a certain class.(package private) int
maxFetchDepth
Maximum depth to fetch from the root object.static java.lang.String
NONE
Constant defing no fields.static int
RECURSION_DEPTH_FK_ONLY
static int
RECURSION_DEPTH_UNLIMITED
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description FetchPlan(ExecutionContext ec, ClassLoaderResolver clr)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
addDynamicGroup(java.lang.String grpName)
Convenience method to add dynamic fetch groups for the specified name.FetchPlan
addGroup(java.lang.String grpName)
Method to add a group to the fetch plan.(package private) void
cacheIsToCallPostLoadFetchPlan(AbstractClassMetaData cmd, java.util.BitSet loadedFields, java.lang.Boolean itcplfp)
private void
clearDynamicGroups()
Convenience method to clear all dynamic groups.FetchPlan
clearGroups()
Method to clear the current groups and activate the DFG.(package private) java.lang.Boolean
getCachedIsToCallPostLoadFetchPlan(AbstractClassMetaData cmd, java.util.BitSet loadedFields)
FetchPlan
getCopy()
Returns a copy of this FetchPlan with all settings initialized.int
getDetachmentOptions()
Return the options to be used at detachment.java.lang.Class[]
getDetachmentRootClasses()
Accessor for the root classes of the detachment graph for DetachAllOnCommit.java.util.Collection<java.lang.Object>
getDetachmentRoots()
Accessor for the roots of the detachment graph for DetachAllOnCommit.FetchPlanForClass
getFetchPlanForClass(AbstractClassMetaData cmd)
Access the fetch plan for the class.int
getFetchSize()
Accessor for the fetch size when using large result sets.java.util.Set<java.lang.String>
getGroups()
Accessor for the static groups for this FetchPlan.int
getMaxFetchDepth()
Accessor for the maximum fetch depth.(package private) void
invalidateCachedIsToCallPostLoadFetchPlan(AbstractClassMetaData cmd)
private void
markDirty()
Mark all managed fetch plans to be dirty, so the active members need to be recomputed.void
notifyFetchGroupChange(FetchGroup group)
Method to notify this FetchPlan that the specified FetchGroup has been updated.void
notifyFetchGroupRemove(FetchGroup group)
Method to notify this FetchPlan that the specified FetchGroup has been updated.FetchPlan
removeGroup(java.lang.String grpName)
Method to remove a group from the fetch plan.(package private) void
resetDetachmentRoots()
Method called at commit() to clear out the detachment roots.FetchPlan
setDetachmentOptions(int options)
Set the options to be used at detachment.FetchPlan
setDetachmentRootClasses(java.lang.Class[] rootClasses)
Set the classes used for roots of the detachment graph for DetachAllOnCommit.FetchPlan
setDetachmentRoots(java.util.Collection<java.lang.Object> roots)
Set the roots for DetachAllOnCommitFetchPlan
setFetchSize(int fetchSize)
Method to set the fetch size when using large result sets.FetchPlan
setGroup(java.lang.String grpName)
Method to set the fetch group.FetchPlan
setGroups(java.lang.String[] grpNames)
Method to set the groups using an array.FetchPlan
setGroups(java.util.Collection<java.lang.String> grpNames)
Method to set the groups of the fetch plan.FetchPlan
setMaxFetchDepth(int max)
Mutator for the maximum fetch depth where -1 implies no restriction on the fetch depth.java.lang.String
toString()
java.lang.String
toStringWithClasses()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
DEFAULT
public static final java.lang.String DEFAULT
Constant defining the fields in the default fetch group.- See Also:
- Constant Field Values
-
ALL
public static final java.lang.String ALL
Constant defining all fields- See Also:
- Constant Field Values
-
NONE
public static final java.lang.String NONE
Constant defing no fields.- See Also:
- Constant Field Values
-
DETACH_UNLOAD_FIELDS
public static final int DETACH_UNLOAD_FIELDS
Members that are loaded but not in current fetch plan should be unloaded before detachment.- See Also:
- Constant Field Values
-
DETACH_LOAD_FIELDS
public static final int DETACH_LOAD_FIELDS
Members that are not loaded but are in the current fetch plan should be loaded before detachment.- See Also:
- Constant Field Values
-
FETCH_SIZE_GREEDY
public static final int FETCH_SIZE_GREEDY
Fetch size to load all possible.- See Also:
- Constant Field Values
-
FETCH_SIZE_OPTIMAL
public static final int FETCH_SIZE_OPTIMAL
Fetch size for the implementation to decide how many to load.- See Also:
- Constant Field Values
-
RECURSION_DEPTH_UNLIMITED
public static final int RECURSION_DEPTH_UNLIMITED
- See Also:
- Constant Field Values
-
RECURSION_DEPTH_FK_ONLY
public static final int RECURSION_DEPTH_FK_ONLY
- See Also:
- Constant Field Values
-
ec
final transient ExecutionContext ec
Execution Context that this FetchPlan relates to.
-
clr
final transient ClassLoaderResolver clr
ClassLoader resolver.
-
groupNames
final java.util.Set<java.lang.String> groupNames
Names of the "defined" fetch groups in the current FetchPlan.
-
dynamicGroups
transient java.util.Set<FetchGroup> dynamicGroups
The "dynamic" fetch groups in the current FetchPlan.
-
fetchSize
int fetchSize
The Fetch size. For use when using large result sets.
-
detachmentOptions
int detachmentOptions
Options to be used during detachment. Spec 12.7 says that the default is DETACH_LOAD_FIELDS.
-
fetchPlansByClassName
final transient java.util.Map<java.lang.String,FetchPlanForClass> fetchPlansByClassName
FetchPlanForClass keyed by the class name.
-
maxFetchDepth
int maxFetchDepth
Maximum depth to fetch from the root object.
-
detachmentRootClasses
java.lang.Class[] detachmentRootClasses
The classes used as the roots for detachment (DetachAllOnCommit).
-
detachmentRoots
java.util.Collection<java.lang.Object> detachmentRoots
The instances used as the roots for detachment (DetachAllOnCommit).
-
isToCallPostLoadFetchPlanByCmd
private transient java.util.Map<AbstractClassMetaData,java.util.Map<java.util.BitSet,java.lang.Boolean>> isToCallPostLoadFetchPlanByCmd
Cache the result of FetchPlanImpl.isToCallPostLoadFetchPlan(): for a given set of loaded members of a certain class. Must be invalidated with any change of fields to load, e.g. adding a fetchgroup.
-
-
Constructor Detail
-
FetchPlan
public FetchPlan(ExecutionContext ec, ClassLoaderResolver clr)
Constructor. Initially has the default fetch group.- Parameters:
ec
- execution contextclr
- ClassLoader Resolver
-
-
Method Detail
-
markDirty
private void markDirty()
Mark all managed fetch plans to be dirty, so the active members need to be recomputed.
-
getFetchPlanForClass
public FetchPlanForClass getFetchPlanForClass(AbstractClassMetaData cmd)
Access the fetch plan for the class.- Parameters:
cmd
- metadata for the class- Returns:
- the FetchPlanForClass
-
addGroup
public FetchPlan addGroup(java.lang.String grpName)
Method to add a group to the fetch plan.- Parameters:
grpName
- The fetch group to add- Returns:
- Updated Fetch Plan
-
removeGroup
public FetchPlan removeGroup(java.lang.String grpName)
Method to remove a group from the fetch plan.- Parameters:
grpName
- The fetch group to remove- Returns:
- Updated Fetch Plan
-
clearGroups
public FetchPlan clearGroups()
Method to clear the current groups and activate the DFG.- Returns:
- The FetchPlan
-
getGroups
public java.util.Set<java.lang.String> getGroups()
Accessor for the static groups for this FetchPlan. Doesn't return the dynamic groups.- Returns:
- The fetch plan groups (unmodifiable)
-
setGroups
public FetchPlan setGroups(java.util.Collection<java.lang.String> grpNames)
Method to set the groups of the fetch plan.- Parameters:
grpNames
- Names of the groups- Returns:
- Updated Fetch Plan
-
setGroups
public FetchPlan setGroups(java.lang.String[] grpNames)
Method to set the groups using an array.- Parameters:
grpNames
- Names of the groups- Returns:
- The Fetch Plan
-
setGroup
public FetchPlan setGroup(java.lang.String grpName)
Method to set the fetch group.- Parameters:
grpName
- Name of the group- Returns:
- The Fetch Plan
-
clearDynamicGroups
private void clearDynamicGroups()
Convenience method to clear all dynamic groups.
-
addDynamicGroup
private boolean addDynamicGroup(java.lang.String grpName)
Convenience method to add dynamic fetch groups for the specified name.- Parameters:
grpName
- Name of group- Returns:
- Whether the groups were changed
-
notifyFetchGroupChange
public void notifyFetchGroupChange(FetchGroup group)
Method to notify this FetchPlan that the specified FetchGroup has been updated. dynamic fetch groups extension- Parameters:
group
- The dynamic FetchGroup
-
notifyFetchGroupRemove
public void notifyFetchGroupRemove(FetchGroup group)
Method to notify this FetchPlan that the specified FetchGroup has been updated. dynamic fetch groups extension- Parameters:
group
- The dynamic FetchGroup
-
setDetachmentRoots
public FetchPlan setDetachmentRoots(java.util.Collection<java.lang.Object> roots)
Set the roots for DetachAllOnCommit- Parameters:
roots
- The roots of the detachment graph.- Returns:
- The fetch plan with these roots
-
getDetachmentRoots
public java.util.Collection<java.lang.Object> getDetachmentRoots()
Accessor for the roots of the detachment graph for DetachAllOnCommit.- Returns:
- The roots of the detachment graph.
-
setDetachmentRootClasses
public FetchPlan setDetachmentRootClasses(java.lang.Class[] rootClasses)
Set the classes used for roots of the detachment graph for DetachAllOnCommit.- Parameters:
rootClasses
- Classes to be used as roots of the detachment graph- Returns:
- The fetch plan with these roots
-
getDetachmentRootClasses
public java.lang.Class[] getDetachmentRootClasses()
Accessor for the root classes of the detachment graph for DetachAllOnCommit.- Returns:
- The classes to be used as the root of the detachment graph.
-
resetDetachmentRoots
void resetDetachmentRoots()
Method called at commit() to clear out the detachment roots.
-
setMaxFetchDepth
public FetchPlan setMaxFetchDepth(int max)
Mutator for the maximum fetch depth where -1 implies no restriction on the fetch depth. Throws NucleusUserException when an illegal value (either 0 or ≤ -2)- Parameters:
max
- The maximum fetch depth to fetch to- Returns:
- The FetchPlan
-
getMaxFetchDepth
public int getMaxFetchDepth()
Accessor for the maximum fetch depth.- Returns:
- The maximum fetch depth
-
setFetchSize
public FetchPlan setFetchSize(int fetchSize)
Method to set the fetch size when using large result sets.- Parameters:
fetchSize
- the size- Returns:
- Updated Fetch Plan
-
getFetchSize
public int getFetchSize()
Accessor for the fetch size when using large result sets.- Returns:
- The size
-
getDetachmentOptions
public int getDetachmentOptions()
Return the options to be used at detachment.- Returns:
- Detachment options
-
setDetachmentOptions
public FetchPlan setDetachmentOptions(int options)
Set the options to be used at detachment.- Parameters:
options
- The options- Returns:
- The updated fetch plan.
-
getCopy
public FetchPlan getCopy()
Returns a copy of this FetchPlan with all settings initialized. Used when a Query has to have its own FetchPlan, so takes a copy of that of the ExecutionContext.- Returns:
- the FetchPlan copy
-
getCachedIsToCallPostLoadFetchPlan
java.lang.Boolean getCachedIsToCallPostLoadFetchPlan(AbstractClassMetaData cmd, java.util.BitSet loadedFields)
-
cacheIsToCallPostLoadFetchPlan
void cacheIsToCallPostLoadFetchPlan(AbstractClassMetaData cmd, java.util.BitSet loadedFields, java.lang.Boolean itcplfp)
-
invalidateCachedIsToCallPostLoadFetchPlan
void invalidateCachedIsToCallPostLoadFetchPlan(AbstractClassMetaData cmd)
-
toStringWithClasses
public java.lang.String toStringWithClasses()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-