org.datanucleus.FetchPlan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datanucleus-core Show documentation
Show all versions of datanucleus-core Show documentation
DataNucleus Core provides the primary components of a heterogenous Java persistence solution.
It supports persistence API's being layered on top of the core functionality.
/**********************************************************************
Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
...
**********************************************************************/
package org.datanucleus;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.datanucleus.exceptions.NucleusUserException;
import org.datanucleus.metadata.AbstractClassMetaData;
import org.datanucleus.util.ConcurrentReferenceHashMap;
import org.datanucleus.util.Localiser;
import org.datanucleus.util.StringUtils;
import org.datanucleus.util.ConcurrentReferenceHashMap.ReferenceType;
/**
* 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.
*
*/
public class FetchPlan implements Serializable
{
private static final long serialVersionUID = 6031608568703439025L;
/** Constant defining the fields in the default fetch group. */
public static final String DEFAULT = "default";
/** Constant defining all fields */
public static final String ALL = "all";
/** Constant defing no fields. */
public static final String NONE = "none";
/** Members that are loaded but not in current fetch plan should be unloaded before detachment. */
public static final int DETACH_UNLOAD_FIELDS = 2;
/** Members that are not loaded but are in the current fetch plan should be loaded before detachment. */
public static final int DETACH_LOAD_FIELDS = 1;
/** Fetch size to load all possible. */
public static final int FETCH_SIZE_GREEDY = -1;
/** Fetch size for the implementation to decide how many to load. */
public static final int FETCH_SIZE_OPTIMAL = 0;
public static final int RECURSION_DEPTH_UNLIMITED = -1;
public static final int RECURSION_DEPTH_FK_ONLY = 0;
/** Execution Context that this FetchPlan relates to. */
transient final ExecutionContext ec; // Defined as transient to avoid Serializable problems
/** ClassLoader resolver. */
transient final ClassLoaderResolver clr; // Defined as transient to avoid Serializable problems
/** Names of the "defined" fetch groups in the current FetchPlan. */
final Set groupNames = new HashSet<>();
/** The "dynamic" fetch groups in the current FetchPlan. */
transient Set dynamicGroups = null; // Defined as transient to avoid Serializable problems
/** The Fetch size. For use when using large result sets. */
int fetchSize = FETCH_SIZE_OPTIMAL;
/** Options to be used during detachment. Spec 12.7 says that the default is DETACH_LOAD_FIELDS. */
int detachmentOptions = FetchPlan.DETACH_LOAD_FIELDS;
/** FetchPlanForClass keyed by the class name. **/
final transient Map fetchPlansByClassName = new HashMap<>();
/** Maximum depth to fetch from the root object. */
int maxFetchDepth = 1;
/** The classes used as the roots for detachment (DetachAllOnCommit). */
Class[] detachmentRootClasses = null;
/** The instances used as the roots for detachment (DetachAllOnCommit). */
Collection