What do you think of the following?  More for discussion than a proposal just 
yet.

Section 12.7.6 states "Fetch groups are only defined in the metadata for a 
class or interface."  It might be convenient for users or tools to be able to 
dynamically modify the FetchPlan or define fetch groups, possibly based on a 
runtime analysis of usage.  Another possible use would be to allow aspects to 
be applied to service-level components to dynamically modify the FetchPlan or 
define fetch groups.

Add a new interface FetchGroup:

public interface FetchGroup {
  String getName();
  boolean getPostLoad();
  Map<String,Integer> getFieldRecursionDepths(); // key is field expression, 
value is recursion depth
  Map<String,Integer> getPropertyRecursionDepths();  // key is property 
expression, value is recursion depth
  
  // Add mutators also?  See possible method additions to FetchPlan or 
PersistenceManager interface below
  void setName(String name);
  void setPostLoad(boolean postLoad);
  void add{Field|Property}(Class clazz, String {field|property}Expression[, int 
recursionDepth]);
  void add{Fields|Properties}(Class clazz, Map<String,Integer> 
{field|property}RecursionDepths);
}

Possible method additions to the FetchPlan or PersistenceManager interface:

FetchGroup newFetchGroup(); // creates an empty fetch group if mutating methods 
allowed on FetchGroup
FetchGroup newFetchGroup(Map<String,Integer> fieldRecursionDepths, 
Map<String,Integer> propertyRecursionDepths, String name, boolean postLoad);

// plus various convenience methods based on above

Possible method additions to FetchPlan interface, all of which add anonymous 
fetch groups to the FetchPlan on which they're called:

FetchPlan addField(Class clazz, String fieldExpression); // defaults 
recursionDepth to 1

FetchPlan addField(Class clazz, String fieldExpression, int recursionDepth);


FetchPlan addFields(Class clazz, Map<String,Integer> fieldRecursionDepths);

FetchPlan addProperty(Class clazz, String propertyExpression); // defaults 
recursionDepth to 1


FetchPlan addProperty(Class clazz, String propertyExpression, int 
recursionDepth);


FetchPlan addProperties(Class clazz, Map<String,Integer> 
propertyRecursionDepths);
FetchPlan addFetchGroups(FetchGroup... fetchGroups);


FetchPlan addClasses(Class... classes); // convenience method that
would add all fields/properties of the given class at a recursion depth
of 0 or 1 (TBD)

// include * remove*(..) methods?

Collection<FetchGroup> getFetchGroups();




Reply via email to