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

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

Go to download

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.

There is a newer version: 6.0.7
Show newest version
/**********************************************************************
Copyright (c) 2004 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.metadata;

import org.datanucleus.util.StringUtils;

/**
 * Representation of the Meta-Data for a field of a class.
 *
 * 

Lifecycle state

* An object of this type has 2 lifecycle states. The first is the raw * constructed object which represents pure MetaData (maybe from a MetaData * file). The second is a "populated" object which represents MetaData for a * Field of a class with the metadata aligned to be appropriate for that Field. * *

Containers

* Each field can represent a container. The container can be an array, a * Collection or a Map. The field type must be of the correct type to represent * these. * *

Field Management

* Each field can be managed by us or not. The class provides a method for * identifying if a field is managed by us (isJdoField()). If a field * is managed by us, it will have a field "id" (within its class). In a class * the field "id" will start at 0 (for the first field, in alphabetical order). */ public class FieldMetaData extends AbstractMemberMetaData { private static final long serialVersionUID = 2280126411219542L; /** * Convenience constructor to copy the specification from the passed field. * This is used when we have an overriding field and we make a copy of the baseline * field as a starting point. * @param parent The parent * @param fmd The field to copy */ public FieldMetaData(MetaData parent, AbstractMemberMetaData fmd) { super(parent, fmd); } /** * Constructor. Saves the MetaData with the specified values. The object is * then in an "unpopulated" state. It can become "populated" by calling the * populate() method which compares it against the field it is to * represent and updates any unset attributes and flags up any errors. * @param parent parent MetaData instance * @param name field name */ public FieldMetaData(MetaData parent, final String name) { super(parent, name); } /** * Returns a string representation of the object using a prefix * This can be used as part of a facility to output a MetaData file. * @param prefix prefix string * @param indent indent string * @return a string representation of the object. */ public String toString(String prefix,String indent) { // If this field is static or final, don't bother with MetaData since we will ignore it anyway. if (isStatic() || isFinal()) { return ""; } // Field needs outputting so generate metadata StringBuilder sb = new StringBuilder(); sb.append(prefix).append("\n"); // Add field containers if (containerMetaData != null) { if (containerMetaData instanceof CollectionMetaData) { CollectionMetaData c = (CollectionMetaData)containerMetaData; sb.append(c.toString(prefix + indent,indent)); } else if (containerMetaData instanceof ArrayMetaData) { ArrayMetaData c = (ArrayMetaData)containerMetaData; sb.append(c.toString(prefix + indent,indent)); } else if (containerMetaData instanceof MapMetaData) { MapMetaData c = (MapMetaData)containerMetaData; sb.append(c.toString(prefix + indent,indent)); } } // Add columns if (columnMetaData != null) { for (int i=0; i\n"); return sb.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy