All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.metadata.FetchGroupMetaData Maven / Gradle / Ivy

/**********************************************************************
Copyright (c) 2004 Erik Bengtson 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:
2004 Andy Jefferson - changed to extend MetaData
2004 Andy Jefferson - added toString()
    ...
**********************************************************************/
package org.datanucleus.metadata;

import java.util.ArrayList;
import java.util.List;

import org.datanucleus.ClassLoaderResolver;
import org.datanucleus.util.StringUtils;

/**
 * A fetch group defines a particular loaded state for an object graph. 
 * It specifies fields/properties to be loaded for all of the instances in the graph when
 * this fetch group is active.
 */
public class FetchGroupMetaData extends MetaData
{
    /**
     * The post-load attribute on the fetch-group element indicates whether the
     * jdoPost-Load callback will be made when the fetch group is loaded. It
     * defaults to false, for all fetch groups except the default fetch group,
     * on which it defaults to true.
     */
    Boolean postLoad;

    /**
     * The name attribute on a field element contained within a fetch-group
     * element is the name of field in the enclosing class or a dot-separated
     * expression identifying a field reachable from the class by navigating a
     * reference, collection or map. For maps of persistencecapable classes
     * "#key" or "#value" may be appended to the name of the map field to
     * navigate the key or value respectively (e.g. to include a field of the
     * key class or value class in the fetch group).
     * 
     * For collection and arrays of persistence-capable classes, "#element" may
     * be appended to the name of the field to navigate the element. This is
     * optional; if omitted for collections and arrays, #element is assumed.
     */
    final String name;

    /**
     * A contained fetch-group element indicates that the named group is to be
     * included in the group being defined. Nested fetch group elements are
     * limited to only the name attribute.
     */
    protected FetchGroupMetaData[] fetchGroupMetaData;

    /** members declared to be in this fetch group. */
    protected AbstractMemberMetaData[] memberMetaData;
    
    // -------------------------------------------------------------------------
    // Fields below here are used in the parsing process, up to the call to
    // initialise(). Thereafter they are typically cleared out and shouldn't be used.

    /**
     * A contained fetch-group element indicates that the named group is to be
     * included in the group being defined. Nested fetch group elements are
     * limited to only the name attribute.
     */
    protected List fetchGroups = new ArrayList();    

    /** members (fields/properties) declared to be in this fetch group. */
    protected List members = new ArrayList();    

    /**
     * Constructor for a named fetch group. Set fields using setters, before populate().
     * @param name Name of fetch group
     */
    public FetchGroupMetaData(String name)
    {
        this.name = name;
    }

    /**
     * Initialisation method. This should be called AFTER using the populate
     * method if you are going to use populate. It creates the internal
     * convenience arrays etc needed for normal operation.
     */
    public void initialise(ClassLoaderResolver clr, MetaDataManager mmgr)
    {
        if (this.postLoad == null)
        {
            this.postLoad = Boolean.FALSE;
        }

        if (members.isEmpty())
        {
            memberMetaData = new AbstractMemberMetaData[0];
        }
        else
        {
            memberMetaData = new AbstractMemberMetaData[members.size()];
            for (int i=0; i\n");
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy